@nodii/dev 0.6.90 → 0.6.92
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 +8 -0
- package/dist/cli.js +1 -1
- package/dist/closeout.js +28 -8
- package/dist/core.js +1 -1
- package/dist/flags.js +1 -1
- package/dist/lanes.js +11 -4
- package/dist/surface.js +82 -24
- package/dist/vendor/render-templates.mjs +94 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -925,6 +925,14 @@ product-page catalog names the Surface by its published component-set key
|
|
|
925
925
|
so a stopped or killed run keeps its reads. Add `--resume` to carry on: it keeps
|
|
926
926
|
a saved tree and reads only the rest. With `--figma-version V`, it keeps only
|
|
927
927
|
trees read at `V`.
|
|
928
|
+
- **Table assembly.** A table drawn as frames goes in the DS `Table`'s anatomy. A
|
|
929
|
+
cell that is no Table part is held in a `TableCell`, and a wrapped cell takes its
|
|
930
|
+
row's density.
|
|
931
|
+
- **Exposed instances and text.** A tree keeps a remote instance's exposed nested
|
|
932
|
+
instances by layer name, for a template's `findInstance`. Text bound to a DS text
|
|
933
|
+
style and a DS colour role is listed as kind `bound-text` and doesn't count against
|
|
934
|
+
a Surface being clean. Text missing either binding is unmapped, and so is text in a
|
|
935
|
+
part that should own it as a property.
|
|
928
936
|
- **Scoreboard.** Every run returns `data.scoreboard`, one row per module, and
|
|
929
937
|
`--all` also prints it: Surfaces clean out of total, not published, not
|
|
930
938
|
generated yet, and unmapped layers by kind. A Surface is clean when it has no
|
package/dist/cli.js
CHANGED
|
@@ -384,7 +384,7 @@ Usage: nodii-dev <command> [options] [--json]
|
|
|
384
384
|
lane freeze drop <key> --section SECTION --item ID --reason TEXT
|
|
385
385
|
lane freeze swap <key> --section SECTION [--item ID] --file VALUE.json --reason TEXT
|
|
386
386
|
lane freeze show|history <key> # durable compact-safe contract and all versions
|
|
387
|
-
lane stop <key> [<key> ...] --reason TEXT [--sweeper LANE] [--no-closeout]
|
|
387
|
+
lane stop <key> [<key> ...] --reason TEXT [--sweeper LANE] [--no-closeout] [--no-closeout-push]
|
|
388
388
|
# hub-268: several keys stop one after another in one process, so the
|
|
389
389
|
# operator's one TOTP code covers them all; a lane that fails is reported
|
|
390
390
|
# and the rest still stop (LANE_STOP_INCOMPLETE names each failure)
|
package/dist/closeout.js
CHANGED
|
@@ -114,7 +114,7 @@ async function closeStoppedPr({ lane, repository, reason, issueKeys, gh }) {
|
|
|
114
114
|
* Close out one repository of a stopped lane. Returns what happened at each
|
|
115
115
|
* step; never throws for a step's failure.
|
|
116
116
|
*/
|
|
117
|
-
export async function closeoutRepository(lane, repository, { reason, issueKeys = [], exec = defaultExec, cwd = process.cwd() } = {}) {
|
|
117
|
+
export async function closeoutRepository(lane, repository, { reason, issueKeys = [], exec = defaultExec, cwd = process.cwd(), push = true, progress = () => {} } = {}) {
|
|
118
118
|
const { worktree, branch } = repository;
|
|
119
119
|
const out = { repo: repository.repo, branch, worktree, pushed: null, pr: null, stacks: [], worktreeRemoved: false, notes: [] };
|
|
120
120
|
if (!worktree || !existsSync(worktree)) {
|
|
@@ -124,6 +124,7 @@ export async function closeoutRepository(lane, repository, { reason, issueKeys =
|
|
|
124
124
|
const git = (...args) => exec("git", ["-C", worktree, ...args]);
|
|
125
125
|
const gh = (...args) => exec("gh", args, { cwd: worktree });
|
|
126
126
|
const base = repository.baseRef ?? "origin/main";
|
|
127
|
+
const say = (text) => progress(`${lane.key} ${repository.repo ?? worktree}: ${text}`);
|
|
127
128
|
let pushedOk = false;
|
|
128
129
|
// A read-only repository (hub-257) holds no work of the lane's:
|
|
129
130
|
// nothing to push and no PR to record.
|
|
@@ -140,23 +141,37 @@ export async function closeoutRepository(lane, repository, { reason, issueKeys =
|
|
|
140
141
|
if (landed) {
|
|
141
142
|
out.pushed = { ahead, head, needed: false };
|
|
142
143
|
pushedOk = true;
|
|
144
|
+
} else if (!push) {
|
|
145
|
+
out.pushed = { ahead, head, needed: true, skipped: true };
|
|
146
|
+
say(`${ahead} leftover commit(s) stay on local branch ${branch} in ${worktree}`);
|
|
147
|
+
out.notes.push(`--no-closeout-push: ${ahead} commit(s) stay on local branch ${branch} in ${worktree}; nodii-dev lane closeout ${lane.key} --reason TEXT pushes them`);
|
|
143
148
|
} else {
|
|
149
|
+
// The repository's own pre-push hook runs here, and on a large repository it takes minutes.
|
|
150
|
+
say(`pushing ${ahead} leftover commit(s) to ${branch}, through the repository's pre-push hook; this can take minutes`);
|
|
144
151
|
await git("push", "--quiet", "-u", "origin", `HEAD:refs/heads/${branch}`);
|
|
145
152
|
const remote = (await git("ls-remote", "origin", `refs/heads/${branch}`)).trim().split(/\s+/)[0] ?? "";
|
|
146
153
|
pushedOk = remote === head;
|
|
147
154
|
out.pushed = { ahead, head, remote, needed: true, readBack: pushedOk };
|
|
155
|
+
say(pushedOk ? "push confirmed" : "push not confirmed");
|
|
148
156
|
if (!pushedOk) out.notes.push(`push read-back failed: remote ${branch} is ${remote || "missing"}, HEAD is ${head}`);
|
|
149
157
|
}
|
|
150
158
|
} catch (error) {
|
|
151
159
|
out.notes.push(`push failed: ${String(error?.stderr || error?.message || error).trim().slice(0, 300)}`);
|
|
160
|
+
say("push failed");
|
|
152
161
|
}
|
|
162
|
+
const skipped = Boolean(out.pushed?.skipped);
|
|
153
163
|
// An open PR is closed as Stopped even when nothing new needed a push.
|
|
154
|
-
if (pushedOk && !repository.readOnly) {
|
|
164
|
+
if ((pushedOk || skipped) && !repository.readOnly) {
|
|
155
165
|
try {
|
|
156
|
-
if (out.pushed.needed
|
|
157
|
-
|
|
166
|
+
if (out.pushed.needed && !skipped) {
|
|
167
|
+
say("closing the PR");
|
|
168
|
+
out.pr = await closeStoppedPr({ lane, repository, reason, issueKeys, gh });
|
|
169
|
+
} else {
|
|
158
170
|
const open = JSON.parse((await gh("pr", "list", "--head", branch, "--state", "open", "--json", "number,url")) || "[]");
|
|
159
|
-
if (open.length)
|
|
171
|
+
if (open.length) {
|
|
172
|
+
say("closing the PR");
|
|
173
|
+
out.pr = await closeStoppedPr({ lane, repository, reason, issueKeys, gh });
|
|
174
|
+
}
|
|
160
175
|
}
|
|
161
176
|
} catch (error) {
|
|
162
177
|
out.notes.push(`PR close-out failed: ${String(error?.stderr || error?.message || error).trim().slice(0, 300)}`);
|
|
@@ -172,6 +187,10 @@ export async function closeoutRepository(lane, repository, { reason, issueKeys =
|
|
|
172
187
|
out.stacks.push({ project, down: false, error: String(error?.stderr || error?.message || error).trim().slice(0, 200) });
|
|
173
188
|
}
|
|
174
189
|
}
|
|
190
|
+
if (skipped) {
|
|
191
|
+
out.notes.push("worktree kept: it holds the unpushed commits");
|
|
192
|
+
return out;
|
|
193
|
+
}
|
|
175
194
|
if (!pushedOk) {
|
|
176
195
|
out.notes.push("worktree kept: the push did not succeed");
|
|
177
196
|
return out;
|
|
@@ -202,7 +221,8 @@ export function describeCloseout(lane, repositories) {
|
|
|
202
221
|
const lines = [`Lane ${lane.key} close-out on this machine:`];
|
|
203
222
|
for (const r of repositories) {
|
|
204
223
|
const parts = [];
|
|
205
|
-
if (r.pushed?.
|
|
224
|
+
if (r.pushed?.skipped) parts.push(`${r.pushed.ahead} commit(s) left unpushed on ${r.branch}`);
|
|
225
|
+
else if (r.pushed?.needed) parts.push(r.pushed.readBack ? `pushed ${r.pushed.ahead} commit(s) to ${r.branch}` : "push not confirmed");
|
|
206
226
|
else if (r.pushed) parts.push("nothing unlanded to push");
|
|
207
227
|
if (r.pr) parts.push(`PR ${r.pr.url} ${r.pr.opened ? "opened and " : ""}closed${r.pr.labelled ? ` with the ${STOPPED_LABEL} label` : ` (the ${STOPPED_LABEL} label did not stick)`}`);
|
|
208
228
|
for (const s of r.stacks) parts.push(s.down ? `test stack ${s.project} taken down` : `test stack ${s.project} NOT taken down (${s.error})`);
|
|
@@ -218,11 +238,11 @@ export function describeCloseout(lane, repositories) {
|
|
|
218
238
|
* Orphan): Dev's refusal of the stop comes first, so nothing local runs for a
|
|
219
239
|
* stop Dev did not allow.
|
|
220
240
|
*/
|
|
221
|
-
export async function closeoutLane(lane, { reason, request, onBehalfOf, exec = defaultExec, cwd = process.cwd() } = {}) {
|
|
241
|
+
export async function closeoutLane(lane, { reason, request, onBehalfOf, exec = defaultExec, cwd = process.cwd(), push = true, progress = () => {} } = {}) {
|
|
222
242
|
const issueKeys = (lane?.issues ?? []).map((issue) => issue.key).filter(Boolean);
|
|
223
243
|
const repositories = [];
|
|
224
244
|
for (const repository of laneRepositories(lane))
|
|
225
|
-
repositories.push(await closeoutRepository(lane, repository, { reason, issueKeys, exec, cwd }));
|
|
245
|
+
repositories.push(await closeoutRepository(lane, repository, { reason, issueKeys, exec, cwd, push, progress }));
|
|
226
246
|
const text = describeCloseout(lane, repositories);
|
|
227
247
|
const recorded = [];
|
|
228
248
|
if (request && repositories.length)
|
package/dist/core.js
CHANGED
|
@@ -4,7 +4,7 @@ import { chmod, mkdir, readFile, rm, writeFile } from "node:fs/promises";
|
|
|
4
4
|
import { homedir, platform } from "node:os";
|
|
5
5
|
import { dirname, join } from "node:path";
|
|
6
6
|
|
|
7
|
-
export const VERSION = "0.6.
|
|
7
|
+
export const VERSION = "0.6.92";
|
|
8
8
|
export const configPath = () =>
|
|
9
9
|
process.env.NODII_DEV_CONFIG_PATH ??
|
|
10
10
|
join(homedir(), ".config/nodii-dev/config.json");
|
package/dist/flags.js
CHANGED
|
@@ -41,7 +41,7 @@ export const COMMAND_FLAGS = {
|
|
|
41
41
|
"lane waits": ["machine"],
|
|
42
42
|
"lane resume": ["override", "reason", "host-lost", "min-free-gb", "stagger-seconds", "profile", "class"],
|
|
43
43
|
"lane transfer": ["reason", "to-agent"],
|
|
44
|
-
"lane stop": ["reason", "sweeper", "no-closeout"],
|
|
44
|
+
"lane stop": ["reason", "sweeper", "no-closeout", "no-closeout-push"],
|
|
45
45
|
"lane closeout": ["reason"],
|
|
46
46
|
"lane repo": ["repo", "branch", "worktree", "read-only", "reason"],
|
|
47
47
|
// hub-232: the honest close-out and the governor.
|
package/dist/lanes.js
CHANGED
|
@@ -1090,7 +1090,10 @@ export async function laneCommand(action, args, flags, deps = {}) {
|
|
|
1090
1090
|
const reason = requireFlag(flags, "reason");
|
|
1091
1091
|
// Dev first: a stop it refuses changes nothing on this machine (hub-244).
|
|
1092
1092
|
const payload = await request("POST", `/api/v1/lanes/${encode(id)}/stop`, { reason, ...(flags.sweeper ? { sweeper: String(flags.sweeper) } : {}), ...via });
|
|
1093
|
-
const
|
|
1093
|
+
const closing = !flags["no-closeout"];
|
|
1094
|
+
// Printed before the close-out starts: the stop is recorded, and what follows only tidies this machine.
|
|
1095
|
+
if (closing) stopProgress(deps)(`${ref}: stopped. Closing out on this machine; the stop stands whatever happens next.`);
|
|
1096
|
+
const closeout = closing ? await laneCloseout(ref, reason, { request, config, closeout: deps.closeout, ...closeoutOptions(flags, deps) }) : null;
|
|
1094
1097
|
return {
|
|
1095
1098
|
payload: { ...payload, ...(closeout ? { closeout: closeout.repositories } : {}) },
|
|
1096
1099
|
human: [`${ref}: stopped.`, holdsLine(payload?.holdsReleased), closeout?.text].filter(Boolean).join("\n"),
|
|
@@ -1202,11 +1205,11 @@ export function holdsLine(released) {
|
|
|
1202
1205
|
* The machine half of a lane's end (closeout.js): push, Stopped PR, test
|
|
1203
1206
|
* stacks, worktree. Runs only after Dev accepted the end.
|
|
1204
1207
|
*/
|
|
1205
|
-
export async function laneCloseout(ref, reason, { request = devRequest, config = readConfig, closeout = closeoutLane, lane } = {}) {
|
|
1208
|
+
export async function laneCloseout(ref, reason, { request = devRequest, config = readConfig, closeout = closeoutLane, lane, push = true, progress } = {}) {
|
|
1206
1209
|
const record = lane ?? (await request("GET", `/api/v1/lanes/${encode(ref)}`)).data;
|
|
1207
1210
|
let onBehalfOf;
|
|
1208
1211
|
try { onBehalfOf = (await config())?.person; } catch { onBehalfOf = undefined; }
|
|
1209
|
-
return closeout(record, { reason, request, onBehalfOf });
|
|
1212
|
+
return closeout(record, { reason, request, onBehalfOf, push, ...(progress ? { progress } : {}) });
|
|
1210
1213
|
}
|
|
1211
1214
|
|
|
1212
1215
|
/**
|
|
@@ -1383,6 +1386,9 @@ const STOP_RUN_ENDING = /^(OPERATOR_STEP_UP_|OPERATOR_REQUIRED$|STAFF_OPERATOR_R
|
|
|
1383
1386
|
// "not stopped".
|
|
1384
1387
|
const STOP_UNCONFIRMED = /^(DEV_TIMEOUT|DEV_UNREACHABLE|HTTP_5\d\d)$/;
|
|
1385
1388
|
|
|
1389
|
+
const stopProgress = (deps) => deps.progress ?? ((line) => process.stderr.write(`${line}\n`));
|
|
1390
|
+
const closeoutOptions = (flags, deps) => ({ push: !flags["no-closeout-push"], progress: stopProgress(deps) });
|
|
1391
|
+
|
|
1386
1392
|
async function stopLanes(keys, flags, deps) {
|
|
1387
1393
|
const { request = devRequest, config = readConfig } = deps;
|
|
1388
1394
|
const stopped = [];
|
|
@@ -1414,8 +1420,9 @@ async function stopLanes(keys, flags, deps) {
|
|
|
1414
1420
|
const entry = { key, payload: result.payload, human: result.human };
|
|
1415
1421
|
stopped.push(entry);
|
|
1416
1422
|
if (flags["no-closeout"]) continue;
|
|
1423
|
+
stopProgress(deps)(`${key}: stopped. Closing out on this machine; the stop stands whatever happens next.`);
|
|
1417
1424
|
try {
|
|
1418
|
-
const closeout = await laneCloseout(key, flags.reason, { request, config, closeout: deps.closeout });
|
|
1425
|
+
const closeout = await laneCloseout(key, flags.reason, { request, config, closeout: deps.closeout, ...closeoutOptions(flags, deps) });
|
|
1419
1426
|
entry.payload = { ...entry.payload, closeout: closeout.repositories };
|
|
1420
1427
|
entry.human = [entry.human, closeout.text].filter(Boolean).join("\n");
|
|
1421
1428
|
} catch (error) {
|
package/dist/surface.js
CHANGED
|
@@ -31,7 +31,7 @@ import { CliError, VERSION, devRequest, readConfig } from "./core.js";
|
|
|
31
31
|
import { createRenderer } from "./vendor/render-templates.mjs";
|
|
32
32
|
|
|
33
33
|
/** Bumped whenever the emitted code changes shape for the same inputs. */
|
|
34
|
-
export const GENERATOR_FORMAT =
|
|
34
|
+
export const GENERATOR_FORMAT = 6;
|
|
35
35
|
export const TREE_DIR = "docs/figma-ux-ds/figma/surface-trees";
|
|
36
36
|
export const GENERATED_SUFFIX = ".surface.generated.tsx";
|
|
37
37
|
const CATALOG_PATH = "packages/blocks/src/product-pages/catalog.ts";
|
|
@@ -255,17 +255,32 @@ export function trimTree(entry, { row, version }) {
|
|
|
255
255
|
|
|
256
256
|
if (node.type === "INSTANCE") {
|
|
257
257
|
const main = components[node.componentId] ?? {};
|
|
258
|
+
const propsOf = (instance) =>
|
|
259
|
+
Object.fromEntries(
|
|
260
|
+
Object.entries(instance.componentProperties ?? {})
|
|
261
|
+
.filter(([, p]) => p.type !== "SLOT")
|
|
262
|
+
.map(([name, p]) => [stripPropId(name), p.type === "INSTANCE_SWAP" ? { swap: keyOf(p.value) } : p.value]),
|
|
263
|
+
);
|
|
258
264
|
out.instance = {
|
|
259
265
|
key: main.key ?? null,
|
|
260
266
|
component: main.name ?? null,
|
|
261
267
|
set: sets[main.componentSetId]?.name ?? null,
|
|
262
268
|
remote: Boolean(main.remote),
|
|
263
|
-
props:
|
|
264
|
-
Object.entries(node.componentProperties ?? {})
|
|
265
|
-
.filter(([, p]) => p.type !== "SLOT")
|
|
266
|
-
.map(([name, p]) => [stripPropId(name), p.type === "INSTANCE_SWAP" ? { swap: keyOf(p.value) } : p.value]),
|
|
267
|
-
),
|
|
269
|
+
props: propsOf(node),
|
|
268
270
|
};
|
|
271
|
+
// An exposed nested instance is set on the Surface, and only a template's
|
|
272
|
+
// findInstance can read it, so its properties are kept by layer name.
|
|
273
|
+
if (main.remote && node.exposedInstances?.length) {
|
|
274
|
+
const exposed = {};
|
|
275
|
+
const walk = (parent) => {
|
|
276
|
+
for (const child of parent.children ?? []) {
|
|
277
|
+
if (child.isExposedInstance && !exposed[child.name]) exposed[child.name] = { key: keyOf(child.componentId), props: propsOf(child) };
|
|
278
|
+
walk(child);
|
|
279
|
+
}
|
|
280
|
+
};
|
|
281
|
+
walk(node);
|
|
282
|
+
if (Object.keys(exposed).length) out.instance.exposed = exposed;
|
|
283
|
+
}
|
|
269
284
|
// A library instance is the template's to draw: only its slots' content is the Surface's.
|
|
270
285
|
const children = main.remote ? (node.children ?? []).filter((c) => c.type === "SLOT") : (node.children ?? []);
|
|
271
286
|
if (children.length) out.children = children.map((c) => trim(c, box));
|
|
@@ -389,7 +404,9 @@ export function emitSurface(tree, row, ds) {
|
|
|
389
404
|
used.add(state);
|
|
390
405
|
const fn = `${pascal(state)}View`;
|
|
391
406
|
const note = (path, kind, detail) => unmapped.push({ variant: variant.name, path, kind, detail });
|
|
392
|
-
const
|
|
407
|
+
const emitted = emitNode(variant.root, { depth: 2, parent: null, path: variant.name, ds, imports, note, root: true }) ?? "";
|
|
408
|
+
// A refused root is only a comment, and `return ({/* … */})` is an object, not JSX.
|
|
409
|
+
const body = emitted.trimStart().startsWith("{/*") ? [" <>", indent(emitted.trim(), 3), " </>"].join("\n") : emitted;
|
|
393
410
|
return { state, fn, body };
|
|
394
411
|
});
|
|
395
412
|
const component = `${pascal(row.id)}Surface`;
|
|
@@ -572,6 +589,12 @@ function colour(prefix, paint, scope, ds, report) {
|
|
|
572
589
|
return null;
|
|
573
590
|
}
|
|
574
591
|
|
|
592
|
+
/** Text with both DS bindings: listed, but not counted against a Surface being clean. */
|
|
593
|
+
const BOUND_TEXT = "bound-text";
|
|
594
|
+
const counted = (unmapped) => unmapped.filter((u) => u.kind !== BOUND_TEXT);
|
|
595
|
+
|
|
596
|
+
/** DS parts whose text should be a component property, not slot content (the Q-211 Lock-Change). */
|
|
597
|
+
const TEXT_PROPERTY_PARTS = new Set(["Table cell", "Table Header", "File Viewer"]);
|
|
575
598
|
const SHAPES = new Set(["RECTANGLE", "ELLIPSE", "LINE", "VECTOR", "BOOLEAN_OPERATION", "STAR", "REGULAR_POLYGON"]);
|
|
576
599
|
const cls = (list) => [...new Set(list.filter(Boolean))].join(" ");
|
|
577
600
|
const describe = (node) => (node.instance ? `${node.instance.set ?? node.instance.component ?? "component"}${node.instance.set ? ` [${node.instance.component}]` : ""}` : node.type);
|
|
@@ -587,8 +610,13 @@ function emitNode(node, ctx) {
|
|
|
587
610
|
// A DS library instance: exactly what its Code Connect template emits for this instance's properties.
|
|
588
611
|
if (node.instance?.remote) {
|
|
589
612
|
const dsNode = node.instance.key ? ds.byKey.get(node.instance.key) : null;
|
|
590
|
-
const
|
|
591
|
-
Object.entries(
|
|
613
|
+
const valuesOf = (props) =>
|
|
614
|
+
Object.fromEntries(Object.entries(props).map(([name, value]) => [name, value && typeof value === "object" && "swap" in value ? (ds.byKey.get(value.swap) ?? value.swap) : value]));
|
|
615
|
+
const values = valuesOf(node.instance.props);
|
|
616
|
+
const nested = Object.fromEntries(
|
|
617
|
+
Object.entries(node.instance.exposed ?? {})
|
|
618
|
+
.filter(([, e]) => ds.byKey.has(e.key))
|
|
619
|
+
.map(([layer, e]) => [layer, { nodeId: ds.byKey.get(e.key), values: valuesOf(e.props) }]),
|
|
592
620
|
);
|
|
593
621
|
const slotContent = (prop) => {
|
|
594
622
|
const slotNode = (node.children ?? []).find((c) => c.type === "SLOT" && c.slot === prop);
|
|
@@ -596,10 +624,11 @@ function emitNode(node, ctx) {
|
|
|
596
624
|
note(`${path} › ${prop}`, "layout", `slot ${prop} has no auto layout`);
|
|
597
625
|
return comment(`unmapped: slot ${JSON.stringify(prop)} has no auto layout`);
|
|
598
626
|
}
|
|
599
|
-
const
|
|
627
|
+
const textOwner = TEXT_PROPERTY_PARTS.has(node.instance.set) ? node.instance.set : ctx.textOwner;
|
|
628
|
+
const inner = (slotNode?.children ?? []).map((c) => emitNode(c, { ...ctx, depth: 0, parent: slotNode, path: `${path} › ${prop}`, root: false, textOwner })).filter((x) => x !== null);
|
|
600
629
|
return inner.length === 0 ? "<></>" : inner.length === 1 ? inner[0] : `<>\n${inner.map((x) => indent(x, 1)).join("\n")}\n</>`;
|
|
601
630
|
};
|
|
602
|
-
const rendered = dsNode ? ds.renderer.renderInstance(ds.dsFileKey, dsNode, values, { slot: slotContent }) : null;
|
|
631
|
+
const rendered = dsNode ? ds.renderer.renderInstance(ds.dsFileKey, dsNode, values, { slot: slotContent, nested }) : null;
|
|
603
632
|
if (!rendered || rendered.error || !rendered.code?.trim()) {
|
|
604
633
|
const why = !dsNode ? "not a published DS library component" : !rendered ? "no Code Connect template" : rendered.error ? `template error: ${rendered.error}` : "the template emits no code";
|
|
605
634
|
note(path, "instance", `${describe(node)}: ${why}`);
|
|
@@ -615,11 +644,19 @@ function emitNode(node, ctx) {
|
|
|
615
644
|
|
|
616
645
|
if (node.type === "TEXT") {
|
|
617
646
|
const utility = textUtility(node.textStyle, ds.textStyles);
|
|
618
|
-
|
|
647
|
+
const role = node.color ? colour("text", node.color, "TEXT_FILL", ds, report) : null;
|
|
648
|
+
// Text bound to a DS text style and a DS colour role is still listed, as its own kind
|
|
649
|
+
// (U08-14), but doesn't count against "clean": its code is that utility and that role,
|
|
650
|
+
// the same "clean" as Dev's Surfaces check. Text missing a binding is unmapped, and so
|
|
651
|
+
// is text that should be a property of the part holding it.
|
|
652
|
+
const shown = JSON.stringify(node.text.length > 60 ? `${node.text.slice(0, 57)}…` : node.text);
|
|
653
|
+
if (ctx.textOwner) note(path, "text", `text ${shown} in a ${ctx.textOwner} slot: it should be a property of ${ctx.textOwner} (DS blocker)`);
|
|
654
|
+
else if (!utility || !role) note(path, "text", `loose text ${shown}${utility ? "" : ` (style ${node.textStyle ?? "none"} has no DS text utility)`}${role ? "" : " (no DS colour role)"}`);
|
|
655
|
+
else note(path, BOUND_TEXT, `text ${shown} bound to ${node.textStyle} and ${role}, with no Code Connect mapping`);
|
|
619
656
|
const classes = cls([
|
|
620
657
|
...sizeClasses(node, parent, false).filter((c) => !c.startsWith("h-")),
|
|
621
658
|
utility,
|
|
622
|
-
|
|
659
|
+
role,
|
|
623
660
|
{ CENTER: "text-center", RIGHT: "text-right", JUSTIFIED: "text-justify" }[node.align],
|
|
624
661
|
node.maxLines === 1 ? "truncate" : node.maxLines ? `line-clamp-${node.maxLines}` : null,
|
|
625
662
|
]);
|
|
@@ -698,7 +735,14 @@ function tableOf(node, ctx) {
|
|
|
698
735
|
const local = [];
|
|
699
736
|
const code = emitNode(cell, { ...ctx, depth: 0, parent: null, path: `${ctx.path} › ${row.name}`, root: false, bare: true, imports: local, note: () => {} });
|
|
700
737
|
const part = tablePart(/^<([A-Za-z]+)/.exec(code ?? "")?.[1]);
|
|
701
|
-
|
|
738
|
+
// A cell that is no Table part (a component with no template, or a DS part drawn
|
|
739
|
+
// in a row) is held in a TableCell: one such cell must not undo the whole table.
|
|
740
|
+
if (!part) {
|
|
741
|
+
imports.push(...local);
|
|
742
|
+
cells.push({ cell, code, held: true });
|
|
743
|
+
continue;
|
|
744
|
+
}
|
|
745
|
+
if (kind && kind !== part) return null;
|
|
702
746
|
kind = part;
|
|
703
747
|
imports.push(...local);
|
|
704
748
|
cells.push({ cell, code });
|
|
@@ -713,15 +757,27 @@ function tableOf(node, ctx) {
|
|
|
713
757
|
ctx.note(ctx.path, "table", `table drawn as frames (${rows.length} row${rows.length === 1 ? "" : "s"}); assembled into the DS Table's parts`);
|
|
714
758
|
ctx.imports.push(...imports, `import { Table, TableBody, TableHeader, TableRow } from "${module}";`);
|
|
715
759
|
const { depth } = ctx;
|
|
716
|
-
|
|
760
|
+
// A cell the generator wraps has no template to say its density, so it takes the one
|
|
761
|
+
// its row's template cells declare, or the table's: a row is one height in Figma.
|
|
762
|
+
const declaredDensity = (cells) => cells.map((c) => (c.held ? null : /\bdensity="(\w+)"/.exec(c.code ?? "")?.[1])).find(Boolean);
|
|
763
|
+
const tableDensity = declaredDensity(parsed.flatMap((p) => p.cells));
|
|
764
|
+
const wrapperAttrs = (w, row) => {
|
|
765
|
+
const density = declaredDensity(parsed.find((p) => p.row === row)?.cells ?? []) ?? tableDensity;
|
|
766
|
+
return `${widthAttr(w)}${density ? ` density="${density}"` : ""}`;
|
|
767
|
+
};
|
|
768
|
+
const cellCode = ({ cell, code, held }, row, d) => {
|
|
717
769
|
const w = columnWidth(cell);
|
|
770
|
+
if (held) {
|
|
771
|
+
const inner = emitNode(cell, { ...ctx, depth: d + 1, parent: null, path: `${ctx.path} › ${row.name}`, root: false, bare: true });
|
|
772
|
+
return [indent(`<TableCell${wrapperAttrs(w, row)}>`, d), inner, indent("</TableCell>", d)].join("\n");
|
|
773
|
+
}
|
|
718
774
|
if (code) {
|
|
719
775
|
// Re-emit for real, so the cell's own unmapped layers are reported.
|
|
720
776
|
return withWidth(emitNode(cell, { ...ctx, depth: d, parent: null, path: `${ctx.path} › ${row.name}`, root: false, bare: true }), w);
|
|
721
777
|
}
|
|
722
778
|
// The frame stood in for the cell: its size and padding are the TableCell's now.
|
|
723
779
|
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 });
|
|
724
|
-
return [indent(`<TableCell${
|
|
780
|
+
return [indent(`<TableCell${wrapperAttrs(w, row)}>`, d), inner, indent("</TableCell>", d)].join("\n");
|
|
725
781
|
};
|
|
726
782
|
// Every column held at px or fill is a fixed table layout; a hug column needs the browser's auto layout.
|
|
727
783
|
const widths = parsed.flatMap((p) => p.cells.map((c) => columnWidth(c.cell)));
|
|
@@ -776,7 +832,7 @@ export function unmappedMarkdown(files) {
|
|
|
776
832
|
const lines = [
|
|
777
833
|
"# Surface layers with no Code Connect mapping (U08-14)",
|
|
778
834
|
"",
|
|
779
|
-
"Generated by `nodii-dev surface generate --report`. Kinds: `instance` (a library instance the generator cannot emit through a template), `text` (
|
|
835
|
+
"Generated by `nodii-dev surface generate --report`. Kinds: `instance` (a library instance the generator cannot emit through a template), `text` (text missing a DS text style or colour role, or text in a part that should own it as a property), `frame` (a frame that paints its own fill, stroke, radius or effect: only its layout is generated), `table` (a table drawn as frames, assembled into the DS Table's parts), `layout` (a frame or slot with no auto layout), `shape` (a rectangle, ellipse or vector: marked, not drawn), `token` (a text colour that matches no colour v2 role: left out), `bound-text` (text bound to a DS text style and colour role, with no Code Connect mapping: listed, not counted against a Surface being clean).",
|
|
780
836
|
"",
|
|
781
837
|
];
|
|
782
838
|
for (const [fileKey, file] of Object.entries(files)) {
|
|
@@ -802,7 +858,7 @@ export function surfaceScoreboard(selected, results, { unpublished = [], notGene
|
|
|
802
858
|
const modules = new Map();
|
|
803
859
|
const of = (row) => {
|
|
804
860
|
const name = moduleOf(row);
|
|
805
|
-
if (!modules.has(name)) modules.set(name, { module: name, total: 0, clean: 0, unmapped: 0, byKind: {}, unpublished: [], notGeneratedYet: [] });
|
|
861
|
+
if (!modules.has(name)) modules.set(name, { module: name, total: 0, clean: 0, unmapped: 0, boundText: 0, byKind: {}, unpublished: [], notGeneratedYet: [] });
|
|
806
862
|
return modules.get(name);
|
|
807
863
|
};
|
|
808
864
|
for (const row of selected) of(row).total += 1;
|
|
@@ -810,9 +866,11 @@ export function surfaceScoreboard(selected, results, { unpublished = [], notGene
|
|
|
810
866
|
for (const row of notGeneratedYet) of(row).notGeneratedYet.push(row.id);
|
|
811
867
|
for (const r of results) {
|
|
812
868
|
const entry = of(r.row);
|
|
813
|
-
|
|
814
|
-
entry.
|
|
815
|
-
|
|
869
|
+
const real = counted(r.unmapped);
|
|
870
|
+
if (!real.length) entry.clean += 1;
|
|
871
|
+
entry.unmapped += real.length;
|
|
872
|
+
entry.boundText += r.unmapped.length - real.length;
|
|
873
|
+
for (const u of real) entry.byKind[u.kind] = (entry.byKind[u.kind] ?? 0) + 1;
|
|
816
874
|
}
|
|
817
875
|
return [...modules.values()];
|
|
818
876
|
}
|
|
@@ -836,7 +894,7 @@ export function scoreboardMarkdown(board, { mode, source, stopped = null }) {
|
|
|
836
894
|
`**Surface scoreboard** (\`surface generate\`, ${mode} run, \`@nodii/dev\` ${VERSION}, ${source}).`,
|
|
837
895
|
"",
|
|
838
896
|
...(stopped ? [`**Partial: Figma answered 429 at \`${stopped.at}\`, so the run stopped with ${stopped.notRead.length} Surface${stopped.notRead.length === 1 ? "" : "s"} not read.** They count as not generated yet.`, ""] : []),
|
|
839
|
-
"A Surface is clean when it has no unmapped layer. Total counts every selected Surface, including those not published or not generated yet.",
|
|
897
|
+
"A Surface is clean when it has no unmapped layer. Text bound to a DS text style and colour role is listed in the report, and is not counted here. Total counts every selected Surface, including those not published or not generated yet.",
|
|
840
898
|
"",
|
|
841
899
|
"| Module | Clean / total | Not published | Not generated yet | Unmapped | By kind |",
|
|
842
900
|
"|---|---:|---:|---:|---:|---|",
|
|
@@ -981,7 +1039,7 @@ export async function surfaceCommand(action, rest, f, deps = {}) {
|
|
|
981
1039
|
const payload = {
|
|
982
1040
|
data: {
|
|
983
1041
|
mode,
|
|
984
|
-
surfaces: results.map((r) => ({ id: r.row.id, componentSetKey: r.row.componentSetKey, file: r.file, states: r.states, unmapped: r.unmapped.length })),
|
|
1042
|
+
surfaces: results.map((r) => ({ id: r.row.id, componentSetKey: r.row.componentSetKey, file: r.file, states: r.states, unmapped: counted(r.unmapped).length })),
|
|
985
1043
|
differences,
|
|
986
1044
|
notGeneratedYet: notYet,
|
|
987
1045
|
unpublished: unpublished.map((row) => ({ id: row.id, componentSetKey: row.componentSetKey, fileKey: row.fileKey })),
|
|
@@ -994,7 +1052,7 @@ export async function surfaceCommand(action, rest, f, deps = {}) {
|
|
|
994
1052
|
const human = () => {
|
|
995
1053
|
if (!f.write && !f.check && !f.all && results.length === 1) return results[0].code;
|
|
996
1054
|
const lines = results.map(
|
|
997
|
-
(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${r.unmapped.length} unmapped layer${r.unmapped.length === 1 ? "" : "s"}`,
|
|
1055
|
+
(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"}`,
|
|
998
1056
|
);
|
|
999
1057
|
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\``);
|
|
1000
1058
|
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(", ")}`);
|
|
@@ -279,7 +279,7 @@ export function createRenderer(root, docs, options = {}) {
|
|
|
279
279
|
return props;
|
|
280
280
|
}
|
|
281
281
|
|
|
282
|
-
function makeInstance(context, setNode, props, depth, label, reads = null) {
|
|
282
|
+
function makeInstance(context, setNode, props, depth, label, reads = null, exposed = null) {
|
|
283
283
|
const need = (name, type) => {
|
|
284
284
|
reads?.add(name);
|
|
285
285
|
const prop = props.get(name);
|
|
@@ -328,6 +328,17 @@ export function createRenderer(root, docs, options = {}) {
|
|
|
328
328
|
return slot;
|
|
329
329
|
},
|
|
330
330
|
getPropertyValue: (name) => need(name).value,
|
|
331
|
+
// The snapshot holds component properties, not the layer tree, so a
|
|
332
|
+
// layer lookup answers as Figma does for a layer it cannot find: an
|
|
333
|
+
// error handle. Templates that read exposed nested instances
|
|
334
|
+
// (DEC-0432) fall back to their placeholders here, unless the caller
|
|
335
|
+
// has the instance's exposed layers (renderInstance's `nested`).
|
|
336
|
+
findInstance: (layerName) =>
|
|
337
|
+
exposed?.(layerName) ?? { type: "ERROR", layerName },
|
|
338
|
+
findText: (layerName) => ({ type: "ERROR", layerName }),
|
|
339
|
+
findConnectedInstance: (layerName) => ({ type: "ERROR", layerName }),
|
|
340
|
+
findConnectedInstances: () => [],
|
|
341
|
+
findLayers: () => [],
|
|
331
342
|
hasCodeConnect: () => true,
|
|
332
343
|
codeConnectId: () => null,
|
|
333
344
|
};
|
|
@@ -591,7 +602,7 @@ export function createRenderer(root, docs, options = {}) {
|
|
|
591
602
|
* instances this way. Returns { code, imports } | { error } | null (no
|
|
592
603
|
* template maps the component).
|
|
593
604
|
*/
|
|
594
|
-
function renderInstance(fileKey, nodeId, values = {}, { slot } = {}) {
|
|
605
|
+
function renderInstance(fileKey, nodeId, values = {}, { slot, nested } = {}) {
|
|
595
606
|
const context = contexts.get(fileKey);
|
|
596
607
|
const found = context ? docForComponent(context, nodeId) : null;
|
|
597
608
|
if (!found?.node) return null;
|
|
@@ -600,6 +611,37 @@ export function createRenderer(root, docs, options = {}) {
|
|
|
600
611
|
? context.byId.get(found.node.parentId)
|
|
601
612
|
: found.node;
|
|
602
613
|
const label = `${setNode.name} instance`;
|
|
614
|
+
// `nested` is this instance's exposed layers, { layerName: { nodeId, values } }.
|
|
615
|
+
const exposed = (layerName) => {
|
|
616
|
+
const entry = nested?.[layerName];
|
|
617
|
+
const target = entry ? docForComponent(context, entry.nodeId) : null;
|
|
618
|
+
if (!target?.node) return null;
|
|
619
|
+
const targetSet =
|
|
620
|
+
target.node.parentType === "COMPONENT_SET"
|
|
621
|
+
? context.byId.get(target.node.parentId)
|
|
622
|
+
: target.node;
|
|
623
|
+
const handle = makeInstance(
|
|
624
|
+
context,
|
|
625
|
+
targetSet,
|
|
626
|
+
propsFor(targetSet, target.node, entry.values),
|
|
627
|
+
1,
|
|
628
|
+
`${label} > ${layerName}`
|
|
629
|
+
);
|
|
630
|
+
return {
|
|
631
|
+
...handle,
|
|
632
|
+
executeTemplate: () => {
|
|
633
|
+
const result = runTemplate(target.doc, handle);
|
|
634
|
+
return {
|
|
635
|
+
example: result.example.sections.map((section, index) =>
|
|
636
|
+
index === 0
|
|
637
|
+
? { ...section, nestedImports: result.imports ?? [] }
|
|
638
|
+
: section
|
|
639
|
+
),
|
|
640
|
+
metadata: result.metadata,
|
|
641
|
+
};
|
|
642
|
+
},
|
|
643
|
+
};
|
|
644
|
+
};
|
|
603
645
|
try {
|
|
604
646
|
const result = runTemplate(
|
|
605
647
|
found.doc,
|
|
@@ -608,7 +650,9 @@ export function createRenderer(root, docs, options = {}) {
|
|
|
608
650
|
setNode,
|
|
609
651
|
propsFor(setNode, found.node, values),
|
|
610
652
|
0,
|
|
611
|
-
label
|
|
653
|
+
label,
|
|
654
|
+
null,
|
|
655
|
+
exposed
|
|
612
656
|
)
|
|
613
657
|
);
|
|
614
658
|
const imports = new Set(result.imports ?? []);
|
|
@@ -736,5 +780,51 @@ export function createRenderer(root, docs, options = {}) {
|
|
|
736
780
|
};
|
|
737
781
|
}
|
|
738
782
|
|
|
739
|
-
|
|
783
|
+
/**
|
|
784
|
+
* Which of its Figma component's properties does a template read, in any
|
|
785
|
+
* case it can be rendered in? (The `code-connect-complete` gate,
|
|
786
|
+
* DESIGN-SYSTEM-252.) Every case `renderDoc` renders (every real variant,
|
|
787
|
+
* booleans at default / all on / all off / each flipped, hostile TEXT) plus
|
|
788
|
+
* every probe of `fidelityOf`, so a property read only behind a toggle
|
|
789
|
+
* counts. Returns { definitions: [{ name, type, options }], read: [name] }
|
|
790
|
+
* or null when the node is not in a snapshot.
|
|
791
|
+
*/
|
|
792
|
+
function readsOf(doc) {
|
|
793
|
+
const nodeId = nodeIdFromUrl(doc.figmaNode);
|
|
794
|
+
const context = [...contexts.entries()].find(([fileKey]) =>
|
|
795
|
+
doc.figmaNode.includes(`/design/${fileKey}/`)
|
|
796
|
+
)?.[1];
|
|
797
|
+
const setNode = context?.byId.get(nodeId);
|
|
798
|
+
if (!setNode) return null;
|
|
799
|
+
const reads = new Set();
|
|
800
|
+
for (const entry of casesFor(context, nodeId)) {
|
|
801
|
+
try {
|
|
802
|
+
runTemplate(
|
|
803
|
+
doc,
|
|
804
|
+
makeInstance(
|
|
805
|
+
context,
|
|
806
|
+
entry.setNode,
|
|
807
|
+
propsFor(entry.setNode, entry.variant, entry.overrides),
|
|
808
|
+
0,
|
|
809
|
+
entry.label,
|
|
810
|
+
reads
|
|
811
|
+
)
|
|
812
|
+
);
|
|
813
|
+
} catch {
|
|
814
|
+
// A render error is the compile gate's to report; the reads made
|
|
815
|
+
// before it still count.
|
|
816
|
+
}
|
|
817
|
+
}
|
|
818
|
+
for (const name of fidelityOf(doc)?.read ?? []) reads.add(name);
|
|
819
|
+
const definitions = Object.entries(setNode.propertyDefinitions ?? {}).map(
|
|
820
|
+
([key, def]) => ({
|
|
821
|
+
name: stripSuffix(key),
|
|
822
|
+
type: def.type,
|
|
823
|
+
options: def.variantOptions ?? null,
|
|
824
|
+
})
|
|
825
|
+
);
|
|
826
|
+
return { definitions, read: [...reads].sort() };
|
|
827
|
+
}
|
|
828
|
+
|
|
829
|
+
return { renderDoc, renderVariants, renderInstance, fidelityOf, readsOf };
|
|
740
830
|
}
|