Command-line interface for generating and maintaining Dart barrel files.
The recommended usage is through bunx
or the equivalent from your package of
choice:
bunx @dbfg/cli@latest [options] <directory>
Globally install it with:
bun install -g @dbfg/cli
You will now have the dbfg-cli
executable available.
dbfg-cli
creates barrel files for your Dart projects, making it easier to manage exports.
The CLI supports three generation modes:
- Regular mode (default): Generates a barrel file for only the specified directory
dbfg-cli <directory>
- Recursive mode: Generates barrel files for the target directory and all nested subdirectories
dbfg-cli --recursive <directory>
- Subfolders mode: Generates a single barrel file that includes exports from all files of subdirectories
dbfg-cli --subfolders <directory>
-V, --version output the version number
-s, --subfolders Include subfolders in the barrel file
-r, --recursive Generate barrel files recursively for all nested directories
-c, --config <string> Path to configuration file
-n, --default-barrel-name <name> Default name for barrel files (default: "")
--excluded-dirs <dirs...> Comma-separated list of directories to exclude (default: [])
--excluded-files <files...> Comma-separated list of files to exclude (default: [])
--exclude-freezed Exclude freezed files (default: false)
--exclude-generated Exclude generated files (default: false)
--skip-empty Skip directories with no files (default: false)
--append-folder-name Append folder name to barrel file name (default: false)
--prepend-folder-name Prepend folder name to barrel file name (default: false)
--prepend-package Prepend package name to exports in lib folder (default: false)
-h, --help display help for command
Generate a barrel file for the lib
directory:
dbfg ./lib
Generate barrel files recursively for the src
directory and all its
subdirectories:
dbfg --recursive ./src
Generate a barrel file for lib
with a custom name:
dbfg ./lib -n index
Exclude generated files:
dbfg ./src --exclude-freezed --exclude-generated
Exclude specific files using patterns:
dbfg ./src --excluded-files "*_one.dart" "*_test.dart"
You can use a JSON configuration file to define default options:
{
"defaultBarrelName": "index",
"excludeFreezed": true,
"excludeGenerated": true,
"excludeFileList": ["*_test.dart"],
"excludeDirList": ["test"],
"prependPackageToLibExport": true
}
Then simply pass the --config
option:
dbfg ./src --config ./dbfg.json