create-knit 0.4.1 → 0.5.0

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.
package/index.mjs CHANGED
@@ -17,6 +17,9 @@ const versions = JSON.parse(readFileSync(join(template, 'versions.json'), 'utf8'
17
17
  const color = (code, text) => (process.stdout.isTTY && !process.env.NO_COLOR ? `\x1b[${code}m${text}\x1b[0m` : text)
18
18
  const bold = text => color('1', text)
19
19
  const dim = text => color('2', text)
20
+ // A coded error (KNIT_E2101…); this script runs before @knit-framework/core is installed.
21
+ const fail = (code, message) => Object.assign(new Error(message), { code })
22
+ const errorDocs = code => `https://3ig.github.io/knit/docs/errors/${code}`
20
23
 
21
24
  function usage() {
22
25
  return `Usage: pnpm create knit [dir] [--examples | --no-examples] [--no-install] [--no-git]
@@ -40,9 +43,9 @@ function parseArgs(argv) {
40
43
  console.log(usage())
41
44
  process.exit(0)
42
45
  }
43
- else if (arg.startsWith('-')) throw new Error(`Unknown option ${arg}\n\n${usage()}`)
46
+ else if (arg.startsWith('-')) throw fail('KNIT_E2101', `Unknown option ${arg}\n\n${usage()}`)
44
47
  else if (!opts.dir) opts.dir = arg
45
- else throw new Error(`Unexpected argument ${arg}\n\n${usage()}`)
48
+ else throw fail('KNIT_E2101', `Unexpected argument ${arg}\n\n${usage()}`)
46
49
  }
47
50
  return opts
48
51
  }
@@ -60,6 +63,7 @@ function localPackages() {
60
63
  const files = readdirSync(dir)
61
64
  const find = prefix => {
62
65
  const file = files.find(f => f.startsWith(prefix) && f.endsWith('.tgz'))
66
+ // internal: KNIT_CREATE_TARBALLS is only set by Knit's own tests
63
67
  if (!file) throw new Error(`KNIT_CREATE_TARBALLS: no ${prefix}*.tgz in ${dir}`)
64
68
  return `file:${resolve(dir, file)}`
65
69
  }
@@ -240,7 +244,7 @@ async function main() {
240
244
  try {
241
245
  const dir = opts.dir ?? await ask(rl, 'Project folder?', 'my-knit-app')
242
246
  const target = resolve(dir)
243
- if (existsSync(target) && readdirSync(target).length) throw new Error(`${dir} already exists and is not empty.`)
247
+ if (existsSync(target) && readdirSync(target).length) throw fail('KNIT_E2102', `${dir} already exists and is not empty.`)
244
248
  const examples = opts.examples ?? (rl ? !/^n/i.test(await ask(rl, 'Include the example apps (blog, dashboard)?', 'Y/n')) : true)
245
249
  rl?.close()
246
250
 
@@ -257,8 +261,8 @@ async function main() {
257
261
  if (opts.git) initGit(target)
258
262
  return
259
263
  }
260
- if (!run('pnpm', ['install'], target)) throw new Error('pnpm install failed (see above).')
261
- if (!run('pnpm', ['manage', 'makemigrations', '--name', 'initial'], target)) throw new Error('Creating the initial migration failed (see above).')
264
+ if (!run('pnpm', ['install'], target)) throw fail('KNIT_E2010', 'pnpm install failed (see above).')
265
+ if (!run('pnpm', ['manage', 'makemigrations', '--name', 'initial'], target)) throw fail('KNIT_E2103', 'Creating the initial migration failed (see above).')
262
266
  }
263
267
 
264
268
  // Last, so the first commit holds the lockfile and the initial migration too.
@@ -277,5 +281,7 @@ async function main() {
277
281
 
278
282
  main().catch((error) => {
279
283
  console.error(`\n${color('31', 'Error:')} ${error instanceof Error ? error.message : String(error)}`)
284
+ const code = error?.code
285
+ if (typeof code === 'string' && /^KNIT_E\d{4}$/.test(code)) console.error(dim(`See ${code} · ${errorDocs(code)}`))
280
286
  process.exit(1)
281
287
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-knit",
3
- "version": "0.4.1",
3
+ "version": "0.5.0",
4
4
  "description": "Create a Knit project: `pnpm create knit my-app`. Knit is the batteries-included full-stack framework for TypeScript, on Nuxt.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -12,9 +12,11 @@ Don't read files to find out what exists. Ask Knit:
12
12
  - `knit_describe`: apps, models with columns, foreign keys and `with:` relations, admin, resources and their permission rules, tasks, channels, routes, commands, migrations. Pass `section` to get one part.
13
13
  - `knit_model`, `knit_resource`: one model; one resource with its endpoints and permission rules.
14
14
  - `knit_routes`, `knit_openapi`: pages, API routes and resource endpoints; the resources' OpenAPI document.
15
- - `knit_check`: run after changes.
15
+ - `knit_check`: run after changes. `knit_doctor`: when the environment seems broken (Node, packages, database, ports), then every check.
16
+ - `knit_reference`: the exact signature, import path, options and example of any Knit function, type, component, setting or command, e.g. `{ "symbol": "defineResource" }`. Use it instead of reading Knit's source.
16
17
  - `knit_migrations`, `knit_migration_plan`, `knit_pending_migration_sql`, `knit_sqlmigrate`.
17
18
  - `knit_docs`: the guides, e.g. `{ "topic": "models" }`. Also as MCP resources: `knit://docs/{topic}`, `knit://describe`, `knit://agents`.
19
+ - **Error codes:** an error with a code (`KNIT_E1203`) has a page that says why and how to fix it: read it with `knit_docs { "topic": "errors/KNIT_E1203" }` before changing code.
18
20
  - Only when the server runs with `--allow-writes`: `knit_startapp`, `knit_generate`, `knit_makemigrations`, `knit_migrate`.
19
21
  - **CLI:** `pnpm -s manage describe --json` (the same document; `--section <name>` for one part), `routes --json`, `openapi`, `check --json`, `showmigrations --json`, `runtask --json`. Commands that change things take `--json` too (`startapp`, `generate`, `makemigrations`, `migrate`, …). `-s` keeps pnpm's banner out of the JSON.
20
22
  - **Library docs:** the `nuxt`, `nuxt-ui` and `better-auth` MCP servers. Use them instead of guessing APIs.
@@ -52,7 +54,7 @@ Don't edit `node_modules/@knit-framework/*`: override instead (a page, component
52
54
  ## 4. Change → verify loop
53
55
 
54
56
  ```bash
55
- pnpm -s manage check --json # schema, admin field names, layers, migrations (or MCP: knit_check)
57
+ pnpm -s manage check --json # schema, admin field names, settings, layers, migrations (or MCP: knit_check)
56
58
  pnpm manage makemigrations --name <slug> # after a schema change; --dry-run to preview
57
59
  pnpm manage migrate # works while pnpm dev runs; pnpm dev also applies on start
58
60
  pnpm typecheck # must pass
@@ -9,10 +9,21 @@ NUXT_BETTER_AUTH_URL=
9
9
 
10
10
  # Use a Postgres server instead of the embedded PGlite database (app + `pnpm manage`).
11
11
  # DATABASE_URL=postgres://user:password@localhost:5432/knit
12
+ # When DATABASE_URL goes through a transaction pooler (PgBouncer, a provider's pooled URL): the direct
13
+ # connection, for migrations and the realtime listener (docs/postgres.md)
14
+ # DATABASE_DIRECT_URL=postgres://user:password@db.internal:5432/knit
15
+ # Postgres pool per server process, idle timeout (s), statement timeout (ms, 0 = none), TLS (require | no-verify)
16
+ # NUXT_KNIT_DATABASE_POOL_MAX=10
17
+ # NUXT_KNIT_DATABASE_IDLE_TIMEOUT=10
18
+ # NUXT_KNIT_DATABASE_STATEMENT_TIMEOUT=0
19
+ # NUXT_KNIT_DATABASE_SSL=
12
20
 
13
21
  # PGlite data directory (relative to apps/web, or to the folder holding a deployed .output). Default: .data/pglite
14
22
  # NUXT_KNIT_DATA_DIR=.data/pglite
15
23
 
24
+ # Read migrations from this folder at startup instead of the copy bundled into the build
25
+ # NUXT_KNIT_MIGRATIONS_DIR=server/database/migrations
26
+
16
27
  # Apply pending migrations at startup: dev (default) | always | never
17
28
  # NUXT_KNIT_AUTO_MIGRATE=dev
18
29
 
@@ -38,10 +49,10 @@ NUXT_BETTER_AUTH_URL=
38
49
  # Default sender address
39
50
  # NUXT_MAIL_FROM=Knit <webmaster@localhost>
40
51
 
41
- # Used by `pnpm manage createsuperuser --noinput`
52
+ # Used by `pnpm manage createsuperuser --no-input`
42
53
  # KNIT_SUPERUSER_PASSWORD=
43
54
 
44
- # Used by `pnpm manage changepassword <email> --noinput`
55
+ # Used by `pnpm manage changepassword <email> --no-input`
45
56
  # KNIT_NEW_PASSWORD=
46
57
  # ── Logging (LogLayer) ─────────────────────────────────────────────────────────
47
58
  # trace | debug | info | warn | error | fatal (default: debug in dev, info in production)
@@ -88,6 +99,8 @@ NUXT_BETTER_AUTH_URL=
88
99
  # NUXT_KNIT_TASKS_POLL_INTERVAL=1000
89
100
  # NUXT_KNIT_TASKS_MAX_ATTEMPTS=3
90
101
  # NUXT_KNIT_TASKS_RETRY_DELAY=10
102
+ # Seconds after which a running task counts as interrupted (its worker died) and is queued again
103
+ # NUXT_KNIT_TASKS_STALE_AFTER=3600
91
104
 
92
105
  # ── Realtime (SSE + WebSocket channels) ─────────────────────────────────────────
93
106
  # memory (default, one process) | postgres (LISTEN/NOTIFY on DATABASE_URL: several
@@ -5,7 +5,7 @@
5
5
  # docker build -f docker/Dockerfile -t knit . # the app (default target: runtime)
6
6
  # docker build -f docker/Dockerfile -t knit-tools --target tools . # one-off `pnpm manage …` commands
7
7
  #
8
- # See docs/deployment.md.
8
+ # See docs/deployment/.
9
9
 
10
10
  ARG NODE_VERSION=24
11
11
 
@@ -3,7 +3,7 @@
3
3
  # cp docker/.env.production.example docker/.env.production # then fill in the secrets
4
4
  # docker compose -f docker/docker-compose.prod.yml --env-file docker/.env.production up -d --build
5
5
  #
6
- # See docs/deployment.md. Put a TLS-terminating proxy (Caddy, nginx, Traefik…) in front.
6
+ # See docs/deployment/. Put a TLS-terminating proxy (Caddy, nginx, Traefik…) in front.
7
7
 
8
8
  name: knit-prod
9
9
 
@@ -31,11 +31,14 @@ Agents working in a Knit project: read AGENTS.md, and use the `knit` MCP server
31
31
  - [Testing](node_modules/@knit-framework/core/docs/testing.md): Test databases, factories, the HTTP client, `pnpm test`
32
32
  - [`manage` CLI](node_modules/@knit-framework/core/docs/cli.md): Every command, `startapp` and `generate`, JSON output for scripts and agents, seeds, custom commands
33
33
  - [Configuration](node_modules/@knit-framework/core/docs/configuration.md): Every environment variable and setting
34
- - [Deployment](node_modules/@knit-framework/core/docs/deployment.md): Production checklist, build and run
34
+ - [Deployment](node_modules/@knit-framework/core/docs/deployment/index.md): production checklist, what Knit needs from a host, and one page per host (Docker, VPS with systemd and Caddy, Fly.io, Railway, Render; Vercel and Netlify with limits; Cloudflare not supported)
35
+ - [Postgres in production](node_modules/@knit-framework/core/docs/postgres.md): moving off PGlite, DATABASE_DIRECT_URL and poolers, zero-downtime migrations, backups, several instances
35
36
  - [Upgrading](node_modules/@knit-framework/core/docs/upgrading.md): updating the @knit-framework packages, migrating Knit's tables, removing the examples
36
37
  - [How Knit works](node_modules/@knit-framework/core/docs/architecture.md): Discovery, generated modules, request lifecycle
37
38
  - [Working with AI agents](node_modules/@knit-framework/core/docs/ai-agents.md): `AGENTS.md`, the `knit` MCP server (tools, resources, write tools), `describe`, `routes`, `openapi`, skills
38
39
  - [Troubleshooting](node_modules/@knit-framework/core/docs/troubleshooting.md): Common errors and fixes
40
+ - [API reference](node_modules/@knit-framework/core/docs/reference/index.md): every public function, type, component, setting and command with signatures and examples, generated from the source; `node_modules/@knit-framework/core/docs/reference/reference.json` has the same as data
41
+ - [Error codes](node_modules/@knit-framework/core/docs/errors/index.md): every `KNIT_E…` code with its cause and fix; read one as `node_modules/@knit-framework/core/docs/errors/<code>.md`
39
42
  - [Roadmap](node_modules/@knit-framework/core/docs/roadmap.md): what's proposed next, and why
40
43
  - [Coming from Django](node_modules/@knit-framework/core/docs/coming-from-django.md): every Django concept and its Knit equivalent
41
44
 
@@ -1,5 +1,5 @@
1
1
  {
2
- "knit": "0.4.1",
2
+ "knit": "0.5.0",
3
3
  "nuxt": "^4.7.0",
4
4
  "drizzleOrm": "^0.45.4",
5
5
  "typescript": "^6.0.3",