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/edit-look.mjs
CHANGED
|
@@ -5,7 +5,10 @@
|
|
|
5
5
|
// theme it opens in and whether the picker holds it to its brand's themes,
|
|
6
6
|
// and the three things a marketplace hands a deck to wear (themes, design
|
|
7
7
|
// systems, fonts), each listed from the cache and marked or dropped in the
|
|
8
|
-
// deck's config block (SPEC THEME_DISTRIBUTION, DESIGN_SYSTEMS, FONTS)
|
|
8
|
+
// deck's config block (SPEC THEME_DISTRIBUTION, DESIGN_SYSTEMS, FONTS) — and
|
|
9
|
+
// the marketplaces themselves (SPEC MARKETPLACES_SCREEN): listed, checked,
|
|
10
|
+
// updated and added, every one of them through the `decklight marketplace`
|
|
11
|
+
// command it would be at a terminal.
|
|
9
12
|
//
|
|
10
13
|
// They came out of cli/edit.mjs because they are a family with one shape and
|
|
11
14
|
// one set of needs. Every one either lists what the cached catalogs offer
|
|
@@ -23,6 +26,9 @@
|
|
|
23
26
|
// edit.mjs's top-level `await`).
|
|
24
27
|
|
|
25
28
|
import { readFileSync } from 'node:fs';
|
|
29
|
+
import { execFile } from 'node:child_process';
|
|
30
|
+
import { basename, dirname } from 'node:path';
|
|
31
|
+
import { fileURLToPath } from 'node:url';
|
|
26
32
|
|
|
27
33
|
import { oneline } from './git.mjs';
|
|
28
34
|
import { setDeckTheme, setDeckBrandThemesOnly } from './runtime-link.mjs';
|
|
@@ -40,8 +46,16 @@ import { setDeckTheme, setDeckBrandThemesOnly } from './runtime-link.mjs';
|
|
|
40
46
|
* tells the deck watcher that the next write of exactly these bytes updates
|
|
41
47
|
* the page itself and must not reload it. `quiet` is a setter, not the
|
|
42
48
|
* variable, because the watcher in editMain reads and clears it.
|
|
49
|
+
* `deckPath` is where a relative marketplace path is read from, and
|
|
50
|
+
* `marketplace(args)` runs `decklight marketplace <args…>` (a test hands in
|
|
51
|
+
* its own); `addMarketplace(spec, ref)` is its `add` (with `--branch ref` when
|
|
52
|
+
* one is given), kept apart because a test of the add door replaces only that.
|
|
43
53
|
*/
|
|
44
|
-
export function registerLookRoutes(routes, {
|
|
54
|
+
export function registerLookRoutes(routes, {
|
|
55
|
+
readDeck, applyEdit, writeDeck, history, broadcast = () => {}, quiet = () => {},
|
|
56
|
+
deckPath = null, marketplace = runMarketplace,
|
|
57
|
+
addMarketplace = (spec, ref = null) => marketplace(['add', spec, ...(ref ? ['--branch', ref] : [])]),
|
|
58
|
+
}) {
|
|
45
59
|
// The deck's theme (PRESENTING): in write mode a pick is the deck's, not
|
|
46
60
|
// the viewer's — written the way this deck carries it (setDeckTheme), quiet
|
|
47
61
|
// and in place like a layout pick, with a `theme` event for every other
|
|
@@ -232,7 +246,7 @@ export function registerLookRoutes(routes, { readDeck, applyEdit, writeDeck, his
|
|
|
232
246
|
deckRef = designSystemRefs(before).find((x) => x.ref === ref || x.name === p.name)?.ref ?? ref;
|
|
233
247
|
}
|
|
234
248
|
let out;
|
|
235
|
-
try { out = setDesignSystem(before, deckRef, on, { source }); }
|
|
249
|
+
try { out = setDesignSystem(before, deckRef, on, { source, version: manifest?.version ?? null }); }
|
|
236
250
|
catch (e) {
|
|
237
251
|
if (e instanceof MarketplaceError) return json(409, { ok: false, error: e.message });
|
|
238
252
|
throw e;
|
|
@@ -272,7 +286,7 @@ export function registerLookRoutes(routes, { readDeck, applyEdit, writeDeck, his
|
|
|
272
286
|
*/
|
|
273
287
|
async function designSystemApplyRoute({ body, json }) {
|
|
274
288
|
const req = JSON.parse(body || '{}');
|
|
275
|
-
const { designSystemRefs, resolveDesignSystemRef } = await import('./design-system-refs.mjs');
|
|
289
|
+
const { designSystemRefs, resolveDesignSystemRef, recordVersionIfCurrent } = await import('./design-system-refs.mjs');
|
|
276
290
|
const { markedSources, parseRef } = await import('./theme-refs.mjs');
|
|
277
291
|
const { checkDir } = await import('./design-system.mjs');
|
|
278
292
|
const { recordInstall } = await import('./marketplace.mjs');
|
|
@@ -286,7 +300,8 @@ export function registerLookRoutes(routes, { readDeck, applyEdit, writeDeck, his
|
|
|
286
300
|
const verdict = checkDir(r.dir);
|
|
287
301
|
if (!verdict.ok) return json(409, { ok: false, error: `${hit.ref} no longer passes its check` });
|
|
288
302
|
const plan = deps.planRecommended(before, { manifest: verdict.manifest, local: r.local });
|
|
289
|
-
|
|
303
|
+
// a deck that records no version takes this one, as `design-system apply` does (SPEC DESIGN_SYSTEM_MIGRATIONS)
|
|
304
|
+
let html = deps.writePlan(recordVersionIfCurrent(before, hit.ref, verdict.manifest, deckPath ? dirname(deckPath) : process.cwd()), plan);
|
|
290
305
|
const look = deps.lookOf(html, plan);
|
|
291
306
|
if (look.differs) html = deps.applyLook(html, look);
|
|
292
307
|
look.phrase = deps.lookPhrase(look, plan);
|
|
@@ -374,6 +389,184 @@ export function registerLookRoutes(routes, { readDeck, applyEdit, writeDeck, his
|
|
|
374
389
|
const themeAddRoute = ({ body, json }) =>
|
|
375
390
|
themeMarkRoute({ body: JSON.stringify({ ref: JSON.parse(body || '{}').ref, marked: true }), json });
|
|
376
391
|
|
|
392
|
+
/**
|
|
393
|
+
* `POST /deck/edit/marketplace/add` `{ spec, ref?, confirm? }`: register a
|
|
394
|
+
* marketplace from inside the deck (SPEC MARKETPLACES_SCREEN, PLATFORM
|
|
395
|
+
* MARKETPLACE_REGISTRY). `ref` is the command's `--branch`, a branch or a
|
|
396
|
+
* tag to pin the catalog to. Two steps, like publish. Without `confirm` it says
|
|
397
|
+
* what it is about to do (`planAdd`: which URL it would clone, or which
|
|
398
|
+
* directory it would read) and touches nothing. With it, it runs
|
|
399
|
+
* `decklight marketplace add` itself, as a child process: the same command,
|
|
400
|
+
* so the registry cannot tell the two doors apart, and a clone that takes
|
|
401
|
+
* thirty seconds holds up nobody but the person who asked for it. A relative
|
|
402
|
+
* path is the deck's directory's, and is registered absolute. Nothing in
|
|
403
|
+
* the deck changes, so there is no undo entry and no reload: the pickers ask
|
|
404
|
+
* again, and find it.
|
|
405
|
+
*/
|
|
406
|
+
async function marketplaceAddRoute({ body, json }) {
|
|
407
|
+
const req = JSON.parse(body || '{}');
|
|
408
|
+
if (req.ref != null && typeof req.ref !== 'string') return json(400, { ok: false, error: '--branch takes a branch or tag name' });
|
|
409
|
+
const { planAdd, loadRegistry, loadCatalog, MarketplaceError, configHome } = await import('./marketplace.mjs');
|
|
410
|
+
let plan;
|
|
411
|
+
try { plan = planAdd(req.spec, { ref: req.ref?.trim() || null, base: deckPath ? dirname(deckPath) : process.cwd(), home: configHome() }); }
|
|
412
|
+
catch (e) {
|
|
413
|
+
if (e instanceof MarketplaceError) return json(400, { ok: false, error: e.message });
|
|
414
|
+
throw e;
|
|
415
|
+
}
|
|
416
|
+
if (req.confirm !== true) return json(200, { ok: true, confirm: true, plan });
|
|
417
|
+
const out = await addMarketplace(plan.spec, plan.ref);
|
|
418
|
+
if (!out.ok) return json(409, { ok: false, error: out.error, plan });
|
|
419
|
+
const reg = loadRegistry(configHome()).marketplaces ?? {};
|
|
420
|
+
const name = Object.keys(reg).find((n) => reg[n].source === plan.spec) ?? null;
|
|
421
|
+
const cat = name ? loadCatalog(name, configHome()) : null;
|
|
422
|
+
const counts = {};
|
|
423
|
+
for (const e of cat?.ok ? cat.manifest.entries ?? [] : []) counts[e.type] = (counts[e.type] ?? 0) + 1;
|
|
424
|
+
console.log(` marketplace: ${plan.registered ? 'refreshed' : 'registered'} ${name ?? plan.spec} from ${plan.spec}`);
|
|
425
|
+
return json(200, { ok: true, name, spec: plan.spec, refreshed: !!plan.registered, counts, said: out.said });
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
/**
|
|
429
|
+
* `GET /deck/edit/marketplaces`: every registered marketplace, from the
|
|
430
|
+
* registry and the cache alone (SPEC MARKETPLACES_SCREEN) — what
|
|
431
|
+
* `marketplace list` says, as data. Per marketplace: where it comes from
|
|
432
|
+
* and at which ref and commit, whether it was ever fetched (`state`), what
|
|
433
|
+
* its catalog offers per kind (`counts`), what its last update changed
|
|
434
|
+
* (`changes`, as `update` recorded it), and which installs the catalog now
|
|
435
|
+
* has newer (`newer`). No network: whether a source has MOVED is
|
|
436
|
+
* `/deck/edit/marketplace/check`'s question, asked only when somebody asks.
|
|
437
|
+
*/
|
|
438
|
+
async function marketplacesRoute({ json }) {
|
|
439
|
+
const { loadRegistry, loadCatalog, newerThanInstalled, classifySource, configHome, MarketplaceError } = await import('./marketplace.mjs');
|
|
440
|
+
let reg;
|
|
441
|
+
try { reg = loadRegistry(configHome()).marketplaces ?? {}; } catch (e) {
|
|
442
|
+
if (e instanceof MarketplaceError) return json(409, { ok: false, error: e.message });
|
|
443
|
+
throw e;
|
|
444
|
+
}
|
|
445
|
+
const newer = newerThanInstalled(configHome());
|
|
446
|
+
const marketplaces = Object.keys(reg).sort().map((name) => {
|
|
447
|
+
const m = reg[name];
|
|
448
|
+
const cat = loadCatalog(name, configHome());
|
|
449
|
+
const counts = {};
|
|
450
|
+
for (const e of cat?.ok ? cat.manifest.entries : []) counts[e.type] = (counts[e.type] ?? 0) + 1;
|
|
451
|
+
return {
|
|
452
|
+
name, source: m.source, ref: m.ref ?? null, commit: m.commit ?? null, firstParty: !!m.firstParty,
|
|
453
|
+
local: classifySource(m.source).kind === 'local',
|
|
454
|
+
state: cat === null ? 'unfetched' : cat.ok ? 'fetched' : 'unreadable',
|
|
455
|
+
description: cat?.ok ? cat.manifest.description ?? null : null,
|
|
456
|
+
counts, changes: m.changes ?? null,
|
|
457
|
+
newer: newer.filter((n) => n.qualified.endsWith(`@${name}`)),
|
|
458
|
+
};
|
|
459
|
+
});
|
|
460
|
+
// the last check's answer, whoever asked (C, the command line, or the
|
|
461
|
+
// auto-check a starting server ran), so the list says it without a C;
|
|
462
|
+
// and whether that auto-check is on, and if not, whether to ask once
|
|
463
|
+
const { readCheckRecord, autoCheckOn, autoCheckOffered } = await import('./marketplace-autocheck.mjs');
|
|
464
|
+
const rec = readCheckRecord(configHome());
|
|
465
|
+
const on = autoCheckOn(configHome());
|
|
466
|
+
return json(200, {
|
|
467
|
+
ok: true, marketplaces, cacheOnly: true,
|
|
468
|
+
checked: rec ? { at: new Date(rec.checkedAt).toISOString(), marketplaces: rec.marketplaces } : null,
|
|
469
|
+
autoCheck: { on, ask: !on && !autoCheckOffered(configHome()) },
|
|
470
|
+
});
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
/**
|
|
474
|
+
* `GET /deck/edit/marketplace/auto-check`: what the auto-check found that
|
|
475
|
+
* the open deck should offer (SPEC MARKETPLACES_SCREEN) — every marketplace
|
|
476
|
+
* the last check found behind, not dismissed at that commit, with what this
|
|
477
|
+
* deck uses from it. Read from the record; asks nothing. Empty while the
|
|
478
|
+
* switch is off.
|
|
479
|
+
*/
|
|
480
|
+
async function autoCheckGetRoute({ json }) {
|
|
481
|
+
const { configHome } = await import('./marketplace.mjs');
|
|
482
|
+
const { readCheckRecord, autoCheckOn, autoCheckOffers } = await import('./marketplace-autocheck.mjs');
|
|
483
|
+
let html = null;
|
|
484
|
+
try { html = readDeck(); } catch { /* no deck to say what it uses */ }
|
|
485
|
+
const rec = readCheckRecord(configHome());
|
|
486
|
+
return json(200, {
|
|
487
|
+
ok: true, on: autoCheckOn(configHome()),
|
|
488
|
+
checkedAt: rec ? new Date(rec.checkedAt).toISOString() : null,
|
|
489
|
+
offers: await autoCheckOffers(html, configHome()),
|
|
490
|
+
});
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
/**
|
|
494
|
+
* `POST /deck/edit/marketplace/auto-check` `{ on } | { asked: true } |
|
|
495
|
+
* { dismiss, remote }`: turn the auto-check on or off (O on the screen; the
|
|
496
|
+
* file `decklight marketplace auto-check` writes), say the screen has asked
|
|
497
|
+
* its one question, or dismiss an offer at the commit it was made for.
|
|
498
|
+
* Turning it on is the consent, so a check that is due runs then, in the
|
|
499
|
+
* background, and the pages are told when its answer lands.
|
|
500
|
+
*/
|
|
501
|
+
async function autoCheckPostRoute({ body, json }) {
|
|
502
|
+
const req = JSON.parse(body || '{}');
|
|
503
|
+
const { configHome } = await import('./marketplace.mjs');
|
|
504
|
+
const ac = await import('./marketplace-autocheck.mjs');
|
|
505
|
+
if (typeof req.dismiss === 'string') {
|
|
506
|
+
if (!/^\w[\w-]*$/.test(req.dismiss)) return json(400, { ok: false, error: 'which marketplace? — its registered name' });
|
|
507
|
+
ac.dismissOffer(req.dismiss, typeof req.remote === 'string' ? req.remote : null, configHome());
|
|
508
|
+
return json(200, { ok: true, dismissed: req.dismiss });
|
|
509
|
+
}
|
|
510
|
+
if (req.asked === true) { ac.markAutoCheckOffered(configHome()); return json(200, { ok: true }); }
|
|
511
|
+
if (typeof req.on !== 'boolean') return json(400, { ok: false, error: 'on is true or false' });
|
|
512
|
+
const on = ac.setAutoCheck(req.on, configHome());
|
|
513
|
+
console.log(` marketplaces: auto-check ${on ? 'on' : 'off'}`);
|
|
514
|
+
if (on) autoCheckInBackground({ run: marketplace, broadcast });
|
|
515
|
+
return json(200, { ok: true, on });
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
/**
|
|
519
|
+
* `POST /deck/edit/marketplace/check` `{ name? }`: which marketplaces are
|
|
520
|
+
* behind their source — `decklight marketplace outdated --json`, run as a
|
|
521
|
+
* child like `add`. It ASKS each remote where its ref points (`git
|
|
522
|
+
* ls-remote`, the caller's credentials) and fetches nothing, so it is one
|
|
523
|
+
* explicit press, not a confirm; it never runs on its own.
|
|
524
|
+
*/
|
|
525
|
+
async function marketplaceCheckRoute({ body, json }) {
|
|
526
|
+
const req = JSON.parse(body || '{}');
|
|
527
|
+
if (req.name != null && !/^\w[\w-]*$/.test(String(req.name))) return json(400, { ok: false, error: 'which marketplace? — its registered name' });
|
|
528
|
+
const out = await marketplace(['outdated', '--json', ...(req.name ? [String(req.name)] : [])]);
|
|
529
|
+
if (!out.ok) return json(409, { ok: false, error: out.error });
|
|
530
|
+
let parsed;
|
|
531
|
+
try { parsed = JSON.parse(out.stdout); } catch { return json(500, { ok: false, error: 'decklight marketplace outdated answered something that is not JSON' }); }
|
|
532
|
+
return json(200, { ok: true, marketplaces: parsed.marketplaces ?? [] });
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
/**
|
|
536
|
+
* `POST /deck/edit/marketplace/update` `{ name }`: `decklight marketplace
|
|
537
|
+
* update <name>`, run as a child — the same re-clone, at the same pinned
|
|
538
|
+
* ref, with the same refusals; a failed one leaves the cache and checkout
|
|
539
|
+
* as they were. Answers with what the update changed (the `changes` the
|
|
540
|
+
* command recorded: added, removed, versions moved) and which installs the
|
|
541
|
+
* catalog now has newer, with the command that takes each — the screen's
|
|
542
|
+
* what's new — and `behind`, the design systems the open deck is now
|
|
543
|
+
* behind (`deckBehind`), which the screen offers to migrate. Nothing in
|
|
544
|
+
* the deck changes, so no undo entry and no reload.
|
|
545
|
+
*/
|
|
546
|
+
async function marketplaceUpdateRoute({ body, json }) {
|
|
547
|
+
const req = JSON.parse(body || '{}');
|
|
548
|
+
const name = typeof req.name === 'string' ? req.name : '';
|
|
549
|
+
if (!/^\w[\w-]*$/.test(name)) return json(400, { ok: false, error: 'which marketplace? — its registered name' });
|
|
550
|
+
const { loadRegistry, loadCatalog, newerThanInstalled, configHome } = await import('./marketplace.mjs');
|
|
551
|
+
if (!loadRegistry(configHome()).marketplaces?.[name]) return json(404, { ok: false, error: `no marketplace "${name}" is registered` });
|
|
552
|
+
const out = await marketplace(['update', name]);
|
|
553
|
+
if (!out.ok) return json(409, { ok: false, error: out.error });
|
|
554
|
+
const m = loadRegistry(configHome()).marketplaces?.[name] ?? {};
|
|
555
|
+
const cat = loadCatalog(name, configHome());
|
|
556
|
+
const counts = {};
|
|
557
|
+
for (const e of cat?.ok ? cat.manifest.entries : []) counts[e.type] = (counts[e.type] ?? 0) + 1;
|
|
558
|
+
console.log(` marketplace: updated ${name}${m.commit ? ` (${m.commit.slice(0, 7)})` : ''}`);
|
|
559
|
+
// What the update means for the deck that is open (SPEC
|
|
560
|
+
// DESIGN_SYSTEM_MIGRATIONS): the design systems it is now behind, read
|
|
561
|
+
// as `check` reads them — the page offers Migrate without a reload.
|
|
562
|
+
const { withMigrationHint, deckBehind } = await import('./design-system-refs.mjs');
|
|
563
|
+
const newer = newerThanInstalled(configHome(), name).map((n) => withMigrationHint(n, configHome()));
|
|
564
|
+
let behind = [];
|
|
565
|
+
try { if (deckPath) behind = deckBehind(readDeck(), dirname(deckPath), configHome(), { deck: basename(deckPath) }); } catch { /* the deck unreadable: nothing to offer */ }
|
|
566
|
+
for (const b of behind) console.log(` design system: ${b.ref} — ${b.message}`);
|
|
567
|
+
return json(200, { ok: true, name, commit: m.commit ?? null, changes: m.changes ?? null, counts, newer, behind, said: out.said });
|
|
568
|
+
}
|
|
569
|
+
|
|
377
570
|
routes.set('POST /deck/edit/theme', themeRoute);
|
|
378
571
|
routes.set('POST /deck/edit/brand-themes', brandThemesRoute);
|
|
379
572
|
routes.set('GET /deck/edit/theme/browse', themeBrowseRoute);
|
|
@@ -384,5 +577,55 @@ export function registerLookRoutes(routes, { readDeck, applyEdit, writeDeck, his
|
|
|
384
577
|
routes.set('POST /deck/edit/design-system/apply', designSystemApplyRoute);
|
|
385
578
|
routes.set('GET /deck/edit/font/browse', fontBrowseRoute);
|
|
386
579
|
routes.set('POST /deck/edit/font/mark', fontMarkRoute);
|
|
580
|
+
routes.set('POST /deck/edit/marketplace/add', marketplaceAddRoute);
|
|
581
|
+
routes.set('GET /deck/edit/marketplaces', marketplacesRoute);
|
|
582
|
+
routes.set('POST /deck/edit/marketplace/check', marketplaceCheckRoute);
|
|
583
|
+
routes.set('POST /deck/edit/marketplace/update', marketplaceUpdateRoute);
|
|
584
|
+
routes.set('GET /deck/edit/marketplace/auto-check', autoCheckGetRoute);
|
|
585
|
+
routes.set('POST /deck/edit/marketplace/auto-check', autoCheckPostRoute);
|
|
387
586
|
return routes;
|
|
388
587
|
}
|
|
588
|
+
|
|
589
|
+
/**
|
|
590
|
+
* The auto-check, if it is due (SPEC MARKETPLACES_SCREEN): `run` is
|
|
591
|
+
* `decklight marketplace <args…>`, and `broadcast` tells every page when the
|
|
592
|
+
* answer lands, so the deck offers it without a reload. Never awaited by a
|
|
593
|
+
* caller that matters, and silent on failure: resolves to the record, or null.
|
|
594
|
+
* The edit server calls it once as it starts; turning the switch on calls it too.
|
|
595
|
+
*/
|
|
596
|
+
export function autoCheckInBackground({ run = runMarketplace, broadcast = () => {} } = {}) {
|
|
597
|
+
return import('./marketplace-autocheck.mjs')
|
|
598
|
+
.then(({ runAutoCheck, checkSummary }) => runAutoCheck({ run }).then((rec) => {
|
|
599
|
+
if (!rec) return null;
|
|
600
|
+
broadcast('marketplaces', { checkedAt: rec.checkedAt, summary: checkSummary(rec) });
|
|
601
|
+
return rec;
|
|
602
|
+
}))
|
|
603
|
+
.catch(() => null);
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
const CLI = fileURLToPath(new URL('./decklight.mjs', import.meta.url));
|
|
607
|
+
|
|
608
|
+
/**
|
|
609
|
+
* Run `decklight marketplace <args…>` and say how it went: `{ ok, said,
|
|
610
|
+
* stdout }` with the command's own first line, or `{ ok: false, error }` with
|
|
611
|
+
* what it printed on the way out, prefix dropped. git is told never to prompt
|
|
612
|
+
* (the command does that too; a server has no terminal to prompt on), and the
|
|
613
|
+
* update notice is the command line's business, not this sentence's.
|
|
614
|
+
*/
|
|
615
|
+
export function runMarketplace(args, { timeoutMs = 120000 } = {}) {
|
|
616
|
+
return new Promise((done) => {
|
|
617
|
+
execFile(process.execPath, [CLI, 'marketplace', ...args], {
|
|
618
|
+
encoding: 'utf8', timeout: timeoutMs,
|
|
619
|
+
// no version banner: the server already said which version this is,
|
|
620
|
+
// and on stderr it would open every refusal read back from there
|
|
621
|
+
env: { ...process.env, GIT_TERMINAL_PROMPT: '0', DECKLIGHT_NO_UPDATE_CHECK: '1', DECKLIGHT_BANNER: '1' },
|
|
622
|
+
}, (err, stdout, stderr) => {
|
|
623
|
+
if (!err) return done({ ok: true, said: String(stdout).trim().split('\n')[0] ?? '', stdout: String(stdout) });
|
|
624
|
+
const said = String(stderr).trim().replace(new RegExp(`^decklight marketplace ${args[0]}: `), '');
|
|
625
|
+
done({ ok: false, error: said || (err.killed ? `gave up after ${Math.round(timeoutMs / 1000)}s` : oneline(err)) });
|
|
626
|
+
});
|
|
627
|
+
});
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
/** `decklight marketplace add <spec>` — the add door's one command. */
|
|
631
|
+
export const runMarketplaceAdd = (spec, opts) => runMarketplace(['add', spec], opts);
|