Skip to content

Scaffolding components ​

Run pnpm new:component Switch from the repository root. GhostSwitch is also accepted and produces the same name. Names must be PascalCase with at least two characters (the manifest id convention); existing files, exports, and example ids are rejected before anything is written. pnpm new:component Switch --dry-run lists the identical plan without writing. No dependencies are installed by the generator.

The component gate approves the specification before implementation, so docs/components/<slug>-spec.md may already exist when you scaffold. The generator keeps that file byte-for-byte, lists it as keep in its output, and scaffolds everything else around it. Any other existing file still stops the run before anything is written.

Pass --headless-only when the approved spec rules out a themed wrapper or keeps the composable internal. It skips everything in @ghostvue/themes (wrapper, CSS recipe, themed manifest, themesCssImports entry and themed budgets), the themed ref test, and the public use-ghost-* composable and its barrel line. The lead example then imports from @ghostvue/vue and is registered as a headless example. Combine it with --dry-run to preview the plan.

The scaffold creates:

  • packages/vue/src/GhostSwitch.vue, its ghost-switch.ts ref contract, use-ghost-switch.ts composable and colocated unit test.
  • Without --headless-only, a themed wrapper and CSS recipe under packages/themes/src, using existing --ghost-* tokens, plus a themed ref test. Both exports expose the content root as element; the themed wrapper forwards the headless ref contract. The root exposes data-part="root" and data-ghost-switch hooks.
  • Vue and themed manifests, a docs page and draft specification, and a lead example at examples/switch/basic.vue. The sample imports @ghostvue/themes, belongs to the themed manifest, and appears in the generated docs page and playground as a themed example.
  • A runnable Playwright/Axe smoke test at tests/e2e/ghost-switch.spec.ts.

It registers the example in packages/vue/registry/<slug>.registry.json, adds the family to familyOrder (and the recipe to themesCssImports) in registry/primitives.registry.json, lists the themed wrapper in the wrapper-root table of docs/themes/default.md (the themed wrapper renders through useThemedScopeWrapper('contents')), and runs pnpm registries:write so public barrels, examples, and docs sidebar slices regenerate locally (gitignored .registries/ output). It also seeds provisional gzip budgets in scripts/bundle-size-budgets.json: 2 kB for the headless import, 2 kB plus the default stylesheet budget for the themed import, and 300 bytes for the standalone recipe. A --headless-only scaffold seeds only the headless budget. Run pnpm build and pnpm size:write to replace those with measured budgets once the implementation lands. See the performance standard. Vue refs and composables stay in vue; a neutral scaffold has no useful framework-independent behavior to put in core or shared.

The generated component passes the repository verification gate as a neutral, non-interactive content container. It does not implement switch semantics, state or keyboard behavior. Follow the component gate: complete the draft specification using the template, obtain design approval, then replace the scaffolding with the approved contract and behavior tests. Keep the headless component thin and behavior in its composable. Do not ship the starter as a production widget.

The generator prints a short version of these steps when it finishes. After implementation, run pnpm manifests:write, fill out manifest prose, run pnpm docs:api:write to refresh the page's generated API tables, and run focused checks for the component with pnpm verify:component Switch (see component verification). CI runs full repository verification and browser checks on the pushed branch, so full local pnpm verify is only needed to diagnose a failure across stages. New registered examples need visual baselines via pnpm test:visual:docker before browser CI can pass (without Docker, add the update-baselines label to the PR; see regenerating baselines in CI). Add a Changeset when the component changes a published package's output. The scaffold generator itself is tooling and requires no Changeset.

Diagnostic codes ​

Development diagnostics use GHOST0xx codes from packages/vue/src/dev-codes.ts. Before an implementation branch adds codes, reserve a range for the component on master in a small PR: add an entry after the last one in reservedGhostCodeRanges and leave room for the warnings the spec lists. The branch then assigns codes from its own range, so parallel component PRs cannot take the same number. dev-codes.test.ts fails when a new code falls outside its range or when ranges overlap. A component that runs out of codes reserves a second range the same way.