@decohere/create 0.0.1-dev.20261123.374 → 0.0.1-dev.20261123.401

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +44 -11
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -50,6 +50,8 @@ The scaffolded Dev Container asks no questions. `gh` is installed in it: run `gh
50
50
 
51
51
  Scaffolds a full web API using `@decohere/http` (HTTP), `@decohere/crucible` (DI), `@decohere/config` (configuration) and Scribe (logging), plus a Dev Container workspace.
52
52
 
53
+ What it writes is checked-in files, not code generated on the fly: the workspace every project starts with, then the **web API recipe**, a complete app on Fastify that the Decohere repo boots and tests as it is ([scaffold](../scaffold/README.md)). Only names and ports change. `--database` and `--auth` are the same [add steps](#add-to-a-project) you can run later, applied on top of the recipe.
54
+
53
55
  ```bash
54
56
  npx @decohere/create webapi -d my-app
55
57
  npx @decohere/create webapi -d my-app --name billing
@@ -78,7 +80,7 @@ my-app/
78
80
  .devcontainer/
79
81
  projects/
80
82
  api/ # or projects/<name> when --name is set
81
- package.json # private: true (app, not an npm package)
83
+ package.json # private: true; "decohere" records the recipe and the steps added
82
84
  Dockerfile # copies .package/ (written by `forge package`)
83
85
  .dockerignore
84
86
  src/
@@ -107,7 +109,7 @@ USER node
107
109
 
108
110
  #### The app and its test
109
111
 
110
- `src/app.ts` is the app's composition, written out so you can see and change every part: Pino logging, `http(FastifyProvider, …)` with an OpenAPI document, `config(…)` from `config/` and the environment, and `health()`. To use another HTTP provider or logger, edit that line; nothing is hidden behind a preset ([architecture: progressive](../../docs/architecture/README.md#4-progressive-new-apps-start-from-a-recipe-the-app-owns)). `src/main.ts` only starts it:
112
+ `src/app.ts` is the app's composition, written out so you can see and change every part: Pino logging, `http(FastifyProvider, …)` with an OpenAPI document, `config(…)` from `config/` and the environment, and `health()`. To use another HTTP provider or logger, edit that line; nothing is hidden behind a preset ([architecture: progressive](../../docs/contributing/architecture/README.md#4-progressive-new-apps-start-from-a-recipe-the-app-owns)). `src/main.ts` only starts it:
111
113
 
112
114
  ```ts
113
115
  import { createApp } from "./app.js";
@@ -127,20 +129,39 @@ export default app;
127
129
  | `package` / `package:<name>` | release build, then `forge package` (all APIs, or that one) | Before `docker build` |
128
130
  | `start` | `node dist/release/projects/<first>/es6/src/main.js` | Production default API (`pnpm start`) |
129
131
  | `start:<name>` | same path for that API | Deploy that API (`pnpm run start:billing`) |
130
- | `dev` | `flux serve --env-file-if-exists .env` (plus `--project @<app>/<first>` when named) | Local HMR for the first API; loads `.env` if present |
132
+ | `dev` | `PORT=3000 flux serve --env-file-if-exists .env --project @<app>/<first>` | Local HMR for the first API; loads `.env` if present |
131
133
  | `dev:<name>` | `PORT=<3000+n> flux serve --env-file-if-exists .env --project @<app>/<name>` | Local HMR for that API |
132
134
  | `lint` | `oxlint --fix`, then `prettier --write .`, skipping `.devcontainer` | Fix and format |
133
135
  | `lint:check` / `typecheck` / `test` | oxlint and Prettier / forge typecheck / vitest | CI |
134
136
 
135
- #### Multiple APIs / add later
137
+ #### Add to a project
138
+
139
+ Each part a project can have is an add step. `create` runs the ones you choose on top of the recipe; in the project's Dev Container you can run any of them later:
136
140
 
137
141
  ```bash
138
- decohere add api billing
139
- # empty machine / npm create still maps `webapi add`:
140
- npx @decohere/create webapi add billing -d my-app
142
+ pnpm decohere add api billing # the web API recipe again, as projects/billing (asks for its steps)
143
+ pnpm decohere add postgres # Postgres in the Dev Container, a database and sample table per API
144
+ pnpm decohere add postgres --orm typeorm # the same, mapped with TypeORM instead of MikroORM
145
+ pnpm decohere add auth0 # Auth0: every route needs a token (see below)
146
+ pnpm decohere add users # with Postgres and Auth0: a local profile per user, admin seeded
141
147
  ```
142
148
 
143
- Adds `projects/billing`, `start:billing` / `package:billing` / `dev:billing`, and `projects/billing/Dockerfile`. Does not rewrite the first API or workspace files like `.prettierrc.json`.
149
+ | `create` option | Is the recipe, plus |
150
+ |---|---|
151
+ | `--database postgres/mikro-orm` | `add postgres` |
152
+ | `--database postgres/typeorm` | `add postgres --orm typeorm` |
153
+ | `--auth auth0` | `add auth0` |
154
+ | both | `add postgres`, `add auth0`, then `add users` |
155
+
156
+ Every step:
157
+
158
+ - **Adds, and never takes away.** A file the project doesn't have is copied in. One it has is merged: `package.json`, `devcontainer.json`, `docker-compose.yml` and `config/*.yaml` get only the keys and list items they lack (a data source by its `name`), `.env` only the variables it doesn't set, `.gitignore` only missing lines, `README.md` only missing `##` sections.
159
+ - **Changes nothing when run again.** `--dry-run` lists what it would change and writes nothing (and touches no Auth0 tenant).
160
+ - **Edits `app.ts` only in the shape it generated.** It inserts its lines (`.use(auth())` after `.use(config(…))`, the data provider before `.build()`, and so on). If one can't go in, it leaves the file as it is and prints every line to add.
161
+ - **Replaces a sample file only if you haven't touched it.** `add auth0` and `add users` rewrite `hello.controller.ts` and its test only while they are exactly what the recipe (or `add auth0`) wrote; otherwise they print where their version is.
162
+ - **Records itself** in the API's `package.json`, under `"decohere": { "recipe", "steps" }`.
163
+
164
+ `add api billing` adds `projects/billing`, `start:billing` / `package:billing` / `dev:billing`, its port in the Dev Container, and `projects/billing/Dockerfile`. It doesn't rewrite the first API or workspace files like `.prettierrc.json`. From an empty machine, `npx @decohere/create webapi add billing -d my-app` does the same.
144
165
 
145
166
  Each API is a separate deploy: package it (`pnpm run package:billing`) and build the image from its folder (`docker build projects/billing`), or set the start command to `pnpm run start:billing`. Workspace `config/` is shared; each API still has its own named datasource and `{PREFIX}_DB_*` env (host/port default to the Compose Postgres).
146
167
 
@@ -169,7 +190,7 @@ In the project's Dev Container:
169
190
  pnpm decohere add auth0
170
191
  ```
171
192
 
172
- This logs in if needed, creates the Auth0 API and a `<project> Dev` login app, writes `AUTH0_ISSUER_BASE_URL`, `AUTH0_AUDIENCE` and `AUTH0_CLIENT_ID` to `.env`, adds the `auth` section to `config/config.yaml`, and adds `.use(auth())` to each API's `app.ts`. Running it again changes nothing. If an `app.ts` no longer has the generated shape, the command leaves it alone and prints the lines to add. It also creates a `<project> Token` machine app (written to `.env` as `AUTH0_TOKEN_CLIENT_ID`). It doesn't add the local user profile a new project with Postgres gets.
193
+ This logs in if needed, creates the Auth0 API and a `<project> Dev` login app, writes `AUTH0_ISSUER_BASE_URL`, `AUTH0_AUDIENCE` and `AUTH0_CLIENT_ID` to `.env`, adds the `auth` section to `config/config.yaml`, and adds `.use(auth())` to each API's `app.ts`. It gives the Hello controller `@Authorize` permissions and its test a token check of its own. It also creates a `<project> Token` machine app (written to `.env` as `AUTH0_TOKEN_CLIENT_ID`). With Postgres too, `pnpm decohere add users` adds the local user profile a new project with both gets; with `DECOHERE_ADMIN_PASSWORD` set, it also creates the admin user on Auth0.
173
194
 
174
195
  Once Auth0 is added, **every route needs a token** unless it has `@AllowAnonymous()`, because `auth()` is secure by default. To call one, in the Dev Container:
175
196
 
@@ -218,7 +239,7 @@ npx @decohere/create webapi -d my-app --name api --name billing --database postg
218
239
 
219
240
  `config.yaml` lists one datasource per API (`name: billing` → `mikroOrm({ name: "billing" })`). Locally they share host `postgres` port `5432`. Point `BILLING_DB_HOST` / `BILLING_DB_PORT` at another server to split later. `webapi add billing --database postgres/mikro-orm` appends a datasource; the bootstrap `CREATE DATABASE`s it on first run.
220
241
 
221
- Each API builds in `src/app.ts` (`createApp()`) and starts in `src/main.ts`. Its migrations are in `src/migrations/`, starting with one per table the scaffold maps, and development applies them on start. `pnpm decohere db <command>` runs `src/db.ts` (add `--api billing` when there are several APIs): `generate <name>` writes a migration from your mapping changes, and `migrate`, `status`, `revert` and `new` do what they say. See [Migrations](../../docs/recipes/migrations.md).
242
+ Each API builds in `src/app.ts` (`createApp()`) and starts in `src/main.ts`. Its migrations are in `src/migrations/`, starting with one per table the scaffold maps, and development applies them on start. `pnpm decohere db <command>` runs `src/db.ts` (add `--api billing` when there are several APIs): `generate <name>` writes a migration from your mapping changes, and `migrate`, `status`, `revert` and `new` do what they say. See [Migrations](../../docs/guide/recipes/migrations.md).
222
243
 
223
244
  #### Health probes
224
245
 
@@ -259,7 +280,7 @@ While the API is running, `http://localhost:3000/openapi.json` describes every r
259
280
  | `--name <slug>` | `webapi` | API directory under `projects/` (repeatable; default `api`) |
260
281
  | `add api <name>` | `decohere add api` | Add an API to an existing Decohere workspace |
261
282
  | `add auth0` | `decohere add auth0` | Add Auth0 to an existing workspace |
262
- | `auth0 login` | `decohere auth0` | Device/URL login; keeps tokens in `~/.config/auth0` |
283
+ | `auth0 login` | `decohere auth0` | Device/URL login; keeps the login in the project's own folder on your machine (see [`auth0`](#auth0)) |
263
284
  | `auth0 configure` | `decohere auth0` | Update the Auth0 API, login app and token app for an existing workspace |
264
285
  | `auth0 token` | `decohere auth0` | Print an access token for calling the API in development |
265
286
  | `--database <provider>` | `webapi` / `add` | `none` \| `postgres/mikro-orm` \| `postgres/typeorm` |
@@ -308,3 +329,15 @@ gh auth status -t
308
329
  ```
309
330
 
310
331
  If you still get `403` after adding `read:packages`, ask an org admin to grant your user/team access to the `typesmiths/decohere/create` package.
332
+
333
+ ## Working on this package
334
+
335
+ For contributors to Decohere: how the package is laid out and tested. Using it needs nothing below.
336
+
337
+ `@decohere/create` is the launcher: its `create-decohere` bin (`npm create @decohere`) works out where a command runs and starts it there. The scaffolder itself is [`@decohere/scaffold`](../scaffold/README.md). `src/` is flat:
338
+
339
+ - `resolve-launch.ts`: maps what the user typed onto the product CLI's command line (`create webapi`, `add api`).
340
+ - `runner.ts`: `launch` runs the command here when this container has Decohere's tools (`tools.ts`, `DECOHERE_TOOLS`), otherwise `runInBuilder` runs it in the scaffolder image, `ghcr.io/typesmiths/decohere/create:<version>`, and copies the project out.
341
+ - `cli.ts` is the bin, and `version.ts` the version the image and scaffold package are pinned to. The image is built from `Dockerfile`, with `pack-builder-tgz.mjs` packing the scaffolder into it.
342
+
343
+ The canonical suite for what a user installs is `e2e/real-install.e2e.spec.ts`, against a temporary registry, in CI's `verify-release` job on `main`; `runInBuilder` and its argv are covered in `tests/runner.spec.ts` ([testing](../../docs/contributing/testing/README.md#canonical-suite-ownership)). Specs are in `tests/` today and move beside the code ([ADR 0027](../../docs/contributing/adr/0027-code-design.md)).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@decohere/create",
3
- "version": "0.0.1-dev.20261123.374",
3
+ "version": "0.0.1-dev.20261123.401",
4
4
  "description": "Download the Decohere scaffolder image and run it (npm create @decohere)",
5
5
  "keywords": [
6
6
  "decohere",