Index Generator
Automatically generate index / barrel files with all the exports needed for your library.
Stable release
There will be no more breaking changes
Usage
-
Activate: dart/flutter pub global activate index_generator
-
Create index_generator.yaml file or add in your pubspec.yaml file:
index_generator:
exclude:
- "**.g.dart"
libraries:
- directory_path: lib
- You can generate index files with:
<dart|flutter> pub global run index_generator
Advance Usage
See more examples
index_generator:
default_file_name: barrel
exclude:
- "**.g.dart"
- "{_,**/_}*.dart"
libraries:
- directory_path: lib
include:
- "src/**"
exports:
- package: package:args/args.dart
show:
- ArgResults
hide:
- ArgParser
- directory_path: generator
file_name: main
disclaimer: false
include_library: true
comments: |
Copyright (c) 2020 BreX900
docs: |
Automatically generate index / barrel / library files
with all the export needed for your library.
name: index_generator
use_package_exports: true
output_path: lib/generated
- directory_path: Path in which to create the index file. All filters will get the relative path from this directory
- output_path: Custom output path for the generated index file. If not specified, the file will be created in the directory_path
- file_name: Prioritize ownership in folders, otherwise it will use the one defined in the generator with
default_file_name key.
If it is missing, if the folder is lib it will use the package name otherwise the folder name
- name: The name of the library used in the index dart file by the
library keyword
- include_library: Include or exclude the
library keyword in the generated file. Defaults to true
- docs: Documentation comments added above the library declaration. Only included when
include_library is true
- include | exclude: You can define filters that exclude or include files to be included in the index. The filters are passed paths relative to the
index file. You can use Glob expressions.
- exports: You can define specific export dart packages in index file.
You can use
package to export a dart file package or dart core library.
- use_package_exports: When enabled, generates package-style exports for internal files (e.g.,
'package:app/main.dart' instead of 'main.dart').
This is useful for libraries that want to ensure consistent import paths. Defaults to false.
Command
--help command output:
-s, --settings=<Define a yaml file path.> If not present use the "index_generator.yaml" file if it exists otherwise use the "pubspec.yaml" file.
-v, --[no-]verbose Print verbose logs
-h, --help
Build runner
index_generator can be run via build_runner. To do so, add the following dependancies:
dev_dependencies:
build_runner: ^2.10.0
index_generator: ^4.1.0
and enable it in build.yaml file
targets:
$default:
builders:
index_generator:
enabled: true
To generate use <dart|flutter> pub run build_runner <build|watch>
Features and bugs
Please file feature requests and bugs at the issue tracker.
Extra
- mek_assets: Automatically generate dart classes / flutter pubspec entries for your assets files.
- mek_data_class: Generate
hashCode, ==, toString, copyWith and change methods with low code.