Skip to content

Generation

Use ctx.generate(...) when the output is fully owned by the generator and should be overwritten on each run.

ctx.generate(templatePath, filePath, data);

The runtime:

  1. Resolves templatePath relative to ccode_path.
  2. Renders the template with data.
  3. Resolves relative filePath under output_path.
  4. Creates parent directories.
  5. Writes the rendered content.
import type { Context } from "@ccode/context";
export default function main(ctx: Context) {
ctx.generate("templates/status.tpl", "generated/status.md", {
status: "alpha",
});
}

Template:

# Project status
{{ data.status }}

Result:

generated/status.md

Use generate for:

  • docs extracted from source metadata
  • files that should match a schema exactly
  • generated indexes
  • temporary artifacts
  • code that should never be hand-edited

Do not use generate for files that are expected to receive manual changes. Use Accelerators instead.