Target path and project metadata
The target path is the destination for the new project. The scaffolding flow checks that this path is safe to use, obtains the generated project's package metadata, and uses that metadata to choose compatible commands and apply template-defined changes before the project is handed to dependency installation and the user.
Destination directory
The destination directory is treated as an output boundary for the scaffold operation. The clone stage refuses to write when the path already exists, while the overall workflow remembers whether the path existed so that a failed run can remove only a directory it created itself. targetDirectory carries this path through the creation tasks.
The path is also the base for template file changes. Rename rules check that each named target exists before they search it, so a missing optional file produces an error log and does not stop other rename work.
References: src/…/get-args-result.ts• L5-19 src/…/create-app.ts• L22-25 src/…/create-app.ts• L74-78 src/…/create-app-task-clone-template.ts• L43-50 src/…/init-script-rename.ts• L128-142
Package metadata
The generated project's package.json is the shared metadata record for the later scaffold stages. The loader reads it from the target directory and accepts the fields needed for project naming, package-manager selection, scripts, and the template initialization contract while preserving other fields for writes.
The loader stops the workflow when the file is absent, empty, malformed, or has invalid shapes for the fields it reads. This keeps later actions from using an incomplete project description.
References: src/…/get-package-json-path.ts• L1-5 src/…/get-package-json.ts• L6-31 src/…/init-script-schema.ts• L4-5
Package-manager compatibility
The template may declare a required package manager through its initialization metadata. That requirement becomes the effective package manager unless the user explicitly chose a different one. An explicit conflict stops the flow, and an unavailable required manager also stops it.
After the effective manager is known, the workflow checks the ordinary packageManager pin in package.json. It keeps a matching pin and removes a conflicting pin with a warning. This prevents the package manager from rejecting the generated project during install, even when installation is skipped.
References: src/…/init-script-package-manager.ts• L8-32 src/…/remove-incompatible-package-manager.ts• L5-35 src/…/create-app.ts• L32-47
Project naming
Project naming aligns the template's built-in name with the requested project name. The flow updates the package name and searches the configured project files for common forms of the old name, such as compact, kebab, Pascal, and snake forms.
Template rename entries extend this work to selected paths. Each entry maps an old value to a requested value and can use {{name}} as the project name. A rename entry that targets the original package name is skipped after the project-wide name replacement to avoid applying the same change twice.
References: src/…/init-script-rename.ts• L20-49 src/…/init-script-rename.ts• L56-109 src/…/init-script-rename.ts• L112-163
Metadata cleanup
The initialization metadata is temporary control data for project creation. After its version checks, option changes, renames, and user instructions are applied, the flow removes that metadata from the generated package.json and writes the remaining project data back in readable JSON form.
References: src/…/create-app-task-run-init-script.ts• L11-17 src/…/create-app-task-run-init-script.ts• L34-48 src/…/init-script-delete.ts• L7-14
Command selection
Package scripts connect generated project metadata to user-facing actions. Selected template options may require named scripts, and the flow validates each required script before it runs the command through the effective package manager. These option scripts run before dependency installation so changes to package.json affect the installed project.
The optional setup script runs after dependency installation. It supports project preparation work such as building a program or generating a client, and it is skipped with installation when the user chooses to skip installation.
References: src/…/create-app.ts• L50-69 src/…/create-app-task-run-option-script.ts• L8-55 src/…/create-app-task-run-setup.ts• L7-31
Start command
The completion message discovers the command that starts the generated app from its scripts. A dev script takes priority over start; when neither script exists, the message does not invent a start command. If installation was skipped, the message also tells the user to install dependencies before running the chosen command.
This creates a small contract between generated metadata and the final user handoff: the scaffold flow prepares the project, then reports the package-manager command that the project itself declares.
References: src/…/get-start-script.ts• L1-10 src/…/final-note.ts• L11-27 src/index.ts• L83-91
Metadata lifecycle
The metadata lifecycle orders validation and mutation so each later stage sees the correct project state. The following flow shows the main handoff from the destination path to the final start guidance.
flowchart LR
A[Target path] --> B[Template files]
B --> C[Read package metadata]
C --> D[Resolve package manager]
D --> E[Clean conflicting pin]
E --> F[Snapshot init metadata and options]
F --> G[Run option scripts]
G --> H[Install dependencies]
H --> I[Run setup]
I --> J[Apply renames and cleanup]
J --> K[Discover dev or start command]
K --> L[Completion guidance]
The snapshot before option scripts is important. An option script may rewrite package.json, but the selected options and initialization metadata remain available for the later customization stage. The final note reads the resulting package.json, so its start guidance reflects the project's final scripts.
References: src/…/create-app.ts• L27-72 src/…/create-app-task-run-option-script.ts• L8-14 src/…/create-app-task-run-init-script.ts• L11-17 src/…/final-note.ts• L11-27
Change checklist
When these files or sections are changed, remember to consider these:
- Keep the package metadata fields accepted by
getPackageJsonaligned with every writer and with the initialization metadata schema. - Preserve the effective package-manager order: template requirements must resolve before conflicting
packageManagerpins are removed and before package scripts run. - Keep the initialization metadata snapshot stable when option scripts can rewrite package.json.
- Keep
getStartScriptandfinalNotealigned so the completion message names a script that the generated project actually exposes. - Keep target cleanup limited to directories created by the current scaffold run.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| The target directory already exists | Template acquisition stops before it overwrites an existing project | The clone stage checks the destination path first |
| package.json is missing, empty, malformed, or has invalid script data | Metadata-driven stages cannot continue | The metadata loader validates the file before use |
| The template requires a package manager that conflicts with an explicit user choice | Creation stops before commands run with the wrong manager | The template requirement is checked against the explicit choice |
| A pinned package manager does not match the effective manager | Dependency installation can fail or be rejected by the package manager | The conflicting pin is removed and a warning is shown |
| A selected template option has no matching package script | The selected customization cannot run | Required scripts are checked before execution |
No dev or start script exists | Completion output has no start command | Start guidance is omitted instead of using an assumed command |
Key files
| File | Why to read it |
|---|---|
| src/…/create-app.ts | Shows where target state, metadata resolution, cleanup, and task ordering meet |
| src/…/ensure-target-path.ts | Shows the existence check used by path-based rename work |
| src/…/get-package-json.ts | Defines the metadata read boundary and validation behavior |
| src/…/init-script-package-manager.ts | Explains template package-manager requirements and precedence |
| src/…/remove-incompatible-package-manager.ts | Shows how conflicting package-manager pins are made safe for the selected manager |
| src/…/init-script-rename.ts | Describes project-name replacement and configured path-based renames |
| src/…/create-app-task-run-option-script.ts | Shows how selected template options depend on package scripts |
| src/…/create-app-task-run-setup.ts | Shows the role of the optional post-install setup command |
| src/…/get-start-script.ts | Defines the dev-then-start command choice |
| src/…/final-note.ts | Shows how final project instructions use the generated metadata |