@unbase-app/cli 0.4.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/bin/unbase.mjs CHANGED
@@ -17,6 +17,7 @@
17
17
  // ============================================================================
18
18
 
19
19
  import { createInterface } from "node:readline/promises";
20
+ import { renderContent } from "../lib/content.mjs";
20
21
  import { doctor } from "../lib/doctor.mjs";
21
22
  import { COULD_NOT_RUN, CouldNotRun } from "../lib/errors.mjs";
22
23
  import { FRAMEWORKS } from "../lib/frameworks/index.mjs";
@@ -118,6 +119,7 @@ function render(r) {
118
119
  if (c.detail && c.state !== "ok") out.push(...String(c.detail).split("\n").map((l) => ` | ${l}`));
119
120
  }
120
121
  }
122
+ out.push(...renderContent(r.content));
121
123
  const s = r.summary;
122
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.`);
123
125
  } else if (r.command === "uninstall") {
@@ -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);