@beechcms/cms 0.4.0-preview.12 → 0.4.0-preview.13

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 (4) hide show
  1. package/README.md +107 -107
  2. package/bin/cli.mjs +188 -129
  3. package/bin/create.mjs +433 -428
  4. package/package.json +14 -2
package/README.md CHANGED
@@ -1,107 +1,107 @@
1
- ![beechLogoDark.png](docs/images/beechLogoDark.png)
2
-
3
- **BeechCMS** is a precision-engineered, solo-developer headless CMS built for developers who deliver high-performance websites for clients with **zero infrastructure overhead**.
4
-
5
- The pitch is simple: you build the site, you hand it over, and your client can manage their own content forever — with **zero hosting costs**. No monthly subscriptions, no server bills, no maintenance contract needed just to keep the lights on.
6
-
7
- This is possible because BeechCMS runs entirely on **Cloudflare's free tier** — Workers for the API, D1 (SQLite at the edge) for the database, and R2 for media storage. A Cloudflare account is all the infrastructure a client ever needs.
8
-
9
- ---
10
-
11
- ## Why Beech?
12
-
13
- ### Zero running costs for your clients
14
-
15
- Cloudflare's free tier covers D1, R2, and Workers for the vast majority of real-world content sites. You deliver a fully self-managed product — dashboard, API, media uploads — and the client pays nothing to keep it running. That's a compelling offer.
16
-
17
- ### Native SQL Performance
18
- Unlike other "flexible" CMSs that store data in slow JSON blobs, Beech generates **dedicated SQL tables** for every content type. Enjoy native B-Tree indexing, `REAL` and `INTEGER` types for mathematical operations, and ultra-fast queries.
19
-
20
- ### Schema-as-Code
21
- Define your content model once in TypeScript. The **Botanical Engine** compiles your definitions into deterministic SQL DDL. Run `beech seed:load` and your database schema is automatically synchronized. No manual migrations, no manual SQL, no schema drift.
22
-
23
- ### Works as a dependency, not a boilerplate
24
-
25
- Your project is four files. The BeechCMS engine, dashboard, and API live inside `node_modules/@beechcms/api`. Update with `npm update @beechcms/api`.
26
-
27
- ---
28
-
29
- ## Getting Started
30
-
31
- ```bash
32
- npx @beechcms/cms
33
- ```
34
-
35
- The interactive wizard scaffolds a ready-to-use project in seconds. For everything from configuration to deployment, see the **[Developer Guide](./docs/guide.md)**.
36
-
37
- ---
38
-
39
- ## The Botanical Engine
40
-
41
- The heart of BeechCMS is the **Botanical Engine**, a high-performance **Schema Compiler** that bridges the gap between TypeScript definitions and SQL infrastructure.
42
-
43
- Instead of generic document storage, the Engine analyzes your **Seeds** (content types) and compiles them into **dedicated SQL tables** within Cloudflare D1. Every field you define becomes a native, type-safe SQL column, allowing for:
44
-
45
- - **Native Performance**: Real B-Tree indices and FTS5 virtual tables for ultra-fast filtering and full-text search.
46
- - **Data Integrity**: Native SQL types (REAL, INTEGER, TEXT) with CHECK constraints for robust data handling.
47
- - **Zero-Manual SQL**: Deterministic DDL generation—I define the schema in code, and the Engine handles the database synchronization.
48
-
49
- ---
50
-
51
- ## Tech Stack
52
-
53
- | Layer | Technology |
54
- |---|---|
55
- | Edge runtime | Cloudflare Workers (V8 Isolates) |
56
- | API framework | Hono v4 |
57
- | Database | Cloudflare D1 (SQLite at the edge) |
58
- | Object storage | Cloudflare R2 (zero egress cost) |
59
- | Shared logic | `@beechcms/core` — Botanical Engine, types, validation |
60
- | Dashboard | React 19 + Vite 7 |
61
- | UI | Tailwind CSS v4 + Shadcn/ui |
62
- | Server state | TanStack Query v5 |
63
- | Rich text | TipTap v3 + KaTeX |
64
- | Auth | `jose` JWT + bcryptjs |
65
- | Validation | Zod v4 |
66
- | Testing | Vitest v3 |
67
- | Build orchestration | Turborepo v2 |
68
-
69
-
70
- ---
71
- ## Documentation
72
-
73
- | Document | Description |
74
- |---|---|
75
- | [Developer Guide](./docs/guide.md) | End-to-end guide: scaffolding, seeds, API consumption, deployment |
76
- | [Architecture](./docs/nuovidocs/architecture.md) | Monorepo topology, Botanical Engine data flow, D1 model |
77
- | [API Reference](./docs/nuovidocs/api-reference.md) | Auth, Content CRUD, Media Engine, Public API, rate limiting |
78
- | [Frontend Guide](./docs/nuovidocs/frontend-guide.md) | FieldRenderer registry, TanStack Query patterns, adding field types |
79
- | [System Map](./docs/SYSTEM_MAP.md) | Folder structure, conventions, and architectural constraints |
80
-
81
- ---
82
- # Faq about BeechCMS
83
- ## Why "Beech"?
84
-
85
- One afternoon I was staring at half a CMS with no name. I'd spent weeks building my desk setup — monitors, peripherals, the works — and the last thing I added was a beech wood desktop. I cut it, shaped it, sanded it, finished it until it was exactly right.
86
-
87
- I was sitting at that desk trying to think of a name, looked to the side, and saw the wood. Beech. And then it clicked — seeds, branches, the forest, the fruit. The whole metaphor was already there in the project: content types are seeds, fields are branches, the data that grows from them is the fruit. The name took about three seconds.
88
-
89
- Sometimes the best names aren't invented. They're found.
90
-
91
- ## Why I Built This
92
-
93
- In 2025 I lost a €2,000 contract for a React showcase site for a construction company. The client needed two things beyond a static site: a blog where they could post photos of new builds, and a contact form. Simple requests — but they turned the project into a problem.
94
-
95
- The tools that existed were either too heavy (WordPress, which the client had already had a bad experience with), too expensive once you added hosting and a managed database, or simply not designed to work alongside a modern React frontend without standing up a dedicated backend. The monthly running costs pushed my quote above what a larger agency — one that already had its own internal tooling — could offer. I lost the contract.
96
-
97
- That was the moment I understood the real gap. Small agencies and freelancers don't lose on talent or quality. They lose because they don't have the same leverage as larger competitors who've already amortized the cost of building their own CMS. I decided to build mine.
98
-
99
- **Why Cloudflare?** I was already looking for an alternative to Vercel that didn't require a paid plan for commercial projects. When I discovered that Cloudflare's free tier included not just Workers but also D1 (a relational database at the edge) and R2 (S3-compatible object storage), the whole architecture became clear. A full CMS backend — API, database, media storage, auth — with zero monthly cost for the client.
100
-
101
- **Why the Botanical Engine?** I built the Botanical Engine as a high-performance **Schema Compiler**. It bridges the gap between the flexibility of a CMS and the power of a relational database. Instead of storing data in generic blobs, it compiles TypeScript definitions into native SQL tables and columns. This ensures rigid data integrity (crucial for things like financial records) and unlocks massive performance gains by leveraging native D1 indexing. This true relational model maintains the simplicity of "Schema-as-Code" while allowing for advanced features like cross-seed relations and complex aggregations.
102
-
103
- **What I learned building it.** BeechCMS is my first serious serverless project. I had no prior experience with Cloudflare Workers, edge computing, or D1. Everything I know about this stack I learned by building this — reading documentation, hitting limits, understanding why they exist, and finding the right abstractions. The project is currently in active development toward a public 1.0 release and is already available on npm.
104
-
105
- ---
106
-
107
- _BeechCMS — Precision-engineered content infrastructure for the edge._
1
+ ![beechLogoDark.png](docs/images/beechLogoDark.png)
2
+
3
+ **BeechCMS** is a precision-engineered, solo-developer headless CMS built for developers who deliver high-performance websites for clients with **zero infrastructure overhead**.
4
+
5
+ The pitch is simple: you build the site, you hand it over, and your client can manage their own content forever — with **zero hosting costs**. No monthly subscriptions, no server bills, no maintenance contract needed just to keep the lights on.
6
+
7
+ This is possible because BeechCMS runs entirely on **Cloudflare's free tier** — Workers for the API, D1 (SQLite at the edge) for the database, and R2 for media storage. A Cloudflare account is all the infrastructure a client ever needs.
8
+
9
+ ---
10
+
11
+ ## Why Beech?
12
+
13
+ ### Zero running costs for your clients
14
+
15
+ Cloudflare's free tier covers D1, R2, and Workers for the vast majority of real-world content sites. You deliver a fully self-managed product — dashboard, API, media uploads — and the client pays nothing to keep it running. That's a compelling offer.
16
+
17
+ ### Native SQL Performance
18
+ Unlike other "flexible" CMSs that store data in slow JSON blobs, Beech generates **dedicated SQL tables** for every content type. Enjoy native B-Tree indexing, `REAL` and `INTEGER` types for mathematical operations, and ultra-fast queries.
19
+
20
+ ### Schema-as-Code
21
+ Define your content model once in TypeScript. The **Botanical Engine** compiles your definitions into deterministic SQL DDL. Run `beech seed:load` and your database schema is automatically synchronized. No manual migrations, no manual SQL, no schema drift.
22
+
23
+ ### Works as a dependency, not a boilerplate
24
+
25
+ Your project is four files. The BeechCMS engine, dashboard, and API live inside `node_modules/@beechcms/api`. Update with `npm update @beechcms/api`.
26
+
27
+ ---
28
+
29
+ ## Getting Started
30
+
31
+ ```bash
32
+ npx @beechcms/cms
33
+ ```
34
+
35
+ The interactive wizard scaffolds a ready-to-use project in seconds. For everything from configuration to deployment, see the **[Developer Guide](./docs/guide.md)**.
36
+
37
+ ---
38
+
39
+ ## The Botanical Engine
40
+
41
+ The heart of BeechCMS is the **Botanical Engine**, a high-performance **Schema Compiler** that bridges the gap between TypeScript definitions and SQL infrastructure.
42
+
43
+ Instead of generic document storage, the Engine analyzes your **Seeds** (content types) and compiles them into **dedicated SQL tables** within Cloudflare D1. Every field you define becomes a native, type-safe SQL column, allowing for:
44
+
45
+ - **Native Performance**: Real B-Tree indices and FTS5 virtual tables for ultra-fast filtering and full-text search.
46
+ - **Data Integrity**: Native SQL types (REAL, INTEGER, TEXT) with CHECK constraints for robust data handling.
47
+ - **Zero-Manual SQL**: Deterministic DDL generation—I define the schema in code, and the Engine handles the database synchronization.
48
+
49
+ ---
50
+
51
+ ## Tech Stack
52
+
53
+ | Layer | Technology |
54
+ |---|---|
55
+ | Edge runtime | Cloudflare Workers (V8 Isolates) |
56
+ | API framework | Hono v4 |
57
+ | Database | Cloudflare D1 (SQLite at the edge) |
58
+ | Object storage | Cloudflare R2 (zero egress cost) |
59
+ | Shared logic | `@beechcms/core` — Botanical Engine, types, validation |
60
+ | Dashboard | React 19 + Vite 7 |
61
+ | UI | Tailwind CSS v4 + Shadcn/ui |
62
+ | Server state | TanStack Query v5 |
63
+ | Rich text | TipTap v3 + KaTeX |
64
+ | Auth | `jose` JWT + bcryptjs |
65
+ | Validation | Zod v4 |
66
+ | Testing | Vitest v3 |
67
+ | Build orchestration | Turborepo v2 |
68
+
69
+
70
+ ---
71
+ ## Documentation
72
+
73
+ | Document | Description |
74
+ |---|---|
75
+ | [Developer Guide](./docs/guide.md) | End-to-end guide: scaffolding, seeds, API consumption, deployment |
76
+ | [Architecture](./docs/nuovidocs/architecture.md) | Monorepo topology, Botanical Engine data flow, D1 model |
77
+ | [API Reference](./docs/nuovidocs/api-reference.md) | Auth, Content CRUD, Media Engine, Public API, rate limiting |
78
+ | [Frontend Guide](./docs/nuovidocs/frontend-guide.md) | FieldRenderer registry, TanStack Query patterns, adding field types |
79
+ | [System Map](./docs/SYSTEM_MAP.md) | Folder structure, conventions, and architectural constraints |
80
+
81
+ ---
82
+ # Faq about BeechCMS
83
+ ## Why "Beech"?
84
+
85
+ One afternoon I was staring at half a CMS with no name. I'd spent weeks building my desk setup — monitors, peripherals, the works — and the last thing I added was a beech wood desktop. I cut it, shaped it, sanded it, finished it until it was exactly right.
86
+
87
+ I was sitting at that desk trying to think of a name, looked to the side, and saw the wood. Beech. And then it clicked — seeds, branches, the forest, the fruit. The whole metaphor was already there in the project: content types are seeds, fields are branches, the data that grows from them is the fruit. The name took about three seconds.
88
+
89
+ Sometimes the best names aren't invented. They're found.
90
+
91
+ ## Why I Built This
92
+
93
+ In 2025 I lost a €2,000 contract for a React showcase site for a construction company. The client needed two things beyond a static site: a blog where they could post photos of new builds, and a contact form. Simple requests — but they turned the project into a problem.
94
+
95
+ The tools that existed were either too heavy (WordPress, which the client had already had a bad experience with), too expensive once you added hosting and a managed database, or simply not designed to work alongside a modern React frontend without standing up a dedicated backend. The monthly running costs pushed my quote above what a larger agency — one that already had its own internal tooling — could offer. I lost the contract.
96
+
97
+ That was the moment I understood the real gap. Small agencies and freelancers don't lose on talent or quality. They lose because they don't have the same leverage as larger competitors who've already amortized the cost of building their own CMS. I decided to build mine.
98
+
99
+ **Why Cloudflare?** I was already looking for an alternative to Vercel that didn't require a paid plan for commercial projects. When I discovered that Cloudflare's free tier included not just Workers but also D1 (a relational database at the edge) and R2 (S3-compatible object storage), the whole architecture became clear. A full CMS backend — API, database, media storage, auth — with zero monthly cost for the client.
100
+
101
+ **Why the Botanical Engine?** I built the Botanical Engine as a high-performance **Schema Compiler**. It bridges the gap between the flexibility of a CMS and the power of a relational database. Instead of storing data in generic blobs, it compiles TypeScript definitions into native SQL tables and columns. This ensures rigid data integrity (crucial for things like financial records) and unlocks massive performance gains by leveraging native D1 indexing. This true relational model maintains the simplicity of "Schema-as-Code" while allowing for advanced features like cross-seed relations and complex aggregations.
102
+
103
+ **What I learned building it.** BeechCMS is my first serious serverless project. I had no prior experience with Cloudflare Workers, edge computing, or D1. Everything I know about this stack I learned by building this — reading documentation, hitting limits, understanding why they exist, and finding the right abstractions. The project is currently in active development toward a public 1.0 release and is already available on npm.
104
+
105
+ ---
106
+
107
+ _BeechCMS — Precision-engineered content infrastructure for the edge._
package/bin/cli.mjs CHANGED
@@ -1,129 +1,188 @@
1
- #!/usr/bin/env node
2
- // @ts-check
3
-
4
- import { spawnSync } from 'node:child_process'
5
- import { existsSync } from 'node:fs'
6
- import { resolve } from 'node:path'
7
- import { pathToFileURL } from 'node:url'
8
-
9
-
10
- const [,, command, ...args] = process.argv
11
-
12
- const COMMANDS = {
13
- build: cmdBuild,
14
- 'seed:load': cmdSeedLoad,
15
- }
16
-
17
- function help() {
18
- console.log(`
19
- beech <command> [options]
20
-
21
- Commands:
22
- build Rebuild @beechcms/core after editing seeds.ts
23
- seed:load Create/update DB tables from SEED_REGISTRY
24
- --dry-run Print SQL without executing
25
- --diff Show schema differences vs current DB
26
- --remote Execute against remote D1 (default: local)
27
- --db <name> Override D1 database name
28
-
29
- Run npx @beechcms/cms to scaffold a new project.
30
- `)
31
- }
32
-
33
- function cmdBuild() {
34
- console.log(
35
- '\nNo build step needed for BeechCMS projects.\n' +
36
- 'Edit seeds.ts then run `npx beech seed:load` to sync schema changes to D1.\n'
37
- )
38
- }
39
-
40
- async function tryLoadLocalRegistry() {
41
- const cwd = process.cwd()
42
-
43
- // Try compiled JS first (root or apps/api)
44
- const searchDirs = [cwd, resolve(cwd, 'apps', 'api')]
45
- for (const dir of searchDirs) {
46
- for (const name of ['seeds.js', 'seeds.mjs', 'seed.js', 'seed.mjs']) {
47
- const p = resolve(dir, name)
48
- if (existsSync(p)) {
49
- try {
50
- const mod = await import(pathToFileURL(p).href)
51
- if (mod.SEED_REGISTRY && typeof mod.SEED_REGISTRY === 'object') {
52
- return mod.SEED_REGISTRY
53
- }
54
- if (Array.isArray(mod.seeds)) {
55
- return Object.fromEntries(mod.seeds.map(s => [s.slug, s]))
56
- }
57
- if (Array.isArray(mod.default)) {
58
- return Object.fromEntries(mod.default.map(s => [s.slug, s]))
59
- }
60
- } catch {}
61
- }
62
- }
63
- }
64
-
65
- // Try seeds.ts / seed.ts (root or apps/api)
66
- let tsPath = null
67
- for (const dir of searchDirs) {
68
- const p = existsSync(resolve(dir, 'seeds.ts'))
69
- ? resolve(dir, 'seeds.ts')
70
- : resolve(dir, 'seed.ts')
71
- if (existsSync(p)) {
72
- tsPath = p
73
- break
74
- }
75
- }
76
-
77
- if (tsPath) {
78
- const result = spawnSync(process.execPath, [
79
- '--experimental-strip-types',
80
- '--input-type=module',
81
- '--eval',
82
- `
83
- import * as mod from ${JSON.stringify(pathToFileURL(tsPath).href)};
84
- let out = null;
85
- if (mod.SEED_REGISTRY && typeof mod.SEED_REGISTRY === 'object') out = mod.SEED_REGISTRY;
86
- else if (Array.isArray(mod.seeds)) out = Object.fromEntries(mod.seeds.map(s => [s.slug, s]));
87
- else if (Array.isArray(mod.default)) out = Object.fromEntries(mod.default.map(s => [s.slug, s]));
88
- if (out) process.stdout.write(JSON.stringify(out));
89
- `.trim(),
90
- ], { encoding: 'utf-8' })
91
-
92
- if (result.status === 0 && result.stdout) {
93
- try { return JSON.parse(result.stdout) } catch (err) {
94
- console.error(' Failed to parse seeds.ts output:', err)
95
- }
96
- } else if (result.status !== 0) {
97
- console.error(' Error loading seeds.ts:')
98
- console.error(result.stderr || result.stdout || 'Unknown error')
99
- if (process.version.slice(1).split('.')[0] < 22) {
100
- console.warn(' Note: Node.js 22.6+ is required to load .ts files directly. Current version:', process.version)
101
- }
102
- }
103
- }
104
-
105
- return null
106
- }
107
-
108
- async function cmdSeedLoad(args) {
109
- const dryRun = args.includes('--dry-run')
110
- const diff = args.includes('--diff')
111
- const remote = args.includes('--remote')
112
- const dbIdx = args.indexOf('--db')
113
- const db = dbIdx !== -1 ? args[dbIdx + 1] : undefined
114
-
115
- const registry = await tryLoadLocalRegistry()
116
-
117
- const { seedLoad } = await import('@beechcms/cli')
118
- await seedLoad({ dryRun, diff, local: !remote, db, registry })
119
- }
120
-
121
- const handler = COMMANDS[command]
122
- if (!handler) {
123
- help()
124
- if (command) process.exit(1)
125
- } else if (args.includes('--help') || args.includes('-h')) {
126
- help()
127
- } else {
128
- await handler(args)
129
- }
1
+ #!/usr/bin/env node
2
+ // @ts-check
3
+
4
+ import { spawnSync } from 'node:child_process'
5
+ import { existsSync } from 'node:fs'
6
+ import { resolve } from 'node:path'
7
+ import { pathToFileURL } from 'node:url'
8
+
9
+
10
+ const [,, command, ...args] = process.argv
11
+
12
+ const COMMANDS = {
13
+ build: cmdBuild,
14
+ 'seed:load': cmdSeedLoad,
15
+ 'seed:create': cmdSeedCreate,
16
+ 'init': cmdInit,
17
+ 'validate': cmdValidate,
18
+ 'deploy': cmdDeploy,
19
+ }
20
+
21
+ function help() {
22
+ console.log(`
23
+ beech <command> [options]
24
+
25
+ Commands:
26
+ init Check project files and optionally initialise the database
27
+ --db Also initialise the D1 database (system tables)
28
+ --remote Target remote D1 instead of local (default: local)
29
+ --db-name <n> Override D1 database name
30
+
31
+ build Rebuild @beechcms/core after editing seeds.ts
32
+
33
+ validate Validate SEED_REGISTRY for common errors (duplicate aliases,
34
+ missing displayNameAlias, duplicate slugs). Exit code 1 on errors.
35
+
36
+ seed:load Create/update content tables from SEED_REGISTRY
37
+ --dry-run Print SQL without executing
38
+ --diff Show schema differences vs current DB
39
+ --remote Execute against remote D1 (default: local)
40
+ --db <name> Override D1 database name
41
+
42
+ seed:create Interactive wizard — generate a new Seed definition and append
43
+ it to seeds.ts, including SEED_REGISTRY entry
44
+
45
+ deploy Deploy Worker, sync remote schema, and verify /admin
46
+ --skip-seed Skip remote seed:load step
47
+ --skip-check Skip /admin reachability check
48
+
49
+ Scaffold a new project (interactive, or pass --yes for non-interactive defaults):
50
+ npm create @beechcms/cms [project-name] [--yes] [--with-examples]
51
+
52
+ Golden path (local):
53
+ npx beech init --db --local
54
+ npx beech seed:load --local
55
+ npx wrangler dev
56
+
57
+ Golden path (deploy):
58
+ npx beech deploy
59
+ npx beech init --db --remote # verify remote DB post-deploy
60
+ `)
61
+ }
62
+
63
+ function cmdBuild() {
64
+ console.log(
65
+ '\nNo build step needed for BeechCMS projects.\n' +
66
+ 'Edit seeds.ts then run `npx beech seed:load` to sync schema changes to D1.\n'
67
+ )
68
+ }
69
+
70
+ async function tryLoadLocalRegistry() {
71
+ const cwd = process.cwd()
72
+
73
+ // Try compiled JS first (root or apps/api)
74
+ const searchDirs = [cwd, resolve(cwd, 'apps', 'api')]
75
+ for (const dir of searchDirs) {
76
+ for (const name of ['seeds.js', 'seeds.mjs', 'seed.js', 'seed.mjs']) {
77
+ const p = resolve(dir, name)
78
+ if (existsSync(p)) {
79
+ try {
80
+ const mod = await import(pathToFileURL(p).href)
81
+ if (mod.SEED_REGISTRY && typeof mod.SEED_REGISTRY === 'object') {
82
+ return mod.SEED_REGISTRY
83
+ }
84
+ if (Array.isArray(mod.seeds)) {
85
+ return Object.fromEntries(mod.seeds.map(s => [s.slug, s]))
86
+ }
87
+ if (Array.isArray(mod.default)) {
88
+ return Object.fromEntries(mod.default.map(s => [s.slug, s]))
89
+ }
90
+ } catch {}
91
+ }
92
+ }
93
+ }
94
+
95
+ // Try seeds.ts / seed.ts (root or apps/api)
96
+ let tsPath = null
97
+ for (const dir of searchDirs) {
98
+ const p = existsSync(resolve(dir, 'seeds.ts'))
99
+ ? resolve(dir, 'seeds.ts')
100
+ : resolve(dir, 'seed.ts')
101
+ if (existsSync(p)) {
102
+ tsPath = p
103
+ break
104
+ }
105
+ }
106
+
107
+ if (tsPath) {
108
+ const result = spawnSync(process.execPath, [
109
+ '--experimental-strip-types',
110
+ '--input-type=module',
111
+ '--eval',
112
+ `
113
+ import * as mod from ${JSON.stringify(pathToFileURL(tsPath).href)};
114
+ let out = null;
115
+ if (mod.SEED_REGISTRY && typeof mod.SEED_REGISTRY === 'object') out = mod.SEED_REGISTRY;
116
+ else if (Array.isArray(mod.seeds)) out = Object.fromEntries(mod.seeds.map(s => [s.slug, s]));
117
+ else if (Array.isArray(mod.default)) out = Object.fromEntries(mod.default.map(s => [s.slug, s]));
118
+ if (out) process.stdout.write(JSON.stringify(out));
119
+ `.trim(),
120
+ ], { encoding: 'utf-8' })
121
+
122
+ if (result.status === 0 && result.stdout) {
123
+ try { return JSON.parse(result.stdout) } catch (err) {
124
+ console.error(' Failed to parse seeds.ts output:', err)
125
+ }
126
+ } else if (result.status !== 0) {
127
+ console.error(' Error loading seeds.ts:')
128
+ console.error(result.stderr || result.stdout || 'Unknown error')
129
+ if (process.version.slice(1).split('.')[0] < 22) {
130
+ console.warn(' Note: Node.js 22.6+ is required to load .ts files directly. Current version:', process.version)
131
+ }
132
+ }
133
+ }
134
+
135
+ return null
136
+ }
137
+
138
+ async function cmdInit(args) {
139
+ const initDb = args.includes('--db')
140
+ const remote = args.includes('--remote')
141
+ const dbIdx = args.indexOf('--db-name')
142
+ const db = dbIdx !== -1 ? args[dbIdx + 1] : undefined
143
+
144
+ const { init } = await import('@beechcms/cli')
145
+ await init({ initDb, local: !remote, db })
146
+ }
147
+
148
+ async function cmdSeedLoad(args) {
149
+ const dryRun = args.includes('--dry-run')
150
+ const diff = args.includes('--diff')
151
+ const remote = args.includes('--remote')
152
+ const dbIdx = args.indexOf('--db')
153
+ const db = dbIdx !== -1 ? args[dbIdx + 1] : undefined
154
+
155
+ const registry = await tryLoadLocalRegistry()
156
+
157
+ const { seedLoad } = await import('@beechcms/cli')
158
+ await seedLoad({ dryRun, diff, local: !remote, db, registry })
159
+ }
160
+
161
+ async function cmdValidate(args) {
162
+ const registry = await tryLoadLocalRegistry()
163
+ const { validate } = await import('@beechcms/cli')
164
+ await validate({ registry })
165
+ }
166
+
167
+ async function cmdSeedCreate(_args) {
168
+ const { seedCreate } = await import('@beechcms/cli')
169
+ await seedCreate({})
170
+ }
171
+
172
+ async function cmdDeploy(args) {
173
+ const skipSeed = args.includes('--skip-seed')
174
+ const skipCheck = args.includes('--skip-check')
175
+ const registry = skipSeed ? null : await tryLoadLocalRegistry()
176
+ const { deploy } = await import('@beechcms/cli')
177
+ await deploy({ registry, skipSeed, skipCheck })
178
+ }
179
+
180
+ const handler = COMMANDS[command]
181
+ if (!handler) {
182
+ help()
183
+ if (command) process.exit(1)
184
+ } else if (args.includes('--help') || args.includes('-h')) {
185
+ help()
186
+ } else {
187
+ await handler(args)
188
+ }