@nodii/dev 0.6.119 → 0.6.121
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 +14 -2
- package/dist/core.js +1 -1
- package/dist/review.js +27 -4
- package/dist/surface.js +79 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -945,12 +945,24 @@ product-page catalog names the Surface by its published component-set key
|
|
|
945
945
|
any head part is a header row, and a body part in it (a select-all Rich Cell)
|
|
946
946
|
keeps its own code. What follows the rows (an Empty or Error State, bare, in
|
|
947
947
|
its own frame, or as a last row holding one DS instance) follows the Table.
|
|
948
|
+
- **A Table's loading state (U07-34.15.3).** The Table cell template emits
|
|
949
|
+
`TableSkeletonRows` for `State=Loading`. When every body row is a row of
|
|
950
|
+
loading cells, as many as the real header has columns, the body becomes one
|
|
951
|
+
`<TableSkeletonRows columns={M} rows={N} cellProps={[…]} />` under the real
|
|
952
|
+
`TableHeader`. Each column's `cellProps` carry its width as the header's column
|
|
953
|
+
carries it (the head template's own `width`, else the head cell's Figma
|
|
954
|
+
sizing), `colAlign: "end"` when the loading cell is right-aligned, and the
|
|
955
|
+
table's density. A row that mixes loading and other cells, a row of loading
|
|
956
|
+
cells beside body rows that are not loading, one with a different number of
|
|
957
|
+
cells than the header, or loading rows with no header row, is marked in the
|
|
958
|
+
code and reported as kind `table`, never guessed.
|
|
948
959
|
- **Tabs.** The Tab template draws one tab as a whole strip, so two or more
|
|
949
960
|
sibling Tabs are gathered into one `Tabs panelless` › `TabsList`, values
|
|
950
961
|
`tab-1`, `tab-2`, …, with the selected tab as `defaultValue`. A lone Tab
|
|
951
962
|
stays as its template gives it. This rule goes when DESIGN-SYSTEM-271 lands.
|
|
952
|
-
- **What isn't recognised stays unmapped.** A Table part
|
|
953
|
-
|
|
963
|
+
- **What isn't recognised stays unmapped.** A Table part (a loading cell's
|
|
964
|
+
`TableSkeletonRows` included) outside any table the generator recognises is
|
|
965
|
+
reported as kind `table`, never passed off as mapped.
|
|
954
966
|
- **Exposed instances and text.** A tree keeps a remote instance's exposed nested
|
|
955
967
|
instances by layer name, for a template's `findInstance`. Text bound to a DS text
|
|
956
968
|
style and a DS colour role is listed as kind `bound-text` and doesn't count against
|
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.121";
|
|
8
8
|
export const configPath = () =>
|
|
9
9
|
process.env.NODII_DEV_CONFIG_PATH ??
|
|
10
10
|
join(homedir(), ".config/nodii-dev/config.json");
|
package/dist/review.js
CHANGED
|
@@ -13,6 +13,7 @@ import { CliError, encode } from "./core.js";
|
|
|
13
13
|
import { pickerPrompt } from "./gather.js";
|
|
14
14
|
import { componentSetsIn, designCatalogSets } from "./figma-scope.js";
|
|
15
15
|
import { gitPrivatePath } from "./safety.js";
|
|
16
|
+
import { GENERATED_PAGE_GLOB, GENERATED_SUFFIX, hasGeneratedPageStamp } from "./surface.js";
|
|
16
17
|
|
|
17
18
|
const execFileAsync = promisify(execFile);
|
|
18
19
|
export const CHECKS = ["rules", "figma", "code"];
|
|
@@ -128,8 +129,17 @@ export async function repoGeneratedPaths(request, repo) {
|
|
|
128
129
|
*/
|
|
129
130
|
export const GENERATED_DATA_PATHS = ["docs/figma-ux-ds/figma/surface-trees/"];
|
|
130
131
|
|
|
131
|
-
/**
|
|
132
|
-
|
|
132
|
+
/**
|
|
133
|
+
* NODII-DEV-CLI-77: a generated product page is the generator's output from
|
|
134
|
+
* its Surface tree, and the surface-gen-equal gate refuses one that differs.
|
|
135
|
+
* It is left out only while it carries the generator's stamp; a page without
|
|
136
|
+
* the stamp is reviewed like any hand-written file.
|
|
137
|
+
*/
|
|
138
|
+
export const GENERATED_PAGE_PATHS = [GENERATED_PAGE_GLOB];
|
|
139
|
+
const isGeneratedPagePath = (path) => path.startsWith(GENERATED_PAGE_GLOB.slice(0, GENERATED_PAGE_GLOB.indexOf("*"))) && path.endsWith(GENERATED_SUFFIX);
|
|
140
|
+
|
|
141
|
+
/** One exclude pathspec per prefix or glob, never per file, so a big regeneration cannot hit E2BIG. A prefix covers everything under it. */
|
|
142
|
+
export const generatedPathspecs = (prefixes) => prefixes.map((prefix) => `:(exclude,glob)${prefix.includes("*") ? prefix : `${prefix}**`}`);
|
|
133
143
|
|
|
134
144
|
/**
|
|
135
145
|
* DEV-REV-6: the worktree against its origin/main merge base, tracked and
|
|
@@ -144,12 +154,20 @@ export async function laneDiff(cwd, { exec = execFileAsync, generatedPaths = []
|
|
|
144
154
|
const mergeBase = (await git("merge-base", "origin/main", "HEAD")).trim();
|
|
145
155
|
const changedNames = async (...specs) => (await git("diff", "--name-only", mergeBase, ...(specs.length ? ["--", ".", ...specs] : []))).split("\n").map((x) => x.trim()).filter(Boolean);
|
|
146
156
|
const untrackedNames = async (...specs) => (await git("ls-files", "--others", "--exclude-standard", "-z", ...(specs.length ? ["--", ".", ...specs] : []))).split("\0").filter(Boolean);
|
|
147
|
-
const specs = generatedPathspecs([...GENERATED_DATA_PATHS, ...generatedPaths]);
|
|
157
|
+
const specs = generatedPathspecs([...GENERATED_DATA_PATHS, ...GENERATED_PAGE_PATHS, ...generatedPaths]);
|
|
148
158
|
const tracked = await git("diff", "--no-color", "--no-ext-diff", mergeBase);
|
|
149
159
|
const names = await changedNames();
|
|
150
160
|
const untracked = await untrackedNames();
|
|
151
161
|
const kept = new Set(specs.length ? [...await changedNames(...specs), ...await untrackedNames(...specs)] : [...names, ...untracked]);
|
|
152
162
|
const paths = [...new Set([...names, ...untracked])];
|
|
163
|
+
// A page left out by the glob alone, without the generator's stamp, goes back to the reviewer.
|
|
164
|
+
// A deleted page has no text to stamp; its removal is not hand-written code.
|
|
165
|
+
const unstamped = [];
|
|
166
|
+
for (const path of paths) {
|
|
167
|
+
if (kept.has(path) || !isGeneratedPagePath(path) || generatedPaths.some((prefix) => !prefix.includes("*") && path.startsWith(prefix))) continue;
|
|
168
|
+
const text = await readFile(join(cwd, path), "utf8").catch((error) => { if (error.code === "ENOENT") return null; throw error; });
|
|
169
|
+
if (text !== null && !hasGeneratedPageStamp(text)) { kept.add(path); unstamped.push(path); }
|
|
170
|
+
}
|
|
153
171
|
const generated = paths.filter((path) => !kept.has(path));
|
|
154
172
|
const added = [];
|
|
155
173
|
const reviewAdded = [];
|
|
@@ -161,7 +179,12 @@ export async function laneDiff(cwd, { exec = execFileAsync, generatedPaths = []
|
|
|
161
179
|
added.push(chunk);
|
|
162
180
|
if (kept.has(path)) reviewAdded.push(chunk);
|
|
163
181
|
}
|
|
164
|
-
const
|
|
182
|
+
const unstampedTracked = unstamped.filter((path) => names.includes(path));
|
|
183
|
+
// Every tracked path kept (unstamped pages included): the whole diff is the review text.
|
|
184
|
+
const reviewTracked = names.some((path) => !kept.has(path))
|
|
185
|
+
? await git("diff", "--no-color", "--no-ext-diff", mergeBase, "--", ".", ...specs) +
|
|
186
|
+
(unstampedTracked.length ? await git("diff", "--no-color", "--no-ext-diff", mergeBase, "--", ...unstampedTracked.map((path) => `:(literal)${path}`)) : "")
|
|
187
|
+
: tracked;
|
|
165
188
|
return { mergeBase, text: tracked + added.join(""), reviewText: reviewTracked + reviewAdded.join(""), paths, generated };
|
|
166
189
|
}
|
|
167
190
|
|
package/dist/surface.js
CHANGED
|
@@ -35,6 +35,11 @@ import { createRenderer } from "./vendor/render-templates.mjs";
|
|
|
35
35
|
export const GENERATOR_FORMAT = 7;
|
|
36
36
|
export const TREE_DIR = "docs/figma-ux-ds/figma/surface-trees";
|
|
37
37
|
export const GENERATED_SUFFIX = ".surface.generated.tsx";
|
|
38
|
+
/** Where every generated product page lives, as a git glob (NODII-DEV-CLI-77). */
|
|
39
|
+
export const GENERATED_PAGE_GLOB = `packages/blocks/src/product-pages/**/*${GENERATED_SUFFIX}`;
|
|
40
|
+
const PAGE_STAMP = /^\/\/ GENERATED by `nodii-dev surface generate` [^\n]*\n\/\/ regenerate with [^\n]*\n\/\/ Surface: [^\n]+ · Figma file \S+ @ version \S+ · format \d+\n/;
|
|
41
|
+
/** True when a product page's text opens with the stamp `surface generate` writes (the header below). */
|
|
42
|
+
export const hasGeneratedPageStamp = (text) => PAGE_STAMP.test(text);
|
|
38
43
|
const CATALOG_PATH = "packages/blocks/src/product-pages/catalog.ts";
|
|
39
44
|
const DS_FILE_META = "infra/figma/figma-file.json";
|
|
40
45
|
const ONE_TO_ONE_SNAPSHOT = "docs/figma-ux-ds/figma/1to1/figma-file.snapshot.json";
|
|
@@ -716,7 +721,8 @@ function emitNode(node, ctx) {
|
|
|
716
721
|
const code = rendered.code.trim();
|
|
717
722
|
// A Table part is valid only inside the DS Table. One the generator could not assemble
|
|
718
723
|
// into a Table stays reported, never passed off as mapped (MW8-17.3).
|
|
719
|
-
|
|
724
|
+
const tag = /^<([A-Za-z]+)/.exec(code)?.[1];
|
|
725
|
+
if (!ctx.inTable && (tablePart(tag) || tag === SKELETON_ROWS)) note(path, "table", `${describe(node)} is a Table part outside any table the generator recognises`);
|
|
720
726
|
if (!sizing.length) return indent(code, depth);
|
|
721
727
|
// Layout around a DS component is the page's; the component itself takes no className (U07-19).
|
|
722
728
|
return [indent(`<div className="${cls(["flex", "flex-col", ...sizing])}">`, depth), indent(code, depth + 1), indent("</div>", depth)].join("\n");
|
|
@@ -837,6 +843,17 @@ function tabStrip(run, ctx) {
|
|
|
837
843
|
* row) becomes a TableCell holding that content. Returns null for anything else.
|
|
838
844
|
*/
|
|
839
845
|
const tablePart = (tag) => (/^Table[A-Za-z]*Head$/.test(tag ?? "") ? "head" : /^Table[A-Za-z]*Cell$/.test(tag ?? "") ? "body" : null);
|
|
846
|
+
/**
|
|
847
|
+
* What the Table cell template emits for `State=Loading` (U07-34.15.3, DEC-0457):
|
|
848
|
+
* one column of the Table's loading state. A body of them becomes one
|
|
849
|
+
* TableSkeletonRows under the real TableHeader (MW8-17.3), never a Skeleton
|
|
850
|
+
* inside a TableCell (A-065 #3).
|
|
851
|
+
*/
|
|
852
|
+
const SKELETON_ROWS = "TableSkeletonRows";
|
|
853
|
+
/** Row kinds while a table is parsed: every cell loading, or loading cells mixed with others. */
|
|
854
|
+
const LOADING = "loading";
|
|
855
|
+
const MIXED = "mixed";
|
|
856
|
+
const isSkeleton = (code) => new RegExp(`^<${SKELETON_ROWS}\\b`).test(code ?? "");
|
|
840
857
|
/**
|
|
841
858
|
* A column's width as Figma sizes the cell (DESIGN-SYSTEM-177; the DS
|
|
842
859
|
* `TableColumnWidth`): px for FIXED, "fill" for FILL, "hug" for HUG. A template
|
|
@@ -878,6 +895,11 @@ function tableOf(node, ctx) {
|
|
|
878
895
|
if (cell.instance?.remote) {
|
|
879
896
|
const local = [];
|
|
880
897
|
const code = emitNode(cell, { ...ctx, depth: 0, parent: null, path: `${ctx.path} › ${row.name}`, root: false, bare: true, inTable: true, imports: local, note: () => {} });
|
|
898
|
+
if (isSkeleton(code?.trim())) {
|
|
899
|
+
imports.push(...local);
|
|
900
|
+
cells.push({ cell, code: code.trim(), loading: true });
|
|
901
|
+
continue;
|
|
902
|
+
}
|
|
881
903
|
const part = tablePart(/^<([A-Za-z]+)/.exec(code ?? "")?.[1]);
|
|
882
904
|
// A cell that is no Table part (a component with no template, or a DS part drawn
|
|
883
905
|
// in a row) is held in a TableCell: one such cell must not undo the whole table.
|
|
@@ -894,6 +916,13 @@ function tableOf(node, ctx) {
|
|
|
894
916
|
} else if (cell.layout || cell.type === "TEXT") cells.push({ cell, code: null });
|
|
895
917
|
else return null;
|
|
896
918
|
}
|
|
919
|
+
// A row of loading cells is one body row of the Table's loading state; a row that
|
|
920
|
+
// mixes loading cells with others is no row the generator recognises (checked below).
|
|
921
|
+
const loading = cells.filter((c) => c.loading).length;
|
|
922
|
+
if (loading) {
|
|
923
|
+
parsed.push({ row, kind: loading === cells.length && kind !== "head" ? LOADING : MIXED, cells, spanning: false, inHeader: kind === "head" });
|
|
924
|
+
continue;
|
|
925
|
+
}
|
|
897
926
|
// A row with no Table part (a loading row of frame cells) is a body row only beside
|
|
898
927
|
// rows of Table parts, and only with as many cells as they have; checked below.
|
|
899
928
|
const spanning = !kind && cells.length === 1 && cells[0].held;
|
|
@@ -917,9 +946,39 @@ function tableOf(node, ctx) {
|
|
|
917
946
|
}
|
|
918
947
|
const module = imports.map((s) => /\{[^}]*\bTable[A-Za-z]*(Cell|Head)\b[^}]*\}\s+from\s+["']([^"']+)["']/.exec(s)?.[2]).find(Boolean);
|
|
919
948
|
if (!module) return null;
|
|
949
|
+
// The loading state: every body row a row of loading cells, as many as the real header
|
|
950
|
+
// has columns, becomes one TableSkeletonRows (U07-34.15.3). Any other row of loading
|
|
951
|
+
// cells (mixed with other cells, beside rows that are not loading, or not spanning the
|
|
952
|
+
// header) is reported and marked, never guessed (MW8-17.3).
|
|
953
|
+
const headRow = parsed.filter((p) => p.kind === "head").at(-1) ?? null;
|
|
954
|
+
const loadingRows = parsed.filter((p) => p.kind === LOADING);
|
|
955
|
+
const bodyRows = parsed.filter((p) => p.kind !== "head");
|
|
956
|
+
// The column count is the real header's: with no header row there is none to take.
|
|
957
|
+
const columnCount = headRow?.cells.length ?? 0;
|
|
958
|
+
const skeleton = headRow !== null && loadingRows.length > 0 && loadingRows.length === bodyRows.length && loadingRows.every((p) => p.cells.length === columnCount);
|
|
959
|
+
for (const p of parsed) {
|
|
960
|
+
if (p.kind !== MIXED && (p.kind !== LOADING || skeleton)) continue;
|
|
961
|
+
const loadingCells = p.cells.filter((c) => c.loading).length;
|
|
962
|
+
const why =
|
|
963
|
+
p.kind === MIXED
|
|
964
|
+
? `row ${JSON.stringify(p.row.name)} mixes ${loadingCells} loading Table cell${loadingCells === 1 ? "" : "s"} with ${p.cells.length - loadingCells} other${p.cells.length - loadingCells === 1 ? "" : "s"}`
|
|
965
|
+
: !headRow
|
|
966
|
+
? `row ${JSON.stringify(p.row.name)} of loading Table cells has no header row to take its columns from`
|
|
967
|
+
: p.cells.length !== columnCount
|
|
968
|
+
? `row ${JSON.stringify(p.row.name)} has ${p.cells.length} loading Table cells under a header of ${columnCount} columns`
|
|
969
|
+
: `row ${JSON.stringify(p.row.name)} of loading Table cells sits beside body rows that are not loading`;
|
|
970
|
+
ctx.note(`${ctx.path} › ${p.row.name}`, "table", `${why}: no Table loading state the generator recognises (U07-34.15.3, MW8-17.3)`);
|
|
971
|
+
p.unrecognised = `unmapped: ${why}`;
|
|
972
|
+
if (p.kind === MIXED) p.kind = p.inHeader ? "head" : "body";
|
|
973
|
+
}
|
|
974
|
+
for (const p of parsed) if (p.kind === LOADING) p.kind = "body";
|
|
920
975
|
const plain = parsed.length - partRows.length;
|
|
921
|
-
ctx.note(
|
|
922
|
-
|
|
976
|
+
ctx.note(
|
|
977
|
+
ctx.path,
|
|
978
|
+
ASSEMBLED,
|
|
979
|
+
`${rows.length} row${rows.length === 1 ? "" : "s"} of Table parts${plain ? ` (${plain} of them frame cells only)` : ""} assembled into one DS Table${skeleton ? ` (its ${loadingRows.length} row${loadingRows.length === 1 ? "" : "s"} of loading cells as one ${SKELETON_ROWS})` : ""} (MW8-17.3)`,
|
|
980
|
+
);
|
|
981
|
+
ctx.imports.push(...imports, `import { Table, TableBody, TableHeader, TableRow${skeleton ? `, ${SKELETON_ROWS}` : ""} } from "${module}";`);
|
|
923
982
|
const { depth } = ctx;
|
|
924
983
|
// A cell the generator wraps has no template to say its density, so it takes the one
|
|
925
984
|
// its row's template cells declare, or the table's: a row is one height in Figma.
|
|
@@ -946,12 +1005,28 @@ function tableOf(node, ctx) {
|
|
|
946
1005
|
// Every column held at px or fill is a fixed table layout; a hug column needs the browser's auto layout.
|
|
947
1006
|
const widths = parsed.flatMap((p) => p.cells.map((c) => columnWidth(c.cell)));
|
|
948
1007
|
const fixed = widths.length > 0 && widths.every((w) => w !== null && w !== "hug");
|
|
1008
|
+
// Each column's width as the header's column carries it (the head template's own
|
|
1009
|
+
// `width`, else the head cell's sizing); its alignment as the loading cell draws it.
|
|
1010
|
+
const skeletonRows = () => {
|
|
1011
|
+
const declared = (code) => /\bwidth=(?:\{(\d+)\}|"(\w+)")/.exec(/^[^>]*/.exec(code ?? "")?.[0] ?? "");
|
|
1012
|
+
const props = Array.from({ length: columnCount }, (_, i) => {
|
|
1013
|
+
const head = headRow.cells[i];
|
|
1014
|
+
const d = head?.code ? declared(head.code) : null;
|
|
1015
|
+
const w = d ? (d[1] ? Number(d[1]) : d[2]) : columnWidth(head.cell);
|
|
1016
|
+
const end = loadingRows.some((p) => /\bcolAlign:\s*"end"/.test(p.cells[i].code));
|
|
1017
|
+
return [w === null ? null : `width: ${JSON.stringify(w)}`, end ? 'colAlign: "end"' : null, tableDensity ? `density: ${JSON.stringify(tableDensity)}` : null].filter(Boolean);
|
|
1018
|
+
});
|
|
1019
|
+
const cellProps = props.some((p) => p.length) ? ` cellProps={[${props.map((p) => (p.length ? `{ ${p.join(", ")} }` : "{}")).join(", ")}]}` : "";
|
|
1020
|
+
return indent(`<${SKELETON_ROWS} columns={${columnCount}} rows={${loadingRows.length}}${cellProps} />`, depth + 2);
|
|
1021
|
+
};
|
|
949
1022
|
const section = (kind, tag) => {
|
|
950
1023
|
const list = parsed.filter((p) => p.kind === kind);
|
|
951
1024
|
if (!list.length) return [];
|
|
952
1025
|
return [
|
|
953
1026
|
indent(`<${tag}>`, depth + 1),
|
|
954
|
-
...
|
|
1027
|
+
...(kind === "body" && skeleton
|
|
1028
|
+
? [skeletonRows()]
|
|
1029
|
+
: 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)]))),
|
|
955
1030
|
indent(`</${tag}>`, depth + 1),
|
|
956
1031
|
];
|
|
957
1032
|
};
|