decklight 0.9.0 → 0.10.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/PLATFORM.md +44 -3
- package/README.md +7 -5
- package/SPEC.md +100 -31
- package/cli/agent-review.mjs +5 -4
- package/cli/agents.mjs +11 -5
- package/cli/bundle-audio.mjs +10 -3
- package/cli/bundle-module.mjs +95 -0
- package/cli/bundle.mjs +58 -6
- package/cli/cast.mjs +41 -5
- package/cli/check-fixes.mjs +186 -0
- package/cli/check.mjs +32 -5
- package/cli/commit-flow.mjs +7 -3
- package/cli/commit-message.mjs +1 -1
- package/cli/commit-split.mjs +2 -2
- package/cli/deck-refs.mjs +8 -3
- package/cli/design-system-refs.mjs +263 -6
- package/cli/design-system.mjs +82 -14
- package/cli/edit-git.mjs +2 -2
- package/cli/edit-handover.mjs +129 -23
- package/cli/edit-look.mjs +248 -5
- package/cli/edit.mjs +504 -58
- package/cli/enhance.mjs +12 -10
- package/cli/git.mjs +13 -0
- package/cli/init.mjs +8 -3
- package/cli/marketplace-autocheck.mjs +200 -0
- package/cli/marketplace.mjs +250 -13
- package/cli/narrate.mjs +78 -3
- package/cli/open.mjs +24 -6
- package/cli/pdf.mjs +27 -8
- package/cli/pptx-export.mjs +7 -4
- package/cli/record.mjs +73 -13
- package/cli/remote.mjs +32 -6
- package/cli/serve.mjs +2 -2
- package/cli/skill-content.mjs +40 -3
- package/cli/skills.mjs +247 -3
- package/cli/theme-refs.mjs +14 -2
- package/cli/units.mjs +75 -7
- package/dist/build-info.json +1 -1
- package/dist/decklight.css +429 -32
- package/dist/decklight.js +169 -123
- package/dist/decklight.js.map +4 -4
- package/package.json +1 -1
- package/tools/design-system-format.mjs +25 -0
- package/tools/design-system-migrations.mjs +207 -0
- package/tools/exec.mjs +10 -2
- package/tools/narration-manifest.mjs +77 -3
- package/tools/site-clip.mjs +114 -0
- package/tools/video.mjs +69 -6
package/cli/design-system.mjs
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
// decklight design-system gate <dir>
|
|
8
8
|
// decklight design-system add|remove <name@marketplace> <deck.html>
|
|
9
9
|
// decklight design-system list [<deck.html>]
|
|
10
|
+
// decklight design-system migrate <name@marketplace> <deck.html>
|
|
10
11
|
// decklight design-system templates <name@marketplace>
|
|
11
12
|
//
|
|
12
13
|
// `check` is the admission gate a catalog's own CI runs, in the mould of
|
|
@@ -23,12 +24,12 @@
|
|
|
23
24
|
// ~/.decklight/ — the ledger only remembers which version a deck took.
|
|
24
25
|
|
|
25
26
|
import { existsSync, lstatSync, readdirSync, readFileSync, realpathSync, statSync } from 'node:fs';
|
|
26
|
-
import { join, relative, resolve, sep } from 'node:path';
|
|
27
|
+
import { dirname, join, relative, resolve, sep } from 'node:path';
|
|
27
28
|
import { argReader, isMain } from '../tools/args.mjs';
|
|
28
29
|
import { checkPackage, DESIGN_SYSTEM_API_VERSION, ASSET_EXTENSIONS } from '../tools/design-system-format.mjs';
|
|
29
30
|
import { THEMES_DIR } from './pkg.mjs';
|
|
30
31
|
|
|
31
|
-
const USAGE = `usage: decklight design-system <add|remove|list|templates|apply|gate> …
|
|
32
|
+
const USAGE = `usage: decklight design-system <add|remove|list|templates|apply|migrate|gate> …
|
|
32
33
|
|
|
33
34
|
decklight design-system add <name@marketplace> <deck.html> [--no-recommended] [--apply|--no-apply]
|
|
34
35
|
reference a design system from a deck — after the package passes check;
|
|
@@ -43,6 +44,13 @@ const USAGE = `usage: decklight design-system <add|remove|list|templates|apply|g
|
|
|
43
44
|
give a deck the look a design system it uses was drawn for: its first
|
|
44
45
|
recommended theme and font (bringing any that are missing)
|
|
45
46
|
|
|
47
|
+
decklight design-system migrate <name@marketplace> <deck.html>
|
|
48
|
+
move a deck written for an older version onto the one this machine
|
|
49
|
+
serves: the renames its migrations declare (roles, tokens, classes,
|
|
50
|
+
themes — whole names, in the deck and the stylesheets it links), then the
|
|
51
|
+
version the deck records. A removed name with no successor is a
|
|
52
|
+
judgement call: the migration's skill makes it, not this command.
|
|
53
|
+
|
|
46
54
|
decklight design-system remove <name@marketplace> <deck.html>
|
|
47
55
|
drop the reference; the package stays in its marketplace, and so do the
|
|
48
56
|
themes and fonts it brought — other slides may use them (it lists them)
|
|
@@ -69,7 +77,8 @@ const USAGE = `usage: decklight design-system <add|remove|list|templates|apply|g
|
|
|
69
77
|
palette [{ group, label, token }] or { colors: { <name>:
|
|
70
78
|
{ label, weights: { "100": "#hex" … "1000" } } } } with
|
|
71
79
|
themes [{ name, title, mode, tokens }] (SPEC BRAND_PALETTE),
|
|
72
|
-
recommendedThemes
|
|
80
|
+
recommendedThemes, migrations { "<version>": { skill,
|
|
81
|
+
roles, tokens, classes, themes } } (SPEC DESIGN_SYSTEM_MIGRATIONS)
|
|
73
82
|
design-system.css prefixed tokens and per-template rules; url()s relative to it
|
|
74
83
|
templates.html inert <template data-template="…"> blocks, with data-slot containers
|
|
75
84
|
assets/… ${ASSET_EXTENSIONS.join(' · ')}
|
|
@@ -176,6 +185,9 @@ export function reportLines(dir, r) {
|
|
|
176
185
|
out.push(` theme ${t.name} (${t.mode}) — ${t.stated.length} token${t.stated.length === 1 ? '' : 's'} stated${via ? ` (${via} through roles)` : ''}, ${t.chosen.length} chosen from the palette`
|
|
177
186
|
+ `${roles.length ? `, every role set` : ''}`);
|
|
178
187
|
}
|
|
188
|
+
for (const m of s.migrations ?? []) {
|
|
189
|
+
out.push(` migration ${m.version} — ${m.renames} rename${m.renames === 1 ? '' : 's'}${m.skill ? ` · skill ${m.skill}` : ''}`);
|
|
190
|
+
}
|
|
179
191
|
const assets = s.assets ?? [];
|
|
180
192
|
const byExt = {};
|
|
181
193
|
for (const a of assets) byExt[a.ext] = (byExt[a.ext] ?? 0) + 1;
|
|
@@ -230,7 +242,7 @@ async function addMain(args, on) {
|
|
|
230
242
|
const d = readDeckArg(cmd, deck);
|
|
231
243
|
if (!d) return 1;
|
|
232
244
|
const { MarketplaceError, resolveEntry, recordInstall, loadRegistry, configHome } = await import('./marketplace.mjs');
|
|
233
|
-
const { resolveDesignSystemRef, setDesignSystem, designSystemRefs } = await import('./design-system-refs.mjs');
|
|
245
|
+
const { resolveDesignSystemRef, setDesignSystem, designSystemRefs, recordVersionIfCurrent } = await import('./design-system-refs.mjs');
|
|
234
246
|
const { refForDeck, writeFileAtomic } = { ...(await import('./theme-refs.mjs')), ...(await import('../tools/atomic-write.mjs')) };
|
|
235
247
|
try {
|
|
236
248
|
if (!on) {
|
|
@@ -269,7 +281,10 @@ async function addMain(args, on) {
|
|
|
269
281
|
return 1;
|
|
270
282
|
}
|
|
271
283
|
const deckRef = refForDeck(d.html, r.name, r.local, r.source ?? null);
|
|
272
|
-
const out = setDesignSystem(d.html, deckRef, true, { source: r.source ?? null });
|
|
284
|
+
const out = setDesignSystem(d.html, deckRef, true, { source: r.source ?? null, version: verdict.manifest.version });
|
|
285
|
+
// a deck that already used it and records no version takes this one —
|
|
286
|
+
// unless it still uses names a migration renamed, which `migrate` moves first
|
|
287
|
+
if (!out.changed) out.html = recordVersionIfCurrent(out.html, deckRef, verdict.manifest, dirname(d.path));
|
|
273
288
|
// its themes and fonts, in the SAME string — one write, one edit
|
|
274
289
|
const recommended = !args.includes('--no-recommended');
|
|
275
290
|
const deps = await import('./design-system-deps.mjs');
|
|
@@ -283,9 +298,12 @@ async function addMain(args, on) {
|
|
|
283
298
|
recordInstall({ type: 'design-system', name: r.name, marketplace: r.local, version: r.entry.version ?? null, commit });
|
|
284
299
|
if (recommended) for (const inst of deps.plannedInstalls(plan)) recordInstall(inst);
|
|
285
300
|
const v = verdict.summary.version ? ` ${verdict.summary.version}` : '';
|
|
301
|
+
const { deckDesignSystemVersions } = await import('./design-system-refs.mjs');
|
|
302
|
+
const took = deckDesignSystemVersions(html)[deckRef];
|
|
286
303
|
console.log(out.changed
|
|
287
304
|
? `${deck} now uses ${deckRef}${v} — ${verdict.summary.title}; every server links it from the marketplace on this machine`
|
|
288
|
-
: `${deck} already uses ${deckRef} —
|
|
305
|
+
: took ? `${deck} already uses ${deckRef} — written for ${took}${took !== verdict.summary.version ? `; this machine serves ${verdict.summary.version} (decklight design-system migrate ${deckRef} ${deck})` : ''}`
|
|
306
|
+
: `${deck} already uses ${deckRef} — it uses names from before ${verdict.summary.version}: decklight design-system migrate ${deckRef} ${deck}`);
|
|
289
307
|
if (recommended) for (const line of deps.planLines(plan)) console.log(line);
|
|
290
308
|
else if (plan.items.some((it) => it.status === 'add')) {
|
|
291
309
|
console.log(' --no-recommended: not added — what it recommends:');
|
|
@@ -317,21 +335,26 @@ async function addMain(args, on) {
|
|
|
317
335
|
|
|
318
336
|
async function listMain(args) {
|
|
319
337
|
const [deck] = args.filter((a) => !a.startsWith('-'));
|
|
320
|
-
const { marketplaceDesignSystems, designSystemRefs, resolveDesignSystemRef } = await import('./design-system-refs.mjs');
|
|
321
|
-
const {
|
|
338
|
+
const { marketplaceDesignSystems, designSystemRefs, resolveDesignSystemRef, deckDesignSystemVersions } = await import('./design-system-refs.mjs');
|
|
339
|
+
const { semverCompare } = await import('./marketplace.mjs');
|
|
340
|
+
const { majorOf } = await import('../tools/design-system-migrations.mjs');
|
|
322
341
|
const { markedSources } = await import('./theme-refs.mjs');
|
|
323
|
-
const installs = loadLedger().installs;
|
|
324
342
|
if (deck) {
|
|
325
343
|
const d = readDeckArg('list', deck);
|
|
326
344
|
if (!d) return 1;
|
|
327
345
|
const refs = designSystemRefs(d.html);
|
|
328
346
|
if (!refs.length) { console.log(`${deck} uses no design system — decklight design-system add <name@marketplace> ${deck}`); return 0; }
|
|
329
347
|
const sources = markedSources(d.html);
|
|
348
|
+
// the version the DECK took, against the catalog's — never this machine's
|
|
349
|
+
// ledger, which knows nothing of a deck written elsewhere (SPEC DESIGN_SYSTEM_MIGRATIONS)
|
|
350
|
+
const took = deckDesignSystemVersions(d.html);
|
|
330
351
|
for (const ref of refs) {
|
|
331
352
|
const r = resolveDesignSystemRef(ref, undefined, { source: sources[ref.marketplace] ?? null });
|
|
332
|
-
const had =
|
|
353
|
+
const had = took[ref.ref] ?? null;
|
|
333
354
|
const now = r.entry?.version ?? null;
|
|
334
|
-
const
|
|
355
|
+
const newer = had && now && semverCompare(now, had) > 0;
|
|
356
|
+
const major = newer && majorOf(had) !== null && majorOf(had) < majorOf(now);
|
|
357
|
+
const ver = newer ? ` ${had} → ${now}${major ? ' (major: migrate)' : ''}` : had ? ` ${had}` : now ? ` ${now} (the deck records no version)` : '';
|
|
335
358
|
console.log(`${ref.ref}${ver}${r.missing ? ` — missing: ${r.missing}` : r.title ? ` — ${r.title}` : ''}`);
|
|
336
359
|
}
|
|
337
360
|
return 0;
|
|
@@ -378,7 +401,7 @@ async function applyMain(args) {
|
|
|
378
401
|
if (!ref) { console.error(`decklight design-system apply: needs a design system and a deck\n\n${USAGE}`); return 1; }
|
|
379
402
|
const d = readDeckArg('apply', deck);
|
|
380
403
|
if (!d) return 1;
|
|
381
|
-
const { designSystemRefs, resolveDesignSystemRef } = await import('./design-system-refs.mjs');
|
|
404
|
+
const { designSystemRefs, resolveDesignSystemRef, recordVersionIfCurrent } = await import('./design-system-refs.mjs');
|
|
382
405
|
const { markedSources } = await import('./theme-refs.mjs');
|
|
383
406
|
const { writeFileAtomic } = await import('../tools/atomic-write.mjs');
|
|
384
407
|
const { recordInstall } = await import('./marketplace.mjs');
|
|
@@ -390,7 +413,7 @@ async function applyMain(args) {
|
|
|
390
413
|
if (!verdict.ok) { console.error(`decklight design-system apply: ${hit.ref} no longer passes its check — decklight design-system gate ${r.dir}`); return 1; }
|
|
391
414
|
const deps = await import('./design-system-deps.mjs');
|
|
392
415
|
const plan = deps.planRecommended(d.html, { manifest: verdict.manifest, local: r.local });
|
|
393
|
-
let html = deps.writePlan(d.html, plan);
|
|
416
|
+
let html = deps.writePlan(recordVersionIfCurrent(d.html, hit.ref, verdict.manifest, dirname(d.path)), plan);
|
|
394
417
|
const look = deps.lookOf(html, plan);
|
|
395
418
|
// recorded even when the deck is left as it is: one already there may be
|
|
396
419
|
// one the catalog has a newer version of, and the ledger is where that goes
|
|
@@ -410,6 +433,50 @@ async function applyMain(args) {
|
|
|
410
433
|
return 0;
|
|
411
434
|
}
|
|
412
435
|
|
|
436
|
+
/**
|
|
437
|
+
* `design-system migrate` (SPEC DESIGN_SYSTEM_MIGRATIONS): the renames the
|
|
438
|
+
* package declares since the version the deck records, applied as whole
|
|
439
|
+
* names to the deck and to the stylesheets it links beside it, and the
|
|
440
|
+
* recorded version moved to the one this machine serves. Every file is
|
|
441
|
+
* renamed in memory before any is written. What a rename cannot decide — a
|
|
442
|
+
* name removed with no successor — is the migration's skill's, and said.
|
|
443
|
+
*/
|
|
444
|
+
async function migrateMain(args) {
|
|
445
|
+
const [ref, deck] = args.filter((a) => !a.startsWith('-'));
|
|
446
|
+
if (!ref) { console.error(`decklight design-system migrate: needs a design system and a deck\n\n${USAGE}`); return 1; }
|
|
447
|
+
const d = readDeckArg('migrate', deck);
|
|
448
|
+
if (!d) return 1;
|
|
449
|
+
const { planMigration, migrationLines } = await import('./design-system-refs.mjs');
|
|
450
|
+
const { writeFileAtomic } = await import('../tools/atomic-write.mjs');
|
|
451
|
+
const plan = planMigration(d.html, dirname(d.path), ref);
|
|
452
|
+
if (plan.error) { console.error(`decklight design-system migrate: ${plan.error.replace(/^the deck/, deck)}`); return 1; }
|
|
453
|
+
if (!plan.changed) { console.log(`${deck} is already on ${plan.ref} ${plan.version} — nothing to migrate`); return 0; }
|
|
454
|
+
for (const x of plan.sheets) writeFileAtomic(x.path, x.text);
|
|
455
|
+
if (plan.html !== d.html) writeFileAtomic(d.path, plan.html);
|
|
456
|
+
const { placedSkill, placeSkill, skillPlaces, skillPlaceAnswer, skillPlaceQuestion } = await import('./skills.mjs');
|
|
457
|
+
const placed = (s) => placedSkill(s);
|
|
458
|
+
for (const line of migrationLines(plan, deck, { placed })) console.log(line);
|
|
459
|
+
// On a terminal, a skill the agent does not have yet is offered, every
|
|
460
|
+
// project first. An agent running this (the edit server's Migrate) has no
|
|
461
|
+
// TTY, and its server asked the author before it started (#893).
|
|
462
|
+
const missing = plan.status.skills.filter((s) => !placed(s));
|
|
463
|
+
if (missing.length && process.stdin.isTTY && process.stdout.isTTY) {
|
|
464
|
+
const { createInterface } = await import('node:readline/promises');
|
|
465
|
+
const rl = createInterface({ input: process.stdin, output: process.stdout });
|
|
466
|
+
try {
|
|
467
|
+
for (const s of missing) {
|
|
468
|
+
const where = skillPlaceAnswer(await rl.question(skillPlaceQuestion(s, skillPlaces(s))));
|
|
469
|
+
if (!where) continue;
|
|
470
|
+
try {
|
|
471
|
+
const { lines } = await placeSkill(s, { global: where === 'global', ref: plan.marketplace ? `${s}@${plan.marketplace}` : s });
|
|
472
|
+
for (const line of lines) console.log(` ${line}`);
|
|
473
|
+
} catch (e) { console.error(` could not install ${s}: ${e.message}`); }
|
|
474
|
+
}
|
|
475
|
+
} finally { rl.close(); }
|
|
476
|
+
}
|
|
477
|
+
return 0;
|
|
478
|
+
}
|
|
479
|
+
|
|
413
480
|
export async function designSystemMain(args = []) {
|
|
414
481
|
const sub = args[0];
|
|
415
482
|
if (!sub || sub === '--help' || sub === '-h' || sub === 'help') { console.log(USAGE); return sub ? 0 : 1; }
|
|
@@ -422,7 +489,8 @@ export async function designSystemMain(args = []) {
|
|
|
422
489
|
if (sub === 'list') return listMain(rest);
|
|
423
490
|
if (sub === 'templates') return templatesMain(rest);
|
|
424
491
|
if (sub === 'apply') return applyMain(rest);
|
|
425
|
-
|
|
492
|
+
if (sub === 'migrate') return migrateMain(rest);
|
|
493
|
+
console.error(`decklight design-system: unknown subcommand "${sub}" — add, remove, apply, migrate, list, templates, check\n\n${USAGE}`);
|
|
426
494
|
return 1;
|
|
427
495
|
}
|
|
428
496
|
|
package/cli/edit-git.mjs
CHANGED
|
@@ -128,7 +128,7 @@ export function registerGitRoutes(routes, {
|
|
|
128
128
|
return json(200, { ok: true, subject: null });
|
|
129
129
|
}
|
|
130
130
|
|
|
131
|
-
// "write
|
|
131
|
+
// "write it for me": the uncommitted work cut into the commits an agent
|
|
132
132
|
// proposes (cli/commit-split.mjs). The plan carries `base`, the fingerprint
|
|
133
133
|
// of the work it was made on, which the split route checks before it
|
|
134
134
|
// commits anything. Asked only on the click, like the one-line subject.
|
|
@@ -143,7 +143,7 @@ export function registerGitRoutes(routes, {
|
|
|
143
143
|
if (!work) return json(409, { ok: false, code: 'FIRST', error: 'the first commit is one commit — write its message' });
|
|
144
144
|
if (!commits) return json(200, { ok: true, base: work.base, units: [], commits: [] });
|
|
145
145
|
if (!describer() && work.units.some((u) => u.file === deckRel)) {
|
|
146
|
-
return json(409, { ok: false, error: 'no agent is installed on this machine to write
|
|
146
|
+
return json(409, { ok: false, error: 'no agent is installed on this machine to write one — decklight doctor lists the ones it can use' });
|
|
147
147
|
}
|
|
148
148
|
return json(200, { ok: true, base: work.base, units: work.units.map(unitSummary), commits });
|
|
149
149
|
}
|
package/cli/edit-handover.mjs
CHANGED
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
// waiting on it. Nothing here reads those bindings until a request arrives.
|
|
23
23
|
|
|
24
24
|
import { existsSync } from 'node:fs';
|
|
25
|
-
import { basename, dirname,
|
|
25
|
+
import { basename, dirname, relative, resolve, sep } from 'node:path';
|
|
26
26
|
import { fileURLToPath } from 'node:url';
|
|
27
27
|
import { spawn } from 'node:child_process';
|
|
28
28
|
|
|
@@ -33,6 +33,21 @@ import { CommandError } from './util.mjs';
|
|
|
33
33
|
import { THEME_NAME, GEN_THEME } from '../tools/render-theme.mjs';
|
|
34
34
|
import { locateSlide, sectionChildRanges } from '../tools/deck-html.mjs';
|
|
35
35
|
|
|
36
|
+
/** How long a stopped child has to clean up after SIGTERM before SIGKILL. */
|
|
37
|
+
const STOP_GRACE_MS = 5000;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Why `module` cannot name a chapter to bundle, or null when it can (or is
|
|
41
|
+
* absent: the whole deck). The bundle card sends the chapter's NUMBER, never
|
|
42
|
+
* its title: `--module` takes a full title too, but a title is free text and
|
|
43
|
+
* a number is the one thing the picker and the CLI count the same way.
|
|
44
|
+
* Whether the deck has that chapter is the bundler's to say.
|
|
45
|
+
*/
|
|
46
|
+
export function moduleProblem(module) {
|
|
47
|
+
if (module == null) return null;
|
|
48
|
+
return /^[1-9]\d{0,3}$/.test(String(module)) ? null : 'the module is a chapter number, counting from 1';
|
|
49
|
+
}
|
|
50
|
+
|
|
36
51
|
/**
|
|
37
52
|
* Put the hand-over routes into `routes`, the table cli/edit.mjs dispatches
|
|
38
53
|
* on, and hand it back.
|
|
@@ -43,10 +58,13 @@ import { locateSlide, sectionChildRanges } from '../tools/deck-html.mjs';
|
|
|
43
58
|
* `broadcast` for the export's progress, and `gitOn()` for whether this
|
|
44
59
|
* session has a repository to publish from: a getter, not a copy, because it
|
|
45
60
|
* is a `let` of editMain's and the answer is whatever it holds when a publish
|
|
46
|
-
* asks.
|
|
61
|
+
* asks. `onExport` hears `{ kind, what }` when an export starts and null when
|
|
62
|
+
* it ends, so `/deck/ping` can tell a page that loads mid-render there is one
|
|
63
|
+
* to stop.
|
|
47
64
|
*/
|
|
48
|
-
export function registerHandoverRoutes(routes, { readDeck, deckPath, root, gitOn, broadcast = () => {} }) {
|
|
65
|
+
export function registerHandoverRoutes(routes, { readDeck, deckPath, root, gitOn, broadcast = () => {}, onExport = () => {} }) {
|
|
49
66
|
let exporting = false; // an export in flight — one browser, one output path, any kind
|
|
67
|
+
let stopExport = null; // stops it, while it is one that can be stopped
|
|
50
68
|
let publishing = false; // a publish in flight — one push at a time
|
|
51
69
|
|
|
52
70
|
// ── hand-over: the files this deck can be written out as, and publishing ───
|
|
@@ -79,6 +97,9 @@ export function registerHandoverRoutes(routes, { readDeck, deckPath, root, gitOn
|
|
|
79
97
|
* - it must SAY WHERE IT IS. An export is tens of seconds, so each slide
|
|
80
98
|
* is announced on the `export` channel of the same SSE stream the agent
|
|
81
99
|
* chip rides, and the deck rewrites its one progress row from it.
|
|
100
|
+
*
|
|
101
|
+
* And it can be STOPPED (`exportStopRoute`), so a ten-minute video started
|
|
102
|
+
* on the wrong slides is not a reason to kill the session it runs in.
|
|
82
103
|
*/
|
|
83
104
|
async function exportRoute({ url, body, json }) {
|
|
84
105
|
const req = JSON.parse(body || '{}');
|
|
@@ -108,6 +129,8 @@ export function registerHandoverRoutes(routes, { readDeck, deckPath, root, gitOn
|
|
|
108
129
|
if (alreadyOneFile(readDeck())) {
|
|
109
130
|
return json(409, { ok: false, error: 'this deck is already one file — send it as it is' });
|
|
110
131
|
}
|
|
132
|
+
const bad = moduleProblem(req.module);
|
|
133
|
+
if (bad) return json(400, { ok: false, error: bad });
|
|
111
134
|
}
|
|
112
135
|
const unmarked = await unmarkedOnScreen(req.theme, { carried: kind === 'bundle' });
|
|
113
136
|
if (unmarked) return json(409, { ok: false, unmarked, error: `${unmarked} is not marked for this deck` });
|
|
@@ -123,12 +146,17 @@ export function registerHandoverRoutes(routes, { readDeck, deckPath, root, gitOn
|
|
|
123
146
|
return json(503, { ok: false, error: 'no Chrome found — install one, or point $CHROME at it' });
|
|
124
147
|
}
|
|
125
148
|
exporting = true;
|
|
149
|
+
// Every kind but the bundle: the bundle launches nothing and is seconds
|
|
150
|
+
// from done, so there is nothing to stop part-way.
|
|
151
|
+
const stop = new AbortController();
|
|
152
|
+
stopExport = kind === 'bundle' ? null : () => stop.abort();
|
|
153
|
+
onExport({ kind, what: job.what });
|
|
126
154
|
const started = Date.now();
|
|
127
155
|
console.log(` export: ${basename(deckPath)} → ${job.what}${req.slides ? ` of slides ${req.slides}` : ''}`
|
|
128
156
|
+ `${req.synthesize ? `, voiced by ${req.synthesize.engine} into ${req.synthesize.dir}/` : ''} …`);
|
|
129
157
|
broadcast('export', { state: 'start', kind, what: job.what });
|
|
130
158
|
try {
|
|
131
|
-
let out, code, reason = null, subs = null;
|
|
159
|
+
let out, code, reason = null, subs = null, notes = null;
|
|
132
160
|
if (kind === 'video') {
|
|
133
161
|
const { videoOut, videoProgress, voiceoverProgress, subtitlesOut } = await import('../tools/video.mjs');
|
|
134
162
|
out = videoOut(deckPath, req.slides || null, req.format || 'mp4');
|
|
@@ -138,9 +166,9 @@ export function registerHandoverRoutes(routes, { readDeck, deckPath, root, gitOn
|
|
|
138
166
|
// read as stuck on slide one.
|
|
139
167
|
if (req.synthesize) {
|
|
140
168
|
({ code, reason } = await runTool('voiceover', await voiceoverArgv(req),
|
|
141
|
-
voiceoverProgress((n, of) => broadcast('export', { state: 'slide', kind, phase: 'voice', n, of }))));
|
|
169
|
+
voiceoverProgress((n, of) => broadcast('export', { state: 'slide', kind, phase: 'voice', n, of })), stop.signal));
|
|
142
170
|
}
|
|
143
|
-
if (!code) {
|
|
171
|
+
if (!code && !stop.signal.aborted) {
|
|
144
172
|
const narration = req.synthesize?.dir ?? req.narration ?? null;
|
|
145
173
|
({ code, reason } = await runTool('video', [deckPath, '-o', out, ...themed,
|
|
146
174
|
...(req.slides ? ['--slides', req.slides] : []),
|
|
@@ -150,31 +178,40 @@ export function registerHandoverRoutes(routes, { readDeck, deckPath, root, gitOn
|
|
|
150
178
|
...(narration ? ['--narration', resolve(dirname(deckPath), narration)] : req.silent ? ['--no-narration'] : []),
|
|
151
179
|
// the card showed the track as recorded from older notes and it was picked anyway (#536)
|
|
152
180
|
...(req.allowStale === true ? ['--allow-stale'] : [])],
|
|
153
|
-
videoProgress((n, of) => broadcast('export', { state: 'slide', kind, phase: 'render', n, of }))));
|
|
181
|
+
videoProgress((n, of) => broadcast('export', { state: 'slide', kind, phase: 'render', n, of })), stop.signal));
|
|
154
182
|
}
|
|
155
183
|
} else if (kind === 'bundle') {
|
|
156
|
-
//
|
|
157
|
-
// `decklight bundle` write the same one
|
|
158
|
-
// (
|
|
159
|
-
//
|
|
160
|
-
//
|
|
184
|
+
// No -o: the CLI names the file, beside the deck, so the row and
|
|
185
|
+
// `decklight bundle` write the same one — `<deck>-standalone.html`,
|
|
186
|
+
// or for one chapter (`module`, its number: --module) the chapter's
|
|
187
|
+
// own name, which never overwrites the whole deck's. `audio` is its
|
|
188
|
+
// --audio ('original', 'aac' or 'opus'), the recorded voice carried
|
|
189
|
+
// inside. bundleMain returns nothing on success and throws a sentence
|
|
190
|
+
// on a refusal (an unknown chapter among them, before any file is
|
|
191
|
+
// written) — the catch below says it. The notes it prints after the
|
|
192
|
+
// file come back too: which chapter went in, and where the audio is.
|
|
161
193
|
const { bundleMain } = await import('./bundle.mjs');
|
|
162
194
|
const { AUDIO_CHOICES } = await import('./bundle-audio.mjs');
|
|
163
|
-
|
|
164
|
-
code = (await bundleMain([deckPath,
|
|
165
|
-
...(
|
|
195
|
+
const report = {};
|
|
196
|
+
code = (await bundleMain([deckPath, ...(req.theme ? ['--theme', req.theme] : []),
|
|
197
|
+
...(req.module != null ? ['--module', String(req.module)] : []),
|
|
198
|
+
...(AUDIO_CHOICES.includes(req.audio) ? ['--audio', req.audio] : [])], { report })) ?? 0;
|
|
199
|
+
out = report.out;
|
|
200
|
+
notes = report.notices;
|
|
166
201
|
} else if (kind === 'pptx') {
|
|
167
202
|
const { pptxMain, pptxOut } = await import('./pptx-export.mjs');
|
|
168
203
|
out = pptxOut(deckPath);
|
|
169
204
|
code = await pptxMain([deckPath, ...themed], {
|
|
170
205
|
log: (line) => console.log(` ${line}`),
|
|
171
206
|
onSlide: (n, of) => broadcast('export', { state: 'slide', kind, n, of }),
|
|
207
|
+
signal: stop.signal,
|
|
172
208
|
});
|
|
173
209
|
} else {
|
|
174
210
|
const { pdfMain, pdfOut } = await import('./pdf.mjs');
|
|
175
211
|
out = pdfOut(deckPath, null, job.variant);
|
|
176
|
-
code = await pdfMain([deckPath, ...themed, ...(job.variant ? [`--${job.variant}`] : [])]);
|
|
212
|
+
code = await pdfMain([deckPath, ...themed, ...(job.variant ? [`--${job.variant}`] : [])], { signal: stop.signal });
|
|
177
213
|
}
|
|
214
|
+
if (stop.signal.aborted) return stopped();
|
|
178
215
|
const file = relative(process.cwd(), out) || basename(out);
|
|
179
216
|
const seconds = Math.round((Date.now() - started) / 100) / 10;
|
|
180
217
|
if (code !== 0) {
|
|
@@ -188,19 +225,48 @@ export function registerHandoverRoutes(routes, { readDeck, deckPath, root, gitOn
|
|
|
188
225
|
...(subs && existsSync(subs) ? { subtitles: relative(process.cwd(), subs) || basename(subs) } : {}),
|
|
189
226
|
};
|
|
190
227
|
broadcast('export', { state: 'done', kind, ok: true, file, seconds, ...voiced });
|
|
191
|
-
return json(200, { ok: true, kind, what: job.what, file, seconds, ...voiced });
|
|
228
|
+
return json(200, { ok: true, kind, what: job.what, file, seconds, ...voiced, ...(notes ? { notes } : {}) });
|
|
192
229
|
} catch (e) {
|
|
230
|
+
if (stop.signal.aborted) return stopped();
|
|
193
231
|
// A render that hangs or a Chrome that dies is the export's problem,
|
|
194
232
|
// never the session's: the message goes back to the palette and the
|
|
195
|
-
// server carries on serving the deck.
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
233
|
+
// server carries on serving the deck. A command's refusal is a sentence
|
|
234
|
+
// and then, at most, a list it introduces ("— its chapters are:"); the
|
|
235
|
+
// sentence is what fits on a card, and the card has the list already.
|
|
236
|
+
const said = e instanceof CommandError ? e.message.split('\n')[0].replace(/\s+—[^—]*:$/, '') : oneline(e);
|
|
237
|
+
console.log(` export: ${job.what} failed — ${said}`);
|
|
238
|
+
broadcast('export', { state: 'done', kind, ok: false, error: said });
|
|
239
|
+
return json(500, { ok: false, error: said });
|
|
199
240
|
} finally {
|
|
200
241
|
exporting = false;
|
|
242
|
+
stopExport = null;
|
|
243
|
+
onExport(null);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
// Not a failure: what was asked for. The voice a stopped export had
|
|
247
|
+
// already synthesized stays where it was written — it is the deck's own
|
|
248
|
+
// folder, and the next export finds those slides done.
|
|
249
|
+
function stopped() {
|
|
250
|
+
const kept = req.synthesize && existsSync(resolve(dirname(deckPath), req.synthesize.dir)) ? { voiced: req.synthesize.dir } : {};
|
|
251
|
+
console.log(` export: ${job.what} stopped — nothing written`);
|
|
252
|
+
broadcast('export', { state: 'done', kind, ok: false, stopped: true, ...kept });
|
|
253
|
+
return json(200, { ok: false, stopped: true, kind, what: job.what, ...kept });
|
|
201
254
|
}
|
|
202
255
|
}
|
|
203
256
|
|
|
257
|
+
/**
|
|
258
|
+
* POST /deck/edit/export/stop — stop the export in flight. Answers at once;
|
|
259
|
+
* the export's own request is the one that says it stopped (`{ stopped }`),
|
|
260
|
+
* once its children are gone and its scratch files with them.
|
|
261
|
+
*/
|
|
262
|
+
function exportStopRoute({ json }) {
|
|
263
|
+
if (!exporting) return json(409, { ok: false, error: 'no export is running' });
|
|
264
|
+
if (!stopExport) return json(409, { ok: false, error: 'a bundle cannot be stopped part-way — it is seconds from done' });
|
|
265
|
+
console.log(' export: stopping …');
|
|
266
|
+
stopExport();
|
|
267
|
+
return json(200, { ok: true });
|
|
268
|
+
}
|
|
269
|
+
|
|
204
270
|
/**
|
|
205
271
|
* `decklight video` (and `decklight narrate` before it, when the export
|
|
206
272
|
* voices its slides), run as CHILDREN rather than through their `main`s like
|
|
@@ -211,12 +277,22 @@ export function registerHandoverRoutes(routes, { readDeck, deckPath, root, gitOn
|
|
|
211
277
|
*
|
|
212
278
|
* Served from the same root `pptx` picks: the current directory when the deck
|
|
213
279
|
* is under it, its own directory otherwise.
|
|
280
|
+
*
|
|
281
|
+
* `signal` stops it: SIGTERM, which `decklight video` answers by killing its
|
|
282
|
+
* Chrome and ffmpeg and clearing its scratch frames, then SIGKILL for a child
|
|
283
|
+
* that has not gone a few seconds later.
|
|
214
284
|
*/
|
|
215
|
-
function runTool(name, argv, onLine) {
|
|
285
|
+
function runTool(name, argv, onLine, signal = null) {
|
|
216
286
|
const script = fileURLToPath(new URL(`../tools/${name}.mjs`, import.meta.url));
|
|
217
287
|
const cwd = deckPath.startsWith(process.cwd() + sep) ? process.cwd() : dirname(deckPath);
|
|
218
288
|
return new Promise((done) => {
|
|
219
289
|
const child = spawn(process.execPath, [script, ...argv], { cwd, stdio: ['ignore', 'pipe', 'pipe'] });
|
|
290
|
+
let hard = null;
|
|
291
|
+
const stop = () => {
|
|
292
|
+
child.kill('SIGTERM');
|
|
293
|
+
hard = setTimeout(() => child.kill('SIGKILL'), STOP_GRACE_MS);
|
|
294
|
+
};
|
|
295
|
+
if (signal?.aborted) stop(); else signal?.addEventListener('abort', stop, { once: true });
|
|
220
296
|
let pending = '', err = '';
|
|
221
297
|
child.stdout.on('data', (chunk) => {
|
|
222
298
|
pending += chunk;
|
|
@@ -230,6 +306,8 @@ export function registerHandoverRoutes(routes, { readDeck, deckPath, root, gitOn
|
|
|
230
306
|
child.stderr.on('data', (chunk) => { err += chunk; process.stdout.write(String(chunk).replace(/^/gm, ' ')); });
|
|
231
307
|
child.on('error', (e) => done({ code: 1, reason: oneline(e) }));
|
|
232
308
|
child.on('close', (code) => {
|
|
309
|
+
clearTimeout(hard);
|
|
310
|
+
signal?.removeEventListener('abort', stop);
|
|
233
311
|
// the command's own refusal is the sentence the deck shows
|
|
234
312
|
const said = err.split('\n').map((l) => l.trim()).filter(Boolean);
|
|
235
313
|
const prefix = `decklight ${name}:`;
|
|
@@ -358,8 +436,12 @@ export function registerHandoverRoutes(routes, { readDeck, deckPath, root, gitOn
|
|
|
358
436
|
if (kind !== 'bundle') return json(400, { ok: false, error: `no estimate for ${kind ?? 'that'} — only a bundle has one` });
|
|
359
437
|
const theme = url.searchParams.get('theme');
|
|
360
438
|
if (theme != null && !THEME_NAME.test(theme)) return json(400, { ok: false, error: 'the theme is a theme name' });
|
|
439
|
+
// one chapter is estimated as one chapter: its slides, its share of the audio
|
|
440
|
+
const module = url.searchParams.get('module');
|
|
441
|
+
const bad = moduleProblem(module);
|
|
442
|
+
if (bad) return json(400, { ok: false, error: bad });
|
|
361
443
|
const { bundleMain } = await import('./bundle.mjs');
|
|
362
|
-
const estimate = (argv) => bundleMain([deckPath, ...argv], { estimate: true });
|
|
444
|
+
const estimate = (argv) => bundleMain([deckPath, ...argv, ...(module != null ? ['--module', module] : [])], { estimate: true });
|
|
363
445
|
try {
|
|
364
446
|
// in the theme on screen, as the export will be — or, when that one
|
|
365
447
|
// cannot be bundled yet (the export asks to mark it first), in the
|
|
@@ -413,6 +495,28 @@ export function registerHandoverRoutes(routes, { readDeck, deckPath, root, gitOn
|
|
|
413
495
|
return json(200, { ok: true, file: basename(deckPath), lines: span(range.start, range.end), blocks, findings });
|
|
414
496
|
}
|
|
415
497
|
|
|
498
|
+
/**
|
|
499
|
+
* Every finding `decklight check`'s static half has for the whole deck,
|
|
500
|
+
* for Check deck… (PRESENTING_EDITING): head-level ones (a design system
|
|
501
|
+
* the deck is behind, a theme off the brand, a missing file) with
|
|
502
|
+
* `slide: null`, then each slide's, the same rule ids `check --json`
|
|
503
|
+
* prints — and on each the quick fix the server could apply for it
|
|
504
|
+
* (cli/check-fixes.mjs), so the row says what pressing it would do. Read-
|
|
505
|
+
* only, like the inspector's read above; the render half is the open
|
|
506
|
+
* page's own (src/core/deckcheck.js measures it).
|
|
507
|
+
*/
|
|
508
|
+
async function checkRoute({ json }) {
|
|
509
|
+
const { sectionRanges, staticFindings } = await import('./check.mjs');
|
|
510
|
+
const { quickFixes } = await import('./check-fixes.mjs');
|
|
511
|
+
const html = readDeck();
|
|
512
|
+
const dir = dirname(deckPath);
|
|
513
|
+
const found = staticFindings(html, { dir, deck: basename(deckPath) });
|
|
514
|
+
return json(200, {
|
|
515
|
+
ok: true, file: basename(deckPath), slides: sectionRanges(html).length,
|
|
516
|
+
findings: quickFixes(found, html, dir, { deck: basename(deckPath) }),
|
|
517
|
+
});
|
|
518
|
+
}
|
|
519
|
+
|
|
416
520
|
/**
|
|
417
521
|
* The marketplace theme on screen that this deck does not mark, as a
|
|
418
522
|
* reference — or null. An export or a publish of an unmarked theme would
|
|
@@ -437,8 +541,10 @@ export function registerHandoverRoutes(routes, { readDeck, deckPath, root, gitOn
|
|
|
437
541
|
}
|
|
438
542
|
|
|
439
543
|
routes.set('POST /deck/edit/export', exportRoute);
|
|
544
|
+
routes.set('POST /deck/edit/export/stop', exportStopRoute);
|
|
440
545
|
routes.set('GET /deck/edit/export/estimate', exportEstimateRoute);
|
|
441
546
|
routes.set('GET /deck/edit/inspect', inspectRoute);
|
|
547
|
+
routes.set('GET /deck/edit/check', checkRoute);
|
|
442
548
|
routes.set('GET /deck/edit/publish/plan', publishPlanRoute);
|
|
443
549
|
routes.set('POST /deck/edit/publish', publishRoute);
|
|
444
550
|
return routes;
|