@nodii/dev 0.6.89 → 0.6.91
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 +9 -2
- package/dist/cli.js +5 -4
- package/dist/closeout.js +28 -8
- package/dist/core.js +1 -1
- package/dist/flags.js +2 -2
- package/dist/lanes.js +11 -4
- package/dist/review.js +10 -2
- package/dist/surface.js +64 -26
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -873,8 +873,8 @@ run the same command again.
|
|
|
873
873
|
### Product pages from Surfaces: `surface generate` (MW8-17)
|
|
874
874
|
|
|
875
875
|
```sh
|
|
876
|
-
nodii-dev surface generate <componentSetKey|route> [--write] [--check] [--fetch] [--figma-version V] [--report FILE] [--post-scoreboard ISSUE]
|
|
877
|
-
nodii-dev surface generate --all [--module M] [--type page|dialog] [--write] [--check] [--fetch] [--report FILE] [--post-scoreboard ISSUE]
|
|
876
|
+
nodii-dev surface generate <componentSetKey|route> [--write] [--check] [--fetch] [--figma-version V] [--report FILE] [--post-scoreboard ISSUE] [--resume]
|
|
877
|
+
nodii-dev surface generate --all [--module M] [--type page|dialog] [--write] [--check] [--fetch] [--figma-version V] [--report FILE] [--post-scoreboard ISSUE] [--resume]
|
|
878
878
|
```
|
|
879
879
|
|
|
880
880
|
Run in a design-system checkout. It turns a Figma Surface into its product
|
|
@@ -918,6 +918,13 @@ product-page catalog names the Surface by its published component-set key
|
|
|
918
918
|
is not among its file's published sets, names it as not published (`--json`:
|
|
919
919
|
`data.unpublished`), and still generates and scores the rest. A Surface named
|
|
920
920
|
on its own still fails with `SURFACE_NOT_PUBLISHED`.
|
|
921
|
+
- **A 429 stops the read.** `--fetch` never retries a 429. `--all` then generates
|
|
922
|
+
and scores what it read, reports the rest as not generated yet (`--json`:
|
|
923
|
+
`data.stopped`) and exits 1. A Surface named on its own fails with
|
|
924
|
+
`FIGMA_RATE_LIMITED`. With `--write`, each tree is saved as soon as it is read,
|
|
925
|
+
so a stopped or killed run keeps its reads. Add `--resume` to carry on: it keeps
|
|
926
|
+
a saved tree and reads only the rest. With `--figma-version V`, it keeps only
|
|
927
|
+
trees read at `V`.
|
|
921
928
|
- **Scoreboard.** Every run returns `data.scoreboard`, one row per module, and
|
|
922
929
|
`--all` also prints it: Surfaces clean out of total, not published, not
|
|
923
930
|
generated yet, and unmapped layers by kind. A Surface is clean when it has no
|
package/dist/cli.js
CHANGED
|
@@ -165,15 +165,16 @@ Usage: nodii-dev <command> [options] [--json]
|
|
|
165
165
|
# values not bound to a variable and non-DS instances; submit reports the
|
|
166
166
|
# same on any Surface node a set touches (refuses where the host enforces).
|
|
167
167
|
# Reads Figma on Dev's token; exit 1 = SURFACES_CHECK_FAILED
|
|
168
|
-
surface generate <componentSetKey|route> [--write] [--check] [--fetch] [--figma-version V] [--report FILE] [--post-scoreboard ISSUE]
|
|
169
|
-
surface generate --all [--module M] [--type page|dialog] [--write] [--check] [--fetch] [--report FILE] [--post-scoreboard ISSUE]
|
|
168
|
+
surface generate <componentSetKey|route> [--write] [--check] [--fetch] [--figma-version V] [--report FILE] [--post-scoreboard ISSUE] [--resume]
|
|
169
|
+
surface generate --all [--module M] [--type page|dialog] [--write] [--check] [--fetch] [--figma-version V] [--report FILE] [--post-scoreboard ISSUE] [--resume]
|
|
170
170
|
# a Surface -> its product page's presentational code, from Code Connect
|
|
171
171
|
# (MW8-17), in a design-system checkout. --fetch reads Figma (FIGMA_PAT, one
|
|
172
172
|
# call per 8 s); --write writes <page>.surface.generated.tsx (and, with --fetch,
|
|
173
173
|
# the committed tree); --check refuses a difference (the surface-gen-equal gate);
|
|
174
174
|
# --report writes the unmapped layers per file (U08-14), .md or .json;
|
|
175
175
|
# --all --fetch skips and reports a Surface that is not published;
|
|
176
|
-
# --post-scoreboard comments the per-module scoreboard on the issue
|
|
176
|
+
# --post-scoreboard comments the per-module scoreboard on the issue;
|
|
177
|
+
# a 429 stops the read, and --fetch --write --resume keeps what is saved
|
|
177
178
|
figma lock FILE_KEY --title TEXT [--scope KIND:ID ...]
|
|
178
179
|
# scopes: component:NODE page:NODE section:NODE foundations create:PAGE:NAME;
|
|
179
180
|
# no --scope locks the whole file (DEC-0032)
|
|
@@ -383,7 +384,7 @@ Usage: nodii-dev <command> [options] [--json]
|
|
|
383
384
|
lane freeze drop <key> --section SECTION --item ID --reason TEXT
|
|
384
385
|
lane freeze swap <key> --section SECTION [--item ID] --file VALUE.json --reason TEXT
|
|
385
386
|
lane freeze show|history <key> # durable compact-safe contract and all versions
|
|
386
|
-
lane stop <key> [<key> ...] --reason TEXT [--sweeper LANE] [--no-closeout]
|
|
387
|
+
lane stop <key> [<key> ...] --reason TEXT [--sweeper LANE] [--no-closeout] [--no-closeout-push]
|
|
387
388
|
# hub-268: several keys stop one after another in one process, so the
|
|
388
389
|
# operator's one TOTP code covers them all; a lane that fails is reported
|
|
389
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.91";
|
|
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.
|
|
@@ -70,7 +70,7 @@ export const COMMAND_FLAGS = {
|
|
|
70
70
|
"figma changeset": ["file", "actionable", "all", "limit"],
|
|
71
71
|
"figma apply": ["file", "figma-version"],
|
|
72
72
|
"figma lock": ["title", "scope"],
|
|
73
|
-
"surface generate": ["write", "check", "fetch", "all", "module", "type", "figma-version", "report", "post-scoreboard"],
|
|
73
|
+
"surface generate": ["write", "check", "fetch", "all", "module", "type", "figma-version", "report", "post-scoreboard", "resume"],
|
|
74
74
|
};
|
|
75
75
|
|
|
76
76
|
/** Refuse a flag the command does not declare (USAGE, exit 2), naming the valid ones. */
|
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/review.js
CHANGED
|
@@ -116,6 +116,13 @@ export async function repoGeneratedPaths(request, repo) {
|
|
|
116
116
|
return (Array.isArray(harness?.generatedPaths) ? harness.generatedPaths : []).filter((path) => typeof path === "string" && path.trim());
|
|
117
117
|
}
|
|
118
118
|
|
|
119
|
+
/**
|
|
120
|
+
* Data no reviewer can read, left out in every repo alongside Dev's list: a
|
|
121
|
+
* Surface tree is Figma's own document, written only by `surface generate`, and
|
|
122
|
+
* a full set runs to 100 MB (DESIGN-SYSTEM-249).
|
|
123
|
+
*/
|
|
124
|
+
export const GENERATED_DATA_PATHS = ["docs/figma-ux-ds/figma/surface-trees/"];
|
|
125
|
+
|
|
119
126
|
/** One exclude pathspec per prefix, never per file, so a big regeneration cannot hit E2BIG. */
|
|
120
127
|
export const generatedPathspecs = (prefixes) => prefixes.map((prefix) => `:(exclude,glob)${prefix}**`);
|
|
121
128
|
|
|
@@ -127,11 +134,12 @@ export const generatedPathspecs = (prefixes) => prefixes.map((prefix) => `:(excl
|
|
|
127
134
|
* the diff the reviewer reads never disagree.
|
|
128
135
|
*/
|
|
129
136
|
export async function laneDiff(cwd, { exec = execFileAsync, generatedPaths = [] } = {}) {
|
|
130
|
-
|
|
137
|
+
// The same ceiling as the receipt's diff: `text` holds generated data too, so the digest covers every change.
|
|
138
|
+
const git = async (...args) => (await exec("git", ["-C", cwd, ...args], { encoding: "utf8", maxBuffer: 256 * 1024 * 1024 })).stdout;
|
|
131
139
|
const mergeBase = (await git("merge-base", "origin/main", "HEAD")).trim();
|
|
132
140
|
const changedNames = async (...specs) => (await git("diff", "--name-only", mergeBase, ...(specs.length ? ["--", ".", ...specs] : []))).split("\n").map((x) => x.trim()).filter(Boolean);
|
|
133
141
|
const untrackedNames = async (...specs) => (await git("ls-files", "--others", "--exclude-standard", "-z", ...(specs.length ? ["--", ".", ...specs] : []))).split("\0").filter(Boolean);
|
|
134
|
-
const specs = generatedPathspecs(generatedPaths);
|
|
142
|
+
const specs = generatedPathspecs([...GENERATED_DATA_PATHS, ...generatedPaths]);
|
|
135
143
|
const tracked = await git("diff", "--no-color", "--no-ext-diff", mergeBase);
|
|
136
144
|
const names = await changedNames();
|
|
137
145
|
const untracked = await untrackedNames();
|
package/dist/surface.js
CHANGED
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
// Figma reads (only with --fetch) are paced to one call per 8 s or slower;
|
|
25
25
|
// a 429 waits out Retry-After, or 30 s doubling when Figma sends none.
|
|
26
26
|
import { execFileSync } from "node:child_process";
|
|
27
|
-
import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
27
|
+
import { existsSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
28
28
|
import { tmpdir } from "node:os";
|
|
29
29
|
import { dirname, join, relative, resolve } from "node:path";
|
|
30
30
|
import { CliError, VERSION, devRequest, readConfig } from "./core.js";
|
|
@@ -42,12 +42,12 @@ const TYPE_EDGES_CATALOG = "packages/tokens/src/generated/type-edges-v2-catalog.
|
|
|
42
42
|
const SURFACE_REFERENCE = "docs/figma-ux-ds/figma/surface-reference.json";
|
|
43
43
|
const FIGMA_API = "https://api.figma.com/v1";
|
|
44
44
|
export const MIN_FIGMA_INTERVAL_MS = 8_000;
|
|
45
|
-
const
|
|
45
|
+
const BACKOFF_MS = 30_000;
|
|
46
46
|
const SET_KEY = /^[0-9a-f]{40}$/;
|
|
47
47
|
|
|
48
48
|
export const SURFACE_USAGE =
|
|
49
|
-
"surface generate <componentSetKey|route> [--write] [--check] [--fetch] [--figma-version V] [--report FILE] [--post-scoreboard ISSUE]\n" +
|
|
50
|
-
"surface generate --all [--module M] [--type page|dialog] [--write] [--check] [--fetch] [--report FILE] [--post-scoreboard ISSUE]";
|
|
49
|
+
"surface generate <componentSetKey|route> [--write] [--check] [--fetch] [--figma-version V] [--report FILE] [--post-scoreboard ISSUE] [--resume]\n" +
|
|
50
|
+
"surface generate --all [--module M] [--type page|dialog] [--write] [--check] [--fetch] [--figma-version V] [--report FILE] [--post-scoreboard ISSUE] [--resume]";
|
|
51
51
|
|
|
52
52
|
// ---------------------------------------------------------------------------
|
|
53
53
|
// Repository inputs
|
|
@@ -139,19 +139,20 @@ export function pacedFigma(token, { fetchImpl = fetch, sleep = (ms) => new Promi
|
|
|
139
139
|
response = await fetchImpl(`${FIGMA_API}${path}`, { headers: { "X-Figma-Token": token }, signal: AbortSignal.timeout(180_000) });
|
|
140
140
|
} catch (error) {
|
|
141
141
|
if (attempt >= attempts) throw new CliError("FIGMA_UNREACHABLE", `Cannot reach Figma: ${error.message}`);
|
|
142
|
-
await sleep(
|
|
142
|
+
await sleep(BACKOFF_MS);
|
|
143
143
|
continue;
|
|
144
144
|
}
|
|
145
145
|
if (response.ok) return response.json();
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
const ms =
|
|
146
|
+
// A 429 is never retried: it means stop reading (DS-249 ruling), so it falls through to the throw.
|
|
147
|
+
if (response.status >= 500 && attempt < attempts) {
|
|
148
|
+
const ms = BACKOFF_MS * 2 ** (attempt - 1);
|
|
149
149
|
log(`Figma answered ${response.status} for ${path.split("?")[0]}; waiting ${Math.round(ms / 1000)} s`);
|
|
150
150
|
await sleep(ms);
|
|
151
151
|
continue;
|
|
152
152
|
}
|
|
153
153
|
const code = { 404: "FIGMA_NOT_FOUND", 403: "FIGMA_FORBIDDEN", 429: "FIGMA_RATE_LIMITED" }[response.status] ?? "FIGMA_ERROR";
|
|
154
|
-
|
|
154
|
+
const retryAfter = Number(response.headers?.get?.("retry-after"));
|
|
155
|
+
throw new CliError(code, `Figma answered ${response.status} for ${path.split("?")[0]}`, 1, { status: response.status, ...(retryAfter > 0 ? { retryAfterSeconds: retryAfter } : {}) });
|
|
155
156
|
}
|
|
156
157
|
};
|
|
157
158
|
}
|
|
@@ -438,6 +439,8 @@ export function emitSurface(tree, row, ds) {
|
|
|
438
439
|
* `ComponentProps<typeof Tag>["attr"]` for a prop, ReactNode for a child, an
|
|
439
440
|
* object of those for a member read. Sets each view's `uses`.
|
|
440
441
|
*/
|
|
442
|
+
const JS_LITERALS = new Set(["true", "false", "null", "undefined", "this"]);
|
|
443
|
+
|
|
441
444
|
function dataProps(views) {
|
|
442
445
|
const data = new Map();
|
|
443
446
|
const entry = (name) => data.get(name) ?? data.set(name, { attrs: new Set(), child: false, members: new Map() }).get(name);
|
|
@@ -445,6 +448,7 @@ function dataProps(views) {
|
|
|
445
448
|
view.uses = new Set();
|
|
446
449
|
const body = view.body;
|
|
447
450
|
for (const m of body.matchAll(/([A-Za-z][\w-]*)=\{([a-z][A-Za-z0-9]*)(?:\.([A-Za-z][A-Za-z0-9]*))?\}/g)) {
|
|
451
|
+
if (JS_LITERALS.has(m[2])) continue;
|
|
448
452
|
const tag = openingTag(body, m.index);
|
|
449
453
|
if (!tag) continue;
|
|
450
454
|
const ref = `ComponentProps<typeof ${tag}>[${JSON.stringify(m[1])}]`;
|
|
@@ -454,6 +458,7 @@ function dataProps(views) {
|
|
|
454
458
|
view.uses.add(m[2]);
|
|
455
459
|
}
|
|
456
460
|
for (const m of body.matchAll(/(^|>)\s*\{([a-z][A-Za-z0-9]*)\}/gm)) {
|
|
461
|
+
if (JS_LITERALS.has(m[2])) continue;
|
|
457
462
|
entry(m[2]).child = true;
|
|
458
463
|
view.uses.add(m[2]);
|
|
459
464
|
}
|
|
@@ -826,10 +831,11 @@ export function scoreboardText(board) {
|
|
|
826
831
|
}
|
|
827
832
|
|
|
828
833
|
/** The scoreboard as an issue comment. `source` names what the run read (P-4). */
|
|
829
|
-
export function scoreboardMarkdown(board, { mode, source }) {
|
|
834
|
+
export function scoreboardMarkdown(board, { mode, source, stopped = null }) {
|
|
830
835
|
const lines = [
|
|
831
836
|
`**Surface scoreboard** (\`surface generate\`, ${mode} run, \`@nodii/dev\` ${VERSION}, ${source}).`,
|
|
832
837
|
"",
|
|
838
|
+
...(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.`, ""] : []),
|
|
833
839
|
"A Surface is clean when it has no unmapped layer. Total counts every selected Surface, including those not published or not generated yet.",
|
|
834
840
|
"",
|
|
835
841
|
"| Module | Clean / total | Not published | Not generated yet | Unmapped | By kind |",
|
|
@@ -859,6 +865,7 @@ export async function surfaceCommand(action, rest, f, deps = {}) {
|
|
|
859
865
|
if (rest.length > 1 || (rest.length && f.all)) throw new CliError("USAGE", SURFACE_USAGE, 2);
|
|
860
866
|
if (f.write && f.check) throw new CliError("USAGE", "--write and --check are separate runs: --write updates the files, --check refuses a difference", 2);
|
|
861
867
|
if (f.check && f.fetch) throw new CliError("USAGE", "--check regenerates from the committed trees and never reads Figma; drop --fetch", 2);
|
|
868
|
+
if (f.resume && !(f.fetch && f.write)) throw new CliError("USAGE", "--resume continues a stopped read: use it with --fetch --write", 2);
|
|
862
869
|
const postTo = f["post-scoreboard"];
|
|
863
870
|
if (postTo === true || postTo === "") throw new CliError("USAGE", "--post-scoreboard needs an issue key, for example DESIGN-SYSTEM-249", 2);
|
|
864
871
|
const { env = process.env, exec = execFileSync, log = (line) => process.stderr.write(`${line}\n`), figmaGet: injected, docs, cwd } = deps;
|
|
@@ -876,20 +883,51 @@ export async function surfaceCommand(action, rest, f, deps = {}) {
|
|
|
876
883
|
const indexes = new Map();
|
|
877
884
|
const trees = new Map();
|
|
878
885
|
const unpublished = [];
|
|
886
|
+
const stable = (value) => `${JSON.stringify(value, null, 2)}\n`;
|
|
887
|
+
// Saved as soon as it is read, through a rename, so a stopped or killed run keeps its reads whole.
|
|
888
|
+
const saveTree = (row, tree) => {
|
|
889
|
+
const path = treePath(root, row);
|
|
890
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
891
|
+
writeFileSync(`${path}.tmp`, stable(tree));
|
|
892
|
+
renameSync(`${path}.tmp`, path);
|
|
893
|
+
};
|
|
894
|
+
const figmaVersion = f["figma-version"] && f["figma-version"] !== true ? String(f["figma-version"]) : null;
|
|
895
|
+
let stopped = null;
|
|
896
|
+
let kept = 0;
|
|
879
897
|
for (const row of targets) {
|
|
880
898
|
const path = treePath(root, row);
|
|
881
899
|
if (f.fetch) {
|
|
900
|
+
if (f.resume && existsSync(path)) {
|
|
901
|
+
const saved = readJson(path);
|
|
902
|
+
if (!figmaVersion || saved.figmaVersion === figmaVersion) {
|
|
903
|
+
log(`keeping ${row.componentSetName ?? row.id}: read at version ${saved.figmaVersion ?? "unknown"}`);
|
|
904
|
+
trees.set(row, saved);
|
|
905
|
+
kept += 1;
|
|
906
|
+
continue;
|
|
907
|
+
}
|
|
908
|
+
}
|
|
882
909
|
figmaGet ??= pacedFigma(figmaTokenFrom(env), { log });
|
|
883
|
-
|
|
910
|
+
let tree;
|
|
911
|
+
try {
|
|
912
|
+
if (!indexes.has(row.fileKey)) indexes.set(row.fileKey, await setIndex(figmaGet, row.fileKey));
|
|
884
913
|
// --all covers a module: one unpublished Surface is reported, and the rest still generate.
|
|
885
914
|
// A Surface named on its own stays a refusal, because the run has nothing else to do.
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
915
|
+
if (f.all && !indexes.get(row.fileKey).has(row.componentSetKey)) {
|
|
916
|
+
log(`skipping ${row.componentSetName ?? row.id}: not among ${row.fileKey}'s published component sets`);
|
|
917
|
+
unpublished.push(row);
|
|
918
|
+
continue;
|
|
919
|
+
}
|
|
920
|
+
log(`reading ${row.componentSetName ?? row.id} from Figma`);
|
|
921
|
+
tree = await fetchSurfaceTree(figmaGet, row, { index: indexes.get(row.fileKey), version: pinnedVersion(root, row, f["figma-version"]) });
|
|
922
|
+
} catch (error) {
|
|
923
|
+
// --all keeps what it read and scores it; a Surface named on its own has nothing to keep.
|
|
924
|
+
if (!f.all || error?.code !== "FIGMA_RATE_LIMITED") throw error;
|
|
925
|
+
stopped = { code: error.code, at: row.id, retryAfterSeconds: error.details?.retryAfterSeconds ?? null };
|
|
926
|
+
log(`stopping at ${row.componentSetName ?? row.id}: Figma answered 429`);
|
|
927
|
+
break;
|
|
890
928
|
}
|
|
891
|
-
|
|
892
|
-
|
|
929
|
+
trees.set(row, tree);
|
|
930
|
+
if (f.write) saveTree(row, tree);
|
|
893
931
|
} else if (existsSync(path)) {
|
|
894
932
|
trees.set(row, readJson(path));
|
|
895
933
|
} else {
|
|
@@ -904,16 +942,11 @@ export async function surfaceCommand(action, rest, f, deps = {}) {
|
|
|
904
942
|
return { row, tree, ...emitSurface(tree, row, ds) };
|
|
905
943
|
});
|
|
906
944
|
|
|
907
|
-
const stable = (value) => `${JSON.stringify(value, null, 2)}\n`;
|
|
908
945
|
const differences = [];
|
|
909
946
|
for (const r of results) {
|
|
910
947
|
const out = generatedPath(root, r.row);
|
|
911
948
|
r.file = relative(root, out);
|
|
912
949
|
if (f.write) {
|
|
913
|
-
if (f.fetch) {
|
|
914
|
-
mkdirSync(dirname(treePath(root, r.row)), { recursive: true });
|
|
915
|
-
writeFileSync(treePath(root, r.row), stable(r.tree));
|
|
916
|
-
}
|
|
917
950
|
writeFileSync(out, r.code);
|
|
918
951
|
} else if (f.check) {
|
|
919
952
|
const current = existsSync(out) ? readFileSync(out, "utf8") : null;
|
|
@@ -929,14 +962,16 @@ export async function surfaceCommand(action, rest, f, deps = {}) {
|
|
|
929
962
|
}
|
|
930
963
|
|
|
931
964
|
const mode = f.check ? "check" : f.write ? "write" : "print";
|
|
932
|
-
const
|
|
965
|
+
const unread = stopped ? targets.filter((row) => !trees.has(row) && !unpublished.includes(row)) : [];
|
|
966
|
+
if (stopped) stopped.notRead = unread.map((row) => row.id);
|
|
967
|
+
const scoreboard = surfaceScoreboard(selected, results, { unpublished, notGeneratedYet: [...notYetRows, ...unread] });
|
|
933
968
|
let posted = null;
|
|
934
969
|
if (postTo) {
|
|
935
970
|
const commit = checkoutCommit(root, exec);
|
|
936
|
-
const source = `${f.fetch ?
|
|
971
|
+
const source = `${f.fetch ? `trees read from Figma${kept ? `, ${kept} of them kept from an earlier read by --resume` : ""}` : "committed trees"}${commit ? ` in checkout \`${commit}\`` : ""}`;
|
|
937
972
|
const { comment = async (key, body) => devRequest("POST", `/api/v1/issues/${encodeURIComponent(key)}/comment`, { body, onBehalfOf: (await readConfig()).person }) } = deps;
|
|
938
973
|
try {
|
|
939
|
-
await comment(String(postTo), scoreboardMarkdown(scoreboard, { mode, source }));
|
|
974
|
+
await comment(String(postTo), scoreboardMarkdown(scoreboard, { mode, source, stopped }));
|
|
940
975
|
} catch (error) {
|
|
941
976
|
throw new CliError("COMMENT_FAILED", `The run finished${f.write ? " and its files are written" : ""}, but the scoreboard was not posted on ${postTo} (${error?.code ?? "error"}: ${error?.message ?? error}).`, 1);
|
|
942
977
|
}
|
|
@@ -952,6 +987,7 @@ export async function surfaceCommand(action, rest, f, deps = {}) {
|
|
|
952
987
|
unpublished: unpublished.map((row) => ({ id: row.id, componentSetKey: row.componentSetKey, fileKey: row.fileKey })),
|
|
953
988
|
scoreboard,
|
|
954
989
|
scoreboardPostedOn: posted,
|
|
990
|
+
stopped,
|
|
955
991
|
unmapped: report,
|
|
956
992
|
},
|
|
957
993
|
};
|
|
@@ -964,9 +1000,11 @@ export async function surfaceCommand(action, rest, f, deps = {}) {
|
|
|
964
1000
|
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(", ")}`);
|
|
965
1001
|
if (f.check && differences.length)
|
|
966
1002
|
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`);
|
|
1003
|
+
if (stopped)
|
|
1004
|
+
lines.push(`FIGMA_RATE_LIMITED: Figma answered 429 at ${stopped.at}; stopped with ${stopped.notRead.length} Surface${stopped.notRead.length === 1 ? "" : "s"} not read. ${f.write ? "What was read is saved: carry on later with the same command plus --resume." : "Nothing was saved, because this run has no --write."}`);
|
|
967
1005
|
if (f.all) lines.push("", scoreboardText(scoreboard));
|
|
968
1006
|
if (posted) lines.push(`scoreboard posted on ${posted}`);
|
|
969
1007
|
return lines.join("\n");
|
|
970
1008
|
};
|
|
971
|
-
return { payload, human, exitCode: f.check && differences.length ? 1 : 0 };
|
|
1009
|
+
return { payload, human, exitCode: stopped || (f.check && differences.length) ? 1 : 0 };
|
|
972
1010
|
}
|