@nodii/dev 0.6.130 → 0.6.132

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/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 = 10;
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: its label
623
- * or title property, else its layer name, in camelCase (`Subject kind` →
624
- * `subjectKind`).
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
- function scopeName(node, ctx = {}) {
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.state) return camelName(ctx.state);
667
+ if (/Dialog$/.test(node.instance?.set ?? "") && ctx?.state) return camelName(ctx.state);
629
668
  const props = node.instance?.props ?? {};
630
- const text = [props.label, props.title].find((v) => typeof v === "string" && /[A-Za-z0-9]/.test(v)) ?? node.name ?? "";
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 = (scope, name) => (lifted.push(name), mark(ctx, scope, name));
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: a filter's own placeholder
748
- * ("Status: All" → status), the label drawn just before it ("Organisation
749
- * name"), a search box (search), else its layer name.
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, attrs) {
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(attrs);
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, attrs);
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 code = ctx.scopes ? scopeIdentifiers(own, control ? fieldScope(node, ctx, own) : scopeName(node, ctx), ctx.scopes) : own;
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
- 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);
1536
- const liftedRows = () => {
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
- const first = dataRows[0];
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 selected = selectTargets(rows, rest[0], { all: Boolean(f.all), module: f.module === true ? undefined : f.module, type: f.type === true ? undefined : f.type });
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`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nodii/dev",
3
- "version": "0.6.130",
3
+ "version": "0.6.132",
4
4
  "description": "Agent CLI for Nodii Dev, reached through the platform edge",
5
5
  "type": "module",
6
6
  "bin": {