Templates
create()’s path and template are both template strings, rendered against the same
single options object. This page covers where rendering happens and what to do when it fails. The
language itself (variables, pipes, range, if, with, whitespace) is in the
template language reference.
Where rendering happens
Section titled “Where rendering happens”Rendering happens in the engine at builder execute time, never in the SDK. Your factory ships
the template and options verbatim, so template errors (a typo’d option name, a type mismatch)
surface at run time, and the test harness stores the raw {= .name =} text, not rendered output.
import { create } from "@pbuilder/sdk/commons";
create("src/{= .name | dasherize =}.ts", { template: "export const {= .name | classify =} = 1;\n", options: { name: "myThing" },});renders to path src/my-thing.ts with content:
export const MyThing = 1;The call takes three parts:
| You pass | What it does |
|---|---|
path (first argument) |
A template string, rendered to produce the output file path. |
template |
A template string, rendered to produce the file’s byte content. |
options |
The data context: the single set of values shared by both renders. |
The templateFile overload, create(path, { templateFile, options }), reads a package-local
file instead of an inline template string; everything in the template language reference applies to it unchanged.
Templating the output path
Section titled “Templating the output path”The path argument uses the same language as template, with the same fields, pipes, and
sandbox (see the template language reference). That’s how you get a cased directory and filename from one option:
create("src/{= .name | dasherize =}/{= .name | classify =}.ts", { template, options });with name: "userProfile" → src/user-profile/UserProfile.ts.
The rendered path is checked for containment: a path that tries to escape the workspace (for
example via ../) is rejected with a typed error and zero files are written.
When something goes wrong
Section titled “When something goes wrong”Every failure is a typed, positioned error (it names a File:Line:Column) and, on failure,
no files are written: the engine fails the whole render closed rather than producing a
partial file. A mistyped option name gives you the exact line and column of the reference.
Because the SDK never renders, all template errors surface at run time, never at the moment
create() is called. See error handling for the full taxonomy.
Next steps
Section titled “Next steps”For anything bigger than a couple of files, keep a folder of template files and mirror it with
scaffold() instead of writing one create() per file. The rest of the
mutation surface lives in mutation verbs.