decklight 0.9.0 → 0.11.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/NOTICE +2 -0
- package/PLATFORM.md +61 -3
- package/README.md +58 -28
- package/SPEC.md +1326 -85
- package/cli/agent-review.mjs +5 -4
- package/cli/agents.mjs +148 -18
- package/cli/bundle-audio.mjs +10 -3
- package/cli/bundle-module.mjs +95 -0
- package/cli/bundle.mjs +125 -7
- package/cli/cast.mjs +86 -19
- package/cli/check-fixes.mjs +194 -0
- package/cli/check-watch.mjs +151 -0
- package/cli/check.mjs +491 -75
- package/cli/code-editor.mjs +287 -0
- package/cli/commands.mjs +13 -2
- package/cli/commit-flow.mjs +7 -3
- package/cli/commit-message.mjs +35 -8
- package/cli/commit-split.mjs +125 -25
- package/cli/deck-refs.mjs +8 -3
- package/cli/decklight.mjs +11 -1
- package/cli/design-system-edit.mjs +37 -1
- package/cli/design-system-refs.mjs +263 -6
- package/cli/design-system.mjs +82 -14
- package/cli/edit-address.mjs +184 -0
- package/cli/edit-git.mjs +23 -6
- package/cli/edit-handover.mjs +257 -40
- package/cli/edit-look.mjs +293 -6
- package/cli/edit-open.mjs +143 -0
- package/cli/edit-slides.mjs +1043 -67
- package/cli/edit-translate.mjs +243 -0
- package/cli/edit.mjs +3680 -319
- package/cli/editor-support.mjs +286 -0
- package/cli/enhance.mjs +157 -27
- package/cli/find-replace.mjs +142 -0
- package/cli/fix-review.mjs +368 -0
- package/cli/git.mjs +13 -0
- package/cli/init.mjs +101 -22
- package/cli/keep-awake.mjs +68 -0
- package/cli/marketplace-autocheck.mjs +200 -0
- package/cli/marketplace.mjs +250 -13
- package/cli/migrate-writing.mjs +214 -0
- package/cli/narrate.mjs +121 -5
- package/cli/open.mjs +53 -15
- package/cli/outside-edit.mjs +257 -0
- package/cli/paste.mjs +92 -0
- package/cli/pdf.mjs +88 -10
- package/cli/pptx-export.mjs +10 -5
- package/cli/publish.mjs +24 -3
- package/cli/record.mjs +86 -15
- package/cli/remote.mjs +32 -6
- package/cli/rewrite.mjs +265 -0
- package/cli/runtime-link.mjs +218 -17
- package/cli/serve.mjs +9 -6
- package/cli/setup.mjs +2 -2
- package/cli/skill-content.mjs +251 -10
- package/cli/skills/slide-writing.md +333 -0
- package/cli/skills/voiceover.md +423 -0
- package/cli/skills.mjs +282 -15
- package/cli/starter-full.mjs +353 -0
- package/cli/supervise.mjs +14 -0
- package/cli/theme-refs.mjs +14 -2
- package/cli/theme.mjs +3 -2
- package/cli/translate-core.mjs +466 -0
- package/cli/translate-files.mjs +149 -0
- package/cli/translate.mjs +458 -0
- package/cli/units.mjs +75 -7
- package/cli/util.mjs +25 -0
- package/cli/vocabulary-docs.mjs +138 -0
- package/dist/decklight.css +2506 -113
- package/dist/decklight.js +385 -175
- package/dist/decklight.js.map +4 -4
- package/docs/GLOSSARY.md +9 -2
- package/docs/WRITING_RESEARCH.md +327 -0
- package/package.json +5 -3
- package/themes/coastal.css +3 -0
- package/themes/metropolis.css +2 -0
- package/themes/reveal-blood.css +3 -0
- package/themes/reveal-league.css +2 -0
- package/themes/reveal-moon.css +2 -0
- package/themes/reveal-serif.css +1 -0
- package/themes/reveal-sky.css +1 -0
- package/themes/reveal-solarized.css +4 -0
- package/tools/brand-palette.mjs +6 -1
- package/tools/build-groups.mjs +28 -8
- package/tools/cdp.mjs +176 -0
- package/tools/chart-spec.mjs +242 -0
- package/tools/click-match.mjs +70 -0
- package/tools/code-options.mjs +174 -0
- package/tools/conversation.mjs +49 -0
- package/tools/deck-family.mjs +101 -0
- package/tools/deck-html.mjs +212 -15
- package/tools/design-system-format.mjs +40 -1
- package/tools/design-system-migrations.mjs +207 -0
- package/tools/diagram-shapes.mjs +221 -0
- package/tools/elevenlabs-tts.mjs +62 -53
- package/tools/exec.mjs +10 -2
- package/tools/face-clip.mjs +96 -0
- package/tools/face-layout.mjs +94 -0
- package/tools/gemini-tts.mjs +1 -1
- package/tools/invisible-in-print.mjs +27 -0
- package/tools/lipsync-auto.mjs +197 -0
- package/tools/lipsync-config.mjs +16 -0
- package/tools/lipsync-engines.mjs +22 -4
- package/tools/lipsync-server.mjs +8 -5
- package/tools/lipsync.mjs +122 -30
- package/tools/local-voice.mjs +1 -1
- package/tools/mouth-file.mjs +26 -0
- package/tools/mouth.mjs +320 -0
- package/tools/narration-manifest.mjs +100 -6
- package/tools/narration-synth.mjs +96 -76
- package/tools/recording-impact.mjs +16 -1
- package/tools/sentences.mjs +7 -1
- package/tools/site-clip.mjs +114 -0
- package/tools/starters.mjs +402 -0
- package/tools/steps.mjs +118 -0
- package/tools/take-check.mjs +146 -0
- package/tools/template-theme.mjs +3 -1
- package/tools/test-impact.mjs +36 -12
- package/tools/theme-check.mjs +196 -1
- package/tools/tone-cue.mjs +108 -0
- package/tools/tts-cache.mjs +9 -3
- package/tools/tts-engines.mjs +100 -11
- package/tools/video-cache.mjs +93 -0
- package/tools/video-live.mjs +349 -0
- package/tools/video-options.mjs +11 -0
- package/tools/video.mjs +825 -117
- package/tools/viseme-fit.mjs +27 -0
- package/tools/viseme-match.mjs +77 -0
- package/tools/vocabulary.mjs +397 -0
- package/tools/voice-renumber.mjs +605 -0
- package/tools/voiceover-server.mjs +42 -11
- package/tools/voiceover.mjs +48 -20
- package/dist/build-info.json +0 -1
package/cli/marketplace.mjs
CHANGED
|
@@ -7,6 +7,8 @@
|
|
|
7
7
|
// decklight marketplace add <owner/repo | git url | path> [--name x]
|
|
8
8
|
// decklight marketplace list
|
|
9
9
|
// decklight marketplace update <name> [--branch <ref>]
|
|
10
|
+
// decklight marketplace outdated [<name>] [--json]
|
|
11
|
+
// decklight marketplace auto-check [on|off]
|
|
10
12
|
// decklight marketplace remove <name>
|
|
11
13
|
//
|
|
12
14
|
// A marketplace is a git repo (or a local directory) with
|
|
@@ -25,8 +27,9 @@
|
|
|
25
27
|
// offered them.
|
|
26
28
|
//
|
|
27
29
|
// The invariant this module exists to keep (SPEC MARKETPLACE_REGISTRY): the
|
|
28
|
-
// network is touched ONLY by an explicit `add` or `
|
|
29
|
-
// source
|
|
30
|
+
// network is touched ONLY by an explicit `add`, `update` or `outdated` of a
|
|
31
|
+
// remote source — and `outdated` only asks where a ref points (`git
|
|
32
|
+
// ls-remote`), it fetches no file. Registering is a filesystem write; `list` reads only the cache;
|
|
30
33
|
// installing an entry reads the checkout; nothing on the deck-load or
|
|
31
34
|
// presenting path imports this module at all. A deck on conference wifi, on a
|
|
32
35
|
// plane, or air-gapped behaves identically to one at a desk, marketplace or
|
|
@@ -35,7 +38,7 @@
|
|
|
35
38
|
import {
|
|
36
39
|
existsSync, mkdirSync, mkdtempSync, readFileSync, renameSync, rmSync, statSync, writeFileSync,
|
|
37
40
|
} from 'node:fs';
|
|
38
|
-
import { execFileSync } from 'node:child_process';
|
|
41
|
+
import { execFile, execFileSync } from 'node:child_process';
|
|
39
42
|
// The registry is the file that says which marketplaces exist at all. A
|
|
40
43
|
// truncate interrupted halfway leaves JSON that no longer parses, and
|
|
41
44
|
// loadRegistry rightly refuses to guess at it — so the write is a rename.
|
|
@@ -663,6 +666,48 @@ export function classifySource(spec, { exists = existsSync } = {}) {
|
|
|
663
666
|
return { kind: 'local', root: resolve(spec), spec };
|
|
664
667
|
}
|
|
665
668
|
|
|
669
|
+
/**
|
|
670
|
+
* What `add <spec>` is about to do, said before it does it — the in-deck door's
|
|
671
|
+
* first ⏎ (SPEC DESIGN_SYSTEMS). Touches no network: it classifies the spec,
|
|
672
|
+
* and for a local directory checks that the manifest is there, since that much
|
|
673
|
+
* is free and saying it now beats saying it after a second ⏎.
|
|
674
|
+
*
|
|
675
|
+
* `base` is the directory a relative path is read against: the deck's, for
|
|
676
|
+
* the door, where the CLI uses its cwd. A local spec comes back ABSOLUTE in
|
|
677
|
+
* `spec`, because the registry keeps the source as given and a relative one
|
|
678
|
+
* would mean something else from the next directory `update` runs in.
|
|
679
|
+
* `registered` names the marketplace already registered from that source, if
|
|
680
|
+
* any: adding it again re-clones it, as `add` does at the command line.
|
|
681
|
+
* `ref` is `--branch`: held to the same rule as the command line's, and
|
|
682
|
+
* refused on a local directory now rather than after the second ⏎.
|
|
683
|
+
*/
|
|
684
|
+
export function planAdd(rawSpec, { ref = null, base = process.cwd(), home = configHome(), exists = existsSync } = {}) {
|
|
685
|
+
const raw = String(rawSpec ?? '').trim();
|
|
686
|
+
if (!raw) throw new MarketplaceError('needs an owner/repo, a git url, or a path');
|
|
687
|
+
const bad = ref === null ? null : refProblem(String(ref));
|
|
688
|
+
if (bad) throw new MarketplaceError(`--branch ${JSON.stringify(String(ref))} ${bad}`);
|
|
689
|
+
// it becomes one argument of `decklight marketplace add`: never an option,
|
|
690
|
+
// never more than one line
|
|
691
|
+
if (raw.startsWith('-') || /[\u0000-\u001f\u007f]/.test(raw) || raw.length > 2048) {
|
|
692
|
+
throw new MarketplaceError(`${JSON.stringify(raw.slice(0, 80))} is not an owner/repo, a git url, or a path`);
|
|
693
|
+
}
|
|
694
|
+
const src = classifySource(raw, { exists: (p) => exists(resolve(base, p)) });
|
|
695
|
+
let spec = raw, does;
|
|
696
|
+
if (src.kind === 'local') {
|
|
697
|
+
const root = resolve(base, raw);
|
|
698
|
+
if (!exists(root)) throw new MarketplaceError(`no such directory: ${root}`);
|
|
699
|
+
if (!exists(join(root, MANIFEST_PATH))) throw new MarketplaceError(`${root} has no ${MANIFEST_PATH} — is it a marketplace?`);
|
|
700
|
+
if (ref) throw new MarketplaceError(`${raw} is a local directory — --branch needs a repository to clone`);
|
|
701
|
+
spec = root;
|
|
702
|
+
does = `register ${root} — read in place, nothing is fetched`;
|
|
703
|
+
} else {
|
|
704
|
+
does = `clone ${cloneUrl(src)}${ref ? ` at ${ref}` : ''} with your git credentials on this machine`;
|
|
705
|
+
}
|
|
706
|
+
const reg = loadRegistry(home).marketplaces ?? {};
|
|
707
|
+
const registered = Object.keys(reg).find((n) => reg[n].source === spec) ?? null;
|
|
708
|
+
return { spec, ref: ref ?? null, kind: src.kind, url: src.kind === 'local' ? null : cloneUrl(src), path: src.kind === 'local' ? spec : null, does, registered };
|
|
709
|
+
}
|
|
710
|
+
|
|
666
711
|
/** The URL git is handed for a remote source. */
|
|
667
712
|
export const cloneUrl = (src) =>
|
|
668
713
|
(src.kind === 'github' ? `https://github.com/${src.owner}/${src.repo}.git` : src.url);
|
|
@@ -940,9 +985,131 @@ export function resolveEntry(ref, catalogs) {
|
|
|
940
985
|
return hits[0];
|
|
941
986
|
}
|
|
942
987
|
|
|
988
|
+
// ── what changed, and what is behind ──────────────────────────────────────
|
|
989
|
+
|
|
990
|
+
const entryKey = (e) => `${e.type}:${e.name}`;
|
|
991
|
+
|
|
992
|
+
/**
|
|
993
|
+
* What one fetch of a catalog changed against the copy it replaced: entries
|
|
994
|
+
* `added` and `removed`, and entries whose `version` moved (`changed`, with
|
|
995
|
+
* `from` and `to`). `before` is null for a first fetch, when everything is
|
|
996
|
+
* new — said as `first`, so a reader does not call forty entries "news".
|
|
997
|
+
* Pure: two entry lists in, one record out.
|
|
998
|
+
*/
|
|
999
|
+
export function catalogChanges(before, after) {
|
|
1000
|
+
const was = new Map((before ?? []).map((e) => [entryKey(e), e]));
|
|
1001
|
+
const now = new Map((after ?? []).map((e) => [entryKey(e), e]));
|
|
1002
|
+
const brief = (e) => ({ type: e.type, name: e.name, version: e.version ?? null });
|
|
1003
|
+
const added = [...now.values()].filter((e) => !was.has(entryKey(e))).map(brief);
|
|
1004
|
+
const removed = [...was.values()].filter((e) => !now.has(entryKey(e))).map(brief);
|
|
1005
|
+
const changed = [...now.values()]
|
|
1006
|
+
.filter((e) => was.has(entryKey(e)) && (was.get(entryKey(e)).version ?? null) !== (e.version ?? null))
|
|
1007
|
+
.map((e) => ({ type: e.type, name: e.name, from: was.get(entryKey(e)).version ?? null, to: e.version ?? null }));
|
|
1008
|
+
const order = (a, b) => a.type.localeCompare(b.type) || a.name.localeCompare(b.name);
|
|
1009
|
+
return { first: before === null, added: added.sort(order), removed: removed.sort(order), changed: changed.sort(order) };
|
|
1010
|
+
}
|
|
1011
|
+
|
|
1012
|
+
/**
|
|
1013
|
+
* Remember what a fetch changed on the marketplace's registry record, so the
|
|
1014
|
+
* "what's new" of its last update can be read again later — by `list`, by the
|
|
1015
|
+
* Marketplaces… screen — and not only in the moment it was printed.
|
|
1016
|
+
*/
|
|
1017
|
+
function noteChanges(record, beforeCat, afterManifest, { from = null, to = null, now = Date.now() } = {}) {
|
|
1018
|
+
const before = beforeCat?.ok ? beforeCat.manifest.entries : null;
|
|
1019
|
+
record.changes = { at: new Date(now).toISOString(), from: from ?? null, to: to ?? null, ...catalogChanges(before, afterManifest.entries) };
|
|
1020
|
+
return record.changes;
|
|
1021
|
+
}
|
|
1022
|
+
|
|
1023
|
+
/** The what's-new lines `update` prints: `+ new`, `− gone`, `↑ moved`. */
|
|
1024
|
+
function changeLines(name, c) {
|
|
1025
|
+
return [
|
|
1026
|
+
...c.added.map((e) => `+ ${e.name}@${name}${e.version ? ` ${e.version}` : ''} (${e.type})`),
|
|
1027
|
+
...c.removed.map((e) => `− ${e.name}@${name} (${e.type}) — no longer offered`),
|
|
1028
|
+
...c.changed.map((e) => `↑ ${e.name}@${name} ${e.from ?? 'unversioned'} → ${e.to ?? 'unversioned'}`),
|
|
1029
|
+
];
|
|
1030
|
+
}
|
|
1031
|
+
|
|
1032
|
+
/** `git ls-remote`, asynchronously: several marketplaces are asked at once. */
|
|
1033
|
+
const lsRemote = (url, patterns, { timeoutMs }) => new Promise((done, fail) => {
|
|
1034
|
+
execFile('git', ['ls-remote', '--', url, ...patterns], {
|
|
1035
|
+
encoding: 'utf8', timeout: timeoutMs,
|
|
1036
|
+
// never a password prompt, as for a clone: an unreachable repo is an answer
|
|
1037
|
+
env: { ...process.env, GIT_TERMINAL_PROMPT: '0' },
|
|
1038
|
+
}, (err, stdout, stderr) => (err ? fail(Object.assign(err, { stderr })) : done(stdout)));
|
|
1039
|
+
});
|
|
1040
|
+
|
|
1041
|
+
/**
|
|
1042
|
+
* The commit `ref` names in an `ls-remote` answer — the one `clone --branch`
|
|
1043
|
+
* would check out: a branch before a tag of the same name, and a tag PEELED
|
|
1044
|
+
* (`^{}`), since an annotated tag's own object is not the commit a clone lands
|
|
1045
|
+
* on. No ref is the remote's `HEAD`, as no `--branch` is.
|
|
1046
|
+
*/
|
|
1047
|
+
export function remoteCommit(lsRemoteOut, ref = null) {
|
|
1048
|
+
const rows = String(lsRemoteOut).split('\n').map((l) => l.trim().split(/\s+/))
|
|
1049
|
+
.filter(([sha, name]) => /^[0-9a-f]{40,64}$/.test(sha ?? '') && name);
|
|
1050
|
+
const at = (name) => rows.find(([, n]) => n === name)?.[0] ?? null;
|
|
1051
|
+
if (!ref) return at('HEAD');
|
|
1052
|
+
return at(`refs/heads/${ref}`) ?? at(`refs/tags/${ref}^{}`) ?? at(`refs/tags/${ref}`) ?? at(ref);
|
|
1053
|
+
}
|
|
1054
|
+
|
|
1055
|
+
/**
|
|
1056
|
+
* Is a marketplace behind its source? Asked, never fetched: a remote is asked
|
|
1057
|
+
* where its ref points now (`git ls-remote`, the caller's credentials, no
|
|
1058
|
+
* prompt) and that is held against the commit the cached catalog came from; a
|
|
1059
|
+
* local directory's manifest is compared with the cached copy, with no
|
|
1060
|
+
* network at all. Nothing on disk changes — `update` is what takes it.
|
|
1061
|
+
*
|
|
1062
|
+
* `state` is one of: `current`; `behind` (with `remote`, the commit an update
|
|
1063
|
+
* would bring); `unfetched` (never fetched, so `update` is its first fetch);
|
|
1064
|
+
* `unknown` (fetched before commits were recorded — an update records one);
|
|
1065
|
+
* `unreachable` (with `error`, the reason).
|
|
1066
|
+
*/
|
|
1067
|
+
export async function checkMarketplace(name, home = configHome(), { ask = lsRemote, timeoutMs = 15000 } = {}) {
|
|
1068
|
+
const m = loadRegistry(home).marketplaces?.[name];
|
|
1069
|
+
if (!m) throw new MarketplaceError(`no marketplace "${name}" (decklight marketplace list)`);
|
|
1070
|
+
const src = classifySource(m.source);
|
|
1071
|
+
const base = { name, source: m.source, ref: m.ref ?? null, local: src.kind === 'local', commit: m.commit ?? null, remote: null, error: null };
|
|
1072
|
+
if (loadCatalog(name, home) === null) return { ...base, state: 'unfetched' };
|
|
1073
|
+
if (src.kind === 'local') {
|
|
1074
|
+
let raw;
|
|
1075
|
+
try { raw = readFileSync(join(src.root, MANIFEST_PATH), 'utf8'); } catch {
|
|
1076
|
+
return { ...base, state: 'unreachable', error: `${m.source} has no ${MANIFEST_PATH} any more` };
|
|
1077
|
+
}
|
|
1078
|
+
let cached = null;
|
|
1079
|
+
try { cached = readFileSync(cachePath(home, name), 'utf8'); } catch { /* read just above; gone since */ }
|
|
1080
|
+
return { ...base, state: raw === cached ? 'current' : 'behind' };
|
|
1081
|
+
}
|
|
1082
|
+
let out;
|
|
1083
|
+
// a tag's peeled line answers only when asked for by name
|
|
1084
|
+
try { out = await ask(cloneUrl(src), m.ref ? [m.ref, `${m.ref}^{}`] : ['HEAD'], { timeoutMs }); } catch (e) {
|
|
1085
|
+
return { ...base, state: 'unreachable', error: `git ls-remote ${cloneUrl(src)} failed — ${e.killed ? `no answer in ${Math.round(timeoutMs / 1000)}s` : oneline(e)}` };
|
|
1086
|
+
}
|
|
1087
|
+
const remote = remoteCommit(out, m.ref ?? null);
|
|
1088
|
+
if (!remote) return { ...base, state: 'unreachable', error: m.ref ? `no branch or tag "${m.ref}" in ${m.source}` : `${m.source} has no HEAD` };
|
|
1089
|
+
if (!m.commit) return { ...base, remote, state: 'unknown' };
|
|
1090
|
+
return { ...base, remote, state: remote === m.commit ? 'current' : 'behind' };
|
|
1091
|
+
}
|
|
1092
|
+
|
|
1093
|
+
/** `checkMarketplace` for every registered marketplace (or `only` one), asked at once. */
|
|
1094
|
+
export async function checkMarketplaces(home = configHome(), { only = null, ...opts } = {}) {
|
|
1095
|
+
const names = only ? [only] : Object.keys(loadRegistry(home).marketplaces ?? {}).sort();
|
|
1096
|
+
return Promise.all(names.map((n) => checkMarketplace(n, home, opts)));
|
|
1097
|
+
}
|
|
1098
|
+
|
|
1099
|
+
/** One line of `outdated`: the state, and the command that acts on it. */
|
|
1100
|
+
function outdatedLine(r) {
|
|
1101
|
+
const at = (c) => (c ? `@${c.slice(0, 7)}` : '');
|
|
1102
|
+
const fix = ` — decklight marketplace update ${r.name}`;
|
|
1103
|
+
if (r.state === 'current') return `${r.name} up to date${r.commit ? ` ${at(r.commit)}` : ''}`;
|
|
1104
|
+
if (r.state === 'behind') return r.local ? `${r.name} changed on disk${fix}` : `${r.name} behind ${at(r.commit)} → ${at(r.remote)}${fix}`;
|
|
1105
|
+
if (r.state === 'unfetched') return `${r.name} registered, not fetched${fix}`;
|
|
1106
|
+
if (r.state === 'unknown') return `${r.name} no commit recorded to compare (the source is at ${at(r.remote)})${fix}`;
|
|
1107
|
+
return `${r.name} could not ask — ${r.error}`;
|
|
1108
|
+
}
|
|
1109
|
+
|
|
943
1110
|
// ── the command ────────────────────────────────────────────────────────────
|
|
944
1111
|
|
|
945
|
-
const USAGE = `usage: decklight marketplace <add|list|update|remove> …
|
|
1112
|
+
const USAGE = `usage: decklight marketplace <add|list|update|outdated|auto-check|remove> …
|
|
946
1113
|
|
|
947
1114
|
decklight marketplace add <owner/repo | git url | path> [--name <name>]
|
|
948
1115
|
[--branch <ref>]
|
|
@@ -971,15 +1138,30 @@ const USAGE = `usage: decklight marketplace <add|list|update|remove> …
|
|
|
971
1138
|
re-clone a marketplace, refreshing the cached manifest and the checkout
|
|
972
1139
|
(at the ref it was added with, unless --branch moves the pin)
|
|
973
1140
|
its entries install from; for a registered-not-fetched marketplace this is
|
|
974
|
-
the FIRST fetch it ever gets. Then it
|
|
975
|
-
|
|
976
|
-
|
|
1141
|
+
the FIRST fetch it ever gets. Then it says what's new in the catalog
|
|
1142
|
+
(entries added, gone, or at a new version — remembered, so the
|
|
1143
|
+
Marketplaces… screen shows it again), names every entry you installed
|
|
1144
|
+
from it that the catalog now has newer, and the command that takes it —
|
|
1145
|
+
it installs nothing itself
|
|
1146
|
+
|
|
1147
|
+
decklight marketplace outdated [<name>] [--json]
|
|
1148
|
+
which marketplaces are behind their source: a remote is ASKED where its
|
|
1149
|
+
ref points now (git ls-remote — no clone, nothing written), a local
|
|
1150
|
+
directory's manifest is compared with the cached copy. Each behind one is
|
|
1151
|
+
named with the update that takes it
|
|
1152
|
+
|
|
1153
|
+
decklight marketplace auto-check [on|off]
|
|
1154
|
+
whether an edit server that starts runs outdated by itself, in the
|
|
1155
|
+
background and at most once in 12 hours, and the deck offers to update
|
|
1156
|
+
what it found behind. Off until you turn it on; it only ever offers, an
|
|
1157
|
+
update is still yours. With no argument, says which it is
|
|
977
1158
|
|
|
978
1159
|
decklight marketplace remove <name>
|
|
979
1160
|
unregister a marketplace and drop its cached manifest and checkout
|
|
980
1161
|
|
|
981
|
-
registering is not fetching: the network is touched only by an explicit add
|
|
982
|
-
or
|
|
1162
|
+
registering is not fetching: the network is touched only by an explicit add,
|
|
1163
|
+
update or outdated (or the auto-check you turned on), never when a deck loads
|
|
1164
|
+
or presents (SPEC MARKETPLACE_REGISTRY).
|
|
983
1165
|
DECKLIGHT_HOME overrides ~/.decklight/.`;
|
|
984
1166
|
|
|
985
1167
|
const printManifestErrors = (cmd, spec, errors) => {
|
|
@@ -1033,6 +1215,8 @@ async function addMain(args, home) {
|
|
|
1033
1215
|
reg.marketplaces[name] = {
|
|
1034
1216
|
...(existing ?? {}), source: spec, ref: ref ?? undefined, commit: got.commit ?? undefined,
|
|
1035
1217
|
};
|
|
1218
|
+
// a re-add is a refresh, and says what it changed as `update` does
|
|
1219
|
+
if (existing) noteChanges(reg.marketplaces[name], loadCatalog(name, home), v.manifest, { from: existing.commit, to: got.commit });
|
|
1036
1220
|
writeCache(home, name, got.raw);
|
|
1037
1221
|
const at = adoptCheckout(home, name, got.checkout);
|
|
1038
1222
|
got.checkout = null;
|
|
@@ -1068,7 +1252,7 @@ function versionNote(entry, installed) {
|
|
|
1068
1252
|
return ` ${had} → ${entry.version}`;
|
|
1069
1253
|
}
|
|
1070
1254
|
|
|
1071
|
-
function listMain(home) {
|
|
1255
|
+
async function listMain(home) {
|
|
1072
1256
|
const installs = loadLedger(home).installs;
|
|
1073
1257
|
const reg = loadRegistry(home);
|
|
1074
1258
|
const names = Object.keys(reg.marketplaces).sort();
|
|
@@ -1076,6 +1260,7 @@ function listMain(home) {
|
|
|
1076
1260
|
console.log('no marketplaces registered — decklight marketplace add <owner/repo | git url | path>');
|
|
1077
1261
|
return 0;
|
|
1078
1262
|
}
|
|
1263
|
+
console.log(await autoCheckLine(reg, home));
|
|
1079
1264
|
for (const name of names) {
|
|
1080
1265
|
const m = reg.marketplaces[name];
|
|
1081
1266
|
// The commit is what the manifest AND every entry's files came from — one
|
|
@@ -1117,6 +1302,30 @@ function listMain(home) {
|
|
|
1117
1302
|
return 0;
|
|
1118
1303
|
}
|
|
1119
1304
|
|
|
1305
|
+
// The auto-check (cli/marketplace-autocheck.mjs) imports this module, so the
|
|
1306
|
+
// commands that use it load it when they run.
|
|
1307
|
+
let autoCheckModule = null;
|
|
1308
|
+
const loadAutoCheck = async () => (autoCheckModule ??= await import('./marketplace-autocheck.mjs'));
|
|
1309
|
+
|
|
1310
|
+
/** Whether an edit server checks for updates as it starts, and what it last found. */
|
|
1311
|
+
async function autoCheckLine(reg, home) {
|
|
1312
|
+
if (reg.autoCheck !== true) return 'auto-check: off — decklight marketplace auto-check on checks for updates when decklight starts';
|
|
1313
|
+
const { readCheckRecord, checkSummary } = await loadAutoCheck();
|
|
1314
|
+
const rec = readCheckRecord(home);
|
|
1315
|
+
return `auto-check: on — ${rec ? checkSummary(rec) : 'not checked yet: the next edit server to start asks'}`;
|
|
1316
|
+
}
|
|
1317
|
+
|
|
1318
|
+
async function autoCheckMain(args, home) {
|
|
1319
|
+
const [want] = args.filter((a) => !a.startsWith('-'));
|
|
1320
|
+
if (want === undefined) { console.log(await autoCheckLine(loadRegistry(home), home)); return 0; }
|
|
1321
|
+
if (want !== 'on' && want !== 'off') { console.error(`decklight marketplace auto-check: on or off, not "${want}"`); return 1; }
|
|
1322
|
+
(await loadAutoCheck()).setAutoCheck(want === 'on', home);
|
|
1323
|
+
console.log(want === 'on'
|
|
1324
|
+
? 'auto-check: on — an edit server that starts asks each source whether it has moved (nothing is fetched), at most once in 12 hours, and the deck offers what it finds'
|
|
1325
|
+
: 'auto-check: off — nothing is asked until you press C on Marketplaces… or run decklight marketplace outdated');
|
|
1326
|
+
return 0;
|
|
1327
|
+
}
|
|
1328
|
+
|
|
1120
1329
|
async function updateMain(args, home) {
|
|
1121
1330
|
const [name] = args.filter((a, i) => !a.startsWith('-') && args[i - 1] !== '--branch');
|
|
1122
1331
|
if (!name) { console.error(`decklight marketplace update: which one?\n\n${USAGE}`); return 1; }
|
|
@@ -1146,6 +1355,7 @@ async function updateMain(args, home) {
|
|
|
1146
1355
|
try {
|
|
1147
1356
|
const v = validateManifest(got.raw);
|
|
1148
1357
|
if (!v.ok) { printManifestErrors('update', m.source, v.errors); return 1; }
|
|
1358
|
+
const before = loadCatalog(name, home);
|
|
1149
1359
|
writeCache(home, name, got.raw);
|
|
1150
1360
|
const at = adoptCheckout(home, name, got.checkout);
|
|
1151
1361
|
got.checkout = null;
|
|
@@ -1154,18 +1364,30 @@ async function updateMain(args, home) {
|
|
|
1154
1364
|
reg2.marketplaces[name] = {
|
|
1155
1365
|
...reg2.marketplaces[name], ref: ref ?? undefined, commit: got.commit ?? undefined,
|
|
1156
1366
|
};
|
|
1367
|
+
noteChanges(reg2.marketplaces[name], before, v.manifest, { from: m.commit, to: got.commit });
|
|
1157
1368
|
saveRegistry(reg2, home);
|
|
1158
1369
|
}
|
|
1370
|
+
// the last check found this one behind: it no longer is, and nothing offers it
|
|
1371
|
+
(await loadAutoCheck()).noteUpdated(name, got.commit ?? null, home);
|
|
1159
1372
|
console.log(`${first ? 'fetched' : 'updated'} ${name}${ref ? ` at ${ref}` : ''} — ${entriesSummary(name, v.manifest.entries)}`);
|
|
1160
1373
|
if (at) console.log(` cloned to ${at}${got.commit ? ` (${got.commit.slice(0, 7)})` : ''}`);
|
|
1374
|
+
// What's new in the CATALOG — the first fetch has no "before" to hold it
|
|
1375
|
+
// against, so it is the entries line above and nothing more.
|
|
1376
|
+
if (!first && before?.ok) {
|
|
1377
|
+
const lines = changeLines(name, catalogChanges(before.manifest.entries, v.manifest.entries));
|
|
1378
|
+
console.log(lines.length ? ` what's new:\n${lines.map((l) => ` ${l}`).join('\n')}` : ' nothing in the catalog changed');
|
|
1379
|
+
}
|
|
1161
1380
|
// What you installed from it that the catalog now has newer — and the
|
|
1162
1381
|
// one command that takes each. Nothing is installed here: an update
|
|
1163
1382
|
// refreshes the catalog, and taking a new version stays your call.
|
|
1164
|
-
|
|
1383
|
+
// A design system whose new version declares migrations says what that
|
|
1384
|
+
// means for the decks on it, and what moves them, instead of a re-add.
|
|
1385
|
+
const { withMigrationHint } = await import('./design-system-refs.mjs');
|
|
1386
|
+
const newer = newerThanInstalled(home, name).map((n) => withMigrationHint(n, home));
|
|
1165
1387
|
if (newer.length) {
|
|
1166
1388
|
console.log(` newer than what you installed:`);
|
|
1167
1389
|
for (const n of newer) {
|
|
1168
|
-
console.log(` ${n.qualified} ${n.from ?? 'unversioned'} → ${n.to}${n.how ? ` — ${n.how}` : ''}`);
|
|
1390
|
+
console.log(` ${n.qualified} ${n.from ?? 'unversioned'} → ${n.to}${n.note ? ` (${n.note})` : ''}${n.how ? ` — ${n.how}` : ''}`);
|
|
1169
1391
|
}
|
|
1170
1392
|
}
|
|
1171
1393
|
return 0;
|
|
@@ -1174,6 +1396,19 @@ async function updateMain(args, home) {
|
|
|
1174
1396
|
}
|
|
1175
1397
|
}
|
|
1176
1398
|
|
|
1399
|
+
async function outdatedMain(args, home) {
|
|
1400
|
+
const [name] = args.filter((a) => !a.startsWith('-'));
|
|
1401
|
+
const reg = loadRegistry(home);
|
|
1402
|
+
if (name && !reg.marketplaces[name]) { console.error(`decklight marketplace outdated: no marketplace "${name}" (decklight marketplace list)`); return 1; }
|
|
1403
|
+
const results = await checkMarketplaces(home, { only: name ?? null });
|
|
1404
|
+
// the answer is kept: Marketplaces… starts from it, and the auto-check's window is measured from it
|
|
1405
|
+
(await loadAutoCheck()).recordCheck(results, home, { all: !name });
|
|
1406
|
+
if (args.includes('--json')) { console.log(JSON.stringify({ marketplaces: results }, null, 2)); return 0; }
|
|
1407
|
+
if (!results.length) { console.log('no marketplaces registered — decklight marketplace add <owner/repo | git url | path>'); return 0; }
|
|
1408
|
+
for (const r of results) console.log(outdatedLine(r));
|
|
1409
|
+
return 0;
|
|
1410
|
+
}
|
|
1411
|
+
|
|
1177
1412
|
function removeMain(args, home) {
|
|
1178
1413
|
const [name] = args.filter((a) => !a.startsWith('-'));
|
|
1179
1414
|
if (!name) { console.error(`decklight marketplace remove: which one?\n\n${USAGE}`); return 1; }
|
|
@@ -1197,9 +1432,11 @@ export async function marketplaceMain(args = []) {
|
|
|
1197
1432
|
const home = configHome();
|
|
1198
1433
|
try {
|
|
1199
1434
|
if (sub === 'add') return await addMain(rest, home);
|
|
1200
|
-
if (sub === 'list') return listMain(home);
|
|
1435
|
+
if (sub === 'list') return await listMain(home);
|
|
1201
1436
|
if (sub === 'update') return await updateMain(rest, home);
|
|
1437
|
+
if (sub === 'outdated') return await outdatedMain(rest, home);
|
|
1202
1438
|
if (sub === 'remove') return removeMain(rest, home);
|
|
1439
|
+
if (sub === 'auto-check') return await autoCheckMain(rest, home);
|
|
1203
1440
|
} catch (e) {
|
|
1204
1441
|
if (e instanceof MarketplaceError) { console.error(`decklight marketplace ${sub}: ${e.message}`); return 1; }
|
|
1205
1442
|
throw e;
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
// Copyright 2026 Gilles Philippart
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
// LETTER_BY_LETTER. The accessible label is the one complete sentence in a
|
|
5
|
+
// legacy title, including in translations whose visible slots got scrambled.
|
|
6
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
7
|
+
import { basename, dirname, join } from 'node:path';
|
|
8
|
+
import { writeFileAtomic } from '../tools/atomic-write.mjs';
|
|
9
|
+
import { deckFamily } from '../tools/deck-family.mjs';
|
|
10
|
+
import { decodeNoteEntities, elementChildRanges, sectionCloseIndex, splitOpenTag } from '../tools/deck-html.mjs';
|
|
11
|
+
import { escapeHtml } from '../tools/escape.mjs';
|
|
12
|
+
import { attrList, attrOf, withAttr, withStyle } from './edit-address.mjs';
|
|
13
|
+
import { deckParts, formatRecord, parseRecord, slideParts, slideShape } from './translate-core.mjs';
|
|
14
|
+
import { recordOf, resolveSource } from './translate-files.mjs';
|
|
15
|
+
|
|
16
|
+
const irrelevant = new Set(['aside', 'code', 'pre', 'script', 'style', 'svg', 'template', 'textarea']);
|
|
17
|
+
const inline = new Set(['span', 'b', 'i', 'em', 'strong', 'small', 'mark', 'u', 's', 'sub', 'sup']);
|
|
18
|
+
const graphemes = new Intl.Segmenter(undefined, { granularity: 'grapheme' });
|
|
19
|
+
const oneGrapheme = (text) => !!text.trim() && graphemes.segment(text).containing(0)?.segment === text;
|
|
20
|
+
const timeIndex = /(?:^|;)\s*--i\s*:\s*\d+\s*(?=;|$)/;
|
|
21
|
+
const timeCount = /(?:^|;)\s*--n\s*:\s*\d+\s*(?=;|$)/;
|
|
22
|
+
|
|
23
|
+
function openParts(el) {
|
|
24
|
+
const { attrs, close, rest } = splitOpenTag(el);
|
|
25
|
+
return { attrs, open: attrs + close, rest };
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function cleanChildren(el, open) {
|
|
29
|
+
const kids = elementChildRanges(el);
|
|
30
|
+
if (!kids.length) return null;
|
|
31
|
+
let at = open.length;
|
|
32
|
+
for (const { start, end, tag } of kids) {
|
|
33
|
+
if (decodeNoteEntities(el.slice(at, start)).trim() || irrelevant.has(tag)) return null;
|
|
34
|
+
at = end;
|
|
35
|
+
}
|
|
36
|
+
const close = el.lastIndexOf('</');
|
|
37
|
+
return close >= at && !el.slice(at, close).trim() ? { kids, close } : null;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function legacyTitle(el, start, sourceAt) {
|
|
41
|
+
const { attrs, open } = openParts(el);
|
|
42
|
+
const label = attrList(attrs).find((a) => a.name === 'aria-label');
|
|
43
|
+
const text = decodeNoteEntities(label?.value).trim();
|
|
44
|
+
if (!text) return null;
|
|
45
|
+
const parent = cleanChildren(el, open);
|
|
46
|
+
if (!parent) return null;
|
|
47
|
+
let total = 0;
|
|
48
|
+
const timed = timeCount.test(attrOf(attrs, 'style') ?? '');
|
|
49
|
+
const words = [];
|
|
50
|
+
for (const w of parent.kids) {
|
|
51
|
+
if (!inline.has(w.tag)) return null;
|
|
52
|
+
const word = el.slice(w.start, w.end);
|
|
53
|
+
const wrapped = cleanChildren(word, openParts(word).open);
|
|
54
|
+
if (!wrapped) return null;
|
|
55
|
+
let original = '';
|
|
56
|
+
for (const c of wrapped.kids) {
|
|
57
|
+
if (!inline.has(c.tag)) return null;
|
|
58
|
+
const { attrs: letterAttrs, open: letterOpen, rest } = openParts(word.slice(c.start, c.end));
|
|
59
|
+
const close = rest.indexOf('<');
|
|
60
|
+
if (close < 0 || !rest.startsWith('</', close)) return null;
|
|
61
|
+
const visible = decodeNoteEntities(rest.slice(0, close));
|
|
62
|
+
const source = sourceAt?.get(start + w.start + c.start + letterOpen.length) ?? visible;
|
|
63
|
+
if (!oneGrapheme(source) && !(timed && timeIndex.test(attrOf(letterAttrs, 'style') ?? ''))) return null;
|
|
64
|
+
original += source;
|
|
65
|
+
total++;
|
|
66
|
+
}
|
|
67
|
+
words.push(original);
|
|
68
|
+
}
|
|
69
|
+
if (total < 2 && !timed) return null;
|
|
70
|
+
return { start, end: start + el.length, contentStart: start + open.length, contentEnd: start + parent.close,
|
|
71
|
+
label, text, original: words.join(' '), attrs, close: el.slice(parent.close) };
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function scan(body, sourceAt) {
|
|
75
|
+
const titles = [], followers = [];
|
|
76
|
+
if (!/aria-label\s*=/i.test(body)) return { titles, followers };
|
|
77
|
+
const { attrs, close } = splitOpenTag(body);
|
|
78
|
+
const from = attrs.length + close.length;
|
|
79
|
+
const end = sectionCloseIndex(body);
|
|
80
|
+
const section = `<section>${body.slice(from, end < 0 ? undefined : end)}</section>`;
|
|
81
|
+
function visit(el, at, tag) {
|
|
82
|
+
if (irrelevant.has(tag)) return;
|
|
83
|
+
const title = legacyTitle(el, at, sourceAt);
|
|
84
|
+
if (title) { titles.push(title); return; }
|
|
85
|
+
const { attrs: opening } = openParts(el);
|
|
86
|
+
if ((attrOf(opening, 'class') ?? '').split(/\s+/).includes('cf-after')) followers.push({ at, opening });
|
|
87
|
+
for (const c of elementChildRanges(el)) visit(el.slice(c.start, c.end), at + c.start, c.tag);
|
|
88
|
+
}
|
|
89
|
+
for (const c of elementChildRanges(section)) visit(section.slice(c.start, c.end), from - '<section>'.length + c.start, c.tag);
|
|
90
|
+
return { titles, followers };
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export const legacyWriting = (body) => scan(body).titles.map((t) => t.text);
|
|
94
|
+
|
|
95
|
+
function classes(attrs, remove) {
|
|
96
|
+
return (attrOf(attrs, 'class') ?? '').split(/\s+/).filter((c) => c && !remove.includes(c)).join(' ') || null;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function replacement(title) {
|
|
100
|
+
const out = (attrOf(title.attrs, 'class') ?? '').split(/\s+/).includes('cf-write-out');
|
|
101
|
+
let attrs = withAttr(title.attrs, 'class', classes(title.attrs, ['cf-write', 'cf-write-out']));
|
|
102
|
+
attrs = withAttr(attrs, 'aria-label', null);
|
|
103
|
+
if (timeCount.test(attrOf(attrs, 'style') ?? '')) attrs = withStyle(attrs, '--n', null);
|
|
104
|
+
return `${withAttr(attrs, 'data-write', out ? 'out' : true)}>${escapeHtml(title.text)}${title.close}`;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function migrateSlide(body, record, hash) {
|
|
108
|
+
const old = record ? slideParts(body) : null;
|
|
109
|
+
const belongs = old && old.units.length === record.length && old.units.every((u, i) => u.kind === record[i].kind);
|
|
110
|
+
const runEdits = old?.edits.filter((e) => old.units[e.units?.[0]]?.kind === 'run') ?? [];
|
|
111
|
+
const sourceAt = belongs ? new Map(runEdits.map((e) => [e.start, record[e.units[0]].source])) : null;
|
|
112
|
+
const { titles, followers } = scan(body, sourceAt);
|
|
113
|
+
if (!titles.length) return { body, record, count: 0 };
|
|
114
|
+
if (record && (!belongs || (hash && slideShape(body) !== hash))) {
|
|
115
|
+
throw new Error('the slide differs structurally from its translation record');
|
|
116
|
+
}
|
|
117
|
+
const writes = titles.map((t) => ({ start: t.start, end: t.end, value: replacement(t) }));
|
|
118
|
+
for (const { at, opening } of followers) {
|
|
119
|
+
const attrs = withAttr(opening, 'class', classes(opening, ['cf-after']));
|
|
120
|
+
writes.push({ start: at, end: at + opening.length, value: withAttr(attrs, 'data-write-after', true) });
|
|
121
|
+
}
|
|
122
|
+
let migrated = body;
|
|
123
|
+
for (const { start, end, value } of writes.sort((a, b) => b.start - a.start)) {
|
|
124
|
+
migrated = migrated.slice(0, start) + value + migrated.slice(end);
|
|
125
|
+
}
|
|
126
|
+
if (!record) return { body: migrated, count: titles.length };
|
|
127
|
+
|
|
128
|
+
const removed = new Set();
|
|
129
|
+
const insertions = new Map();
|
|
130
|
+
for (const t of titles) {
|
|
131
|
+
let labelPair;
|
|
132
|
+
for (const e of old.edits) {
|
|
133
|
+
if (e.start >= t.contentStart && e.end <= t.contentEnd) {
|
|
134
|
+
for (const i of e.units ?? []) removed.add(i);
|
|
135
|
+
} else if (e.start >= t.start + t.label.start && e.end <= t.start + t.label.end) {
|
|
136
|
+
const i = e.units?.[0];
|
|
137
|
+
if (i !== undefined) { removed.add(i); labelPair = record[i]; }
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
const run = runEdits.find((e) => e.start >= t.contentStart)?.units[0] ?? runEdits.length;
|
|
141
|
+
const pair = labelPair ? { ...labelPair, kind: 'run', target: t.text } :
|
|
142
|
+
{ kind: 'run', source: t.original, target: t.text, state: 'machine' };
|
|
143
|
+
if (labelPair && labelPair.target !== t.text) { pair.state = 'reviewed'; delete pair.was; }
|
|
144
|
+
const here = insertions.get(run) ?? [];
|
|
145
|
+
here.push(pair);
|
|
146
|
+
insertions.set(run, here);
|
|
147
|
+
}
|
|
148
|
+
const pairs = [...record, null].flatMap((pair, i) => [
|
|
149
|
+
...(insertions.get(i) ?? []), ...(pair && !removed.has(i) ? [pair] : []),
|
|
150
|
+
]);
|
|
151
|
+
const after = slideParts(migrated);
|
|
152
|
+
if (after.units.length !== pairs.length || after.units.some((u, i) => u.kind !== pairs[i].kind)) {
|
|
153
|
+
throw new Error('could not align the converted text with its translation record');
|
|
154
|
+
}
|
|
155
|
+
return { body: migrated, count: titles.length, record: pairs, hash: slideShape(migrated) };
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
function planDeck(path, html, record) {
|
|
159
|
+
const parts = deckParts(html);
|
|
160
|
+
const slides = record?.slides.slice();
|
|
161
|
+
const structure = record?.structure.slice();
|
|
162
|
+
let count = 0;
|
|
163
|
+
for (let at = 2; at < parts.length; at += 2) {
|
|
164
|
+
const index = at / 2 - 1;
|
|
165
|
+
let r;
|
|
166
|
+
try { r = migrateSlide(parts[at], slides?.[index], structure?.[index]); }
|
|
167
|
+
catch (e) { throw new Error(`${basename(path)}, slide ${index + 1}: ${e.message}`); }
|
|
168
|
+
if (!r.count) continue;
|
|
169
|
+
if (record && !slides[index]) throw new Error(`${basename(path)}, slide ${index + 1}: missing translation record`);
|
|
170
|
+
count += r.count;
|
|
171
|
+
parts[at] = r.body;
|
|
172
|
+
if (record) { slides[index] = r.record; structure[index] = r.hash; }
|
|
173
|
+
}
|
|
174
|
+
return { html: parts.join(''), count, record: record && { ...record, slides, structure } };
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/** Plan the whole family before writing. Restore earlier files if a write fails. */
|
|
178
|
+
export function migrateWriting(deck) {
|
|
179
|
+
const { source } = resolveSource(deck);
|
|
180
|
+
const paths = [source, ...deckFamily(source).members.filter((m) => m.lang).map((m) => join(dirname(source), m.name))];
|
|
181
|
+
const writes = [];
|
|
182
|
+
let count = 0;
|
|
183
|
+
for (const path of paths) {
|
|
184
|
+
const html = readFileSync(path, 'utf8');
|
|
185
|
+
const recPath = recordOf(path);
|
|
186
|
+
const rec = path !== source && existsSync(recPath) ? readFileSync(recPath, 'utf8') : null;
|
|
187
|
+
const plan = planDeck(path, html, rec ? parseRecord(rec) : null);
|
|
188
|
+
if (!plan.count) continue;
|
|
189
|
+
count += plan.count;
|
|
190
|
+
writes.push({ path, before: html, after: plan.html });
|
|
191
|
+
if (rec) writes.push({ path: recPath, before: rec, after: formatRecord(plan.record) });
|
|
192
|
+
}
|
|
193
|
+
const done = [];
|
|
194
|
+
try {
|
|
195
|
+
for (const w of writes) {
|
|
196
|
+
const current = readFileSync(w.path, 'utf8');
|
|
197
|
+
if (current === w.after) continue;
|
|
198
|
+
if (current !== w.before) throw new Error(`${basename(w.path)} changed during migration`);
|
|
199
|
+
writeFileAtomic(w.path, w.after);
|
|
200
|
+
done.push(w);
|
|
201
|
+
}
|
|
202
|
+
} catch (e) {
|
|
203
|
+
const couldNotRestore = [];
|
|
204
|
+
for (const w of done.reverse()) {
|
|
205
|
+
try {
|
|
206
|
+
if (readFileSync(w.path, 'utf8') !== w.after) throw new Error('file changed');
|
|
207
|
+
writeFileAtomic(w.path, w.before);
|
|
208
|
+
} catch { couldNotRestore.push(basename(w.path)); }
|
|
209
|
+
}
|
|
210
|
+
if (couldNotRestore.length) throw new Error(`${e.message}. Could not restore ${couldNotRestore.join(', ')}`);
|
|
211
|
+
throw e;
|
|
212
|
+
}
|
|
213
|
+
return count;
|
|
214
|
+
}
|