@tideworthy/tidysites 0.1.18 → 0.1.19
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/tidysites.mjs +14 -10
- package/package.json +1 -1
package/bin/tidysites.mjs
CHANGED
|
@@ -133,11 +133,12 @@ function describeError(e) {
|
|
|
133
133
|
return msg;
|
|
134
134
|
}
|
|
135
135
|
|
|
136
|
-
async function tool(cfg, name, args) {
|
|
136
|
+
async function tool(cfg, name, args, { throws = false } = {}) {
|
|
137
137
|
try {
|
|
138
138
|
return await callTool(cfg, name, args);
|
|
139
139
|
} catch (e) {
|
|
140
|
-
|
|
140
|
+
// A caller that can recover (a menu to create first) takes the error; every other call ends the command with it.
|
|
141
|
+
if (e instanceof ApiError && !throws) fail(describeError(e));
|
|
141
142
|
throw e;
|
|
142
143
|
}
|
|
143
144
|
}
|
|
@@ -367,24 +368,27 @@ async function push(ctx) {
|
|
|
367
368
|
}
|
|
368
369
|
try {
|
|
369
370
|
try {
|
|
370
|
-
await tool(ctx.cfg, 'call_website_site_tool', { site_id: ctx.cfg.site, tool: 'menu_set_items', arguments: { name, items } });
|
|
371
|
+
await tool(ctx.cfg, 'call_website_site_tool', { site_id: ctx.cfg.site, tool: 'menu_set_items', arguments: { name, items } }, { throws: true });
|
|
371
372
|
} catch (e) {
|
|
372
373
|
// A menu the website does not have yet (a phone drawer, a footer column) is created from the file, then filled.
|
|
373
374
|
if (!/not.?found/i.test(e.message ?? '')) throw e;
|
|
374
|
-
|
|
375
|
-
await tool(ctx.cfg, 'call_website_site_tool', { site_id: ctx.cfg.site, tool: '
|
|
375
|
+
if (!/^[a-z][a-z0-9_]*$/.test(name)) throw new Error(`a new menu's name is lowercase letters, digits and underscores (${name} has something else)`);
|
|
376
|
+
await tool(ctx.cfg, 'call_website_site_tool', { site_id: ctx.cfg.site, tool: 'menu_create', arguments: { name, label: m.label || name } }, { throws: true });
|
|
377
|
+
await tool(ctx.cfg, 'call_website_site_tool', { site_id: ctx.cfg.site, tool: 'menu_set_items', arguments: { name, items } }, { throws: true });
|
|
376
378
|
say(`Menu ${name}: created.`);
|
|
377
379
|
}
|
|
378
380
|
say(`Menu ${name}: ${items.length} item${items.length === 1 ? '' : 's'} written.`);
|
|
379
381
|
} catch (e) {
|
|
380
|
-
menuProblems.push(`menus/${name}.json: ${e.message}`);
|
|
382
|
+
menuProblems.push(`menus/${name}.json: ${e instanceof ApiError ? describeError(e) : e.message}`);
|
|
381
383
|
}
|
|
382
384
|
}
|
|
385
|
+
// Refresh what went (the entries, and the menus that were written) before any menu failure is reported, so the snapshot
|
|
386
|
+
// knows the website's new versions and the next push is not refused as "changed on the website".
|
|
387
|
+
const written = menus.filter((n) => !menuProblems.some((p) => p.startsWith(`menus/${n}.json`)));
|
|
388
|
+
const pushed = new Set([...keys, ...written.map((m) => `menus/${m}`)]);
|
|
389
|
+
if (touched.length) await pull(ctx, touched, { overwrite: pushed, menus: written.length > 0 });
|
|
390
|
+
else if (written.length) await pullMenus(ctx);
|
|
383
391
|
if (menuProblems.length) fail(menuProblems.join('\n'));
|
|
384
|
-
// Refresh only what went, and take the website's version of exactly those entries; every other file stays as it is.
|
|
385
|
-
const pushed = new Set([...keys, ...menus.map((m) => `menus/${m}`)]);
|
|
386
|
-
if (touched.length) await pull(ctx, touched, { overwrite: pushed, menus: menus.length > 0 });
|
|
387
|
-
else if (menus.length) await pullMenus(ctx);
|
|
388
392
|
}
|
|
389
393
|
|
|
390
394
|
const MEDIA_TYPES = { png: 'image/png', jpg: 'image/jpeg', jpeg: 'image/jpeg', gif: 'image/gif', webp: 'image/webp', avif: 'image/avif', svg: 'image/svg+xml', ico: 'image/x-icon', mp4: 'video/mp4', m4v: 'video/mp4', webm: 'video/webm', mov: 'video/quicktime', woff2: 'font/woff2', woff: 'font/woff', ttf: 'font/ttf', otf: 'font/otf', pdf: 'application/pdf' };
|
package/package.json
CHANGED