Function: runGenerate()
runGenerate(
options):Promise<{actionCode?:string;actionPath?:string;code:string;outputPath:string;wroteFile:boolean; }>
Defined in: packages/cli/src/index.ts:122
Executes the code generation pipeline for a single Zod schema export.
Loads the config and schema, resolves field overrides, walks the Zod type
tree to produce an intermediate FormField[] representation, and writes a
React form component (plus optional server action and schema-lite files) to
disk. When options.dryRun is true the generated code is printed to stdout
instead of being written.
Parameters
options
GenerateOptions
Generation options including paths for config, schema, and output.
Returns
Promise<{ actionCode?: string; actionPath?: string; code: string; outputPath: string; wroteFile: boolean; }>
Resolved output paths and the generated code string.
Use When
- You need programmatic codegen from a Node.js script or build tool (not just the CLI)
- You are writing tests for the code generation pipeline end-to-end
- You need
dryRunoutput for preview/diffing without touching the filesystem
Avoid When
- Interactive use — run
npx zod-to-form generate(viacreateProgram()) instead - Browser environments — this function uses Node.js
fsandpathAPIs
Pitfalls
- NEVER call with a schema that already has a generated output file when
defaults.overwriteis false — the function silently skips writing and returnswroteFile: falsewith no error; this is intentional but easy to miss in scripts - NEVER rely on generated file content after re-running
runGeneratewithout checkingwroteFile— if the file already exists and overwrite is disabled, the on-disk file is NOT updated even thoughcodeis returned - NEVER use
--watchmode on schema files that have indirect imports — the watcher only tracks the top-level schema file, not its transitive dependencies