@sbuilder/cli 0.13.0 → 0.14.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.
@@ -0,0 +1,114 @@
1
+ import { readdir } from 'node:fs/promises';
2
+ import { join } from 'node:path';
3
+ import { ELEMENT_RULES, REMOVED_TYPES } from './envtypes.gen.js';
4
+ import { VERSION } from './login.js';
5
+ import { linkOn, readManifest, readText, sha256 } from './site.js';
6
+ import { parseSource, SourceError } from './source/parse.js';
7
+ import { tagFor } from './source/print.js';
8
+ const el = (type) => (tagFor(type) ? `<${tagFor(type)}>` : `<Node type="${type}">`);
9
+ /** Every child a page document holds where the schema says it cannot be. */
10
+ export function checkStructure(file, src) {
11
+ const { document, positions } = parseSource(src);
12
+ const nodes = document.nodes;
13
+ const out = [];
14
+ for (const [id, n] of Object.entries(nodes)) {
15
+ const parent = n?.data?.type ?? '';
16
+ const rule = ELEMENT_RULES[parent];
17
+ for (const kid of n?.data?.nodes ?? []) {
18
+ const type = nodes[kid]?.data?.type;
19
+ if (!type)
20
+ continue;
21
+ const at = positions[kid] ?? positions[id] ?? { line: 1, col: 1 };
22
+ const say = (message) => out.push({ file, ...at, message });
23
+ if (REMOVED_TYPES.includes(type)) {
24
+ say(`${el(type)} was removed from the platform and renders nothing — delete it.`);
25
+ continue;
26
+ }
27
+ if (rule?.allows.length && !rule.allows.includes(type)) {
28
+ const sat = rule.satellites.find((x) => x.type === type);
29
+ say(`${el(type)} cannot be a child of ${el(parent)}, which holds only ${rule.allows.map(el).join(', ')}.` +
30
+ (sat
31
+ ? ` ${el(type)} is ${el(parent)}'s satellite (linked by config.${sat.configKey}, kept in \`export const detached\`), never a row.`
32
+ : '') +
33
+ ` Write each child as ${el(rule.allows[0])} instead.`);
34
+ }
35
+ if (ELEMENT_RULES[type]?.rootOnly && parent !== 'root')
36
+ say(`${el(type)} lives only directly inside <Page> — move it out of ${el(parent)}.`);
37
+ }
38
+ }
39
+ return out.sort((a, b) => a.line - b.line || a.col - b.col);
40
+ }
41
+ export const line = (m) => ` ! ${m.file}:${m.line}:${m.col}: ${m.message}`;
42
+ /** Which rules said so: the CLI's own copy of the schema, which a newer platform may have moved past. */
43
+ export const RULES_FROM = `(rules from sb ${VERSION.split('.').slice(0, 2).join('.')} — if the editor allows this, upgrade sb)`;
44
+ /**
45
+ * Push's per-file check, run on a file it is about to send (after it parsed): prints each misplaced
46
+ * element and returns true when the FILE is refused. Only that file is skipped; the push goes on.
47
+ */
48
+ export function refuseStructure(file, text, warn) {
49
+ let bad;
50
+ try {
51
+ bad = checkStructure(file, text);
52
+ }
53
+ catch (err) {
54
+ if (err instanceof SourceError)
55
+ return false; // push already refused it with line:col
56
+ throw err;
57
+ }
58
+ if (!bad.length)
59
+ return false;
60
+ for (const m of bad)
61
+ warn(line(m));
62
+ warn(` ! ${file}: nothing sent — ${bad.length} element(s) sit where the schema does not allow them ${RULES_FROM}.`);
63
+ return true;
64
+ }
65
+ const SOURCE_DIRS = ['design/pages', 'design/globals', 'design/overlays'];
66
+ /**
67
+ * The page-source files of a repo, with what the manifest last synced: `changed` is true for a file
68
+ * push would send (new, or its text differs from the synced sha). A link is skipped — push refuses
69
+ * it on its own, by name.
70
+ */
71
+ export async function sourceFiles(dir) {
72
+ const m = await readManifest(dir).catch(() => undefined);
73
+ const synced = new Map();
74
+ for (const group of [m?.pages, m?.globals, m?.overlays])
75
+ for (const e of Object.values(group ?? {}))
76
+ synced.set(e.file, e.sha256);
77
+ const out = [];
78
+ for (const d of SOURCE_DIRS) {
79
+ for (const f of (await readdir(join(dir, d)).catch(() => [])).sort()) {
80
+ if (!f.endsWith('.page.tsx'))
81
+ continue;
82
+ const file = `${d}/${f}`;
83
+ if (await linkOn(dir, file))
84
+ continue;
85
+ const text = await readText(join(dir, file));
86
+ if (text === undefined)
87
+ continue;
88
+ out.push({ file, text, changed: synced.get(file) !== sha256(text) });
89
+ }
90
+ }
91
+ return out;
92
+ }
93
+ /**
94
+ * What push refuses: misplaced children in the files it would SEND. An unchanged file is the
95
+ * platform's own document already (a page the editor or an older CLI stored that way) and is left
96
+ * to `sb doctor`, so one old page cannot block pushing every other. A file that does not parse is
97
+ * push's to refuse, with its own line:col.
98
+ */
99
+ export async function structureProblems(dir, all = false) {
100
+ const out = [];
101
+ for (const f of await sourceFiles(dir)) {
102
+ if (!all && !f.changed)
103
+ continue;
104
+ try {
105
+ out.push(...checkStructure(f.file, f.text));
106
+ }
107
+ catch (err) {
108
+ if (!(err instanceof SourceError))
109
+ throw err;
110
+ }
111
+ }
112
+ return out;
113
+ }
114
+ //# sourceMappingURL=structure.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"structure.js","sourceRoot":"","sources":["../../src/structure.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAC3C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AACjE,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AACnE,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAC7D,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAkB3C,MAAM,EAAE,GAAG,CAAC,IAAY,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,eAAe,IAAI,IAAI,CAAC,CAAC;AAE5F,4EAA4E;AAC5E,MAAM,UAAU,cAAc,CAAC,IAAY,EAAE,GAAW;IACtD,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,GAAG,WAAW,CAAC,GAAG,CAAC,CAAC;IACjD,MAAM,KAAK,G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 @@
1
+ import { authedFetch } from './auth.js';
2
+ import { DevError } from './dev.js';
3
+ export class TemplateRefused extends DevError {
4
+ }
5
+ /** How long a copy may take before the CLI stops waiting (the site keeps building on the platform). */
6
+ export const COPY_TIMEOUT_MS = 5 * 60_000;
7
+ const POLL_MS = 1_500;
8
+ async function errorText(res) {
9
+ try {
10
+ return (await res.json()).error ?? `HTTP ${res.status}`;
11
+ }
12
+ catch {
13
+ return `HTTP ${res.status}`;
14
+ }
15
+ }
16
+ /** The gallery. Public: no credential is sent, so a signed-out `sb site templates` works too. */
17
+ export async function listTemplates(api) {
18
+ const res = await fetch(`${api}/api/templates`);
19
+ if (!res.ok)
20
+ throw new TemplateRefused(`/api/templates failed: ${await errorText(res)}`);
21
+ const body = (await res.json());
22
+ // A Go nil slice is `null`: never let it reach a .map.
23
+ return (body.templates ?? []).map((t) => ({ ...t, categories: t.categories ?? [] }));
24
+ }
25
+ /** `--template <ref>`: a template's site id or its slug — never a guess between near names. */
26
+ export function findTemplate(list, ref) {
27
+ const t = list.find((x) => x.siteId === ref || (!!x.slug && x.slug === ref));
28
+ if (t)
29
+ return t;
30
+ throw new TemplateRefused(list.length
31
+ ? `No template "${ref}". Pass one of these (slug or id):\n` + templateLines(list).join('\n')
32
+ : 'The platform offers no templates yet.');
33
+ }
34
+ /** What `sb site templates` prints: one block per template, scannable. */
35
+ export function templateLines(list) {
36
+ if (!list.length)
37
+ return ['The platform offers no templates yet.'];
38
+ const out = [];
39
+ for (const t of list) {
40
+ const cats = t.categories.map((c) => c.name).join(', ');
41
+ out.push(` ${t.slug || t.siteId} ${t.name}${cats ? ` (${cats})` : ''}`);
42
+ if (t.description)
43
+ out.push(` ${t.description}`);
44
+ if (t.publicUrl)
45
+ out.push(` live: ${t.publicUrl}`);
46
+ if (t.previewUrl)
47
+ out.push(` preview: ${t.previewUrl}`);
48
+ }
49
+ return out;
50
+ }
51
+ /** Copies the template into a new site in the caller's name and waits for it; returns its id. */
52
+ export async function useTemplate(o) {
53
+ // The gallery copy is made "in the caller's name": a session, never a site's API key.
54
+ if (typeof o.token === 'string' && /^(wbk|sbdk)_/.test(o.token))
55
+ throw new TemplateRefused('Creating a site from a template needs your account: run sb login (an API key in SB_TOKEN belongs to one site).');
56
+ const res = await authedFetch(`${o.api}/api/templates/${encodeURIComponent(o.template.siteId)}`, {
57
+ method: 'POST',
58
+ headers: { 'Content-Type': 'application/json' },
59
+ body: JSON.stringify({ name: o.name }),
60
+ }, o.token);
61
+ if (!res.ok)
62
+ throw new TemplateRefused(`Could not start from "${o.template.name}": ${await errorText(res)}`);
63
+ const { jobId, siteId } = (await res.json());
64
+ if (!jobId || !siteId)
65
+ throw new TemplateRefused('The server answered without a job or a site.');
66
+ o.log(`Copying the template "${o.template.name}" into a new site "${o.name}"…`);
67
+ const sleep = o.sleep ?? ((ms) => new Promise((r) => setTimeout(r, ms)));
68
+ const deadline = Date.now() + (o.timeoutMs ?? COPY_TIMEOUT_MS);
69
+ let said = -1;
70
+ for (;;) {
71
+ const r = await authedFetch(`${o.api}/api/sites/${encodeURIComponent(siteId)}/copy/${encodeURIComponent(jobId)}`, {}, o.token);
72
+ if (!r.ok)
73
+ throw new TemplateRefused(`Could not follow the copy: ${await errorText(r)}`);
74
+ const job = (await r.json()).job;
75
+ if (job?.status === 'done')
76
+ return siteId;
77
+ if (job?.status === 'failed')
78
+ throw new TemplateRefused(`The copy failed: ${job.error || 'no reason given'}. The site "${o.name}" (${siteId}) was ` +
79
+ 'created and holds only what was copied before it stopped — delete it on your dashboard, ' +
80
+ 'or keep it; running this again makes a second site.');
81
+ if (job?.totalParts && job.partsDone !== said) {
82
+ said = job.partsDone ?? 0;
83
+ o.log(` ${said}/${job.totalParts} parts`);
84
+ }
85
+ if (Date.now() > deadline)
86
+ throw new TemplateRefused(`The copy into "${o.name}" (${siteId}) had not finished after ` +
87
+ `${Math.round((o.timeoutMs ?? COPY_TIMEOUT_MS) / 1000)}s; the CLI stopped waiting. ` +
88
+ 'It may still finish, or it may have stopped — the site says which on your dashboard. ' +
89
+ `When it opens there, make the repo with: sb site init ${o.dir ?? '<dir>'} --site ${siteId}`);
90
+ await sleep(POLL_MS);
91
+ }
92
+ }
93
+ //# sourceMappingURL=templates.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"templates.js","sourceRoot":"","sources":["../../src/templates.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAExC,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAgCpC,MAAM,OAAO,eAAgB,SAAQ,QAAQ;CAAG;AAEhD,uGAAuG;AACvG,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,GAAG,MAAM,CAAC;AAC1C,MAAM,OAAO,GAAG,KAAK,CAAC;AAEtB,KAAK,UAAU,SAAS,CAAC,GAAa;IACpC,IAAI,CAAC;QACH,OAAQ,CAAC,MAAM,GAAG,CAAC,IAAI,EAAE,CAAwB,CAAC,KAAK,IAAI,QAAQ,GAAG,CAAC,MAAM,EAAE,CAAC;IAClF,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,QAAQ,GAAG,CAAC,MAAM,EAAE,CAAC;IAC9B,CAAC;AACH,CAAC;AAED,iGAAiG;AACjG,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,GAAW;IAC7C,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,GAAG,GAAG,gBAAgB,CAAC,CAAC;IAChD,IAAI,CAAC,GAAG,CAAC,EAAE;QAAE,MAAM,IAAI,eAAe,CAAC,0BAA0B,MAAM,SAAS,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IACzF,MAAM,IAAI,GAAG,CAAC,MAAM,GAAG,CAAC,IAAI,EAAE,CAAsC,CAAC;IACrE,uDAAuD;IACvD,OAAO,CAAC,IAAI,CAAC,SAAS,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,U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AAC,CAAC,GAAG,CAAC,KAAK,IAAI,IAAI,GAAG,CAAC,UAAU,QAAQ,CAAC,CAAC;QAC7C,CAAC;QACD,IAAI,IAAI,CAAC,GAAG,EAAE,GAAG,QAAQ;YACvB,MAAM,IAAI,eAAe,CACvB,kBAAkB,CAAC,CAAC,IAAI,MAAM,MAAM,2BAA2B;gBAC7D,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,IAAI,eAAe,CAAC,GAAG,IAAI,CAAC,8BAA8B;gBACpF,uFAAuF;gBACvF,yDAAyD,CAAC,CAAC,GAAG,IAAI,OAAO,WAAW,MAAM,EAAE,CAC/F,CAAC;QACJ,MAAM,KAAK,CAAC,OAAO,CAAC,CAAC;IACvB,CAAC;AACH,CAAC"}
@@ -0,0 +1,49 @@
1
+ import { isDeepStrictEqual } from 'node:util';
2
+ const KEYED = {
3
+ colors: 'id',
4
+ textStyles: 'slug',
5
+ schemes: 'id',
6
+ presets: 'id',
7
+ };
8
+ const show = (v) => (typeof v === 'string' ? v : JSON.stringify(v));
9
+ function byKey(list, key) {
10
+ const out = new Map();
11
+ if (Array.isArray(list))
12
+ for (const x of list)
13
+ if (x && typeof x === 'object' && typeof x[key] === 'string')
14
+ out.set(x[key], x);
15
+ return out;
16
+ }
17
+ /** One line per changed token: `colors.primary: value #171717 → #e11d48`, `textStyles.text-3: added`. */
18
+ export function themeDiff(before, after) {
19
+ const a = (before && typeof before === 'object' ? before : {});
20
+ const b = (after && typeof after === 'object' ? after : {});
21
+ const out = [];
22
+ for (const k of [...new Set([...Object.keys(a), ...Object.keys(b)])].sort()) {
23
+ if (isDeepStrictEqual(a[k], b[k]))
24
+ continue;
25
+ const key = KEYED[k];
26
+ if (!key || !Array.isArray(a[k] ?? []) || !Array.isArray(b[k] ?? [])) {
27
+ out.push(`${k}: ${a[k] === undefined ? 'added' : b[k] === undefined ? 'removed' : `${show(a[k])} → ${show(b[k])}`}`);
28
+ continue;
29
+ }
30
+ const was = byKey(a[k], key);
31
+ const now = byKey(b[k], key);
32
+ for (const id of [...new Set([...was.keys(), ...now.keys()])]) {
33
+ const x = was.get(id);
34
+ const y = now.get(id);
35
+ if (isDeepStrictEqual(x, y))
36
+ continue;
37
+ if (!x)
38
+ out.push(`${k}.${id}: added`);
39
+ else if (!y)
40
+ out.push(`${k}.${id}: removed`);
41
+ else
42
+ for (const f of [...new Set([...Object.keys(x), ...Object.keys(y)])].sort())
43
+ if (!isDeepStrictEqual(x[f], y[f]))
44
+ out.push(`${k}.${id}: ${f} ${x[f] === undefined ? '(none)' : show(x[f])} → ${y[f] === undefined ? '(none)' : show(y[f])}`);
45
+ }
46
+ }
47
+ return out;
48
+ }
49
+ //# sourceMappingURL=themediff.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"themediff.js","sourceRoot":"","sources":["../../src/themediff.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAW9C,MAAM,KAAK,GAA2B;IACpC,MAAM,EAAE,IAAI;IACZ,UAAU,EAAE,MAAM;IAClB,OAAO,EAAE,IAAI;IACb,OAAO,EAAE,IAAI;CACd,CAAC;AACF,MAAM,IAAI,GAAG,CAAC,CAAU,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC;AAE7E,SAAS,KAAK,CAAC,IAAa,EAAE,GAAW;IACvC,MAAM,GAAG,GAAG,IAAI,GAAG,EAAe,CAAC;IACnC,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC;QACrB,KAAK,MAAM,CAAC,IAAI,IAAI;YAClB,IAAI,CAAC,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAI,OAAQ,CAAS,CAAC,GAAG,CAAC,KAAK,QAAQ;gBACnE,GAAG,CAAC,GAAG,CAAE,CAAS,CAAC,GAAG,CAAW,E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AC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,SAAS,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CACjH,CAAC;QACV,CAAC;IACH,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sbuilder/cli",
3
- "version": "0.13.0",
3
+ "version": "0.14.0",
4
4
  "description": "The Store Builder command line: keep a site's pages in a GitHub repo, run the editor's AI assistant on your machine, and build apps for the platform.",
5
5
  "keywords": [
6
6
  "sbuilder",