2.3 KiB
2.3 KiB
generator
(no submodules)
Purpose
This module turns a validated PromptAnswers record into either an
in-memory list of GeneratedFile records (generate) or a tree
materialised on disk (scaffold). Splitting the two lets snapshot tests
inspect the rendered tree byte-for-byte without touching the filesystem,
and lets the bin entrypoint stream the same tree out to disk through a
single typed failure surface.
Features
- Pure
generate(options)returns a deterministic, ordered list of files for snapshot comparison. scaffold(options)writes the tree atomically, raisingSCAFFOLD.DIRECTORY_EXISTSwhen the target is non-empty (unlessforceis set) andSCAFFOLD.WRITE_FAILEDfor every fs error.- Engine validation raises
SCAFFOLD.UNKNOWN_ENGINEfor any database value outside the closed vocabulary.
Usage
Basic example
import { scaffold, answersForFixture } from "create-suaveplan-plugin";
const answers = answersForFixture("isolated-sqlite-rest-only", "my-plugin");
scaffold({ answers, targetDir: "./my-plugin" });
Advanced example
import { generate, answersForFixture } from "create-suaveplan-plugin";
const tree = generate({
answers: answersForFixture("trusted-postgres-full", "billing"),
});
for (const file of tree) {
console.log(file.path, file.content.length);
}
API Reference
generate(options: GenerateOptions): readonly GeneratedFile[]— pure in-memory render. Validates answers first.scaffold(options: ScaffoldOptions): ScaffoldResult— writes to disk.GeneratedFile—{ readonly path: string; readonly content: string }.ScaffoldOptions—{ answers, targetDir, force? }.ScaffoldResult—{ files: readonly string[] }(relative paths).
Implementation Notes
directoryIsNonEmptyswallows ENOENT — a missing target is treated as empty so the first-time path needs no special case.- Errors during write are wrapped in
ScaffoldErrorwithcauseset to the originalfserror, so callers retain the original stack via the standardError.causechain. - The path order returned by
generateis stable; snapshot tests rely on this when asserting tree equality. - Coverage is enforced at 100% by the snapshot fixtures plus the
explicit error-path tests in
generator.test.ts.