talira

source_gen

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.

  1. code_builder A fluent, builder-based library for generating valid Dart code
  2. source_helper Utilities for generating Dart source code
  3. json_serializable Generate JSON to and from code for annotated Dart classes
  4. build_version Put your Dart package's version into your source code
  5. copy_with_extension Generates type-safe copyWith extensions for Dart classes

Compare source_gen with the top 3