Generate and watch
Generate once, regenerate while you edit, start your app after the first generation, and check generated files in CI.
Generate
npx golem generategenerate writes the generated files that your editor and your bundler need. It skips a job whose inputs did not change since its last run, when the outputs of that job exist. It does not rewrite your calls (Build tools). golem build generates first, so a build needs no separate generate (build). Configure golem.yaml first.
Files golem owns
generate and check follow these rules:
- Golem replaces the file when it generated that file before.
- Golem also replaces a file that carries the marker of the generator, even if Golem never recorded it.
- Any other file stops
generateandcheckwith an error that names the file. Remove or rename that file, or change the output path of the job. - When no job produces a generated file any more,
generatedeletes it. Golem deletes the file only if it still holds its generated content or its marker. Otherwisegeneratestops and names the file. Move the file or delete it yourself. - A file with a marker can sit in an output folder at a path that no job produces, and Golem never recorded it.
generateleaves that file alone.checkreports it and fails.
Two more rules protect your work:
- Put custom behavior in your classes or application code. Do not edit generated files in
.golem/models/. - Ignore the
.golem/folder.
Watch
npx golem watchwatch generates once. It then reruns when one of these changes:
golem.yaml- the tsconfig and its
extendsfiles - a model or controller source, also a new one
- a file that a source imports
- an OpenAPI document or a manifest
It regenerates everything that depends on the change. A model-only edit does not rerun an unchanged SDK job. The models job reads the whole project, so an edit to any project source runs it again. The watcher does not poll remote references.
Type errors have these effects:
- A type error in a model source stops the write.
- A type error in another file is for
tscandgolem buildto report.
A failed run prints its error, and the watcher keeps running.
Start an app after generation
Use exec when the app must not start before its generated files exist:
npx golem exec --watch -- npm run devThe CLI generates first, then starts the child command and watches until the child exits. If generation fails, the child does not start. Without --watch, exec generates once and forwards the exit status of the child command. Regeneration does not restart your app. Use the reload of your framework.
Check without writing
npx --no-install golem checkcheck exits with code 1 when a generated file is missing or stale, and it writes nothing. It also reports each parse<T>() call that no build tool can rewrite, with its file and line and what to run.
check needs generated files. If you ignore them in git, CI runs golem build or golem generate first. If you commit them, CI runs golem check, and a stale file fails the run (ignore or commit generated files). When Golem has not generated yet, check stops with one message. The message tells you to run golem generate or golem build first.
With --no-install, npx fails when the project does not install Golem.
Recover after a failed run
Fix the model, API document or configuration, then run the same commands again:
npx golem generate
npx golem checkGeneration recreates missing output. If an earlier job succeeded before a later job failed, its updated files remain. Fix the failing input and run generation again.
Use another configuration
Paths in a configuration are relative to that file. Select another configuration with the CLI option --config:
npx golem watch --config ./frontend/golem.yaml