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:
- Resolves
templatePathrelative toccode_path. - Renders the template with
data. - Resolves relative
filePathunderoutput_path. - Creates parent directories.
- Writes the rendered content.
Example
Section titled “Example”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.mdWhen generate is the right choice
Section titled “When generate is the right choice”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.