@nodii/dev 0.6.86 → 0.6.87

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 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]
877
- nodii-dev surface generate --all [--module M] [--type page|dialog] [--write] [--check] [--fetch] [--report FILE]
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]
878
878
  ```
879
879
 
880
880
  Run in a design-system checkout. It turns a Figma Surface into its product
@@ -914,6 +914,17 @@ product-page catalog names the Surface by its published component-set key
914
914
  `surface generate --all --check` with a pinned `@nodii/dev`; `--all`
915
915
  without `--fetch` covers the Surfaces that have a committed tree or a
916
916
  generated file and lists the rest as not generated yet.
917
+ - **Unpublished Surfaces.** `--all --fetch` skips a Surface whose component set
918
+ is not among its file's published sets, names it as not published (`--json`:
919
+ `data.unpublished`), and still generates and scores the rest. A Surface named
920
+ on its own still fails with `SURFACE_NOT_PUBLISHED`.
921
+ - **Scoreboard.** Every run returns `data.scoreboard`, one row per module, and
922
+ `--all` also prints it: Surfaces clean out of total, not published, not
923
+ generated yet, and unmapped layers by kind. A Surface is clean when it has no
924
+ unmapped layer. Total counts every selected Surface, so a skipped one still
925
+ counts against the score. `--post-scoreboard ISSUE` also posts it as a comment
926
+ on that issue, and needs a Dev sign-in. If the post fails, the command exits 1
927
+ with `COMMENT_FAILED`; any files from `--write` are already written.
917
928
 
918
929
  ### Large sets: submit as a Dev job
919
930
 
package/dist/cli.js CHANGED
@@ -165,13 +165,15 @@ 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]
169
- surface generate --all [--module M] [--type page|dialog] [--write] [--check] [--fetch] [--report FILE]
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]
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
- # --report writes the unmapped layers per file (U08-14), .md or .json
174
+ # --report writes the unmapped layers per file (U08-14), .md or .json;
175
+ # --all --fetch skips and reports a Surface that is not published;
176
+ # --post-scoreboard comments the per-module scoreboard on the issue
175
177
  figma lock FILE_KEY --title TEXT [--scope KIND:ID ...]
176
178
  # scopes: component:NODE page:NODE section:NODE foundations create:PAGE:NAME;
177
179
  # no --scope locks the whole file (DEC-0032)
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.86";
7
+ export const VERSION = "0.6.87";
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
@@ -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"],
73
+ "surface generate": ["write", "check", "fetch", "all", "module", "type", "figma-version", "report", "post-scoreboard"],
74
74
  };
75
75
 
76
76
  /** Refuse a flag the command does not declare (USAGE, exit 2), naming the valid ones. */
package/dist/surface.js CHANGED
@@ -27,7 +27,7 @@ import { execFileSync } from "node:child_process";
27
27
  import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
28
28
  import { tmpdir } from "node:os";
29
29
  import { dirname, join, relative, resolve } from "node:path";
30
- import { CliError } from "./core.js";
30
+ 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. */
@@ -46,8 +46,8 @@ const BACKOFF_429_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]\n" +
50
- "surface generate --all [--module M] [--type page|dialog] [--write] [--check] [--fetch] [--report FILE]";
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]";
51
51
 
52
52
  // ---------------------------------------------------------------------------
53
53
  // Repository inputs
@@ -705,7 +705,7 @@ function tableOf(node, ctx) {
705
705
  }
706
706
  const module = imports.map((s) => /\{[^}]*\bTable[A-Za-z]*(Cell|Head)\b[^}]*\}\s+from\s+["']([^"']+)["']/.exec(s)?.[2]).find(Boolean);
707
707
  if (!module) return null;
708
- ctx.note(ctx.path, "frame", `table drawn as frames (${rows.length} row${rows.length === 1 ? "" : "s"}); assembled into the DS Table's parts`);
708
+ ctx.note(ctx.path, "table", `table drawn as frames (${rows.length} row${rows.length === 1 ? "" : "s"}); assembled into the DS Table's parts`);
709
709
  ctx.imports.push(...imports, `import { Table, TableBody, TableHeader, TableRow } from "${module}";`);
710
710
  const { depth } = ctx;
711
711
  const cellCode = ({ cell, code }, row, d) => {
@@ -771,7 +771,7 @@ export function unmappedMarkdown(files) {
771
771
  const lines = [
772
772
  "# Surface layers with no Code Connect mapping (U08-14)",
773
773
  "",
774
- "Generated by `nodii-dev surface generate --report`. Kinds: `instance` (a library instance the generator cannot emit through a template), `text` (loose text, drawn with the DS type utility and colour role), `frame` (a frame that paints its own fill, stroke, radius or effect: only its layout is generated), `shape` (a rectangle, ellipse or vector: marked, not drawn), `token` (a text colour that matches no colour v2 role: left out).",
774
+ "Generated by `nodii-dev surface generate --report`. Kinds: `instance` (a library instance the generator cannot emit through a template), `text` (loose text, drawn with the DS type utility and colour role), `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).",
775
775
  "",
776
776
  ];
777
777
  for (const [fileKey, file] of Object.entries(files)) {
@@ -786,6 +786,70 @@ export function unmappedMarkdown(files) {
786
786
  return lines.join("\n");
787
787
  }
788
788
 
789
+ const moduleOf = (row) => row.product ?? "no module";
790
+
791
+ /**
792
+ * One row per module: how many of its Surfaces are clean, and what keeps the rest from it.
793
+ * `total` counts every selected Surface, so one that was skipped or never generated still
794
+ * counts against `clean`: skipping can never raise a module's score.
795
+ */
796
+ export function surfaceScoreboard(selected, results, { unpublished = [], notGeneratedYet = [] } = {}) {
797
+ const modules = new Map();
798
+ const of = (row) => {
799
+ const name = moduleOf(row);
800
+ if (!modules.has(name)) modules.set(name, { module: name, total: 0, clean: 0, unmapped: 0, byKind: {}, unpublished: [], notGeneratedYet: [] });
801
+ return modules.get(name);
802
+ };
803
+ for (const row of selected) of(row).total += 1;
804
+ for (const row of unpublished) of(row).unpublished.push(row.id);
805
+ for (const row of notGeneratedYet) of(row).notGeneratedYet.push(row.id);
806
+ for (const r of results) {
807
+ const entry = of(r.row);
808
+ if (!r.unmapped.length) entry.clean += 1;
809
+ entry.unmapped += r.unmapped.length;
810
+ for (const u of r.unmapped) entry.byKind[u.kind] = (entry.byKind[u.kind] ?? 0) + 1;
811
+ }
812
+ return [...modules.values()];
813
+ }
814
+
815
+ const byKindText = (byKind) =>
816
+ Object.entries(byKind)
817
+ .sort(([a, x], [b, y]) => y - x || a.localeCompare(b))
818
+ .map(([kind, n]) => `${kind} ${n}`)
819
+ .join(", ") || "none";
820
+
821
+ const NAMES_SHOWN = 20;
822
+ const namesText = (ids) => `${ids.slice(0, NAMES_SHOWN).map((id) => `\`${id}\``).join(", ")}${ids.length > NAMES_SHOWN ? `, and ${ids.length - NAMES_SHOWN} more` : ""}`;
823
+
824
+ export function scoreboardText(board) {
825
+ return board.map((m) => `${m.module}\t${m.clean}/${m.total} clean\t${m.unpublished.length} not published\t${m.notGeneratedYet.length} not generated yet\t${m.unmapped} unmapped (${byKindText(m.byKind)})`).join("\n");
826
+ }
827
+
828
+ /** The scoreboard as an issue comment. `source` names what the run read (P-4). */
829
+ export function scoreboardMarkdown(board, { mode, source }) {
830
+ const lines = [
831
+ `**Surface scoreboard** (\`surface generate\`, ${mode} run, \`@nodii/dev\` ${VERSION}, ${source}).`,
832
+ "",
833
+ "A Surface is clean when it has no unmapped layer. Total counts every selected Surface, including those not published or not generated yet.",
834
+ "",
835
+ "| Module | Clean / total | Not published | Not generated yet | Unmapped | By kind |",
836
+ "|---|---:|---:|---:|---:|---|",
837
+ ...board.map((m) => `| ${m.module} | ${m.clean} / ${m.total} | ${m.unpublished.length} | ${m.notGeneratedYet.length} | ${m.unmapped} | ${byKindText(m.byKind)} |`),
838
+ ];
839
+ const skipped = board.filter((m) => m.unpublished.length);
840
+ if (skipped.length) lines.push("", "**Not published, so not generated or scored:**", ...skipped.map((m) => `- ${m.module}: ${namesText(m.unpublished)}`));
841
+ return lines.join("\n");
842
+ }
843
+
844
+ /** The design-system commit a run read, when the checkout has one. */
845
+ function checkoutCommit(root, exec) {
846
+ try {
847
+ return String(exec("git", ["rev-parse", "--short=9", "HEAD"], { cwd: root, encoding: "utf8", stdio: ["ignore", "pipe", "ignore"] })).trim() || null;
848
+ } catch {
849
+ return null;
850
+ }
851
+ }
852
+
789
853
  /**
790
854
  * surface generate: read (or --fetch) each Surface's tree, emit its file,
791
855
  * then print, --write or --check. Exit 1 on a --check difference.
@@ -795,6 +859,8 @@ export async function surfaceCommand(action, rest, f, deps = {}) {
795
859
  if (rest.length > 1 || (rest.length && f.all)) throw new CliError("USAGE", SURFACE_USAGE, 2);
796
860
  if (f.write && f.check) throw new CliError("USAGE", "--write and --check are separate runs: --write updates the files, --check refuses a difference", 2);
797
861
  if (f.check && f.fetch) throw new CliError("USAGE", "--check regenerates from the committed trees and never reads Figma; drop --fetch", 2);
862
+ const postTo = f["post-scoreboard"];
863
+ if (postTo === true || postTo === "") throw new CliError("USAGE", "--post-scoreboard needs an issue key, for example DESIGN-SYSTEM-249", 2);
798
864
  const { env = process.env, exec = execFileSync, log = (line) => process.stderr.write(`${line}\n`), figmaGet: injected, docs, cwd } = deps;
799
865
  const root = findRepoRoot(cwd);
800
866
  const rows = deps.catalog ?? loadCatalog(root, { exec });
@@ -803,16 +869,25 @@ export async function surfaceCommand(action, rest, f, deps = {}) {
803
869
  // file); the rest are listed as not generated yet. A generated file without its tree fails below.
804
870
  const generated = (row) => existsSync(treePath(root, row)) || existsSync(generatedPath(root, row));
805
871
  const targets = f.all && !f.fetch ? selected.filter(generated) : selected;
806
- const notYet = f.all && !f.fetch ? selected.filter((row) => !generated(row)).map((row) => row.id) : [];
872
+ const notYetRows = f.all && !f.fetch ? selected.filter((row) => !generated(row)) : [];
873
+ const notYet = notYetRows.map((row) => row.id);
807
874
 
808
875
  let figmaGet = injected;
809
876
  const indexes = new Map();
810
877
  const trees = new Map();
878
+ const unpublished = [];
811
879
  for (const row of targets) {
812
880
  const path = treePath(root, row);
813
881
  if (f.fetch) {
814
882
  figmaGet ??= pacedFigma(figmaTokenFrom(env), { log });
815
883
  if (!indexes.has(row.fileKey)) indexes.set(row.fileKey, await setIndex(figmaGet, row.fileKey));
884
+ // --all covers a module: one unpublished Surface is reported, and the rest still generate.
885
+ // A Surface named on its own stays a refusal, because the run has nothing else to do.
886
+ if (f.all && !indexes.get(row.fileKey).has(row.componentSetKey)) {
887
+ log(`skipping ${row.componentSetName ?? row.id}: not among ${row.fileKey}'s published component sets`);
888
+ unpublished.push(row);
889
+ continue;
890
+ }
816
891
  log(`reading ${row.componentSetName ?? row.id} from Figma`);
817
892
  trees.set(row, await fetchSurfaceTree(figmaGet, row, { index: indexes.get(row.fileKey), version: pinnedVersion(root, row, f["figma-version"]) }));
818
893
  } else if (existsSync(path)) {
@@ -823,7 +898,7 @@ export async function surfaceCommand(action, rest, f, deps = {}) {
823
898
  }
824
899
 
825
900
  const ds = loadDesignSystem(root, { exec, docs });
826
- const results = targets.map((row) => {
901
+ const results = targets.filter((row) => trees.has(row)).map((row) => {
827
902
  const tree = trees.get(row);
828
903
  if (tree.componentSetKey !== row.componentSetKey) throw new CliError("SURFACE_TREE_MISMATCH", `${relative(root, treePath(root, row))} holds set ${tree.componentSetKey}, not ${row.componentSetKey}`, 1);
829
904
  return { row, tree, ...emitSurface(tree, row, ds) };
@@ -853,23 +928,44 @@ export async function surfaceCommand(action, rest, f, deps = {}) {
853
928
  writeFileSync(target, target.endsWith(".json") ? stable(report) : unmappedMarkdown(report));
854
929
  }
855
930
 
931
+ const mode = f.check ? "check" : f.write ? "write" : "print";
932
+ const scoreboard = surfaceScoreboard(selected, results, { unpublished, notGeneratedYet: notYetRows });
933
+ let posted = null;
934
+ if (postTo) {
935
+ const commit = checkoutCommit(root, exec);
936
+ const source = `${f.fetch ? "trees read from Figma" : "committed trees"}${commit ? ` in checkout \`${commit}\`` : ""}`;
937
+ const { comment = async (key, body) => devRequest("POST", `/api/v1/issues/${encodeURIComponent(key)}/comment`, { body, onBehalfOf: (await readConfig()).person }) } = deps;
938
+ try {
939
+ await comment(String(postTo), scoreboardMarkdown(scoreboard, { mode, source }));
940
+ } catch (error) {
941
+ 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
+ }
943
+ posted = String(postTo);
944
+ }
945
+
856
946
  const payload = {
857
947
  data: {
858
- mode: f.check ? "check" : f.write ? "write" : "print",
948
+ mode,
859
949
  surfaces: results.map((r) => ({ id: r.row.id, componentSetKey: r.row.componentSetKey, file: r.file, states: r.states, unmapped: r.unmapped.length })),
860
950
  differences,
861
951
  notGeneratedYet: notYet,
952
+ unpublished: unpublished.map((row) => ({ id: row.id, componentSetKey: row.componentSetKey, fileKey: row.fileKey })),
953
+ scoreboard,
954
+ scoreboardPostedOn: posted,
862
955
  unmapped: report,
863
956
  },
864
957
  };
865
958
  const human = () => {
866
- if (!f.write && !f.check && results.length === 1) return results[0].code;
959
+ if (!f.write && !f.check && !f.all && results.length === 1) return results[0].code;
867
960
  const lines = results.map(
868
961
  (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"}`,
869
962
  );
870
963
  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\``);
964
+ 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(", ")}`);
871
965
  if (f.check && differences.length)
872
966
  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`);
967
+ if (f.all) lines.push("", scoreboardText(scoreboard));
968
+ if (posted) lines.push(`scoreboard posted on ${posted}`);
873
969
  return lines.join("\n");
874
970
  };
875
971
  return { payload, human, exitCode: f.check && differences.length ? 1 : 0 };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nodii/dev",
3
- "version": "0.6.86",
3
+ "version": "0.6.87",
4
4
  "description": "Agent CLI for Nodii Dev, reached through the platform edge",
5
5
  "type": "module",
6
6
  "bin": {