@kodentuzo/spotcraft
v0.19.0
Published
The spotcraft command: a local stack that matches a Spotcraft server, per repository
Maintainers
Readme
@kodentuzo/spotcraft
The spotcraft command. spotcraft new starts a private, offline-first app from Kodentuzo's
starter (the server is the authority; the device keeps a working copy and a
queue of changes), and spotcraft dev runs a local stack that matches a Spotcraft server, one
per repository (ADR 0037):
Postgres set up as on the server, the user pool, and Mailpit to catch email. It needs Docker.
npm install --save-dev @kodentuzo/spotcraft # same version as the Spotcraft you deploy to
npx spotcraft dev # start, set up this app, fill .env, migrateA new app
pnpm dlx @kodentuzo/spotcraft new my-app # the starter's latest release, in ./my-app
pnpm dlx @kodentuzo/spotcraft new my-app --ref v0.1.0It downloads a release of kodentuzo/starter from GitHub (with the system's tar), then names
it: starter becomes the app's name, Starter its title, and app_starter its schema
(app_my_app) in every text file, outside node_modules. The template's own links stay. It
writes a README and changelog of the app's own, and refuses a folder that isn't empty. The name
follows Spotcraft's rules: lowercase letters, digits and dashes.
It replaces the old spotcraft package.
| Command | What |
| ---------------------- | ------------------------------------------------------------------------------------------------------ |
| dev | starts the stack if needed, sets up this app's schema, adds missing settings to .env, runs migrate |
| dev env [--write] | prints this app's settings; --write adds missing ones to .env |
| dev db reset [--yes] | deletes everything in this app's schema (asks first), then runs migrate |
| dev migrate | runs migrate from spotcraft.json with this app's settings |
| dev status | whether the stack runs, its addresses, and this app's schema |
| dev stop | stops the stack; the data stays |
| dev ls | every repository's stack on this machine |
The app
The app's name comes from --name, else name in spotcraft.json, else the name in
package.json made into an app name (@acme/Blog_API → blog-api). spotcraft.json sits in
the deployable's folder:
{ "name": "lifts-api", "migrate": "pnpm db:migrate" }migrate runs through the shell in that folder, with the app's settings; values in .env win.
On the server, the image's dev.spotcraft.migrate label does that job instead
(the contract).
.env gets the names the server uses, pointing at the local stack: DATABASE_URL,
DATABASE_SCHEMA, APP_NAME, APP_SECRET (random, kept), PUBLIC_URL
(http://localhost:3000; change it to your dev server's), AUTH_URL, AUTH_ISSUER,
AUTH_JWKS_URL, SMTP_URL, MAIL_FROM and LEGAL_FACTS (example facts, in single quotes,
with .invalid addresses). Existing lines are never changed.
The stack
- One per repository, found from the folder you run it in: the nearest folder up with
.gitorpnpm-workspace.yaml. Every deployable in a monorepo shares it, so their tables can point at the same local users. It is the Compose projectspotcraft-dev-<repo folder>-<hash>, with its data in its own volume. The hash is 6 hex characters of the root's absolute path, so two checkouts or worktrees with the same folder name get their own stacks.dev statusprints the name;dev lslists every stack without thespotcraft-dev-prefix. - Ports and the name are picked on the first run and kept in
.spotcraft/dev.jsonat the repository's root, so.envstays valid. A stack made by 0.6.0 keeps its name,spotcraft-dev-<repo folder>..spotcraft/ignores itself in git. - Postgres: the server's pinned image and login rules, the same roles and grants (the deploy
script's SQL), and the same provisioning code as the agent (
@kodentuzo/spotcraft/provision). Every app has its own schema and role in theappsdatabase. Tests fail if the copies of the image, the rules or that SQL drift frominfra/. - The user pool: Spotpass, the same pinned image as
the server (
SPOTPASS_DEV_IMAGEoverrides it, e.g. with a local build), over plain HTTP. It trusts anyhttp://localhost:<port>andhttp://127.0.0.1:<port>origin, where dev servers run. Its cookies are host-only, and browsers sendlocalhostcookies to every port, so an app atlocalhost:3000and the pool at its own port share the session. - Mailpit catches every email sent to
SMTP_URL; its inbox is at the addressdev statusshows.
Everything listens on 127.0.0.1 only. The passwords are fixed (local-<name>-password for an
app), which is fine for throwaway data on your own machine and nowhere else. To remove a stack
and its data: docker compose -p <name from dev status> down -v.
Developing
In the workspace, run it from source with
node --conditions=spotcraft-source packages/cli/src/cli.ts dev … from an app's folder. pnpm
selects this package by folder (--filter ./packages/cli), as spotcraft is also the
workspace root's name. pnpm --filter ./packages/cli build writes dist/: the spotcraft bin,
and @kodentuzo/spotcraft/provision, which the agent imports. That export is for Spotcraft
itself, not for apps.
