A framework for writing Dart code generators
open sourceBSD-3-Clausefree
source_gen is the Dart team's framework for writing Builders that read and produce Dart code, and the convention that lets hand-written and generated code, and several generators, live side by side in one project. You extend Generator or GeneratorForAnnotation, and source_gen calls it for a library or for each element tagged with your annotation. It wraps generators as a SharedPartBuilder (shared .g.dart part files, merged by its combining_builder), a PartBuilder or a LibraryBuilder, giving a friendlier API on top of the analyzer and build packages, and runs through build_runner configured in build.yaml.
Problems it solves
- write a code generator for my Dart package
- generate Dart code from annotations in my source files
- let several code generators share one generated part file in a Dart project
Features
- Generator and GeneratorForAnnotation base classes
- SharedPartBuilder, PartBuilder and LibraryBuilder for where generated code goes
- combining_builder that merges several generators' output into one .g.dart file
- configurable header and ignore_for_file lints for generated files
Alternatives
The same job
These do what source_gen does.
- code_builder A fluent, builder-based library for generating valid Dart code
- source_helper Utilities for generating Dart source code
- json_serializable Generate JSON to and from code for annotated Dart classes
- build_version Put your Dart package's version into your source code
- copy_with_extension Generates type-safe copyWith extensions for Dart classes
