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
|
@@ -32,10 +32,11 @@
|
|
|
32
32
|
// `marketplace update` can change its bytes afterwards — remembered by a
|
|
33
33
|
// stat signature so a page load re-reads nothing that has not changed.
|
|
34
34
|
|
|
35
|
-
import { readFileSync, readdirSync, realpathSync, statSync } from 'node:fs';
|
|
35
|
+
import { existsSync, readFileSync, readdirSync, realpathSync, statSync } from 'node:fs';
|
|
36
36
|
import { dirname, join, resolve, sep } from 'node:path';
|
|
37
37
|
import { escapeHtml } from '../tools/escape.mjs';
|
|
38
|
-
import { DESIGN_SYSTEM_API_VERSION, ASSET_EXTENSIONS } from '../tools/design-system-format.mjs';
|
|
38
|
+
import { DESIGN_SYSTEM_API_VERSION, ASSET_EXTENSIONS, tokenPrefixOf } from '../tools/design-system-format.mjs';
|
|
39
|
+
import { pendingMigrations, composeRenames, findRenamed, majorOf, applyRenames, RENAME_KINDS } from '../tools/design-system-migrations.mjs';
|
|
39
40
|
import { configBlock, isDeck } from './runtime-link.mjs';
|
|
40
41
|
import { configHome, loadRegistry, loadCatalog, MarketplaceError, NAME_RE } from './marketplace.mjs';
|
|
41
42
|
import {
|
|
@@ -46,6 +47,247 @@ import { checkDir } from './design-system.mjs';
|
|
|
46
47
|
|
|
47
48
|
export { DESIGN_SYSTEMS_KEY };
|
|
48
49
|
|
|
50
|
+
/**
|
|
51
|
+
* The config key a deck records the version of each design system it took
|
|
52
|
+
* under (SPEC DESIGN_SYSTEM_MIGRATIONS): `{ "<ref>": "5.0.0" }`, keyed by the
|
|
53
|
+
* deck's own spelling of the reference. The deck's fact, not this machine's:
|
|
54
|
+
* the ledger in ~/.decklight/ says what one machine installed, for every deck
|
|
55
|
+
* at once, and says nothing on the next machine.
|
|
56
|
+
*/
|
|
57
|
+
export const DESIGN_SYSTEM_VERSIONS_KEY = 'designSystemVersions';
|
|
58
|
+
|
|
59
|
+
/** The versions a deck records, `{ ref: version }` — strings only. */
|
|
60
|
+
export function deckDesignSystemVersions(html) {
|
|
61
|
+
const v = configBlock(html)?.config?.[DESIGN_SYSTEM_VERSIONS_KEY];
|
|
62
|
+
if (!v || typeof v !== 'object' || Array.isArray(v)) return {};
|
|
63
|
+
return Object.fromEntries(Object.entries(v).filter(([, x]) => typeof x === 'string'));
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Record (or, with null, forget) the version of one design system the deck
|
|
68
|
+
* took, editing only that key so the author's formatting survives. A deck
|
|
69
|
+
* with no configuration block is returned as it is.
|
|
70
|
+
*/
|
|
71
|
+
export function setDesignSystemVersion(html, ref, version) {
|
|
72
|
+
const block = configBlock(html);
|
|
73
|
+
if (!block || block.error) return html;
|
|
74
|
+
const versions = deckDesignSystemVersions(html);
|
|
75
|
+
if (version) versions[ref] = String(version);
|
|
76
|
+
else delete versions[ref];
|
|
77
|
+
const inner = withKey(block.inner, DESIGN_SYSTEM_VERSIONS_KEY, Object.keys(versions).length ? versions : null);
|
|
78
|
+
return html.slice(0, block.innerStart) + inner + html.slice(block.innerEnd);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* The stylesheets a deck links from its own folder (`<link rel="stylesheet"
|
|
83
|
+
* href="course.css">`), as `[{ href, path, text }]`: what a migration reads
|
|
84
|
+
* and rewrites beside the deck. A URL, a root-absolute path, a design
|
|
85
|
+
* system's or a theme's own link, and a file that is not there are left out.
|
|
86
|
+
*/
|
|
87
|
+
export function linkedStylesheets(html, dir) {
|
|
88
|
+
const out = [];
|
|
89
|
+
const masked = String(html).replace(/<!--[\s\S]*?-->/g, '');
|
|
90
|
+
for (const tag of masked.match(/<link\b[^>]*>/gi) ?? []) {
|
|
91
|
+
if (!/\brel\s*=\s*["']?stylesheet/i.test(tag) || /\bdata-(?:design-system|theme)\b/i.test(tag)) continue;
|
|
92
|
+
const href = /\bhref\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s>]+))/i.exec(tag);
|
|
93
|
+
const url = (href?.[1] ?? href?.[2] ?? href?.[3] ?? '').replace(/[?#].*$/, '');
|
|
94
|
+
if (!url || /^([a-z][a-z0-9+.-]*:|\/)/i.test(url) || url.includes('decklight-design-system/')) continue;
|
|
95
|
+
const path = resolve(dir, decodeURI(url));
|
|
96
|
+
if (out.some((s) => s.path === path)) continue;
|
|
97
|
+
try { if (existsSync(path) && statSync(path).isFile()) out.push({ href: url, path, text: readFileSync(path, 'utf8') }); } catch { /* unreadable: not ours to migrate */ }
|
|
98
|
+
}
|
|
99
|
+
return out;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Is a deck behind the design system this machine serves (SPEC
|
|
104
|
+
* DESIGN_SYSTEM_MIGRATIONS)? From the version the deck records and the
|
|
105
|
+
* names it, and the stylesheets it links, still use:
|
|
106
|
+
* `{ behind, recorded, current, major, found, skills, renames }`
|
|
107
|
+
* `behind` when the deck records an older major, or uses a name a migration
|
|
108
|
+
* since its version renamed; `found` is those names (`findRenamed`), `skills`
|
|
109
|
+
* the skills the pending migrations name. A deck that records no version is
|
|
110
|
+
* held to every migration the package declares.
|
|
111
|
+
*/
|
|
112
|
+
export function migrationStatus(manifest, recorded, texts) {
|
|
113
|
+
const current = manifest?.version ?? null;
|
|
114
|
+
const pending = pendingMigrations(manifest, recorded);
|
|
115
|
+
const renames = composeRenames(pending);
|
|
116
|
+
const found = findRenamed(texts, renames, tokenPrefixOf(manifest));
|
|
117
|
+
const rm = majorOf(recorded), cm = majorOf(current);
|
|
118
|
+
const major = rm !== null && cm !== null && rm < cm;
|
|
119
|
+
return {
|
|
120
|
+
behind: major || found.length > 0, recorded: recorded ?? null, current, major, found,
|
|
121
|
+
skills: [...new Set(pending.map((m) => m.skill).filter(Boolean))], renames,
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Every design system a deck is behind, from what `check` reads: the deck
|
|
127
|
+
* and the stylesheets it links from `dir` (SPEC DESIGN_SYSTEM_MIGRATIONS).
|
|
128
|
+
* `[{ ref, name, title, recorded, current, skills, message }]`, `message`
|
|
129
|
+
* the one sentence (`behindMessage`) with `deck` as the command's argument.
|
|
130
|
+
* A reference this machine cannot serve is not behind: it is missing, and
|
|
131
|
+
* said as that.
|
|
132
|
+
*/
|
|
133
|
+
export function deckBehind(html, dir, home = configHome(), { deck = '<deck.html>' } = {}) {
|
|
134
|
+
const refs = designSystemRefs(html);
|
|
135
|
+
if (!refs.length) return [];
|
|
136
|
+
const sources = markedSources(html);
|
|
137
|
+
const versions = deckDesignSystemVersions(html);
|
|
138
|
+
let texts = null;
|
|
139
|
+
const out = [];
|
|
140
|
+
for (const ref of refs) {
|
|
141
|
+
const r = resolveDesignSystemRef(ref, home, { source: sources[ref.marketplace] ?? null });
|
|
142
|
+
const verdict = r.dir ? packageVerdict(r.dir) : null;
|
|
143
|
+
if (!verdict?.ok) continue;
|
|
144
|
+
texts ??= [html, ...(dir ? linkedStylesheets(html, dir).map((x) => x.text) : [])];
|
|
145
|
+
const status = migrationStatus(verdict.manifest, versions[ref.ref] ?? null, texts);
|
|
146
|
+
if (!status.behind) continue;
|
|
147
|
+
out.push({
|
|
148
|
+
ref: ref.ref, name: ref.name, title: verdict.manifest.title || ref.name,
|
|
149
|
+
recorded: status.recorded, current: status.current, skills: status.skills,
|
|
150
|
+
message: behindMessage(ref.name, status, { ref: ref.ref, deck }),
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
return out;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* A newer design system the catalog offers, said as what it means for the
|
|
158
|
+
* decks on it (SPEC DESIGN_SYSTEM_MIGRATIONS): one `newerThanInstalled` row
|
|
159
|
+
* with `note` (*major: decks that use it need migrating, with the acme-migrate
|
|
160
|
+
* skill*) and `how` (where to find them and what moves one) when the package
|
|
161
|
+
* this machine now has declares migrations since the version installed. Any
|
|
162
|
+
* other row comes back as it was.
|
|
163
|
+
*/
|
|
164
|
+
export function withMigrationHint(n, home = configHome()) {
|
|
165
|
+
if (n?.type !== 'design-system') return n;
|
|
166
|
+
const r = resolveDesignSystemRef(n.qualified, home);
|
|
167
|
+
const verdict = r.dir ? packageVerdict(r.dir) : null;
|
|
168
|
+
if (!verdict?.ok) return n;
|
|
169
|
+
const pending = pendingMigrations(verdict.manifest, n.from);
|
|
170
|
+
if (!pending.length) return n;
|
|
171
|
+
const skills = [...new Set(pending.map((m) => m.skill).filter(Boolean))];
|
|
172
|
+
const major = n.from === null || (majorOf(n.from) ?? 0) < (majorOf(n.to) ?? 0);
|
|
173
|
+
return {
|
|
174
|
+
...n, migrations: pending.map((m) => m.version), skills,
|
|
175
|
+
note: `${major ? 'major: ' : ''}decks that use it need migrating${skills.length ? `, with the ${skills.join(' or ')} skill` : ''}`,
|
|
176
|
+
how: `decklight check finds them; decklight design-system migrate ${n.qualified} <deck.html> moves one`,
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* What `design-system migrate` does to a deck, worked out in memory and
|
|
182
|
+
* written by nobody (SPEC DESIGN_SYSTEM_MIGRATIONS): the command and the
|
|
183
|
+
* edit server's Migrate both apply it. `{ error }` when the deck does not
|
|
184
|
+
* use `ref` or this machine cannot serve it, else
|
|
185
|
+
* `{ ref, name, title, recorded, version, status, html, sheets, renamed, byKind, changed }`
|
|
186
|
+
* — `html` the deck renamed and its version recorded, `sheets` the linked
|
|
187
|
+
* stylesheets a rename touched (`{ href, path, text, count }`), `byKind`
|
|
188
|
+
* `[[kind, found]]` for the report.
|
|
189
|
+
*/
|
|
190
|
+
export function planMigration(html, dir, ref, home = configHome()) {
|
|
191
|
+
const hit = designSystemRefs(html).find((r) => r.ref === ref || r.name === ref);
|
|
192
|
+
if (!hit) return { error: `the deck does not use ${ref}` };
|
|
193
|
+
const r = resolveDesignSystemRef(hit, home, { source: markedSources(html)[hit.marketplace] ?? null });
|
|
194
|
+
if (!r.dir) return { error: `${hit.ref} — ${r.missing}` };
|
|
195
|
+
const verdict = checkDir(r.dir);
|
|
196
|
+
if (!verdict.ok) return { error: `${hit.ref} no longer passes its check — decklight design-system gate ${r.dir}` };
|
|
197
|
+
const m = verdict.manifest;
|
|
198
|
+
const recorded = deckDesignSystemVersions(html)[hit.ref] ?? null;
|
|
199
|
+
const sheets = linkedStylesheets(html, dir);
|
|
200
|
+
const status = migrationStatus(m, recorded, [html, ...sheets.map((x) => x.text)]);
|
|
201
|
+
const prefix = tokenPrefixOf(m);
|
|
202
|
+
const deckOut = applyRenames(html, status.renames, prefix, { config: true });
|
|
203
|
+
const next = setDesignSystemVersion(deckOut.text, hit.ref, m.version);
|
|
204
|
+
const touched = sheets.map((x) => ({ ...x, ...applyRenames(x.text, status.renames, prefix) })).filter((x) => x.count);
|
|
205
|
+
const renamed = deckOut.count + touched.reduce((n, x) => n + x.count, 0);
|
|
206
|
+
return {
|
|
207
|
+
ref: hit.ref, name: hit.name, marketplace: hit.marketplace, title: m.title || hit.name, recorded, version: m.version, status,
|
|
208
|
+
html: next, sheets: touched, renamed,
|
|
209
|
+
byKind: RENAME_KINDS.map((k) => [k, status.found.filter((f) => f.kind === k)]).filter(([, l]) => l.length),
|
|
210
|
+
changed: next !== html || renamed > 0,
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* A migration said in lines — what `design-system migrate` prints and what
|
|
216
|
+
* the agent panel records when the edit server runs one: the versions, the
|
|
217
|
+
* renames by kind, the count and where, and the skill named for what a
|
|
218
|
+
* rename cannot decide. `placed(name)` says whether an agent already loads
|
|
219
|
+
* that skill (cli/skills.mjs `placedSkill`): the line then says so instead
|
|
220
|
+
* of how to install it.
|
|
221
|
+
*/
|
|
222
|
+
export function migrationLines(plan, deck, { placed = () => null } = {}) {
|
|
223
|
+
const out = [`${deck}: ${plan.ref} ${plan.recorded ?? '(no version recorded)'} → ${plan.version}`];
|
|
224
|
+
if (plan.renamed) {
|
|
225
|
+
for (const [kind, list] of plan.byKind) out.push(` ${kind.padEnd(8)} ${list.map((f) => `${f.from} → ${f.to}`).join(', ')}`);
|
|
226
|
+
out.push(` ${plan.renamed} rename${plan.renamed === 1 ? '' : 's'} — in ${deck}${plan.sheets.map((x) => `, ${x.href}`).join('')}`);
|
|
227
|
+
} else out.push(' nothing it uses was renamed — recorded the new version');
|
|
228
|
+
const skills = plan.status.skills;
|
|
229
|
+
if (skills.length) {
|
|
230
|
+
// where the agent finds it, or how to put it there: every project first
|
|
231
|
+
const missing = skills.filter((s) => !placed(s));
|
|
232
|
+
out.push(` what a rename cannot decide (a name removed with no successor) is the ${skills.join(' and ')} skill's:`
|
|
233
|
+
+ (missing.length
|
|
234
|
+
? ` decklight library add skill ${missing[0]} --global (every project; --dir . for this one only), then ask your agent to finish the migration`
|
|
235
|
+
: ' your agent has it, ask it to finish the migration'));
|
|
236
|
+
}
|
|
237
|
+
return out;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* Where a skill's SKILL.md already is on this machine, or null: the library's
|
|
242
|
+
* copy (`~/.decklight/skills/<name>/`) when one is installed, else the
|
|
243
|
+
* catalog entry's source in its marketplace's checkout, `marketplace` first.
|
|
244
|
+
* What a migration's prompt points the agent at, so running one never
|
|
245
|
+
* installs anything into the project (#893).
|
|
246
|
+
*/
|
|
247
|
+
export function skillFile(name, marketplace = null, home = configHome()) {
|
|
248
|
+
const installed = join(home, 'skills', name, 'SKILL.md');
|
|
249
|
+
if (existsSync(installed)) return installed;
|
|
250
|
+
const markets = Object.keys(loadRegistry(home).marketplaces ?? {});
|
|
251
|
+
for (const market of [...(markets.includes(marketplace) ? [marketplace] : []), ...markets.filter((m) => m !== marketplace)]) {
|
|
252
|
+
let cat;
|
|
253
|
+
try { cat = loadCatalog(market, home); } catch { continue; }
|
|
254
|
+
const entry = cat?.ok ? cat.manifest.entries.find((e) => e.type === 'skill' && e.name === name) : null;
|
|
255
|
+
if (!entry?.source || /^https?:\/\//i.test(entry.source)) continue;
|
|
256
|
+
let base;
|
|
257
|
+
try { base = resolveSource(entry.source, { name: market, source: loadRegistry(home).marketplaces[market]?.source }, home); } catch { continue; }
|
|
258
|
+
const file = join(base, 'SKILL.md');
|
|
259
|
+
if (existsSync(file)) return file;
|
|
260
|
+
}
|
|
261
|
+
return null;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* A deck that uses a design system but records no version takes `manifest`'s
|
|
266
|
+
* — unless it, or a stylesheet it links from `dir`, still uses a name a
|
|
267
|
+
* migration renamed: recording the new version then would hide that it is
|
|
268
|
+
* behind, and `migrate` moves it first. The html, recorded or as it was.
|
|
269
|
+
*/
|
|
270
|
+
export function recordVersionIfCurrent(html, ref, manifest, dir) {
|
|
271
|
+
if (deckDesignSystemVersions(html)[ref] || !manifest?.version) return html;
|
|
272
|
+
const status = migrationStatus(manifest, null, [html, ...linkedStylesheets(html, dir).map((x) => x.text)]);
|
|
273
|
+
return status.found.length ? html : setDesignSystemVersion(html, ref, manifest.version);
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* The one sentence that says a deck is behind, with what to do — the same in
|
|
278
|
+
* `check`, the write-mode toast and `design-system migrate`'s refusal.
|
|
279
|
+
*/
|
|
280
|
+
export function behindMessage(name, status, { ref = name, deck = '<deck.html>' } = {}) {
|
|
281
|
+
const was = status.recorded ? `${name} ${status.recorded}` : `an earlier ${name}`;
|
|
282
|
+
const n = status.found.length;
|
|
283
|
+
const shown = status.found.slice(0, 3).map((f) => `${f.from} → ${f.to}`).join(', ');
|
|
284
|
+
const what = n ? `: ${n} renamed name${n === 1 ? '' : 's'} (${shown}${n > 3 ? ', …' : ''})` : ', a new major version';
|
|
285
|
+
const how = status.skills.length
|
|
286
|
+
? `Migrate with the ${status.skills.join(' or ')} skill, or decklight design-system migrate ${ref} ${deck}`
|
|
287
|
+
: `Migrate with decklight design-system migrate ${ref} ${deck}`;
|
|
288
|
+
return `written for ${was}, this machine serves ${status.current}${what}. ${how}`;
|
|
289
|
+
}
|
|
290
|
+
|
|
49
291
|
/** The design systems a deck references, parsed; anything else dropped, not guessed at. */
|
|
50
292
|
export function designSystemRefs(html) {
|
|
51
293
|
const list = configBlock(html)?.config?.[DESIGN_SYSTEMS_KEY];
|
|
@@ -187,14 +429,19 @@ export function brandTags(name, verdict) {
|
|
|
187
429
|
* Nothing when the page already carries `<style data-design-system="<name>">`
|
|
188
430
|
* (a bundle's own copy). An unresolvable reference, or a package that no
|
|
189
431
|
* longer passes the check, becomes `<meta name="decklight-design-system-missing">`
|
|
190
|
-
* naming it and why — never a silently short page.
|
|
432
|
+
* naming it and why — never a silently short page. A deck behind a
|
|
433
|
+
* package's major gets `<meta name="decklight-design-system-behind"
|
|
434
|
+
* data-ref data-version>`, its sentence the content; `dir` is the deck's
|
|
435
|
+
* folder, so the stylesheets it links are read as `check` reads them, and
|
|
436
|
+
* `deck` its file name, for the command the sentence ends on.
|
|
191
437
|
*/
|
|
192
|
-
export function linkDesignSystems(html, home = configHome(), { log = null } = {}) {
|
|
438
|
+
export function linkDesignSystems(html, home = configHome(), { log = null, dir = null, deck = '<deck.html>' } = {}) {
|
|
193
439
|
if (!isDeck(html)) return html;
|
|
194
440
|
const refs = designSystemRefs(html);
|
|
195
441
|
if (!refs.length) return html;
|
|
196
442
|
const sources = markedSources(html);
|
|
197
443
|
const tags = [];
|
|
444
|
+
let texts = null;
|
|
198
445
|
for (const ref of refs) {
|
|
199
446
|
// a bundle's own copy (<style>), or a link this page already got
|
|
200
447
|
const carried = new RegExp(`<(?:style|link)\\b[^>]*\\bdata-design-system\\s*=\\s*["']${ref.name}["']`, 'i');
|
|
@@ -208,6 +455,14 @@ export function linkDesignSystems(html, home = configHome(), { log = null } = {}
|
|
|
208
455
|
tags.push(`<script type="application/json" data-design-system-meta="${name}">${scriptJson(designSystemMeta(verdict))}</script>`);
|
|
209
456
|
tags.push(`<template data-design-system-templates="${name}">\n${verdict.templatesHtml.trim()}\n</template>`);
|
|
210
457
|
tags.push(...brandTags(ref.name, verdict));
|
|
458
|
+
// a deck behind the major this machine serves: said once, while authoring (SPEC DESIGN_SYSTEM_MIGRATIONS)
|
|
459
|
+
// — read as `check` reads it: the deck and the stylesheets it links from `dir`
|
|
460
|
+
texts ??= [html, ...(dir ? linkedStylesheets(html, dir).map((x) => x.text) : [])];
|
|
461
|
+
const status = migrationStatus(verdict.manifest, deckDesignSystemVersions(html)[ref.ref] ?? null, texts);
|
|
462
|
+
if (status.behind) {
|
|
463
|
+
tags.push(`<meta name="decklight-design-system-behind" data-ref="${escapeHtml(ref.ref)}" data-version="${escapeHtml(status.current)}"`
|
|
464
|
+
+ ` content="${escapeHtml(`${verdict.manifest.title || ref.name}: ${behindMessage(ref.name, status, { ref: ref.ref, deck })}`)}">`);
|
|
465
|
+
}
|
|
211
466
|
} else {
|
|
212
467
|
tags.push(`<meta name="decklight-design-system-missing" content="${escapeHtml(`${ref.ref} — ${r.missing}`)}">`);
|
|
213
468
|
log?.(`design system ${ref.ref}: ${r.missing}`);
|
|
@@ -347,7 +602,7 @@ export function designSystemAsset(rel, home = configHome()) {
|
|
|
347
602
|
* and goes only with the last reference of EITHER kind. Returns `{ html,
|
|
348
603
|
* changed }`, or throws a MarketplaceError a command prints as-is.
|
|
349
604
|
*/
|
|
350
|
-
export function setDesignSystem(html, ref, on, { source = null } = {}) {
|
|
605
|
+
export function setDesignSystem(html, ref, on, { source = null, version = null } = {}) {
|
|
351
606
|
const parsed = parseRef(ref);
|
|
352
607
|
if (!parsed) throw new MarketplaceError(`"${ref}" is not a design-system reference — name@marketplace`);
|
|
353
608
|
const block = configBlock(html);
|
|
@@ -374,7 +629,9 @@ export function setDesignSystem(html, ref, on, { source = null } = {}) {
|
|
|
374
629
|
}
|
|
375
630
|
let inner = withKey(block.inner, DESIGN_SYSTEMS_KEY, next.length ? next : null);
|
|
376
631
|
inner = withKey(inner, SOURCES_KEY, Object.keys(sources).length ? sources : null);
|
|
377
|
-
|
|
632
|
+
const out = html.slice(0, block.innerStart) + inner + html.slice(block.innerEnd);
|
|
633
|
+
// the version it took goes in with the reference, and out with it (SPEC DESIGN_SYSTEM_MIGRATIONS)
|
|
634
|
+
return { html: on ? (version ? setDesignSystemVersion(out, parsed.ref, version) : out) : setDesignSystemVersion(out, parsed.ref, null), changed: true };
|
|
378
635
|
}
|
|
379
636
|
|
|
380
637
|
/**
|
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
|
|