The registry for VelaStack patterns.
There's two modes this library can be used. One is in runtime, by the @velastack/cli. The VelaStack CLI uses Commander to get inputs from the CLI and then calls the pattern:
The CLI determines what existing features are in use and passes feature flags to the loadPattern() function.
It also takes any additional wizard inputs from the CLI and passes the data as input.
const pattern = await registry.loadPattern("generate-form", {
env: "runtime",
argv: ["contact", "name:text", "email:email", "message:editor"],
root: "/user/project",
features: {
auth: false,
payments: false,
},
input: {},
});The other way is for the velastack.dev/patterns website. Each pattern is available for browsing. Each pattern is loaded like this:
const pattern = await registry.loadPattern("generate-form", {
env: "preview",
argv: ["contact", "name:text", "email:email", "message:editor"],
});In the runtime, @velastack/patterns loads libraries like pocketbase and ts-morph to make modifications to the user's project.
This isn't possible in the preview environment, so these changes are mocked with stock output. Keeping this separation is important.
Any libraries or node requirements must only be imported inside of generate.runtime.ts files.
Those dependencies are specified as devDependencies and also optionalDependencies for use with the CLI.
For each pattern, generate.ts is the main generator. As much of the pattern as possible should be configured here.
Libraries that can't be run in the preview environment are imported only in generate.runtime.ts, this async import
is only called during the runtime.
However, we still need examples of what generate.runtime.ts outputs, so we have generate.preview.ts, containing
a static version of what we'd typically get from the runtime.
Within each pattern, we have creates, modifies and preview-modifies directories.
The creates directory is directly copied into the target project. Each file is bundled into the library using import.meta.glob.
The modifies directory contains scripts that modify the target project. Modifications use ts-morph when possible.
Each modification should have an extensive test suite with fixtures/expect and fixtures/original to ensure that
the modifications work across a wide range of project setups.
The preview-modifies directory is the mock modify output used only for previews. It's bundled in the same way as the creates directory.
The src/baselines/ directory contains template SvelteKit projects that patterns are applied on top of:
sv— minimal SvelteKit startervelastack— full VelaStack with components, UI, and database setupvelastack-auth— VelaStack with authentication pre-configured
Each baseline is a standalone project with its own package.json. When working with a baseline locally, run npm install inside its directory. The node_modules and .svelte-kit directories inside baselines are gitignored and must be installed locally before running or testing.
Baselines are not bundled into the published package — they are used by the VelaStack CLI's create command and by the velastack.dev website.
- Develop the pattern in the
src/patternsdirectory. - Use the demo script to generate a temporary project with the pattern to see applied changes.
- In the temporary project, run
npm run test:serverto run the tests. - Run
npm run lintandnpm run checkto make sure the code is correct.