@sbuilder/cli 0.7.0 → 0.9.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/README.md +374 -145
- package/README.vi.md +361 -137
- package/dist/bin/sb.js +535 -219
- package/dist/bin/sb.js.map +1 -1
- package/dist/src/appblocks.js +67 -0
- package/dist/src/appblocks.js.map +1 -0
- package/dist/src/appcreate.js +279 -0
- package/dist/src/appcreate.js.map +1 -0
- package/dist/src/auth.js +1 -1
- package/dist/src/code.js +10 -10
- package/dist/src/code.js.map +1 -1
- package/dist/src/deploy.js +3 -3
- package/dist/src/deploy.js.map +1 -1
- package/dist/src/dev.js +9 -5
- package/dist/src/dev.js.map +1 -1
- package/dist/src/export.js +167 -0
- package/dist/src/export.js.map +1 -0
- package/dist/src/host.js +162 -0
- package/dist/src/host.js.map +1 -0
- package/dist/src/init.js +41 -13
- package/dist/src/init.js.map +1 -1
- package/dist/src/login.js +62 -8
- package/dist/src/login.js.map +1 -1
- package/dist/src/new.js +3 -3
- package/dist/src/new.js.map +1 -1
- package/dist/src/next.js +122 -0
- package/dist/src/next.js.map +1 -0
- package/dist/src/repo.js +118 -0
- package/dist/src/repo.js.map +1 -0
- package/dist/src/route.js +66 -0
- package/dist/src/route.js.map +1 -0
- package/dist/src/scaffold.js +169 -2
- package/dist/src/scaffold.js.map +1 -1
- package/dist/src/site.js +448 -0
- package/dist/src/site.js.map +1 -0
- package/dist/src/siteinit.js +326 -0
- package/dist/src/siteinit.js.map +1 -0
- package/dist/src/source/parse.js +470 -0
- package/dist/src/source/parse.js.map +1 -0
- package/dist/src/source/print.js +270 -0
- package/dist/src/source/print.js.map +1 -0
- package/package.json +6 -2
package/dist/src/scaffold.js
CHANGED
|
@@ -37,6 +37,27 @@ function pkg(name) {
|
|
|
37
37
|
*/
|
|
38
38
|
function server() {
|
|
39
39
|
return `import { createServer } from 'node:http';
|
|
40
|
+
import { readFileSync } from 'node:fs';
|
|
41
|
+
|
|
42
|
+
// ── .env ──────────────────────────────────────────────────────────────────
|
|
43
|
+
//
|
|
44
|
+
// \`npm start\` is plain \`node server.js\`, which does not read .env by itself — and
|
|
45
|
+
// \`sb app create\` writes the client id and secret there. A value already in the
|
|
46
|
+
// environment wins. (Node's own --env-file flag would do this, but not on every
|
|
47
|
+
// Node 20.)
|
|
48
|
+
try {
|
|
49
|
+
for (const line of readFileSync(new URL('./.env', import.meta.url), 'utf8').split(/\\r?\\n/)) {
|
|
50
|
+
const m = line.match(/^\\s*(?:export\\s+)?([A-Za-z_][A-Za-z0-9_]*)\\s*=\\s*(.*)$/);
|
|
51
|
+
// An EMPTY shell value counts as unset, or SB_API= would send a local app to production.
|
|
52
|
+
if (m && !process.env[m[1]]) {
|
|
53
|
+
const v = m[2].trim();
|
|
54
|
+
const q = v.match(/^(['"])(.*)\\1$/);
|
|
55
|
+
process.env[m[1]] = q ? q[2] : v.replace(/\\s+#.*$/, '');
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
} catch {
|
|
59
|
+
// No .env yet: the configuration check below says what is missing.
|
|
60
|
+
}
|
|
40
61
|
|
|
41
62
|
// ── Configuration ─────────────────────────────────────────────────────────
|
|
42
63
|
//
|
|
@@ -218,6 +239,140 @@ development only — submitting is refused while either URL is \`localhost\`, an
|
|
|
218
239
|
that refusal is the platform's, not this app's.
|
|
219
240
|
`;
|
|
220
241
|
}
|
|
242
|
+
/** The island and block `--with-block` writes. One name, so the three files cannot disagree. */
|
|
243
|
+
export const BLOCK_ISLAND = 'hello-card';
|
|
244
|
+
/**
|
|
245
|
+
* The block manifest: a heading and a button inside one flex-block, with the
|
|
246
|
+
* island on the flex-block. Checked against the server's own validator by
|
|
247
|
+
* tests/appblock.test.ts — it is not a copy of a schema, it is the thing the
|
|
248
|
+
* server judges.
|
|
249
|
+
*/
|
|
250
|
+
function blocksJson() {
|
|
251
|
+
const props = (specials) => ({ style: {}, config: {}, specials });
|
|
252
|
+
const manifest = {
|
|
253
|
+
blocks: [
|
|
254
|
+
{
|
|
255
|
+
key: BLOCK_ISLAND,
|
|
256
|
+
name: 'Hello card',
|
|
257
|
+
icon: 'hand',
|
|
258
|
+
rootId: 'card',
|
|
259
|
+
nodes: [
|
|
260
|
+
{
|
|
261
|
+
id: 'card',
|
|
262
|
+
type: 'flex-block',
|
|
263
|
+
island: BLOCK_ISLAND,
|
|
264
|
+
children: ['title', 'button'],
|
|
265
|
+
props: { style: { gap: '12px', padding: '16px' }, config: {}, specials: {} },
|
|
266
|
+
},
|
|
267
|
+
{ id: 'title', type: 'heading', props: props({ text: 'Hello from my app' }) },
|
|
268
|
+
{ id: 'button', type: 'button', props: props({ text: 'Click me' }) },
|
|
269
|
+
],
|
|
270
|
+
slots: [{ name: 'title', nodeId: 'title' }],
|
|
271
|
+
traits: [
|
|
272
|
+
{
|
|
273
|
+
key: 'content',
|
|
274
|
+
label: 'Content',
|
|
275
|
+
attributes: [
|
|
276
|
+
{ widget: 'text_content', slot: 'title', target: 'specials', writeKey: 'text' },
|
|
277
|
+
],
|
|
278
|
+
},
|
|
279
|
+
],
|
|
280
|
+
},
|
|
281
|
+
],
|
|
282
|
+
};
|
|
283
|
+
return JSON.stringify(manifest, null, 2) + '\n';
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* The island module: a plain class, because a module the platform hosts has no
|
|
287
|
+
* import path to the runtime's own helpers. The loader constructs it with the
|
|
288
|
+
* host element and calls destroy/serialize/hydrate/beforeUpdate on it.
|
|
289
|
+
*
|
|
290
|
+
* It registers under `app.<appId>.${BLOCK_ISLAND}` — the name the page carries —
|
|
291
|
+
* but the app id exists only after `sb app create`, so the module reads the
|
|
292
|
+
* name off the markers already on the page instead of hard-coding one.
|
|
293
|
+
*/
|
|
294
|
+
function islandModule() {
|
|
295
|
+
return `// The ${BLOCK_ISLAND} island: counts clicks on the block's button.
|
|
296
|
+
//
|
|
297
|
+
// The platform hosts this file and the page loads it when the block scrolls into
|
|
298
|
+
// view. The server-rendered block is already on the page; this only adds the click.
|
|
299
|
+
class HelloCard {
|
|
300
|
+
constructor(host) {
|
|
301
|
+
this.$el = host;
|
|
302
|
+
this.props = {};
|
|
303
|
+
this.count = 0;
|
|
304
|
+
this.button = host.querySelector('button, a');
|
|
305
|
+
this.onClick = () => {
|
|
306
|
+
this.count += 1;
|
|
307
|
+
this.render();
|
|
308
|
+
};
|
|
309
|
+
if (this.button) this.button.addEventListener('click', this.onClick);
|
|
310
|
+
}
|
|
311
|
+
render() {
|
|
312
|
+
if (this.button) this.button.textContent = \`Clicked \${this.count} time\${this.count === 1 ? '' : 's'}\`;
|
|
313
|
+
}
|
|
314
|
+
beforeUpdate() {}
|
|
315
|
+
serialize() {
|
|
316
|
+
return { count: this.count };
|
|
317
|
+
}
|
|
318
|
+
hydrate(snapshot) {
|
|
319
|
+
this.count = Number(snapshot && snapshot.count) || 0;
|
|
320
|
+
this.render();
|
|
321
|
+
}
|
|
322
|
+
destroy() {
|
|
323
|
+
if (this.button) this.button.removeEventListener('click', this.onClick);
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
// The page names the island app.<appId>.${BLOCK_ISLAND}; register under every such
|
|
328
|
+
// name the page carries, so this file needs no id pasted into it.
|
|
329
|
+
const names = new Set();
|
|
330
|
+
for (const el of document.querySelectorAll('[wb\\\\:init], [wb\\\\:now]')) {
|
|
331
|
+
const marker = el.getAttribute('wb:init') || el.getAttribute('wb:now') || '';
|
|
332
|
+
for (const name of marker.split(' ')) {
|
|
333
|
+
if (/^app\\.[^.\\s]+\\.${BLOCK_ISLAND}$/.test(name)) names.add(name);
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
for (const name of names) window.WB.register(name, HelloCard);
|
|
337
|
+
`;
|
|
338
|
+
}
|
|
339
|
+
/**
|
|
340
|
+
* sb.json for a scaffold that already has a block: the five keys `sb app dev` needs
|
|
341
|
+
* and the payload `sb app deploy` sends. The ids are EMPTY — they exist only once
|
|
342
|
+
* the app does, and `sb app create` writes them.
|
|
343
|
+
*/
|
|
344
|
+
function sbJson(port) {
|
|
345
|
+
return (JSON.stringify({
|
|
346
|
+
orgId: '',
|
|
347
|
+
appId: '',
|
|
348
|
+
versionId: '',
|
|
349
|
+
island: BLOCK_ISLAND,
|
|
350
|
+
entry: `islands/${BLOCK_ISLAND}.js`,
|
|
351
|
+
version: {
|
|
352
|
+
version: '0.1.0',
|
|
353
|
+
scopes: ['products.read'],
|
|
354
|
+
embedUrl: `http://localhost:${port}/embed`,
|
|
355
|
+
redirectUri: `http://localhost:${port}/oauth/callback`,
|
|
356
|
+
},
|
|
357
|
+
blocks: 'blocks.json',
|
|
358
|
+
islands: [{ name: BLOCK_ISLAND, entry: `islands/${BLOCK_ISLAND}.js` }],
|
|
359
|
+
}, null, 2) + '\n');
|
|
360
|
+
}
|
|
361
|
+
const BLOCK_README = `
|
|
362
|
+
## The block
|
|
363
|
+
|
|
364
|
+
\`blocks.json\` is one block, "Hello card": a heading and a button, with the
|
|
365
|
+
\`${BLOCK_ISLAND}\` island on it. \`islands/${BLOCK_ISLAND}.js\` is the island — it
|
|
366
|
+
counts clicks on the button.
|
|
367
|
+
|
|
368
|
+
sb app create "<name>" # creates the app, a draft version and a sandbox install
|
|
369
|
+
sb app deploy # sends blocks.json and the island to the draft
|
|
370
|
+
sb app dev # re-uploads the island each time you save it
|
|
371
|
+
|
|
372
|
+
Then open the page editor of the store you installed on: the block is in the
|
|
373
|
+
palette under your app. An island's code comes from the platform, so refresh the
|
|
374
|
+
page after a change — it is not hot reload.
|
|
375
|
+
`;
|
|
221
376
|
/**
|
|
222
377
|
* files returns the whole scaffold as a path→contents map.
|
|
223
378
|
*
|
|
@@ -225,14 +380,26 @@ that refusal is the platform's, not this app's.
|
|
|
225
380
|
* — which is what lets the test assert the CONTENT without touching a disk, and
|
|
226
381
|
* what makes "would this overwrite something" answerable before anything is
|
|
227
382
|
* written.
|
|
383
|
+
*
|
|
384
|
+
* \`withBlock\` adds a working block and island on top of the five files; without
|
|
385
|
+
* it the scaffold is exactly what it always was.
|
|
228
386
|
*/
|
|
229
|
-
export function files(name, port = 3000) {
|
|
230
|
-
|
|
387
|
+
export function files(name, port = 3000, withBlock = false) {
|
|
388
|
+
const base = {
|
|
231
389
|
'package.json': pkg(name),
|
|
232
390
|
'server.js': server(),
|
|
233
391
|
'.env.example': envExample(port),
|
|
234
392
|
'README.md': readme(name, port),
|
|
235
393
|
'.gitignore': 'node_modules\n.env\n',
|
|
236
394
|
};
|
|
395
|
+
if (!withBlock)
|
|
396
|
+
return base;
|
|
397
|
+
return {
|
|
398
|
+
...base,
|
|
399
|
+
'README.md': base['README.md'] + BLOCK_README,
|
|
400
|
+
'blocks.json': blocksJson(),
|
|
401
|
+
[`islands/${BLOCK_ISLAND}.js`]: islandModule(),
|
|
402
|
+
'sb.json': sbJson(port),
|
|
403
|
+
};
|
|
237
404
|
}
|
|
238
405
|
//# sourceMappingURL=scaffold.js.map
|
package/dist/src/scaffold.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scaffold.js","sourceRoot":"","sources":["../../src/scaffold.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,yCAAyC;AACzC,SAAS,GAAG,CAAC,IAAY;IACvB,OAAO,CACL,IAAI,CAAC,SAAS,CACZ;QACE,IAAI;QACJ,OAAO,EAAE,OAAO;QAChB,OAAO,EAAE,IAAI;QACb,IAAI,EAAE,QAAQ;QACd,OAAO,EAAE,EAAE,KAAK,EAAE,gBAAgB,EAAE;KACrC,EACD,IAAI,EACJ,CAAC,CACF,GAAG,IAAI,CACT,CAAC;AACJ,CAAC;AAED;;;;;;GAMG;AACH,SAAS,MAAM;IACb,OAAO
|
|
1
|
+
{"version":3,"file":"scaffold.js","sourceRoot":"","sources":["../../src/scaffold.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,yCAAyC;AACzC,SAAS,GAAG,CAAC,IAAY;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kdir, readdir, readFile, rename, writeFile } from 'node:fs/promises';
|
|
3
|
+
import { dirname, join } from 'node:path';
|
|
4
|
+
import { authedFetch, SB_TOKEN_REFUSED } from './auth.js';
|
|
5
|
+
import { sbJsonSite } from './code.js';
|
|
6
|
+
import { APP_BLOCK_EDITED, appBlockSeals, editedAppBlocks } from './appblocks.js';
|
|
7
|
+
import { DevError, messageOf } from './dev.js';
|
|
8
|
+
import { parsePage, SourceError } from './source/parse.js';
|
|
9
|
+
import { literal, printPage, tagFor } from './source/print.js';
|
|
10
|
+
/**
|
|
11
|
+
* `sb site pull` / `sb site push` — a site's page DRAFTS as `.page.tsx` files in a repo.
|
|
12
|
+
*
|
|
13
|
+
* One `.page.tsx` file per page under `design/pages/` — the builder's document as
|
|
14
|
+
* React-looking source that round-trips losslessly (cli/src/source). Push saves a
|
|
15
|
+
* DRAFT, never publishes.
|
|
16
|
+
*
|
|
17
|
+
* # THE BASE IS THE MANIFEST, THE GUARD IS THE SERVER'S
|
|
18
|
+
*
|
|
19
|
+
* `.sb-site.json` records, per page, the server `rev` and the sha256 of the file
|
|
20
|
+
* as last pulled or pushed. Pull overwrites a file only when the local copy is
|
|
21
|
+
* still that sha; push sends `baseRev` and the server refuses (409 source_stale)
|
|
22
|
+
* a page someone edited in the editor since. Neither side is ever overwritten
|
|
23
|
+
* silently — a clash is named, and `--force` is the deliberate way past it.
|
|
24
|
+
*
|
|
25
|
+
* Pages are never created or deleted from here: a file with no manifest entry is
|
|
26
|
+
* reported, and a page deleted on the platform keeps its file. Deleting something
|
|
27
|
+
* a merchant still depends on is a decision, not a sync side effect.
|
|
28
|
+
*/
|
|
29
|
+
export const SITE_MANIFEST = '.sb-site.json';
|
|
30
|
+
export const PAGES_DIR = 'design/pages';
|
|
31
|
+
export class SiteRefused extends DevError {
|
|
32
|
+
}
|
|
33
|
+
export const SITE_UNAUTHORIZED = 'Not signed in, or the token was refused (expired or revoked). Run `sb login`, or set SB_TOKEN ' +
|
|
34
|
+
'to an API key (wbk_…) with pages.read / pages.write from Settings -> API keys.';
|
|
35
|
+
export const SITE_NO_SITE = 'Which site? Pass --site <id>, or add "siteId" to sb.json. (An API key (wbk_…) in SB_TOKEN implies its site.)';
|
|
36
|
+
const sha256 = (s) => createHash('sha256').update(s, 'utf8').digest('hex');
|
|
37
|
+
/**
|
|
38
|
+
* A page file: the document as `.page.tsx` (cli/src/source, SKILL sbuilder-site-source),
|
|
39
|
+
* plus the page's own facts for the reader. `page` is information only — renaming or
|
|
40
|
+
* moving a page happens in the editor; the parser ignores this export.
|
|
41
|
+
*/
|
|
42
|
+
const fileText = (p, d) => printPage(d.document) +
|
|
43
|
+
`\n// Information only: rename or move the page in the editor.\nexport const page = ${literal({
|
|
44
|
+
id: p.id,
|
|
45
|
+
name: p.name,
|
|
46
|
+
path: p.path,
|
|
47
|
+
type: p.type,
|
|
48
|
+
})};\n`;
|
|
49
|
+
async function readText(path) {
|
|
50
|
+
try {
|
|
51
|
+
return await readFile(path, 'utf8');
|
|
52
|
+
}
|
|
53
|
+
catch (err) {
|
|
54
|
+
if (err.code === 'ENOENT')
|
|
55
|
+
return undefined;
|
|
56
|
+
throw err;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
async function put(path, text) {
|
|
60
|
+
await mkdir(dirname(path), { recursive: true });
|
|
61
|
+
const tmp = `${path}.${process.pid}.tmp`;
|
|
62
|
+
await writeFile(tmp, text, 'utf8');
|
|
63
|
+
await rename(tmp, path);
|
|
64
|
+
}
|
|
65
|
+
export async function readManifest(dir) {
|
|
66
|
+
const text = await readText(join(dir, SITE_MANIFEST));
|
|
67
|
+
if (text === undefined)
|
|
68
|
+
return { siteId: null, pages: {} };
|
|
69
|
+
let m;
|
|
70
|
+
try {
|
|
71
|
+
m = JSON.parse(text);
|
|
72
|
+
}
|
|
73
|
+
catch {
|
|
74
|
+
throw new SiteRefused(`${SITE_MANIFEST} is not valid JSON — fix it, or delete it and pull again.`);
|
|
75
|
+
}
|
|
76
|
+
// A cloned repo's manifest is somebody else's file: a `file` of "../../.ssh/id_rsa"
|
|
77
|
+
// would have push read it and send it, and pull write outside the repo.
|
|
78
|
+
for (const e of Object.values(m.pages ?? {})) {
|
|
79
|
+
if (!SAFE_FILE.test(String(e?.file))) {
|
|
80
|
+
throw new SiteRefused(`${SITE_MANIFEST} names ${JSON.stringify(e?.file)}, which is not a file in ${PAGES_DIR}/ — nothing was read or sent.`);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return { siteId: m.siteId ?? null, pages: m.pages ?? {} };
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* A symbolic link anywhere on a page file's path, or undefined. The name check
|
|
87
|
+
* above cannot see one: design/pages/index.page.tsx committed as a link to
|
|
88
|
+
* ~/.ssh/id_rsa passes it, and push would read the key and send it.
|
|
89
|
+
*/
|
|
90
|
+
async function linkOn(dir, file) {
|
|
91
|
+
const parts = file.split('/');
|
|
92
|
+
for (let i = 1; i <= parts.length; i++) {
|
|
93
|
+
const p = parts.slice(0, i).join('/');
|
|
94
|
+
if ((await lstat(join(dir, p)).catch(() => undefined))?.isSymbolicLink())
|
|
95
|
+
return p;
|
|
96
|
+
}
|
|
97
|
+
return undefined;
|
|
98
|
+
}
|
|
99
|
+
/** A page file this command may touch: one name, directly in design/pages, no dot first. */
|
|
100
|
+
const SAFE_FILE = /^design\/pages\/[A-Za-z0-9_-][A-Za-z0-9._-]*\.page\.tsx$/;
|
|
101
|
+
const saveManifest = (ctx) => put(join(ctx.dir, SITE_MANIFEST), JSON.stringify(ctx.manifest, null, 2) + '\n');
|
|
102
|
+
async function open(o) {
|
|
103
|
+
const cred = o.token;
|
|
104
|
+
if (!cred)
|
|
105
|
+
throw new SiteRefused(SITE_UNAUTHORIZED);
|
|
106
|
+
if (typeof cred === 'string' && cred.startsWith('sbdk_')) {
|
|
107
|
+
throw new SiteRefused('Deploy keys (sbdk_…) only reach an app’s versions; pages are merchant content. ' +
|
|
108
|
+
'Use `sb login`, or an API key (wbk_…) with pages.write.');
|
|
109
|
+
}
|
|
110
|
+
const v1 = typeof cred === 'string' && cred.startsWith('wbk_');
|
|
111
|
+
const manifest = await readManifest(o.dir);
|
|
112
|
+
const named = [o.site, await sbJsonSite(o.dir), manifest.siteId ?? undefined].filter((v) => !!v);
|
|
113
|
+
if (new Set(named).size > 1) {
|
|
114
|
+
throw new SiteRefused(`--site, sb.json and ${SITE_MANIFEST} name different sites (${[...new Set(named)].join(', ')}). ` +
|
|
115
|
+
'Fix one of them; nothing was sent.');
|
|
116
|
+
}
|
|
117
|
+
const siteId = named[0];
|
|
118
|
+
if (!v1 && !siteId)
|
|
119
|
+
throw new SiteRefused(SITE_NO_SITE);
|
|
120
|
+
if (!v1)
|
|
121
|
+
manifest.siteId = siteId;
|
|
122
|
+
const log = o.log ?? console.log;
|
|
123
|
+
return {
|
|
124
|
+
cred,
|
|
125
|
+
v1,
|
|
126
|
+
base: v1 ? `${o.api}/api/v1` : `${o.api}/api/sites/${encodeURIComponent(siteId)}`,
|
|
127
|
+
dir: o.dir,
|
|
128
|
+
manifest,
|
|
129
|
+
log,
|
|
130
|
+
warn: o.warn ?? log,
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
async function send(ctx, url, method, body) {
|
|
134
|
+
let res;
|
|
135
|
+
try {
|
|
136
|
+
res = await authedFetch(url, body === undefined
|
|
137
|
+
? { method }
|
|
138
|
+
: { method, headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(body) }, ctx.cred);
|
|
139
|
+
}
|
|
140
|
+
catch (err) {
|
|
141
|
+
if (err instanceof DevError)
|
|
142
|
+
throw err.message === SB_TOKEN_REFUSED ? new SiteRefused(SITE_UNAUTHORIZED) : err;
|
|
143
|
+
throw new SiteRefused(`Could not reach ${new URL(url).origin}: ${messageOf(err)}. Check SB_API.`);
|
|
144
|
+
}
|
|
145
|
+
if (res.status === 401)
|
|
146
|
+
throw new SiteRefused(SITE_UNAUTHORIZED);
|
|
147
|
+
return res;
|
|
148
|
+
}
|
|
149
|
+
async function errorOf(res) {
|
|
150
|
+
try {
|
|
151
|
+
return (await res.json());
|
|
152
|
+
}
|
|
153
|
+
catch {
|
|
154
|
+
return { error: `HTTP ${res.status}` };
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
async function listPages(ctx) {
|
|
158
|
+
const out = [];
|
|
159
|
+
for (let offset = 0;;) {
|
|
160
|
+
const url = ctx.v1
|
|
161
|
+
? `${ctx.base}/pages?${new URLSearchParams({ limit: '200', offset: String(offset) })}`
|
|
162
|
+
: `${ctx.base}/pages`;
|
|
163
|
+
const res = await send(ctx, url, 'GET');
|
|
164
|
+
if (res.status === 403)
|
|
165
|
+
throw new SiteRefused('this token cannot read pages — it needs pages.read');
|
|
166
|
+
if (!res.ok)
|
|
167
|
+
throw new SiteRefused(`listing pages failed (server: ${(await errorOf(res)).error})`);
|
|
168
|
+
const body = (await res.json());
|
|
169
|
+
out.push(...body.pages);
|
|
170
|
+
offset += body.pages.length;
|
|
171
|
+
if (!ctx.v1 || body.pages.length === 0 || offset >= body.total)
|
|
172
|
+
break;
|
|
173
|
+
}
|
|
174
|
+
return out;
|
|
175
|
+
}
|
|
176
|
+
const docURL = (ctx, id) => `${ctx.base}/pages/${encodeURIComponent(id)}/${ctx.v1 ? 'document' : 'source'}`;
|
|
177
|
+
/** Both surfaces, one shape: v1 answers {document:{…}}, the session {source:{…}}. */
|
|
178
|
+
async function draftOf(res, v1) {
|
|
179
|
+
const body = (await res.json());
|
|
180
|
+
return body[v1 ? 'document' : 'source'];
|
|
181
|
+
}
|
|
182
|
+
async function getDraft(ctx, id) {
|
|
183
|
+
const res = await send(ctx, docURL(ctx, id), 'GET');
|
|
184
|
+
if (res.status === 404)
|
|
185
|
+
return null;
|
|
186
|
+
if (!res.ok)
|
|
187
|
+
throw new SiteRefused(`reading page ${id} failed (server: ${(await errorOf(res)).error})`);
|
|
188
|
+
return draftOf(res, ctx.v1);
|
|
189
|
+
}
|
|
190
|
+
/** A file name from the page's path; the manifest, not the name, is what ties it to the page. */
|
|
191
|
+
function fileFor(p, taken) {
|
|
192
|
+
const stem = (p.isHomepage ? 'index' : (p.slug || p.path).replace(/^\/+/, ''))
|
|
193
|
+
.toLowerCase()
|
|
194
|
+
.replace(/[^a-z0-9._-]+/g, '-')
|
|
195
|
+
.replace(/^[-.]+|-+$/g, '') || `page-${p.id}`;
|
|
196
|
+
let file = `${PAGES_DIR}/${stem}.page.tsx`;
|
|
197
|
+
if (taken.has(file))
|
|
198
|
+
file = `${PAGES_DIR}/${stem}-${p.id}.page.tsx`;
|
|
199
|
+
taken.add(file);
|
|
200
|
+
return file;
|
|
201
|
+
}
|
|
202
|
+
export async function pull(o) {
|
|
203
|
+
const ctx = await open(o);
|
|
204
|
+
const pages = await listPages(ctx);
|
|
205
|
+
const taken = new Set(Object.values(ctx.manifest.pages).map((e) => e.file));
|
|
206
|
+
let clashes = 0;
|
|
207
|
+
let wrote = 0;
|
|
208
|
+
for (const p of pages) {
|
|
209
|
+
const draft = await getDraft(ctx, p.id);
|
|
210
|
+
if (!draft)
|
|
211
|
+
continue; // a page with no draft yet has nothing to hold
|
|
212
|
+
const entry = ctx.manifest.pages[p.id];
|
|
213
|
+
if (entry && entry.rev === draft.rev) {
|
|
214
|
+
// The draft has not moved, but the page may have been re-pathed in the editor.
|
|
215
|
+
if (entry.path !== p.path && !o.dryRun) {
|
|
216
|
+
entry.path = p.path;
|
|
217
|
+
await saveManifest(ctx);
|
|
218
|
+
}
|
|
219
|
+
continue;
|
|
220
|
+
}
|
|
221
|
+
const file = entry?.file ?? fileFor(p, taken);
|
|
222
|
+
const link = await linkOn(ctx.dir, file);
|
|
223
|
+
if (link) {
|
|
224
|
+
ctx.warn(` ! ${file}: ${link} is a symbolic link — not followed, nothing written.`);
|
|
225
|
+
clashes++;
|
|
226
|
+
continue;
|
|
227
|
+
}
|
|
228
|
+
const local = await readText(join(ctx.dir, file));
|
|
229
|
+
if (entry && local !== undefined && sha256(local) !== entry.sha256 && !o.force) {
|
|
230
|
+
ctx.warn(` ! ${file}: changed here AND in the editor — kept yours. sb site pull --force takes the editor's.`);
|
|
231
|
+
clashes++;
|
|
232
|
+
continue;
|
|
233
|
+
}
|
|
234
|
+
if (!entry && local !== undefined && local !== fileText(p, draft) && !o.force) {
|
|
235
|
+
ctx.warn(` ! ${file}: already exists and is not tracked — kept it. Move it aside, or --force.`);
|
|
236
|
+
clashes++;
|
|
237
|
+
continue;
|
|
238
|
+
}
|
|
239
|
+
const text = fileText(p, draft);
|
|
240
|
+
if (!o.dryRun) {
|
|
241
|
+
await put(join(ctx.dir, file), text);
|
|
242
|
+
ctx.manifest.pages[p.id] = {
|
|
243
|
+
file,
|
|
244
|
+
rev: draft.rev,
|
|
245
|
+
sha256: sha256(text),
|
|
246
|
+
schemaVersion: draft.schemaVersion,
|
|
247
|
+
path: p.path,
|
|
248
|
+
appBlocks: appBlockSeals(draft.document),
|
|
249
|
+
};
|
|
250
|
+
await saveManifest(ctx);
|
|
251
|
+
}
|
|
252
|
+
ctx.log(` ↓ ${file}`);
|
|
253
|
+
wrote++;
|
|
254
|
+
}
|
|
255
|
+
const live = new Set(pages.map((p) => p.id));
|
|
256
|
+
for (const [id, e] of Object.entries(ctx.manifest.pages)) {
|
|
257
|
+
if (live.has(id))
|
|
258
|
+
continue;
|
|
259
|
+
ctx.warn(` ! ${e.file}: its page was deleted on the platform — the file is kept; delete it yourself.`);
|
|
260
|
+
if (!o.dryRun)
|
|
261
|
+
delete ctx.manifest.pages[id];
|
|
262
|
+
}
|
|
263
|
+
if (!o.dryRun)
|
|
264
|
+
await saveManifest(ctx);
|
|
265
|
+
ctx.log(`${wrote} page(s) ${o.dryRun ? 'would be ' : ''}pulled${clashes ? `, ${clashes} kept` : ''}.`);
|
|
266
|
+
return clashes ? 1 : 0;
|
|
267
|
+
}
|
|
268
|
+
export async function push(o) {
|
|
269
|
+
const ctx = await open(o);
|
|
270
|
+
const tracked = new Set(Object.values(ctx.manifest.pages).map((e) => e.file));
|
|
271
|
+
let failed = 0;
|
|
272
|
+
let sent = 0;
|
|
273
|
+
for (const [id, entry] of Object.entries(ctx.manifest.pages)) {
|
|
274
|
+
const link = await linkOn(ctx.dir, entry.file);
|
|
275
|
+
if (link) {
|
|
276
|
+
ctx.warn(` ! ${entry.file}: ${link} is a symbolic link — not followed, nothing sent.`);
|
|
277
|
+
failed++;
|
|
278
|
+
continue;
|
|
279
|
+
}
|
|
280
|
+
const text = await readText(join(ctx.dir, entry.file));
|
|
281
|
+
if (text === undefined) {
|
|
282
|
+
ctx.warn(` ! ${entry.file}: missing — pages are not deleted from here; delete the page in the editor.`);
|
|
283
|
+
failed++;
|
|
284
|
+
continue;
|
|
285
|
+
}
|
|
286
|
+
const sha = sha256(text);
|
|
287
|
+
if (sha === entry.sha256)
|
|
288
|
+
continue;
|
|
289
|
+
let document;
|
|
290
|
+
try {
|
|
291
|
+
document = parsePage(text);
|
|
292
|
+
}
|
|
293
|
+
catch (err) {
|
|
294
|
+
// file:line:col — clickable in a terminal and in an editor's problem matcher.
|
|
295
|
+
ctx.warn(err instanceof SourceError
|
|
296
|
+
? ` ! ${entry.file}:${err.message} — nothing sent.`
|
|
297
|
+
: ` ! ${entry.file}: ${messageOf(err)} — nothing sent.`);
|
|
298
|
+
failed++;
|
|
299
|
+
continue;
|
|
300
|
+
}
|
|
301
|
+
const edited = editedAppBlocks(document, entry.appBlocks);
|
|
302
|
+
if (edited.length) {
|
|
303
|
+
// Refused here, not on the server: the platform would save the page and quietly
|
|
304
|
+
// drop the edit, which reads as success. --force does not change that outcome.
|
|
305
|
+
ctx.warn(APP_BLOCK_EDITED(entry.file, edited));
|
|
306
|
+
failed++;
|
|
307
|
+
continue;
|
|
308
|
+
}
|
|
309
|
+
if (o.dryRun) {
|
|
310
|
+
ctx.log(` ↑ ${entry.file} (dry run)`);
|
|
311
|
+
sent++;
|
|
312
|
+
continue;
|
|
313
|
+
}
|
|
314
|
+
const body = (baseRev) => ({
|
|
315
|
+
document,
|
|
316
|
+
schemaVersion: entry.schemaVersion ?? document.schema_version,
|
|
317
|
+
baseRev,
|
|
318
|
+
});
|
|
319
|
+
let res = await send(ctx, docURL(ctx, id), 'PUT', body(entry.rev));
|
|
320
|
+
if (res.status === 409 && o.force) {
|
|
321
|
+
const err = await errorOf(res);
|
|
322
|
+
const cur = Number(err.details?.rev);
|
|
323
|
+
if (err.code === 'source_stale' && cur > 0)
|
|
324
|
+
res = await send(ctx, docURL(ctx, id), 'PUT', body(cur));
|
|
325
|
+
}
|
|
326
|
+
if (!res.ok) {
|
|
327
|
+
const err = await errorOf(res);
|
|
328
|
+
ctx.warn(err.code === 'source_stale'
|
|
329
|
+
? ` ! ${entry.file}: edited in the editor since your last pull — nothing sent. ` +
|
|
330
|
+
'Pull and merge, or sb site push --force to overwrite the editor’s draft.'
|
|
331
|
+
: ` ! ${entry.file}: refused (${err.code ? `${err.code}: ` : ''}${err.error})`);
|
|
332
|
+
failed++;
|
|
333
|
+
continue;
|
|
334
|
+
}
|
|
335
|
+
const draft = await draftOf(res, ctx.v1);
|
|
336
|
+
for (const w of draft.warnings ?? []) {
|
|
337
|
+
const subject = Object.entries(w)
|
|
338
|
+
.filter(([k, v]) => k !== 'code' && typeof v === 'string' && v)
|
|
339
|
+
.map(([k, v]) => `${k} ${v}`)
|
|
340
|
+
.join(', ');
|
|
341
|
+
ctx.warn(` ! ${entry.file}: the platform says ${w.code}${subject ? ` (${subject})` : ''}`);
|
|
342
|
+
}
|
|
343
|
+
ctx.manifest.pages[id] = {
|
|
344
|
+
...entry,
|
|
345
|
+
appBlocks: appBlockSeals(draft.document),
|
|
346
|
+
rev: draft.rev,
|
|
347
|
+
sha256: sha,
|
|
348
|
+
schemaVersion: draft.schemaVersion,
|
|
349
|
+
};
|
|
350
|
+
await saveManifest(ctx);
|
|
351
|
+
ctx.log(` ↑ ${entry.file}`);
|
|
352
|
+
sent++;
|
|
353
|
+
}
|
|
354
|
+
const local = await readdir(join(ctx.dir, PAGES_DIR)).catch(() => []);
|
|
355
|
+
for (const f of local) {
|
|
356
|
+
const file = `${PAGES_DIR}/${f}`;
|
|
357
|
+
if (f.endsWith('.page.tsx') && !tracked.has(file)) {
|
|
358
|
+
ctx.warn(` ? ${file}: not a tracked page — create the page in the editor, then sb site pull.`);
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
ctx.log(`${sent} page draft(s) ${o.dryRun ? 'would be ' : ''}saved. Publish with sb site publish when ready.`);
|
|
362
|
+
return failed ? 1 : 0;
|
|
363
|
+
}
|
|
364
|
+
export const PUBLISH_WHAT = 'Which pages? Name their files (sb site publish design/pages/index.page.tsx) or pass --all. ' +
|
|
365
|
+
'Publishing makes them live; nothing is published by default.';
|
|
366
|
+
/**
|
|
367
|
+
* `sb site publish` — make drafts LIVE. The one command here that visitors see,
|
|
368
|
+
* so it never guesses: files are named, or --all is typed.
|
|
369
|
+
*/
|
|
370
|
+
export async function publish(o) {
|
|
371
|
+
if (!o.all && o.files.length === 0)
|
|
372
|
+
throw new SiteRefused(PUBLISH_WHAT);
|
|
373
|
+
const ctx = await open(o);
|
|
374
|
+
const byFile = new Map(Object.entries(ctx.manifest.pages).map(([id, e]) => [e.file, id]));
|
|
375
|
+
let ids;
|
|
376
|
+
if (!o.all) {
|
|
377
|
+
ids = [];
|
|
378
|
+
for (const f of o.files) {
|
|
379
|
+
const rel = f.replace(/\\/g, '/').replace(/^\.\//, '');
|
|
380
|
+
const id = byFile.get(rel) ?? byFile.get(`${PAGES_DIR}/${rel}`);
|
|
381
|
+
if (!id)
|
|
382
|
+
throw new SiteRefused(`${f} is not a tracked page file — nothing was published.`);
|
|
383
|
+
ids.push(id);
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
if (o.dryRun) {
|
|
387
|
+
ctx.log(ids ? `would publish ${ids.length} page(s)` : 'would publish every page');
|
|
388
|
+
return 0;
|
|
389
|
+
}
|
|
390
|
+
if (!ctx.v1) {
|
|
391
|
+
const res = await send(ctx, `${ctx.base}/publish`, 'POST', ids ? { pageIds: ids } : {});
|
|
392
|
+
if (!res.ok)
|
|
393
|
+
throw new SiteRefused(`publish refused (server: ${(await errorOf(res)).error})`);
|
|
394
|
+
const n = (await res.json()).published.length;
|
|
395
|
+
ctx.log(`${n} page(s) published — they are live now.`);
|
|
396
|
+
return 0;
|
|
397
|
+
}
|
|
398
|
+
// An API key publishes one page at a time (/api/v1 has no site-wide publish).
|
|
399
|
+
const targets = ids ?? (await listPages(ctx)).map((p) => p.id);
|
|
400
|
+
let failed = 0;
|
|
401
|
+
for (const id of targets) {
|
|
402
|
+
const res = await send(ctx, `${ctx.base}/pages/${encodeURIComponent(id)}/publish`, 'POST');
|
|
403
|
+
const file = ctx.manifest.pages[id]?.file ?? id;
|
|
404
|
+
if (res.ok)
|
|
405
|
+
ctx.log(` ✓ ${file}`);
|
|
406
|
+
else if (res.status === 409)
|
|
407
|
+
ctx.log(` · ${file}: no draft to publish`);
|
|
408
|
+
else {
|
|
409
|
+
ctx.warn(` ! ${file}: refused (${(await errorOf(res)).error})`);
|
|
410
|
+
failed++;
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
ctx.log('Published pages are live now.');
|
|
414
|
+
return failed ? 1 : 0;
|
|
415
|
+
}
|
|
416
|
+
/**
|
|
417
|
+
* `sb site blocks` — the blocks this site's installed apps let you place, each with
|
|
418
|
+
* the line to paste into a page file. The platform composes the app's subtree from
|
|
419
|
+
* `appBlockRef` on the next push; `appBlockValues` holds the settings it lists.
|
|
420
|
+
*/
|
|
421
|
+
export async function blocks(o) {
|
|
422
|
+
const ctx = await open(o);
|
|
423
|
+
if (!ctx.v1)
|
|
424
|
+
throw new SiteRefused('sb site blocks reads /api/v1/app-blocks with the repo’s API key — run it inside a repo made by sb site init (its .env has the key), or set SB_TOKEN to a wbk_ key.');
|
|
425
|
+
const res = await send(ctx, `${ctx.base}/app-blocks`, 'GET');
|
|
426
|
+
if (res.status === 403)
|
|
427
|
+
throw new SiteRefused('this key cannot read pages (it needs pages.read)');
|
|
428
|
+
if (!res.ok)
|
|
429
|
+
throw new SiteRefused(`listing app blocks failed (server: ${(await errorOf(res)).error})`);
|
|
430
|
+
const list = (await res.json()).appBlocks;
|
|
431
|
+
if (list.length === 0) {
|
|
432
|
+
ctx.log('No installed app offers a block on this site.');
|
|
433
|
+
return 0;
|
|
434
|
+
}
|
|
435
|
+
for (const b of list) {
|
|
436
|
+
const tag = tagFor(b.rootType) ?? 'Node';
|
|
437
|
+
const type = tag === 'Node' ? ` type=${JSON.stringify(b.rootType)}` : '';
|
|
438
|
+
ctx.log(`${b.appName} · ${b.name}`);
|
|
439
|
+
ctx.log(` <${tag}${type} appBlockRef=${JSON.stringify(b.ref)} />`);
|
|
440
|
+
for (const s of b.settings) {
|
|
441
|
+
ctx.log(` setting: appBlockValues.${s.slot}.${s.target}${s.writeKey ? `.${s.writeKey}` : ''}${s.widget ? ` (${s.widget})` : ''}`);
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
ctx.log('');
|
|
445
|
+
ctx.log('Paste a line into a page file and push; the app fills the block in. Edit only appBlockValues inside it.');
|
|
446
|
+
return 0;
|
|
447
|
+
}
|
|
448
|
+
//# sourceMappingURL=site.js.map
|