@nodii/dev 0.6.131 → 0.6.133
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/README.md +28 -0
- package/dist/cdp.js +138 -0
- package/dist/chrome.js +359 -0
- package/dist/cli.js +44 -1
- package/dist/coordinator-board.js +490 -0
- package/dist/coordinator-watch.js +564 -0
- package/dist/core.js +1 -1
- package/dist/figma-publish.js +207 -0
- package/dist/governor.js +3 -1
- package/dist/surface.js +207 -32
- package/package.json +1 -1
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
// nodii-dev figma publish FILE --sets CS-1,CS-2 [--dry-run]
|
|
2
|
+
//
|
|
3
|
+
// Publishes a Figma library through the machine's shared Chrome with only the
|
|
4
|
+
// components of finished change sets ticked (operator, 13 Nov 2026, N44: "if
|
|
5
|
+
// you need to publish - you can do it through the chrome without waiting for
|
|
6
|
+
// me!"). A finished set is decided and applied: Dev shows it awaiting_publish.
|
|
7
|
+
// Every other row in the dialog is unticked, so a set still being drawn or in
|
|
8
|
+
// review never ships early (MW8-7.1, MW8-4.1).
|
|
9
|
+
//
|
|
10
|
+
// It opens its own tab and closes only that tab (K02-16, K02-17), checks the
|
|
11
|
+
// tab is on www.figma.com and on the named file before it touches anything,
|
|
12
|
+
// and records each fully published set in Dev (figma published).
|
|
13
|
+
import { appendFile, mkdir } from "node:fs/promises";
|
|
14
|
+
import { homedir } from "node:os";
|
|
15
|
+
import { join } from "node:path";
|
|
16
|
+
import { CliError, devRequest, encode } from "./core.js";
|
|
17
|
+
import { cdpConnect } from "./cdp.js";
|
|
18
|
+
import { sharedChromePort } from "./chrome.js";
|
|
19
|
+
import { figmaClient, figmaToken } from "./design.js";
|
|
20
|
+
import { figmaFileKey } from "./figma.js";
|
|
21
|
+
|
|
22
|
+
const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
23
|
+
export const FINISHED_STATE = "awaiting_publish";
|
|
24
|
+
export const publishLogPath = (home = homedir()) => join(home, ".config", "nodii-dev", "coordinator", "publishes.jsonl");
|
|
25
|
+
|
|
26
|
+
/** The ids in --sets, upper-cased and checked. */
|
|
27
|
+
export function parseSets(value) {
|
|
28
|
+
if (typeof value !== "string" || !value.trim()) throw new CliError("USAGE", "figma publish FILE_KEY --sets CS-1,CS-2 [--dry-run]", 2);
|
|
29
|
+
const ids = [...new Set(value.split(",").map((s) => s.trim().toUpperCase()).filter(Boolean))];
|
|
30
|
+
for (const id of ids) if (!/^CS-\d+$/.test(id)) throw new CliError("USAGE", `${id} is not a change set id (CS-123).`, 2);
|
|
31
|
+
return ids;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** The component names an approved set publishes: its approved items, by name. */
|
|
35
|
+
export function setComponentNames(set) {
|
|
36
|
+
return [...new Set((set.items ?? []).filter((item) => item.decision === "approved" && !item.withdrawnReason && item.name).map((item) => item.name.trim()))];
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Reads each set from Dev and refuses the publish when any set is not finished or
|
|
41
|
+
* is on another file. Returns the sets with the names each one publishes.
|
|
42
|
+
*/
|
|
43
|
+
export async function finishedSets(fileKey, ids, { request = devRequest } = {}) {
|
|
44
|
+
const sets = [];
|
|
45
|
+
const refused = [];
|
|
46
|
+
for (const id of ids) {
|
|
47
|
+
const set = (await request("GET", `/api/v1/design/change-sets/${encode(id)}`)).data;
|
|
48
|
+
if (set.fileKey !== fileKey) refused.push(`${id} is on file ${set.fileKey}, not ${fileKey}`);
|
|
49
|
+
else if (set.state !== FINISHED_STATE) refused.push(`${id} is ${set.state}, not ${FINISHED_STATE} (only decided and applied sets publish)`);
|
|
50
|
+
else sets.push({ id, title: set.title ?? "", names: setComponentNames(set) });
|
|
51
|
+
}
|
|
52
|
+
if (refused.length) throw new CliError("PUBLISH_SETS_NOT_FINISHED", `Not published: ${refused.join("; ")}.`, 1, { refused });
|
|
53
|
+
return sets;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Runs in the page. Walks the dialog's virtualized list from top to bottom and
|
|
57
|
+
// sets each row's checkbox: ticked when its name is wanted, unticked otherwise.
|
|
58
|
+
// Returns every row seen, with its state before and after.
|
|
59
|
+
export const DIALOG_SYNC = `async function(wanted, apply){
|
|
60
|
+
const sleep=(ms)=>new Promise(r=>setTimeout(r,ms));
|
|
61
|
+
const want=new Set(wanted);
|
|
62
|
+
const boxes=()=>[...document.querySelectorAll('input[data-testid=publish-library-item-checkbox]')];
|
|
63
|
+
const first=boxes()[0];
|
|
64
|
+
if(!first) return {error:'no publish rows'};
|
|
65
|
+
let scroller=first.parentElement;
|
|
66
|
+
while(scroller && !(scroller.scrollHeight>scroller.clientHeight+4 && /(auto|scroll)/.test(getComputedStyle(scroller).overflowY))) scroller=scroller.parentElement;
|
|
67
|
+
const rows=new Map();
|
|
68
|
+
const visit=async()=>{
|
|
69
|
+
for(const box of boxes()){
|
|
70
|
+
const row=box.closest('label.library_item_row--libraryItemRow--69LPl')||box.closest('label[class*=libraryItemRow]')||box.closest('label');
|
|
71
|
+
const name=(row?.querySelector('[class*=name] [title], span[title]')?.getAttribute('title')||(row?.querySelector('label[for]')?.textContent||'').replace(/^Include /,'').replace(/ in publish$/,'')).trim();
|
|
72
|
+
if(!name) continue;
|
|
73
|
+
const status=(row?.querySelector('[class*=statusTag]')?.textContent||'').trim();
|
|
74
|
+
const before=rows.has(name)?rows.get(name).before:box.checked;
|
|
75
|
+
if(apply && box.checked!==want.has(name)){ box.click(); await sleep(60); }
|
|
76
|
+
rows.set(name,{name,status,before,after:box.checked});
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
const head=[...document.querySelectorAll('*')].find(e=>e.childElementCount<=2&&/^Changes\s*\(\d+ of \d+\)$/.test(e.textContent.trim()));
|
|
80
|
+
const total=head?Number(head.textContent.trim().match(/of (\d+)\)/)[1]):null;
|
|
81
|
+
if(!scroller){ await visit(); return {rows:[...rows.values()],total}; }
|
|
82
|
+
scroller.scrollTop=0; await sleep(300);
|
|
83
|
+
for(let guard=0; guard<400; guard++){
|
|
84
|
+
await visit();
|
|
85
|
+
if(scroller.scrollTop+scroller.clientHeight>=scroller.scrollHeight-2) break;
|
|
86
|
+
scroller.scrollTop+=Math.max(40,scroller.clientHeight-60); await sleep(250);
|
|
87
|
+
}
|
|
88
|
+
await visit();
|
|
89
|
+
scroller.scrollTop=0;
|
|
90
|
+
return {rows:[...rows.values()],total};
|
|
91
|
+
}`;
|
|
92
|
+
|
|
93
|
+
const FILL_DESCRIPTION = `function(text){const t=[...document.querySelectorAll('textarea')].find(x=>/description/i.test(x.placeholder||''));
|
|
94
|
+
if(!t) return false; const s=Object.getOwnPropertyDescriptor(HTMLTextAreaElement.prototype,'value').set; s.call(t,text);
|
|
95
|
+
t.dispatchEvent(new Event('input',{bubbles:true})); return true;}`;
|
|
96
|
+
const CLICK_BUTTON = `function(label){const b=[...document.querySelectorAll('button')].find(x=>x.textContent.trim()===label && !x.disabled);
|
|
97
|
+
if(!b) return false; b.click(); return true;}`;
|
|
98
|
+
const DIALOG_OPEN = "!!document.querySelector('input[data-testid=publish-library-item-checkbox]')";
|
|
99
|
+
|
|
100
|
+
/** What the dialog must look like after the sync: every wanted row ticked, nothing else. */
|
|
101
|
+
export function syncReport(sets, rows, total) {
|
|
102
|
+
const byName = new Map(rows.map((row) => [row.name, row]));
|
|
103
|
+
const wanted = new Set(sets.flatMap((set) => set.names));
|
|
104
|
+
const unmapped = sets.flatMap((set) => set.names.filter((name) => !byName.has(name)).map((name) => ({ set: set.id, name })));
|
|
105
|
+
const wrong = rows.filter((row) => row.after !== wanted.has(row.name)).map((row) => row.name);
|
|
106
|
+
// Every row the dialog counts must have been seen, or an unseen row could ship.
|
|
107
|
+
if (total === undefined) {} // a caller that does not check the count
|
|
108
|
+
else if (!Number.isInteger(total)) wrong.push("(could not read the dialog's change count, so unseen rows can't be ruled out)");
|
|
109
|
+
else if (total !== rows.length) wrong.push(`(saw ${rows.length} of the dialog's ${total} changes)`);
|
|
110
|
+
const ticked = rows.filter((row) => row.after).map((row) => row.name);
|
|
111
|
+
const unticked = rows.filter((row) => !row.after).map((row) => row.name);
|
|
112
|
+
// A set is recorded only when every one of its components is in this publish (P-4).
|
|
113
|
+
const complete = sets.filter((set) => set.names.length && set.names.every((name) => byName.get(name)?.after)).map((set) => set.id);
|
|
114
|
+
return { ticked, unticked, unmapped, wrong, complete, incomplete: sets.map((s) => s.id).filter((id) => !complete.includes(id)) };
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
async function newestVersion(figmaGet, fileKey) {
|
|
118
|
+
const body = await figmaGet(`/v1/files/${encode(fileKey)}/versions`);
|
|
119
|
+
return body?.versions?.[0]?.id ?? null;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export async function figmaPublish(file, flags = {}, {
|
|
123
|
+
request = devRequest, connect = cdpConnect, home = homedir(), env = process.env, sleep = delay,
|
|
124
|
+
figmaGet, log = (line) => appendFile(publishLogPath(home), `${line}\n`), loadSeconds = 20, portOf,
|
|
125
|
+
} = {}) {
|
|
126
|
+
if (!file) throw new CliError("USAGE", "figma publish FILE_KEY --sets CS-1,CS-2 [--dry-run]", 2);
|
|
127
|
+
const fileKey = figmaFileKey(file);
|
|
128
|
+
const ids = parseSets(flags.sets);
|
|
129
|
+
const dryRun = Boolean(flags["dry-run"]);
|
|
130
|
+
const sets = await finishedSets(fileKey, ids, { request });
|
|
131
|
+
const get = dryRun ? null : (figmaGet ?? figmaClient(figmaToken(env)));
|
|
132
|
+
const before = get ? await newestVersion(get, fileKey) : null;
|
|
133
|
+
const port = await (portOf ?? (() => sharedChromePort({ home, request })))();
|
|
134
|
+
const cdp = await connect(port);
|
|
135
|
+
let report;
|
|
136
|
+
let published = false;
|
|
137
|
+
try {
|
|
138
|
+
report = await cdp.withTab(`https://www.figma.com/design/${encode(fileKey)}`, async (tab) => {
|
|
139
|
+
await sleep(loadSeconds * 1000);
|
|
140
|
+
const where = await tab.evaluate("location.host + ' ' + location.pathname");
|
|
141
|
+
if (!String(where).startsWith(`www.figma.com /design/${fileKey}`))
|
|
142
|
+
throw new CliError("PUBLISH_WRONG_PAGE", `The tab is on ${where}, not www.figma.com/design/${fileKey}; nothing was touched.`, 1);
|
|
143
|
+
// Quick actions (Cmd+/) -> "Publish changes to library".
|
|
144
|
+
await tab.key("/", { modifiers: 4, code: "Slash", keyCode: 191 });
|
|
145
|
+
await sleep(1500);
|
|
146
|
+
await tab.send("Input.insertText", { text: "Publish changes to library" });
|
|
147
|
+
await sleep(1500);
|
|
148
|
+
await tab.key("Enter", { keyCode: 13 });
|
|
149
|
+
if (!(await tab.waitFor(DIALOG_OPEN, 30, { sleep })))
|
|
150
|
+
throw new CliError("PUBLISH_DIALOG_NOT_FOUND", "Figma's Publish library dialog did not open (nothing to publish, or the file is not a library).", 1);
|
|
151
|
+
const synced = await tab.call(DIALOG_SYNC, [sets.flatMap((set) => set.names), true]);
|
|
152
|
+
if (synced?.error) throw new CliError("PUBLISH_DIALOG_UNREADABLE", synced.error, 1);
|
|
153
|
+
// Read it again without touching it: the dialog is what gets published.
|
|
154
|
+
const check = await tab.call(DIALOG_SYNC, [[], false]);
|
|
155
|
+
const result = syncReport(sets, check.rows, check.total ?? null);
|
|
156
|
+
if (result.wrong.length) {
|
|
157
|
+
await tab.call(CLICK_BUTTON, ["Cancel"]);
|
|
158
|
+
throw new CliError("PUBLISH_DIALOG_MISMATCH", `These rows would not settle to the wanted state: ${result.wrong.join(", ")}. Nothing was published.`, 1, result);
|
|
159
|
+
}
|
|
160
|
+
if (dryRun || !result.ticked.length) {
|
|
161
|
+
await tab.call(CLICK_BUTTON, ["Cancel"]);
|
|
162
|
+
return result;
|
|
163
|
+
}
|
|
164
|
+
await tab.call(FILL_DESCRIPTION, [sets.map((set) => `${set.id} ${set.title}`.trim()).join("; ").slice(0, 900)]);
|
|
165
|
+
if (!(await tab.call(CLICK_BUTTON, ["Publish"]))) throw new CliError("PUBLISH_BUTTON_NOT_FOUND", "The Publish button was not found or was disabled.", 1, result);
|
|
166
|
+
published = true;
|
|
167
|
+
await tab.waitFor(`!(${DIALOG_OPEN})`, 120, { sleep });
|
|
168
|
+
return result;
|
|
169
|
+
});
|
|
170
|
+
} finally {
|
|
171
|
+
await cdp.close();
|
|
172
|
+
}
|
|
173
|
+
let version = null;
|
|
174
|
+
const recorded = [];
|
|
175
|
+
const notRecorded = report.incomplete.map((id) => ({ id, reason: "not every component of the set was in this publish" }));
|
|
176
|
+
if (published) {
|
|
177
|
+
for (let i = 0; i < 24 && (!version || version === before); i++) {
|
|
178
|
+
await sleep(5000);
|
|
179
|
+
version = await newestVersion(get, fileKey).catch(() => null);
|
|
180
|
+
}
|
|
181
|
+
if (!version || version === before) notRecorded.push(...report.complete.map((id) => ({ id, reason: "Figma showed no new version after the publish" })));
|
|
182
|
+
else
|
|
183
|
+
for (const id of report.complete) {
|
|
184
|
+
try {
|
|
185
|
+
await request("POST", `/api/v1/design/change-sets/${encode(id)}/published`, { figmaVersion: version });
|
|
186
|
+
recorded.push(id);
|
|
187
|
+
} catch (error) {
|
|
188
|
+
notRecorded.push({ id, reason: `${error?.code ?? "PUBLISHED_REFUSED"}: ${error?.message ?? error}` });
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
const data = { fileKey, dryRun, published, version, sets: ids, ...report, recorded, notRecorded };
|
|
193
|
+
await mkdir(join(home, ".config", "nodii-dev", "coordinator"), { recursive: true, mode: 0o700 }).catch(() => {});
|
|
194
|
+
await log(JSON.stringify({ at: new Date().toISOString(), ...data })).catch(() => {});
|
|
195
|
+
return data;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
export function figmaPublishText(d) {
|
|
199
|
+
return [
|
|
200
|
+
d.dryRun ? `Dry run on ${d.fileKey}: nothing published.` : d.published ? `Published ${d.fileKey} as version ${d.version ?? "(not seen yet)"}.` : `Nothing to publish on ${d.fileKey}.`,
|
|
201
|
+
`ticked (${d.ticked.length}): ${d.ticked.join(", ") || "none"}`,
|
|
202
|
+
`unticked (${d.unticked.length}): ${d.unticked.join(", ") || "none"}`,
|
|
203
|
+
...(d.unmapped.length ? [`NOT IN THE DIALOG: ${d.unmapped.map((u) => `${u.set} ${u.name}`).join(", ")}`] : []),
|
|
204
|
+
...(d.recorded.length ? [`recorded in Dev: ${d.recorded.join(", ")}`] : []),
|
|
205
|
+
...d.notRecorded.map((n) => `not recorded: ${n.id} (${n.reason})`),
|
|
206
|
+
].join("\n");
|
|
207
|
+
}
|
package/dist/governor.js
CHANGED
|
@@ -101,7 +101,9 @@ export async function governorSessionStart(deps = {}) {
|
|
|
101
101
|
const { kind, agent } = await governorSessionKind(deps);
|
|
102
102
|
if (!kind || !agent?.machineId) return "";
|
|
103
103
|
const g = await readGovernor(agent.machineId, deps);
|
|
104
|
-
|
|
104
|
+
// hub-405: the coordinator watch's new alerts reach the coordinator session here.
|
|
105
|
+
const alerts = kind === "coordinator" ? await (deps.coordinatorAlerts ?? (async () => (await import("./coordinator-watch.js")).coordinatorAlertLines()))().catch(() => []) : [];
|
|
106
|
+
return [`Session kind: ${kind}.`, ...governorLines(g), ...alerts].join("\n");
|
|
105
107
|
}
|
|
106
108
|
|
|
107
109
|
/**
|
package/dist/surface.js
CHANGED
|
@@ -25,14 +25,14 @@
|
|
|
25
25
|
// Figma reads (only with --fetch) are paced to one call per 8 s or slower;
|
|
26
26
|
// a 429 waits out Retry-After, or 30 s doubling when Figma sends none.
|
|
27
27
|
import { execFileSync } from "node:child_process";
|
|
28
|
-
import { existsSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
28
|
+
import { existsSync, mkdirSync, readFileSync, readdirSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
29
29
|
import { tmpdir } from "node:os";
|
|
30
30
|
import { dirname, join, relative, resolve } from "node:path";
|
|
31
31
|
import { CliError, VERSION, devRequest, readConfig } from "./core.js";
|
|
32
32
|
import { createRenderer } from "./vendor/render-templates.mjs";
|
|
33
33
|
|
|
34
34
|
/** Bumped whenever the emitted code changes shape for the same inputs. */
|
|
35
|
-
export const GENERATOR_FORMAT =
|
|
35
|
+
export const GENERATOR_FORMAT = 11;
|
|
36
36
|
export const TREE_DIR = "docs/figma-ux-ds/figma/surface-trees";
|
|
37
37
|
export const GENERATED_SUFFIX = ".surface.generated.tsx";
|
|
38
38
|
/** Where every generated product page lives, as a git glob (NODII-DEV-CLI-77). */
|
|
@@ -121,6 +121,34 @@ export function selectTargets(rows, target, { all = false, module, type } = {})
|
|
|
121
121
|
throw new CliError("USAGE", `The target is a 40-hex component-set key or a frontend route starting with /, never a node id (MW8-20): got ${target}`, 2);
|
|
122
122
|
}
|
|
123
123
|
|
|
124
|
+
const PAGES_DIR = dirname(CATALOG_PATH);
|
|
125
|
+
const STAMP_KEY = /^[^\n]*\n\/\/ regenerate with `nodii-dev surface generate ([0-9a-f]{40})\b/;
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* The committed generated pages that no catalog row names (hub-426): a
|
|
129
|
+
* stamped `*.surface.generated.tsx` under the product pages that is not the
|
|
130
|
+
* generated path of any catalog Surface. The catalog is the one lookup
|
|
131
|
+
* (MW8-17.1), so such a page can't be regenerated or compared; --all reports it
|
|
132
|
+
* instead of skipping it silently. `module` narrows to that module's folder.
|
|
133
|
+
*/
|
|
134
|
+
export function generatedWithoutCatalogRow(root, rows, { module } = {}) {
|
|
135
|
+
const named = new Set(rows.filter((x) => x.componentSetKey && x.surfaceType !== "kit").map((row) => generatedPath(root, row)));
|
|
136
|
+
const start = module ? join(root, PAGES_DIR, module) : join(root, PAGES_DIR);
|
|
137
|
+
const found = [];
|
|
138
|
+
const walk = (dir) => {
|
|
139
|
+
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
140
|
+
const path = join(dir, entry.name);
|
|
141
|
+
if (entry.isDirectory()) walk(path);
|
|
142
|
+
else if (entry.name.endsWith(GENERATED_SUFFIX) && !named.has(path)) {
|
|
143
|
+
const text = readFileSync(path, "utf8");
|
|
144
|
+
if (hasGeneratedPageStamp(text)) found.push({ file: relative(root, path).split("\\").join("/"), componentSetKey: text.match(STAMP_KEY)?.[1] ?? null });
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
if (existsSync(start)) walk(start);
|
|
149
|
+
return found.sort((a, b) => (a.file < b.file ? -1 : a.file > b.file ? 1 : 0));
|
|
150
|
+
}
|
|
151
|
+
|
|
124
152
|
/** Where a Surface's trimmed tree is committed. */
|
|
125
153
|
export const treePath = (root, row) => join(root, TREE_DIR, row.fileKey, `${row.componentSetKey}.json`);
|
|
126
154
|
/** Where a Surface's generated presentational code goes: beside the hand-built page. */
|
|
@@ -619,18 +647,62 @@ function freeIdentifiers(code) {
|
|
|
619
647
|
}
|
|
620
648
|
|
|
621
649
|
/**
|
|
622
|
-
* The name a DS instance's data is grouped under
|
|
623
|
-
*
|
|
624
|
-
*
|
|
650
|
+
* The name a DS instance's data is grouped under, in camelCase (`Subject kind`
|
|
651
|
+
* → `subjectKind`), so two instances never share a value, a list of options or
|
|
652
|
+
* a handler (NODII-DEV-CLI-84). The first of:
|
|
653
|
+
* - for a Dialog in a view, the view (its title is the record's, lifted);
|
|
654
|
+
* - for a part that shows one value of a record (PiiText, CopyField), the text
|
|
655
|
+
* beside it (`Provider reference` → `providerReference`);
|
|
656
|
+
* - for a table head, its column's key (its header copy, numbered when two
|
|
657
|
+
* columns share it, as the lifted rows name their columns);
|
|
658
|
+
* - the label, title or placeholder its template draws (a SelectField's
|
|
659
|
+
* `Team`), before a property the template doesn't draw (the Select's
|
|
660
|
+
* default `label`, "Option label");
|
|
661
|
+
* - its label or title property;
|
|
662
|
+
* - its layer name.
|
|
625
663
|
*/
|
|
626
|
-
|
|
664
|
+
const BESIDE_TAGS = new Set(["PiiText", "CopyField"]);
|
|
665
|
+
function scopeName(node, code = "", ctx = null) {
|
|
627
666
|
// A dialog's title is the record's (lifted), so the dialog is named by its view.
|
|
628
|
-
if (/Dialog$/.test(node.instance?.set ?? "") && ctx
|
|
667
|
+
if (/Dialog$/.test(node.instance?.set ?? "") && ctx?.state) return camelName(ctx.state);
|
|
629
668
|
const props = node.instance?.props ?? {};
|
|
630
|
-
const
|
|
669
|
+
const named = (v) => typeof v === "string" && /[A-Za-z0-9]/.test(v);
|
|
670
|
+
const tag = /^<([A-Za-z][\w.]*)/.exec(code)?.[1];
|
|
671
|
+
const end = tag ? openTagEnd(code) : -1;
|
|
672
|
+
const open = tag ? code.slice(0, end) : "";
|
|
673
|
+
const drawn = (attr) => {
|
|
674
|
+
const m = new RegExp(String.raw`\b${attr}=(${LITERAL})`).exec(open);
|
|
675
|
+
return m ? literalText(m[1]) : null;
|
|
676
|
+
};
|
|
677
|
+
// A column's key is already an identifier (the lifted rows' own).
|
|
678
|
+
if (tablePart(tag) === "head" && ctx?.column) return ctx.column;
|
|
679
|
+
const text = [
|
|
680
|
+
BESIDE_TAGS.has(tag) ? textBeside(node, ctx) : null,
|
|
681
|
+
drawn("label"),
|
|
682
|
+
drawn("title"),
|
|
683
|
+
drawn("placeholder"),
|
|
684
|
+
props.label,
|
|
685
|
+
props.title,
|
|
686
|
+
].find(named) ?? node.name ?? "";
|
|
631
687
|
return camelName(text);
|
|
632
688
|
}
|
|
633
689
|
|
|
690
|
+
/**
|
|
691
|
+
* The text a part sits beside: the nearest text before it in its frame, else
|
|
692
|
+
* the nearest text before its frame (a row of "Asked by" and a frame holding
|
|
693
|
+
* the PiiText and " · on save"). Null when it has none.
|
|
694
|
+
*/
|
|
695
|
+
function textBeside(node, ctx) {
|
|
696
|
+
const before = (parent, target) => {
|
|
697
|
+
const shown = (parent?.children ?? []).filter((c) => c.visible !== false);
|
|
698
|
+
const at = shown.indexOf(target);
|
|
699
|
+
if (at === -1) return null;
|
|
700
|
+
return shown.slice(0, at).reverse().find((c) => c.type === "TEXT" && /[A-Za-z0-9]/.test(c.text ?? ""))?.text ?? null;
|
|
701
|
+
};
|
|
702
|
+
if (!ctx?.parent) return null;
|
|
703
|
+
return before(ctx.parent, node) ?? (ctx.grand ? before(ctx.grand, ctx.parent) : null);
|
|
704
|
+
}
|
|
705
|
+
|
|
634
706
|
/** Text in camelCase as an identifier (`Subject kind` → `subjectKind`, `2FA` → `field2fa`). */
|
|
635
707
|
function camelName(text) {
|
|
636
708
|
const words = String(text ?? "").match(/[A-Za-z0-9]+/g) ?? [];
|
|
@@ -665,13 +737,20 @@ const literalText = (lit) => JSON.parse(lit.startsWith("{") ? lit.slice(1, -1) :
|
|
|
665
737
|
* - a Dialog's or AlertDialog's title and description: `<view state>Title`,
|
|
666
738
|
* `<view state>Description`;
|
|
667
739
|
* - a DescriptionItem's value, named by its label (the label is copy and stays);
|
|
668
|
-
* - a StatusPill's label and tone, named by where it sits
|
|
740
|
+
* - a StatusPill's label and tone, named by where it sits;
|
|
741
|
+
* - a metric card's value, caption, changeAmount and period, named by its
|
|
742
|
+
* title or label; a MetricFilterCard's `selected` is the list's filter
|
|
743
|
+
* state, on every card (NODII-DEV-CLI-84);
|
|
744
|
+
* - a cursor pager's summary, hasPrev and hasNext, and its PageSizeSelect's
|
|
745
|
+
* value, all list state (U03-19, U03-22; NODII-DEV-CLI-84);
|
|
746
|
+
* - a CopyField's value and a PiiText's maskHint, named by the text beside
|
|
747
|
+
* them (`scope`, see scopeName; NODII-DEV-CLI-84).
|
|
669
748
|
* A run of sibling DescriptionLists and a table's body rows are lifted as lists
|
|
670
749
|
* (liftedDescriptionList, tableOf). Real copy (headings, labels, buttons) stays.
|
|
671
750
|
*/
|
|
672
|
-
function liftRecordData(code, node, ctx, path) {
|
|
751
|
+
function liftRecordData(code, node, ctx, path, scope = scopeName(node)) {
|
|
673
752
|
const lifted = [];
|
|
674
|
-
const lift = (
|
|
753
|
+
const lift = (at, name) => (lifted.push(name), mark(ctx, at, name));
|
|
675
754
|
let out = liftFieldControls(code, node, ctx, lift);
|
|
676
755
|
// An Alert's title or description that names a record's value (a date, an amount, a code).
|
|
677
756
|
out = out.replace(/<(Alert(Title|Description))>(\{"(?:[^"\\\n]|\\.)*"\})<\/\1>/g, (all, tag, part, lit) =>
|
|
@@ -703,6 +782,46 @@ function liftRecordData(code, node, ctx, path) {
|
|
|
703
782
|
next = tone ? next.replace(tone[0], `tone={${lift(scope, "tone")}}`) : next.replace(`label={`, `tone={${lift(scope, "tone")}} label={`);
|
|
704
783
|
return `<StatusPill${next}${close}>`;
|
|
705
784
|
});
|
|
785
|
+
out = rewriteTags(out, String.raw`Metric(?!CardGroup\b)[A-Za-z]*`, (attrs, tag) => {
|
|
786
|
+
const name = new RegExp(String.raw`\b(?:title|label)=(${LITERAL})`).exec(attrs);
|
|
787
|
+
const at = name ? camelName(literalText(name[1])) : scope;
|
|
788
|
+
let next = attrs;
|
|
789
|
+
for (const attr of METRIC_VALUES) {
|
|
790
|
+
const value = new RegExp(String.raw`\b${attr}=${LITERAL}`).exec(next);
|
|
791
|
+
if (value) next = next.replace(value[0], `${attr}={${lift(at, attr)}}`);
|
|
792
|
+
}
|
|
793
|
+
if (tag !== "MetricFilterCard") return next;
|
|
794
|
+
const selected = `selected={${lift(at, "selected")}}`;
|
|
795
|
+
const bare = bareAttr(next, "selected");
|
|
796
|
+
if (bare !== null) return `${next.slice(0, bare)}${selected}${next.slice(bare + "selected".length)}`;
|
|
797
|
+
const handler = /(\n[ \t]*)onSelect=\{/.exec(next);
|
|
798
|
+
if (handler) return next.replace(handler[0], `${handler[1]}${selected}${handler[0]}`);
|
|
799
|
+
return next.replace(/\s*\/?$/, (end) => ` ${selected}${end}`);
|
|
800
|
+
});
|
|
801
|
+
out = rewriteTags(out, "Pagination|CursorPagination", (attrs, tag) => {
|
|
802
|
+
if (tag === "Pagination" && !/\btype="cursor-bar"/.test(attrs)) return attrs;
|
|
803
|
+
let next = attrs;
|
|
804
|
+
const summary = new RegExp(String.raw`\bsummary=${LITERAL}`).exec(next);
|
|
805
|
+
if (summary) next = next.replace(summary[0], `summary={${lift(scope, "summary")}}`);
|
|
806
|
+
for (const attr of ["hasNext", "hasPrev"]) {
|
|
807
|
+
const value = `${attr}={${lift(scope, attr)}}`;
|
|
808
|
+
const bare = bareAttr(next, attr);
|
|
809
|
+
const literal = new RegExp(String.raw`\b${attr}=\{(?:true|false)\}`).exec(next);
|
|
810
|
+
if (bare !== null) next = `${next.slice(0, bare)}${value}${next.slice(bare + attr.length)}`;
|
|
811
|
+
else if (literal) next = next.replace(literal[0], value);
|
|
812
|
+
else if (!new RegExp(String.raw`\b${attr}=`).test(next)) next = ` ${value}${next}`;
|
|
813
|
+
}
|
|
814
|
+
return next;
|
|
815
|
+
});
|
|
816
|
+
out = rewriteTags(out, "PageSizeSelect", (attrs) => attrs.replace(/\bvalue=\{(?:\d+|Number\("(?:[^"\\\n]|\\.)*"\))\}/, () => `value={${lift(scope, "pageSize")}}`));
|
|
817
|
+
out = rewriteTags(out, "CopyField", (attrs) => {
|
|
818
|
+
const value = new RegExp(String.raw`\bvalue=${LITERAL}`).exec(attrs);
|
|
819
|
+
return value ? attrs.replace(value[0], `value={${lift(scope, "value")}}`) : attrs;
|
|
820
|
+
});
|
|
821
|
+
out = rewriteTags(out, "PiiText", (attrs) => {
|
|
822
|
+
const hint = new RegExp(String.raw`\bmaskHint=${LITERAL}`).exec(attrs);
|
|
823
|
+
return hint ? attrs.replace(hint[0], `maskHint={${lift(scope, "maskHint")}}`) : attrs;
|
|
824
|
+
});
|
|
706
825
|
if (lifted.length) ctx.note(path, LIFTED, `${[...new Set(lifted)].join(", ")} lifted from Figma's sample into the page's props (NODII-DEV-CLI-82)`);
|
|
707
826
|
return out;
|
|
708
827
|
}
|
|
@@ -744,15 +863,18 @@ const cap = (s) => s[0].toUpperCase() + s.slice(1);
|
|
|
744
863
|
const kebab = (s) => s.replace(/[A-Z]/g, (c) => `-${c.toLowerCase()}`);
|
|
745
864
|
|
|
746
865
|
/**
|
|
747
|
-
* What a form control's value is named by:
|
|
748
|
-
*
|
|
749
|
-
*
|
|
866
|
+
* What a form control's value is named by: its label or title, when its
|
|
867
|
+
* template draws it (a Select's undrawn default `label`, "Option label", never
|
|
868
|
+
* names it; NODII-DEV-CLI-84), a filter's own placeholder ("Status: All" →
|
|
869
|
+
* status), the label drawn just before it ("Organisation name"), a search box
|
|
870
|
+
* (search), else its layer name. `code` is the instance's emitted code, the
|
|
871
|
+
* same for its value and for its template's identifiers.
|
|
750
872
|
*/
|
|
751
|
-
function fieldScope(node, ctx,
|
|
873
|
+
function fieldScope(node, ctx, code) {
|
|
752
874
|
const props = node.instance?.props ?? {};
|
|
753
|
-
const own = [props.label, props.title].find((v) => typeof v === "string" && /[A-Za-z]/.test(v));
|
|
875
|
+
const own = [props.label, props.title].find((v) => typeof v === "string" && /[A-Za-z]/.test(v) && code.includes(JSON.stringify(v)));
|
|
754
876
|
if (own) return camelName(own);
|
|
755
|
-
const placeholder = new RegExp(String.raw`\bplaceholder=(${LITERAL})`).exec(
|
|
877
|
+
const placeholder = new RegExp(String.raw`\bplaceholder=(${LITERAL})`).exec(code);
|
|
756
878
|
const hint = placeholder ? literalText(placeholder[1]) : "";
|
|
757
879
|
if (/^[^:]{1,32}:/.test(hint)) return camelName(hint.split(":")[0]);
|
|
758
880
|
const shown = (ctx.parent?.children ?? []).filter((c) => c.visible !== false);
|
|
@@ -773,7 +895,7 @@ function fieldScope(node, ctx, attrs) {
|
|
|
773
895
|
function liftFieldControls(code, node, ctx, lift) {
|
|
774
896
|
return code.replace(/<(Input|Textarea|SelectField|RadioGroup)\b((?:[^>"{]|"(?:[^"\\\n]|\\.)*"|\{[^{}]*(?:\{[^{}]*\}[^{}]*)*\})*?)(\s*\/?)>/g, (all, tag, attrs, close) => {
|
|
775
897
|
if (/\b(value|onChange|onValueChange)=/.test(attrs) || /\{\.\.\./.test(attrs)) return all;
|
|
776
|
-
const scope = fieldScope(node, ctx,
|
|
898
|
+
const scope = fieldScope(node, ctx, code);
|
|
777
899
|
const sep = attrs.includes("\n") ? `\n${/\n(\s*)/.exec(attrs)[1]}` : " ";
|
|
778
900
|
const value = `value={${lift(scope, `${scope}Value`)}}`;
|
|
779
901
|
const change = `${FIELD_CONTROLS[tag]}={${lift(scope, `on${cap(scope)}Change`)}}`;
|
|
@@ -784,6 +906,37 @@ function liftFieldControls(code, node, ctx, lift) {
|
|
|
784
906
|
});
|
|
785
907
|
}
|
|
786
908
|
|
|
909
|
+
/** A metric card's values that are Figma's sample, never copy (NODII-DEV-CLI-84). */
|
|
910
|
+
const METRIC_VALUES = ["value", "caption", "changeAmount", "period"];
|
|
911
|
+
|
|
912
|
+
/**
|
|
913
|
+
* Each opening tag of `names` (a regex alternation) in `code`, its attributes
|
|
914
|
+
* (from after the name to its `>`, stepping over braces and strings, so a
|
|
915
|
+
* pager's `trailing={<PageSizeSelect … />}` stays inside) rewritten by
|
|
916
|
+
* `fn(attrs, tag)`.
|
|
917
|
+
*/
|
|
918
|
+
function rewriteTags(code, names, fn) {
|
|
919
|
+
let out = "";
|
|
920
|
+
let last = 0;
|
|
921
|
+
for (const m of code.matchAll(new RegExp(String.raw`<(${names})(?=[\s/>])`, "g"))) {
|
|
922
|
+
if (m.index < last) continue;
|
|
923
|
+
const from = m.index + m[0].length;
|
|
924
|
+
const end = m.index + openTagEnd(code.slice(m.index));
|
|
925
|
+
out += code.slice(last, from) + fn(code.slice(from, end), m[1]);
|
|
926
|
+
last = end;
|
|
927
|
+
}
|
|
928
|
+
return out + code.slice(last);
|
|
929
|
+
}
|
|
930
|
+
|
|
931
|
+
/** Where a bare (valueless) attribute `name` stands in `attrs`, outside strings and braces; else null. */
|
|
932
|
+
function bareAttr(attrs, name) {
|
|
933
|
+
let flat = maskStrings(attrs);
|
|
934
|
+
// Innermost braces first, until none are left (`trailing={<PageSizeSelect value={9} />}`).
|
|
935
|
+
for (let was = null; was !== flat; ) [was, flat] = [flat, flat.replace(/\{[^{}]*\}/g, (b) => " ".repeat(b.length))];
|
|
936
|
+
const m = new RegExp(String.raw`(^|\s)${name}(?=\s|\/|$)`).exec(flat);
|
|
937
|
+
return m ? m.index + m[1].length : null;
|
|
938
|
+
}
|
|
939
|
+
|
|
787
940
|
/** Tabs the page controls: its tab is a prop, and choosing one calls back (NODII-DEV-CLI-83). */
|
|
788
941
|
const CONTROLLED_TABS = (value, onChange) => `<Tabs panelless value={${value}} onValueChange={${onChange}}>`;
|
|
789
942
|
|
|
@@ -1108,7 +1261,7 @@ function emitNode(node, ctx) {
|
|
|
1108
1261
|
if (node.visible === false) return null;
|
|
1109
1262
|
const { ds, note, depth, parent, root } = ctx;
|
|
1110
1263
|
const path = root ? ctx.path : `${ctx.path} › ${node.name}`;
|
|
1111
|
-
const child = (c) => emitNode(c, { ...ctx, depth: depth + 1, parent: node, path, root: false });
|
|
1264
|
+
const child = (c) => emitNode(c, { ...ctx, depth: depth + 1, parent: node, grand: parent, path, root: false });
|
|
1112
1265
|
const report = (detail) => note(path, "token", detail);
|
|
1113
1266
|
|
|
1114
1267
|
// A DS library instance: exactly what its Code Connect template emits for this instance's properties.
|
|
@@ -1138,7 +1291,7 @@ function emitNode(node, ctx) {
|
|
|
1138
1291
|
return comment(`unmapped: slot ${JSON.stringify(prop)} has no auto layout`);
|
|
1139
1292
|
}
|
|
1140
1293
|
const textOwner = TEXT_PROPERTY_PARTS.has(node.instance.set) ? node.instance.set : ctx.textOwner;
|
|
1141
|
-
const slotCtx = { ...ctx, depth: 0, parent: slotNode, path: `${path} › ${prop}`, root: false, textOwner, inTable: false };
|
|
1294
|
+
const slotCtx = { ...ctx, depth: 0, parent: slotNode, grand: null, path: `${path} › ${prop}`, root: false, textOwner, inTable: false };
|
|
1142
1295
|
const inner = emitChildren(slotNode?.children ?? [], (c) => emitNode(c, slotCtx), slotCtx);
|
|
1143
1296
|
return inner.length === 0 ? "<></>" : inner.length === 1 ? inner[0] : `<>\n${inner.map((x) => indent(x, 1)).join("\n")}\n</>`;
|
|
1144
1297
|
};
|
|
@@ -1154,9 +1307,10 @@ function emitNode(node, ctx) {
|
|
|
1154
1307
|
let own = rendered.code.trim().replace(/=\{<>\{([a-z][A-Za-z0-9]*)\}<\/>\}/g, "={$1}");
|
|
1155
1308
|
// A tab strip the page controls (tabOf reads the template's own strip first, to gather a run).
|
|
1156
1309
|
if (!ctx.tabProbe) own = own.replace(/<Tabs panelless(?: defaultValue="[^"]*")?>/g, CONTROLLED_TABS("tab", "onTabChange"));
|
|
1157
|
-
own = controlHalfControlled(liftRecordData(own, node, ctx, path));
|
|
1158
1310
|
const control = /^<(?:Input|Textarea|SelectField)\b/.test(own.replace(/^<Field\b[^>]*>\s*/, ""));
|
|
1159
|
-
const
|
|
1311
|
+
const scope = control ? fieldScope(node, ctx, own) : scopeName(node, own, ctx);
|
|
1312
|
+
own = controlHalfControlled(liftRecordData(own, node, ctx, path, scope));
|
|
1313
|
+
const code = ctx.scopes ? scopeIdentifiers(own, scope, ctx.scopes) : own;
|
|
1160
1314
|
// A Table part is valid only inside the DS Table. One the generator could not assemble
|
|
1161
1315
|
// into a Table stays reported, never passed off as mapped (MW8-17.3).
|
|
1162
1316
|
const tag = /^<([A-Za-z]+)/.exec(code)?.[1];
|
|
@@ -1217,7 +1371,7 @@ function emitNode(node, ctx) {
|
|
|
1217
1371
|
return indent(comment(`unmapped: ${node.type.toLowerCase()} ${JSON.stringify(node.name)} has no auto layout`), depth);
|
|
1218
1372
|
}
|
|
1219
1373
|
const classes = cls([...sizeClasses(node, parent, root), ...layoutClasses(node), node.clips ? "overflow-hidden" : null]);
|
|
1220
|
-
const kids = emitChildren(node.children ?? [], child, { ...ctx, depth: depth + 1, parent: node, path, root: false });
|
|
1374
|
+
const kids = emitChildren(node.children ?? [], child, { ...ctx, depth: depth + 1, parent: node, grand: parent, path, root: false });
|
|
1221
1375
|
const open = `<div${classes ? ` className="${classes}"` : ""}`;
|
|
1222
1376
|
if (!kids.length) return indent(`${open} />`, depth);
|
|
1223
1377
|
return [indent(`${open}>`, depth), ...kids, indent("</div>", depth)].join("\n");
|
|
@@ -1496,7 +1650,7 @@ function tableOf(node, ctx) {
|
|
|
1496
1650
|
const density = declaredDensity(parsed.find((p) => p.row === row)?.cells ?? []) ?? tableDensity;
|
|
1497
1651
|
return `${widthAttr(w)}${density ? ` density="${density}"` : ""}`;
|
|
1498
1652
|
};
|
|
1499
|
-
const cellCode = ({ cell, code, held }, row, d) => {
|
|
1653
|
+
const cellCode = ({ cell, code, held }, row, d, column = null) => {
|
|
1500
1654
|
const w = columnWidth(cell);
|
|
1501
1655
|
if (held) {
|
|
1502
1656
|
const inner = emitNode(cell, { ...ctx, depth: d + 1, parent: null, path: `${ctx.path} › ${row.name}`, root: false, bare: true, inTable: true });
|
|
@@ -1504,7 +1658,7 @@ function tableOf(node, ctx) {
|
|
|
1504
1658
|
}
|
|
1505
1659
|
if (code) {
|
|
1506
1660
|
// Re-emit for real, so the cell's own unmapped layers are reported.
|
|
1507
|
-
return withWidth(emitNode(cell, { ...ctx, depth: d, parent: null, path: `${ctx.path} › ${row.name}`, root: false, bare: true, inTable: true }), w);
|
|
1661
|
+
return withWidth(emitNode(cell, { ...ctx, depth: d, parent: null, path: `${ctx.path} › ${row.name}`, root: false, bare: true, inTable: true, column }), w);
|
|
1508
1662
|
}
|
|
1509
1663
|
// The frame stood in for the cell: its size and padding are the TableCell's now.
|
|
1510
1664
|
const inner = emitNode({ ...cell, sizing: ["HUG", "HUG"], x: undefined, fills: undefined, strokes: undefined, radius: undefined, ...(cell.layout ? { layout: { ...cell.layout, padding: [0, 0, 0, 0] } } : {}) }, { ...ctx, depth: d + 1, parent: null, path: `${ctx.path} › ${row.name}`, root: false, inTable: true });
|
|
@@ -1532,17 +1686,24 @@ function tableOf(node, ctx) {
|
|
|
1532
1686
|
// by its header (NODII-DEV-CLI-82). Rows that differ in their cells, or a row the generator
|
|
1533
1687
|
// couldn't recognise, stay as drawn.
|
|
1534
1688
|
const dataRows = parsed.filter((p) => p.kind === "body");
|
|
1535
|
-
|
|
1536
|
-
|
|
1689
|
+
// Each column's key: its header copy, numbered when two columns share it. It names the
|
|
1690
|
+
// column in the lifted rows and scopes its head's handler (NODII-DEV-CLI-84).
|
|
1691
|
+
const columnKeys = (count) => {
|
|
1537
1692
|
const keys = [];
|
|
1538
|
-
|
|
1539
|
-
first.cells.forEach((_, i) => {
|
|
1693
|
+
for (let i = 0; i < count; i++) {
|
|
1540
1694
|
const head = headRow?.cells[i];
|
|
1541
1695
|
const text = head?.code ? (/\{"((?:[^"\\\n]|\\.)*)"\}/.exec(head.code)?.[1] ?? /\blabel="([^"]*)"/.exec(head.code)?.[1] ?? "") : "";
|
|
1542
1696
|
let key = /[A-Za-z0-9]/.test(text) ? camelName(text) : `column${i + 1}`;
|
|
1543
1697
|
while (keys.includes(key) || key === "id") key = `${key}${i + 1}`;
|
|
1544
1698
|
keys.push(key);
|
|
1545
|
-
}
|
|
1699
|
+
}
|
|
1700
|
+
return keys;
|
|
1701
|
+
};
|
|
1702
|
+
const headKeys = headRow ? columnKeys(headRow.cells.length) : [];
|
|
1703
|
+
const liftable = !skeleton && dataRows.length > 0 && dataRows.every((p) => !p.unrecognised && !p.framesOnly && p.cells.length === dataRows[0].cells.length) && (!headRow || headRow.cells.length === dataRows[0].cells.length);
|
|
1704
|
+
const liftedRows = () => {
|
|
1705
|
+
const first = dataRows[0];
|
|
1706
|
+
const keys = columnKeys(first.cells.length);
|
|
1546
1707
|
const rowsName = mark(ctx, scopeName(node), "rows");
|
|
1547
1708
|
ctx.note(ctx.path, LIFTED, `${dataRows.length} body row${dataRows.length === 1 ? "" : "s"} lifted as data: rows of { id, ${keys.join(", ")} } (NODII-DEV-CLI-82)`);
|
|
1548
1709
|
const cells = first.cells.map((c, i) => {
|
|
@@ -1575,7 +1736,7 @@ function tableOf(node, ctx) {
|
|
|
1575
1736
|
? [skeletonRows()]
|
|
1576
1737
|
: kind === "body" && liftable
|
|
1577
1738
|
? liftedRows()
|
|
1578
|
-
: list.flatMap((p) => (p.unrecognised ? [indent(comment(p.unrecognised), depth + 2)] : [indent("<TableRow>", depth + 2), ...p.cells.map((c) => cellCode(c, p.row, depth + 3)), indent("</TableRow>", depth + 2)]))),
|
|
1739
|
+
: list.flatMap((p) => (p.unrecognised ? [indent(comment(p.unrecognised), depth + 2)] : [indent("<TableRow>", depth + 2), ...p.cells.map((c, i) => cellCode(c, p.row, depth + 3, p === headRow ? headKeys[i] : null)), indent("</TableRow>", depth + 2)]))),
|
|
1579
1740
|
indent(`</${tag}>`, depth + 1),
|
|
1580
1741
|
];
|
|
1581
1742
|
};
|
|
@@ -1711,7 +1872,18 @@ export async function surfaceCommand(action, rest, f, deps = {}) {
|
|
|
1711
1872
|
const { env = process.env, exec = execFileSync, log = (line) => process.stderr.write(`${line}\n`), figmaGet: injected, docs, cwd } = deps;
|
|
1712
1873
|
const root = findRepoRoot(cwd);
|
|
1713
1874
|
const rows = deps.catalog ?? loadCatalog(root, { exec });
|
|
1714
|
-
const
|
|
1875
|
+
const module = f.module === true ? undefined : f.module;
|
|
1876
|
+
let selected;
|
|
1877
|
+
try {
|
|
1878
|
+
selected = selectTargets(rows, rest[0], { all: Boolean(f.all), module, type: f.type === true ? undefined : f.type });
|
|
1879
|
+
} catch (error) {
|
|
1880
|
+
// A key that only a committed generated page carries: say which page, and that the catalog has no row for it.
|
|
1881
|
+
const page = error?.code === "SURFACE_NOT_IN_CATALOG" && SET_KEY.test(rest[0] ?? "") ? generatedWithoutCatalogRow(root, rows).find((x) => x.componentSetKey === rest[0]) : null;
|
|
1882
|
+
if (!page) throw error;
|
|
1883
|
+
throw new CliError("SURFACE_NOT_IN_CATALOG", `${page.file} is generated from componentSetKey ${rest[0]}, but the product-page catalog has no catalog row for it, so it can't be regenerated or compared; add its row to the design-system catalog (MW8-17.1)`, 1);
|
|
1884
|
+
}
|
|
1885
|
+
// Every committed generated page --all can't reach, because no catalog row names it.
|
|
1886
|
+
const withoutRow = f.all ? generatedWithoutCatalogRow(root, rows, { module }) : [];
|
|
1715
1887
|
// --all without --fetch covers the Surfaces already generated (a committed tree or a generated
|
|
1716
1888
|
// file); the rest are listed as not generated yet. A generated file without its tree fails below.
|
|
1717
1889
|
const generated = (row) => existsSync(treePath(root, row)) || existsSync(generatedPath(root, row));
|
|
@@ -1839,6 +2011,7 @@ export async function surfaceCommand(action, rest, f, deps = {}) {
|
|
|
1839
2011
|
surfaces: results.map((r) => ({ id: r.row.id, componentSetKey: r.row.componentSetKey, file: r.file, states: r.states, unmapped: counted(r.unmapped).length })),
|
|
1840
2012
|
differences,
|
|
1841
2013
|
notGeneratedYet: notYet,
|
|
2014
|
+
generatedWithoutCatalogRow: withoutRow,
|
|
1842
2015
|
unpublished: unpublished.map((row) => ({ id: row.id, componentSetKey: row.componentSetKey, fileKey: row.fileKey })),
|
|
1843
2016
|
scoreboard,
|
|
1844
2017
|
scoreboardPostedOn: posted,
|
|
@@ -1852,6 +2025,8 @@ export async function surfaceCommand(action, rest, f, deps = {}) {
|
|
|
1852
2025
|
(r) => `${f.write ? "wrote" : f.check ? (differences.some((d) => d.id === r.row.id) ? "DIFFERS" : "equal") : "generated"}\t${r.file}\t${r.states.length} state${r.states.length === 1 ? "" : "s"}\t${counted(r.unmapped).length} unmapped layer${counted(r.unmapped).length === 1 ? "" : "s"}`,
|
|
1853
2026
|
);
|
|
1854
2027
|
if (notYet.length) lines.push(`not generated yet: ${notYet.length} catalog Surface${notYet.length === 1 ? "" : "s"} (no committed tree); generate one with \`nodii-dev surface generate <componentSetKey> --fetch --write\``);
|
|
2028
|
+
if (withoutRow.length)
|
|
2029
|
+
lines.push(`no catalog row: ${withoutRow.length} generated page${withoutRow.length === 1 ? "" : "s"} not regenerated or compared, because the product-page catalog has no row for ${withoutRow.length === 1 ? "it" : "them"} (MW8-17.1):`, ...withoutRow.map((x) => ` ${x.file}`));
|
|
1855
2030
|
if (unpublished.length) lines.push(`not published: ${unpublished.length} Surface${unpublished.length === 1 ? "" : "s"} skipped, not generated or scored: ${unpublished.map((row) => row.id).join(", ")}`);
|
|
1856
2031
|
if (f.check && differences.length)
|
|
1857
2032
|
lines.push(`SURFACE_GEN_DIFFERS: ${differences.length} product page${differences.length === 1 ? " differs" : "s differ"} from the generator's output; run \`nodii-dev surface generate --all --write\` and commit, never hand-edit a generated file`);
|