@unbase-app/cli 0.3.0 → 0.4.1

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/AGENTS.md CHANGED
@@ -32,7 +32,31 @@ These are conventions, not an Unbase runtime: everything the steps ask for is pl
32
32
  framework that a developer would write, it renders the same with or without Unbase, and you can
33
33
  follow it while a site is first written.
34
34
 
35
+ ## Renaming, duplicating and deleting pages
36
+
37
+ Don't move, copy or delete a page by hand: use the CLI, which does it by Unbase's own rule and so
38
+ makes exactly the changes Unbase's editor would (the page's files, the links to it, its route
39
+ file, `unbase.pages.json`).
40
+
41
+ ```bash
42
+ npx @unbase-app/cli page list # what each page can do here, and why not
43
+ npx @unbase-app/cli page rename /funding /financiering [--name "Financiering"] [--not-live]
44
+ npx @unbase-app/cli page duplicate /pricing [/pricing-2027] [--name "Pricing 2027"]
45
+ npx @unbase-app/cli page delete /old-offer [--redirect /pricing | --not-found] [--not-live]
46
+ ```
47
+
48
+ - Run it with `--dry-run --json` first; it writes the files in the working tree and commits nothing.
49
+ - A page counts as live unless you pass `--not-live` (only for a page that was never on the live
50
+ site). A live page renamed or deleted leaves a redirect in `unbase.pages.json`; never write
51
+ that redirect into the framework's config yourself, and never remove one.
52
+ - A refusal exits 1 with its reason and what it means. `no_redirects`: the site's Unbase package
53
+ is too old to apply redirects; run `npx @unbase-app/cli init` to update it, never `--not-live`
54
+ for a page that was live. `content_bound`, `unparsed`: leave it to a person or Unbase's Operator.
55
+ - `unlinked` lists files that still name a deleted page's address (a link built at runtime, or one
56
+ the rule leaves alone): change those by hand where the site's text allows it.
57
+
35
58
  ## Leaving
36
59
 
37
- `npx @unbase-app/cli uninstall` takes out what init added, after the drafts are published or deleted, and
38
- compares every built page before and after.
60
+ `npx @unbase-app/cli uninstall` takes out what init added, after the drafts are published or deleted
61
+ and the redirects in `unbase.pages.json` are in the site's own config, and compares every built
62
+ page before and after.
package/README.md CHANGED
@@ -6,6 +6,7 @@ Adds [Unbase](https://unbase.app) to an Astro, Vite + React or Next.js site, che
6
6
  npx @unbase-app/cli init # the framework's package, its line in its config, comment-modus.json
7
7
  npx @unbase-app/cli doctor # per feature: on, or what is missing, where, and how to fix it
8
8
  npx @unbase-app/cli uninstall # all of it out again; the built pages compared before and after
9
+ npx @unbase-app/cli page … # rename, duplicate or delete a page, as Unbase's editor does
9
10
  ```
10
11
 
11
12
  Always with the package's name: the unscoped `unbase` on npm is another product's package, so a
@@ -56,7 +57,7 @@ versions:
56
57
 
57
58
  | Package | Version | |
58
59
  |---|---|---|
59
- | `@unbase-app/astro` | 0.2.0 | Unbase in an Astro site, one integration: comment mode (`@jens4m/comment-modus` 1.9.0: comments on the live site; it writes the content schemas Unbase reads), the draft-pages kit (`@unbase-app/pages` 0.3.0: draft pages kept out of production builds) and the analytics beacon (`@unbase-app/analytics` 0.1.0) |
60
+ | `@unbase-app/astro` | 0.3.0 | Unbase in an Astro site, one integration: comment mode (`@jens4m/comment-modus` 1.9.0: comments on the live site; it writes the content schemas Unbase reads), the draft-pages kit (`@unbase-app/pages` 0.4.0: draft pages kept out of production builds, and the redirects a moved page leaves applied) and the analytics beacon (`@unbase-app/analytics` 0.1.0) |
60
61
  | `@unbase-app/cli` | this one | devDependency: `AGENTS.md` and `doctor`, pinned |
61
62
 
62
63
  In `astro.config`, found and changed through its syntax tree, never by text substitution:
@@ -83,7 +84,7 @@ second run changes nothing. It touches no content.
83
84
 
84
85
  ### Vite + React
85
86
 
86
- One package, `@unbase-app/vite` (a devDependency, beside `vite`), at 0.2.0: the draft-pages kit, the analytics beacon and
87
+ One package, `@unbase-app/vite` (a devDependency, beside `vite`), at 0.3.0: the draft-pages kit, the analytics beacon and
87
88
  comment mode's loader in one Vite plugin. In `vite.config`, through its syntax tree (Lovable's
88
89
  `defineConfig(({ mode }) => ({ … }))` and `plugins: [ … ].filter(Boolean)` included):
89
90
 
@@ -101,7 +102,7 @@ Unbase reads and writes as it is; it has no page settings, so nothing is written
101
102
 
102
103
  ### Next.js
103
104
 
104
- On a Next.js site `init` adds `@unbase-app/next` (0.2.0) and wraps the config `next.config` hands Next.js in
105
+ On a Next.js site `init` adds `@unbase-app/next` (0.3.0) and wraps the config `next.config` hands Next.js in
105
106
  `withUnbase(…)` (through its syntax tree; a CommonJS config gets the `require`), writes
106
107
  `comment-modus.json`, and on a Next.js from 15.3 to 16.2 imports the comments' loader in
107
108
  `instrumentation-client.ts` (from 16.3 `withUnbase` injects it). `doctor` builds with `next build`
@@ -196,7 +197,9 @@ an older comment-modus that ignores `"preview"`.
196
197
  ## `unbase uninstall`
197
198
 
198
199
  Refuses while `unbase.pages.json` holds a draft, and lists them: without the kit a draft is built
199
- and goes live, so each is published or deleted in Unbase first. Then it builds the site, removes
200
+ and goes live, so each is published or deleted in Unbase first. It refuses too while the file
201
+ sends old addresses on (`redirects`, left by renaming or deleting a live page), and lists them:
202
+ only the package applies them, so they go into the site's own redirects first. Then it builds the site, removes
200
203
  the packages, their lines in `astro.config`, `comment-modus.json`, `unbase.pages.json`,
201
204
  `src/content/.schemas/`, the collector in the CSP of `vercel.json` and `public/_headers`, and the
202
205
  pointer line, builds again, and compares every page's HTML. Taken out first: comment mode's markers
@@ -208,6 +211,54 @@ a terminal; `--no-build` skips the comparison; `--no-install` writes `package.js
208
211
 
209
212
  The route files, the settings file and the layout's reads stay: they are the site's own code.
210
213
 
214
+ ## `unbase page`
215
+
216
+ Renames, duplicates and deletes a page by the kit's own rule (`planPage` in `@unbase-app/pages`'s
217
+ core, bundled here), so the files change exactly as they do when Unbase's editor does it: the
218
+ same files always give the same changes. It writes them in the working tree and commits nothing;
219
+ review them with `git diff` and commit them yourself.
220
+
221
+ ```bash
222
+ npx @unbase-app/cli page rename /funding /financiering --name Financiering
223
+ npx @unbase-app/cli page duplicate /pricing /pricing-2027
224
+ npx @unbase-app/cli page delete /old-offer --redirect /pricing
225
+ npx @unbase-app/cli page list
226
+ ```
227
+
228
+ | Command | |
229
+ |---|---|
230
+ | `page rename <from> <to> [--name <name>] [--not-live]` | A new address: the page's files move (on Next.js its folder, on React Router the route's `path`), every quoted link to it or below it in code and content follows, its route file's `pad` too, and the pages under it come along. `--name` sets its name in Unbase (`<to>` the same as `<from>`: only the name) |
231
+ | `page duplicate <path> [<to>] [--name <name>]` | A copy, by default at the first free `<path>-copy`, with its own copy of what only the page owns (its modules and content); a draft where the kit is installed. Named "… (copy)" when the original has a name |
232
+ | `page delete <path> [--redirect <to> \| --not-found] [--not-live]` | Its file and what only it owns; shared parts stay. The links to it are listed, not changed. Visitors to the old address go to the page above it, `--redirect`'s page, or with `--not-found` nowhere |
233
+ | `page list [--not-live]` | Per page: whether it can be renamed, duplicated and deleted here, and if not, why |
234
+
235
+ Every one takes `--dry-run` (print the changes, write nothing), `--json` and `--dir`.
236
+
237
+ **Live pages.** A page counts as live unless `--not-live` says it was never on the live site. A
238
+ live page renamed or deleted leaves a redirect in `unbase.pages.json` (old address → new), which
239
+ the framework's package applies at build from `@unbase-app/astro` 0.3.0, `@unbase-app/vite` 0.3.0
240
+ and `@unbase-app/next` 0.3.0 on (`@unbase-app/pages` 0.4.0). On a site with an older one, or none,
241
+ a live rename or delete is refused (`no_redirects`) instead of breaking the old address: run
242
+ `unbase init` to update, or pass `--not-live` for a page that never was live.
243
+
244
+ **Refusals** exit 1 with the reason and what it means (`--json`: `reason`, `detail`, `message`):
245
+
246
+ | Reason | |
247
+ |---|---|
248
+ | `home` | Home can be duplicated, not renamed or deleted |
249
+ | `nested` | Delete: pages are under it; delete those first |
250
+ | `taken` | The new address is a page already, or the site's own redirects send it on |
251
+ | `address` | Not an address the page can have (plain segments, not under itself), or `--redirect` is not a page |
252
+ | `no_redirects` | A live page leaves a redirect, and this site's build does not apply them (above) |
253
+ | `content_bound` | Duplicate: its content is a collection of its own, and a copy needs code the kit does not write. Unbase's Operator can do it |
254
+ | `content_unregistered` | It reads content by a name no content file goes by |
255
+ | `template` | The page is made by a dynamic route: change it where its data is |
256
+ | `unparsed` | The kit cannot trace the page's route to its file |
257
+ | `missing` | The code makes no page at this address |
258
+ | `same` | Nothing to change |
259
+ | `invalid` | `unbase.pages.json` is not valid |
260
+ | `framework` | Not Astro, Next.js or Vite + React Router |
261
+
211
262
  ## For programs
212
263
 
213
264
  - **Never asks without a terminal.** A choice without its flag is an error (exit 2) naming the
@@ -221,10 +272,17 @@ The route files, the settings file and the layout's reads stay: they are the sit
221
272
  with `state` (`on`, `off`, `waiting`, `not-installed`) and `checks` (`id`, `state`, `message`,
222
273
  and for a `missing` or `waiting` check `missing`, `file`, `step`). `uninstall`: `files`
223
274
  (every file it touched, the lockfile included), `packages`, `comparison` (`pages`,
224
- `differences`, `secondBuild`), or `refused: "drafts"` with `drafts`.
275
+ `differences`, `secondBuild`), or `refused: "drafts"` with `drafts`, or `refused: "redirects"`
276
+ with `redirects`. `page`: `files` (each
277
+ `path` and `action`: `created`, `changed`, `moved` or `copied` with `from`, or `deleted`),
278
+ `links` (files whose links it rewrote), `unlinked` (files that still name the old address),
279
+ `redirects` (what changed in `unbase.pages.json`: source → destination, `null` for one that
280
+ went), `moves` (the addresses), `dryRun`; refused: `reason`, `detail`, `message`. `page list`:
281
+ `pages`, each with `rename`, `duplicate` and `delete` as `{ ok }` or `{ ok: false, reason }`,
282
+ and `redirects` (whether the site's build applies them).
225
283
  An error: `{ ok: false, exitCode: 2, error: { code, message, file? } }`.
226
284
  - **Exit codes:** `0` passed, `1` failed (doctor found something missing; uninstall refused or
227
- found a difference), `2` could not run (usage, no Astro site, a config it cannot edit safely, an
285
+ found a difference; a page action refused), `2` could not run (usage, no Astro site, a config it cannot edit safely, an
228
286
  install that failed).
229
287
  - **No login, no project, no network** beyond the package manager's install: it never calls Unbase,
230
288
  and the versions are pinned.
package/bin/unbase.mjs CHANGED
@@ -6,17 +6,24 @@
6
6
  // [--no-install] [--tarballs <dir>] [--yes] [--json] [--dir <path>]
7
7
  // unbase doctor [--no-build] [--json] [--dir <path>]
8
8
  // unbase uninstall [--yes] [--no-build] [--no-install] [--json] [--dir <path>]
9
+ // unbase page rename <from> <to> [--name <name>] [--not-live]
10
+ // duplicate <path> [<to>] [--name <name>]
11
+ // delete <path> [--redirect <to> | --not-found] [--not-live]
12
+ // list [--not-live]
13
+ // [--dry-run] [--json] [--dir <path>]
9
14
  //
10
15
  // Exit codes: 0 passed, 1 failed, 2 could not run. Never asks without a
11
16
  // terminal: a choice without its flag is an error. Never calls Unbase.
12
17
  // ============================================================================
13
18
 
14
19
  import { createInterface } from "node:readline/promises";
20
+ import { renderContent } from "../lib/content.mjs";
15
21
  import { doctor } from "../lib/doctor.mjs";
16
22
  import { COULD_NOT_RUN, CouldNotRun } from "../lib/errors.mjs";
17
23
  import { FRAMEWORKS } from "../lib/frameworks/index.mjs";
18
24
  import { init } from "../lib/init.mjs";
19
25
  import { parseArgs } from "../lib/args.mjs";
26
+ import { page } from "../lib/page.mjs";
20
27
  import { uninstall } from "../lib/uninstall.mjs";
21
28
  import { SELF } from "../lib/versions.mjs";
22
29
 
@@ -39,12 +46,24 @@ const USAGE = `unbase ${SELF.version}: Unbase in a site (${FRAMEWORKS.map((f) =>
39
46
  --yes do it without asking
40
47
  --no-build skip the comparison
41
48
  --no-install change package.json only
49
+ unbase page Rename, duplicate or delete a page by the kit's rule, the changes Unbase's
50
+ editor makes; written in the working tree, never committed
51
+ rename <from> <to> a new address (the links and its route file follow)
52
+ duplicate <path> [<to>] a copy, by default at <path>-copy; a draft where the site has drafts
53
+ delete <path> its file and what only it owns; links to it are listed
54
+ list what each page can do here, and why not
55
+ --name <name> the page's name in Unbase (rename, duplicate)
56
+ --redirect <to> | --not-found
57
+ delete: where visitors to the old address go (default: the page
58
+ above it)
59
+ --not-live the page was never on the live site: no redirect is left
60
+ --dry-run print the changes, write nothing
42
61
 
43
62
  All: --json (for programs), --dir <path> (the site's folder; default: here)
44
63
  Exit codes: 0 passed, 1 failed, 2 could not run.
45
64
  After init: node_modules/${SELF.name}/AGENTS.md has the steps left to do.`;
46
65
 
47
- const COMMANDS = { init, doctor, uninstall };
66
+ const COMMANDS = { init, doctor, uninstall, page };
48
67
 
49
68
  function makeIo(json) {
50
69
  const interactive = !json && !!process.stdin.isTTY && !!process.stdout.isTTY;
@@ -100,10 +119,12 @@ function render(r) {
100
119
  if (c.detail && c.state !== "ok") out.push(...String(c.detail).split("\n").map((l) => ` | ${l}`));
101
120
  }
102
121
  }
122
+ out.push(...renderContent(r.content));
103
123
  const s = r.summary;
104
124
  out.push("", r.ok ? `Passed: ${s.on} on${s.waiting ? `, ${s.waiting} waiting on something outside this repository` : ""}${s.notInstalled ? `, ${s.notInstalled} not installed` : ""}.` : `Failed: ${s.off} feature(s) need a change in the site.`);
105
125
  } else if (r.command === "uninstall") {
106
126
  if (r.refused === "drafts") out.push(r.message, ...r.drafts.map((d) => ` ${d}`));
127
+ else if (r.refused === "redirects") out.push(r.message, ...Object.entries(r.redirects).map(([from, to]) => ` ${from} → ${to}`));
107
128
  else {
108
129
  for (const f of r.files ?? []) {
109
130
  out.push(` ${f.action} ${f.file}`);
@@ -115,14 +136,45 @@ function render(r) {
115
136
  if (d.before) out.push(` before: …${d.before}…`, ` after: …${d.after}…`);
116
137
  }
117
138
  }
139
+ } else if (r.command === "page") {
140
+ out.push(...renderPage(r));
118
141
  }
119
142
  return out.join("\n");
120
143
  }
121
144
 
145
+ const CHANGE = { created: "+", changed: "~", moved: "→", copied: "+", deleted: "-" };
146
+
147
+ function renderPage(r) {
148
+ const out = [];
149
+ if (r.action === "list") {
150
+ const cell = (c) => (c.ok ? "yes" : `no (${c.reason})`);
151
+ for (const p of r.pages) {
152
+ out.push(`${p.path}${p.name ? ` "${p.name}"` : ""}${p.draft ? " draft" : ""}`);
153
+ out.push(` rename ${cell(p.rename)} · duplicate ${cell(p.duplicate)} · delete ${cell(p.delete)}`);
154
+ }
155
+ out.push("", r.live ? "Every page counted as live (--not-live: as never live)." : "No page counted as live.");
156
+ out.push(
157
+ r.redirects
158
+ ? "This site's build applies the redirects a live rename or delete leaves."
159
+ : `This site's build does not apply redirects yet, so a live page cannot be renamed or deleted with one${r.package ? `: ${r.package} ${r.since} or later does` : ""}.`,
160
+ );
161
+ return out;
162
+ }
163
+ if (!r.ok) return [`unbase page ${r.action} ${r.path}: refused (${r.reason})`, ` ${r.message}`];
164
+ out.push(`${r.message}${r.dryRun ? " (dry run: nothing written)" : ""}`);
165
+ out.push(` files: ${r.files.length}`);
166
+ for (const f of r.files) out.push(` ${CHANGE[f.action] ?? "~"} ${f.path}${f.from ? ` (${f.action} from ${f.from})` : f.action === "deleted" ? " (deleted)" : ""}`);
167
+ if (r.links.length) out.push(` links rewritten: ${r.links.length}`, ...r.links.map((l) => ` ${l}`));
168
+ if (r.unlinked.length) out.push(` links left: ${r.unlinked.length} (they still name ${r.path}; change them yourself)`, ...r.unlinked.map((l) => ` ${l}`));
169
+ const redirects = Object.entries(r.redirects);
170
+ if (redirects.length) out.push(` redirects in unbase.pages.json: ${redirects.length}`, ...redirects.map(([from, to]) => ` ${from} → ${to ?? "(removed)"}`));
171
+ return out;
172
+ }
173
+
122
174
  async function main(argv) {
123
175
  let json = argv.includes("--json");
124
176
  try {
125
- const { command, flags } = parseArgs(argv);
177
+ const { command, flags, args } = parseArgs(argv);
126
178
  if (command === "help") {
127
179
  console.log(USAGE);
128
180
  return 0;
@@ -132,7 +184,7 @@ async function main(argv) {
132
184
  return 0;
133
185
  }
134
186
  json = !!flags.json;
135
- const result = await COMMANDS[command](flags, makeIo(json));
187
+ const result = await COMMANDS[command](flags, makeIo(json), args);
136
188
  console.log(json ? JSON.stringify(result, null, 2) : render(result));
137
189
  return result.exitCode;
138
190
  } catch (e) {
package/lib/args.mjs CHANGED
@@ -2,7 +2,8 @@
2
2
  // Flags. Every choice is a flag (`--comments` / `--no-comments`, `--yes`):
3
3
  // without a terminal a missing one is an error, never a question. Unknown
4
4
  // flags are an error too, so a typo in a script fails instead of being
5
- // ignored.
5
+ // ignored. Only `unbase page` takes arguments besides its flags: what to do
6
+ // and the addresses (`unbase page rename /about /about-us`).
6
7
  // ============================================================================
7
8
 
8
9
  import { CouldNotRun } from "./errors.mjs";
@@ -12,20 +13,30 @@ export const FLAGS = {
12
13
  init: { comments: "bool", "no-comments": "bool", project: "value", pointer: "optional-value", "no-pointer": "bool", "no-install": "bool", tarballs: "value", yes: "bool", json: "bool", dir: "value" },
13
14
  doctor: { json: "bool", "no-build": "bool", dir: "value" },
14
15
  uninstall: { yes: "bool", json: "bool", "no-build": "bool", "no-install": "bool", dir: "value" },
16
+ page: { name: "value", "not-live": "bool", redirect: "value", "not-found": "bool", "dry-run": "bool", json: "bool", dir: "value" },
15
17
  };
16
18
 
17
- /** @returns {{ command: string | null, flags: Record<string, string | true> }} */
19
+ /** Commands that take arguments besides their flags. */
20
+ const ARGUMENTS = new Set(["page"]);
21
+
22
+ /** @returns {{ command: string | null, flags: Record<string, string | true>, args: string[] }} */
18
23
  export function parseArgs(argv) {
19
24
  const [command, ...rest] = argv;
20
- if (!command || command === "--help" || command === "-h" || command === "help") return { command: "help", flags: {} };
21
- if (command === "--version" || command === "-v") return { command: "version", flags: {} };
25
+ if (!command || command === "--help" || command === "-h" || command === "help") return { command: "help", flags: {}, args: [] };
26
+ if (command === "--version" || command === "-v") return { command: "version", flags: {}, args: [] };
22
27
  const known = FLAGS[command];
23
- if (!known) throw new CouldNotRun("usage", `Unknown command "${command}". Commands: init, doctor, uninstall.`);
28
+ if (!known) throw new CouldNotRun("usage", `Unknown command "${command}". Commands: ${Object.keys(FLAGS).join(", ")}.`);
24
29
  /** @type {Record<string, string | true>} */
25
30
  const flags = {};
31
+ /** @type {string[]} */
32
+ const args = [];
26
33
  for (let i = 0; i < rest.length; i++) {
27
34
  const arg = rest[i];
28
- if (!arg.startsWith("--")) throw new CouldNotRun("usage", `Unexpected argument "${arg}" for ${command}.`);
35
+ if (!arg.startsWith("--")) {
36
+ if (!ARGUMENTS.has(command)) throw new CouldNotRun("usage", `Unexpected argument "${arg}" for ${command}.`);
37
+ args.push(arg);
38
+ continue;
39
+ }
29
40
  const [name, inline] = arg.slice(2).split(/=(.*)/s, 2);
30
41
  const kind = known[name];
31
42
  if (!kind) throw new CouldNotRun("usage", `Unknown flag --${name} for ${command}. Flags: ${Object.keys(known).map((f) => `--${f}`).join(", ")}.`);
@@ -45,5 +56,6 @@ export function parseArgs(argv) {
45
56
  }
46
57
  if (flags.comments && flags["no-comments"]) throw new CouldNotRun("usage", "Use --comments or --no-comments, not both.");
47
58
  if (flags.pointer && flags["no-pointer"]) throw new CouldNotRun("usage", "Use --pointer or --no-pointer, not both.");
48
- return { command, flags };
59
+ if (flags.redirect !== undefined && flags["not-found"]) throw new CouldNotRun("usage", "Use --redirect or --not-found, not both.");
60
+ return { command, flags, args };
49
61
  }
@@ -0,0 +1,63 @@
1
+ // ============================================================================
2
+ // unbase doctor — the site's content: which code reads each collection, and
3
+ // which code holds an item's values written by hand (docs/plan-cms-release.md
4
+ // R3c). It runs the binding contract's own checks (`reads`,
5
+ // `noCopiedContent`), the code Unbase's CMS and the Operator's gate run, from
6
+ // lib/readers.mjs. It says what it finds and never fails the run: copied
7
+ // content is the site's choice until someone asks to manage it.
8
+ //
9
+ // A collection here is a folder of JSON items under src/content/ (a Next.js
10
+ // site's convention, and an Astro site's JSON collections). Markdown and YAML
11
+ // collections, and Astro collections kept elsewhere, are not listed yet.
12
+ // ============================================================================
13
+
14
+ import { binding } from "./readers.mjs";
15
+
16
+ const ITEM = /^src\/content\/([A-Za-z0-9_][\w-]*)\/([^/]+)\.json$/;
17
+ const CODE = /\.(astro|tsx?|jsx?|mts|mjs|cjs|cts|vue|svelte|mdx?|html)$/;
18
+
19
+ /** The content section of doctor's report, or null when the framework has no binding adapter. */
20
+ export function contentReport(site) {
21
+ const adapter = binding.ADAPTERS[site.framework?.id];
22
+ if (!adapter) return null;
23
+ const paths = site.appPaths;
24
+ /** @type {Map<string, { id: string, file: string, data: unknown }[]>} */
25
+ const items = new Map();
26
+ for (const p of paths) {
27
+ const m = ITEM.exec(p);
28
+ if (!m) continue;
29
+ let data;
30
+ try {
31
+ data = JSON.parse(site.text(p) ?? "null");
32
+ } catch {
33
+ continue;
34
+ }
35
+ if (!items.has(m[1])) items.set(m[1], []);
36
+ items.get(m[1]).push({ id: m[2], file: p, data });
37
+ }
38
+ const files = paths.filter((p) => CODE.test(p) && !p.startsWith("node_modules/")).map((path) => ({ path, text: site.text(path) ?? "" }));
39
+ const edges = binding.reads({ files, adapter });
40
+ // The values its schema fixes (a block's type, an option) are the schema's, not an item's content.
41
+ const fixed = (name) => {
42
+ try {
43
+ return binding.schemaValues(JSON.parse(site.text(`src/content/.schemas/${name}.schema.json`) ?? "null"));
44
+ } catch {
45
+ return [];
46
+ }
47
+ };
48
+ const collections = [...items.keys()].sort().map((name) => ({ name, items: items.get(name), fixed: fixed(name) }));
49
+ const copied = binding.noCopiedContent({ files, collections, adapter });
50
+ return {
51
+ collections: collections.map((c) => ({ name: c.name, items: c.items.length, readBy: [...new Set(edges.filter((r) => r.collection === c.name).map((r) => r.file))].sort() })),
52
+ copied: copied.map((f) => ({ file: f.file, line: f.line, collection: f.collection, item: f.item, field: f.field, value: f.value })),
53
+ };
54
+ }
55
+
56
+ /** The section as doctor prints it. */
57
+ export function renderContent(c) {
58
+ if (!c || (!c.collections.length && !c.copied.length)) return [];
59
+ const out = ["", "Content:"];
60
+ for (const k of c.collections) out.push(` ${k.name} (${k.items} item${k.items === 1 ? "" : "s"}): ${k.readBy.length ? `read by ${k.readBy.join(", ")}` : "no code reads it"}`);
61
+ for (const f of c.copied) out.push(` ! ${f.file}:${f.line} has ${f.collection}/${f.item}'s ${f.field.slice(1)} written in it ("${f.value}"): read it from the collection, so a change in the CMS shows here`);
62
+ return out;
63
+ }
package/lib/doctor.mjs CHANGED
@@ -3,10 +3,13 @@
3
3
  // with Unbase's own readers on the working tree, and one production build.
4
4
  // It never calls Unbase. The features and their checks are the framework's
5
5
  // (frameworks/*.mjs `doctor`); their shapes and states are feature.mjs's.
6
- // A feature that is off fails the run (exit 1).
6
+ // A feature that is off fails the run (exit 1). The site's content (which
7
+ // code reads each collection, and values copied into code) is content.mjs's,
8
+ // and never fails it.
7
9
  // ============================================================================
8
10
 
9
11
  import { buildSite } from "./build.mjs";
12
+ import { contentReport } from "./content.mjs";
10
13
  import { FAILED, PASSED } from "./errors.mjs";
11
14
  import { openSite, refresh } from "./site.mjs";
12
15
 
@@ -21,6 +24,7 @@ export async function doctor(flags, io) {
21
24
  await refresh(site);
22
25
  }
23
26
  const features = await site.framework.doctor(site, { build });
27
+ const content = contentReport(site);
24
28
 
25
29
  build?.dispose();
26
30
  const failed = features.some((f) => f.state === "off");
@@ -32,6 +36,7 @@ export async function doctor(flags, io) {
32
36
  site: site.root,
33
37
  built: build ? build.ok : null,
34
38
  features,
39
+ content,
35
40
  summary: { on: count("on"), off: count("off"), waiting: count("waiting"), notInstalled: count("not-installed") },
36
41
  };
37
42
  }
@@ -47,6 +47,8 @@ const CONTENT_CONFIG = /^src\/(content\.config|content\/config)\.(ts|js|mjs|mts)
47
47
  * comment-modus 1.9.0) or off (`false`). Without comment-modus a production build has none.
48
48
  * `when` is the config's componentMarker as config-edit reads it; null (not literal) counts as the
49
49
  * default, "always".
50
+ * @param {boolean} commentsInstalled
51
+ * @param {string | false | null} [when]
50
52
  */
51
53
  export const markersBelongInProduction = (commentsInstalled, when = "always") => commentsInstalled && when !== "preview" && when !== false;
52
54
 
@@ -203,7 +205,8 @@ function settingsCollections(site) {
203
205
  } catch {}
204
206
  const name = f.slice(0, -".schema.json".length);
205
207
  if (s?.properties?.pad && s?.properties?.seo && !out.route) out.route = name;
206
- if (s?.["x-instellingen"] === "site" && !out.site) out.site = name;
208
+ // comment-modus 1.11 reads x-settings; LEGACY-NL: x-instellingen before it, still read.
209
+ if ((s?.["x-settings"] ?? s?.["x-instellingen"]) === "site" && !out.site) out.site = name;
207
210
  }
208
211
  return out;
209
212
  }
@@ -448,7 +451,7 @@ async function doctorFeatures(site, { build }) {
448
451
  const source = site.text(contentConfig) ?? "";
449
452
  if (!/\bpad\s*:/.test(source) || !/\bseo\s*:/.test(source))
450
453
  checks.push(check("route-files", "missing", "No collection with `pad` and `seo`: page settings have no place per page.", { missing: "a route-file collection", file: contentConfig, step: STEPS.pageSettings }));
451
- if (!/x-instellingen/.test(source))
454
+ if (!/x-(settings|instellingen)/.test(source))
452
455
  checks.push(check("site-settings", "missing", 'No collection marked `"x-instellingen": "site"`: site settings have no place.', { missing: "a site-settings collection", file: contentConfig, step: STEPS.siteSettings }));
453
456
  }
454
457
  } else {
@@ -54,6 +54,7 @@ function requireOf(n) {
54
54
  */
55
55
  export function inspectNextConfig(code, file) {
56
56
  const ast = parseConfig(code, file);
57
+ /** @type {any[]} Babel's statements, narrowed by `type` below. */
57
58
  const body = ast.program.body;
58
59
  const exp = body.find((n) => n.type === "ExportDefaultDeclaration");
59
60
  const cjs = body.find(isModuleExports);