One generator to generated them all

Generated and validate that all checked-in generated code is up to date with the corresponding source DSL. Inspired by treefmt.

Repo

Implementation notes

Config

A treegen.toml file with a simple map of generator names to directory where to run, command to run and output directory.

The output should support checking not only directories but also glob patterns as well.

[open-api-client]
command = "../scripts/gen-open-api-client.sh"
output = "src/api-lib/"
directory = "ui"
 
[open-api-lib]
command = "./scripts/gen-open-api-lib.sh"
output = "api-lib/"
# directory defaults to "."
 
[forms]
command = "yarn form-gen"
output = "src/components/**/*.form.ts*"
directory = "ui"

Semantics

  • Runs each of the generators and makes sure no git changes are found as a result
  • Any resulting git changes should be reported together with the diff (optional)
  • There should be no git pending changes before running the command
  • Should work when run from any sub directory as long as a parent directory containing a treegen.toml is found
  • Should support both checking and generating the code
  • Running on generator mode should commit and report the changes