@nodii/dev 0.6.128 → 0.6.130
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/core.js +1 -1
- package/dist/surface.js +109 -8
- package/dist/watchdog.js +16 -2
- package/package.json +1 -1
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.130";
|
|
8
8
|
export const configPath = () =>
|
|
9
9
|
process.env.NODII_DEV_CONFIG_PATH ??
|
|
10
10
|
join(homedir(), ".config/nodii-dev/config.json");
|
package/dist/surface.js
CHANGED
|
@@ -32,7 +32,7 @@ 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 =
|
|
35
|
+
export const GENERATOR_FORMAT = 10;
|
|
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). */
|
|
@@ -623,7 +623,9 @@ function freeIdentifiers(code) {
|
|
|
623
623
|
* or title property, else its layer name, in camelCase (`Subject kind` →
|
|
624
624
|
* `subjectKind`).
|
|
625
625
|
*/
|
|
626
|
-
function scopeName(node) {
|
|
626
|
+
function scopeName(node, ctx = {}) {
|
|
627
|
+
// 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);
|
|
627
629
|
const props = node.instance?.props ?? {};
|
|
628
630
|
const text = [props.label, props.title].find((v) => typeof v === "string" && /[A-Za-z0-9]/.test(v)) ?? node.name ?? "";
|
|
629
631
|
return camelName(text);
|
|
@@ -670,7 +672,21 @@ const literalText = (lit) => JSON.parse(lit.startsWith("{") ? lit.slice(1, -1) :
|
|
|
670
672
|
function liftRecordData(code, node, ctx, path) {
|
|
671
673
|
const lifted = [];
|
|
672
674
|
const lift = (scope, name) => (lifted.push(name), mark(ctx, scope, name));
|
|
673
|
-
let out = code
|
|
675
|
+
let out = liftFieldControls(code, node, ctx, lift);
|
|
676
|
+
// An Alert's title or description that names a record's value (a date, an amount, a code).
|
|
677
|
+
out = out.replace(/<(Alert(Title|Description))>(\{"(?:[^"\\\n]|\\.)*"\})<\/\1>/g, (all, tag, part, lit) =>
|
|
678
|
+
SAMPLE_VALUE.test(literalText(lit)) ? `<${tag}>{${lift(camelName(ctx.state ?? "alert"), `alert${part}`)}}</${tag}>` : all,
|
|
679
|
+
);
|
|
680
|
+
// An Empty State's text that names the record ("Apex Labs Pvt Ltd was closed on 30 Oct 2026").
|
|
681
|
+
out = out.replace(/<EmptyState\b([^>]*?)(\/?)>/g, (all, attrs, close) =>
|
|
682
|
+
`<EmptyState${attrs.replace(new RegExp(String.raw`\b(title|description)=(${LITERAL})`, "g"), (a, k, lit) => (SAMPLE_VALUE.test(literalText(lit)) ? `${k}={${lift(camelName(`${ctx.state ?? "empty"} empty`), k)}}` : a))}${close}>`,
|
|
683
|
+
);
|
|
684
|
+
// An Input Chip's label is a value the field holds, never copy.
|
|
685
|
+
out = out.replace(/<InputChip\b([^>]*?)(\/?)>/g, (all, attrs, close) => {
|
|
686
|
+
const label = new RegExp(String.raw`\blabel=${LITERAL}`).exec(attrs);
|
|
687
|
+
return label ? `<InputChip${attrs.replace(label[0], `label={${lift(positionScope(node, ctx, "chip"), "label")}}`)}${close}>` : all;
|
|
688
|
+
});
|
|
689
|
+
out = out.replace(new RegExp(String.raw`<((?:Alert)?Dialog(Title|Description))\b([^>]*)>\{"(?:[^"\\\n]|\\.)*"\}</\1>`, "g"), (_, tag, part, attrs) => `<${tag}${attrs}>{${lift(camelName(ctx.state ?? "dialog"), part.toLowerCase())}}</${tag}>`);
|
|
674
690
|
out = out.replace(/<DescriptionItem\b([^>]*?)\/>/g, (all, attrs) => {
|
|
675
691
|
const value = new RegExp(String.raw`\bvalue=${LITERAL}`).exec(attrs);
|
|
676
692
|
if (!value) return all;
|
|
@@ -681,8 +697,7 @@ function liftRecordData(code, node, ctx, path) {
|
|
|
681
697
|
out = out.replace(/<StatusPill\b([^>]*?)(\/?)>/g, (all, attrs, close) => {
|
|
682
698
|
const label = new RegExp(String.raw`\blabel=${LITERAL}`).exec(attrs);
|
|
683
699
|
if (!label) return all;
|
|
684
|
-
const
|
|
685
|
-
const scope = camelName(`${ctx.parent?.name ?? "status"} status${siblings.length > 1 ? ` ${siblings.indexOf(node) + 1}` : ""}`);
|
|
700
|
+
const scope = positionScope(node, ctx, "status");
|
|
686
701
|
const tone = new RegExp(String.raw`\btone=${LITERAL}`).exec(attrs);
|
|
687
702
|
let next = attrs.replace(label[0], `label={${lift(scope, "label")}}`);
|
|
688
703
|
next = tone ? next.replace(tone[0], `tone={${lift(scope, "tone")}}`) : next.replace(`label={`, `tone={${lift(scope, "tone")}} label={`);
|
|
@@ -692,6 +707,83 @@ function liftRecordData(code, node, ctx, path) {
|
|
|
692
707
|
return out;
|
|
693
708
|
}
|
|
694
709
|
|
|
710
|
+
/**
|
|
711
|
+
* Text that names a record's value, not copy: an amount (₹51,900), a date
|
|
712
|
+
* (31 Oct, 09 Oct 2026), an email, a domain or a record code (PAY-8821,
|
|
713
|
+
* CYC-2026-10-HR). Such text is Figma's sample and is lifted (NODII-DEV-CLI-82).
|
|
714
|
+
*/
|
|
715
|
+
export const SAMPLE_VALUE = /₹\s?\d|\b\d{1,2} (?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\b|[\w.+-]+@[a-z0-9-]+\.[a-z]|\b[a-z0-9-]+\.(?:com|in|io|co|org|net)\b|\b[A-Z]{2,5}-\d[\w-]*\b/;
|
|
716
|
+
|
|
717
|
+
/** A part named by where it sits: its parent's name, numbered when the parent holds several of the same set. */
|
|
718
|
+
function positionScope(node, ctx, kind) {
|
|
719
|
+
const siblings = (ctx.parent?.children ?? []).filter((c) => c.visible !== false && (node.instance ? c.instance?.set === node.instance.set : c.type === node.type));
|
|
720
|
+
return camelName(`${ctx.parent?.name ?? kind} ${kind}${siblings.length > 1 ? ` ${siblings.indexOf(node) + 1}` : ""}`);
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
/** The form controls the page owns: a value it passes and a change it hears (NODII-DEV-CLI-82, -83). */
|
|
724
|
+
const FIELD_CONTROLS = { Input: "onChange", Textarea: "onChange", SelectField: "onValueChange", RadioGroup: "onValueChange" };
|
|
725
|
+
|
|
726
|
+
/**
|
|
727
|
+
* A control the template half-controls (`defaultValue="chart"` beside
|
|
728
|
+
* `onValueChange={setView}`, a Segmented Control's view switch), or that
|
|
729
|
+
* hears a change with no value at all, takes its
|
|
730
|
+
* value from the page too: `value={view}`, so the page can set the view it
|
|
731
|
+
* shows, not only hear it change (NODII-DEV-CLI-83).
|
|
732
|
+
*/
|
|
733
|
+
export function controlHalfControlled(code) {
|
|
734
|
+
return code.replace(/<([A-Z][A-Za-z]*)\b((?:[^>"{]|"(?:[^"\\\n]|\\.)*"|\{[^{}]*(?:\{[^{}]*\}[^{}]*)*\})*?)(\s*\/?)>/g, (all, tag, attrs, close) => {
|
|
735
|
+
const setter = /\bonValueChange=\{set([A-Z][A-Za-z0-9]*)\}/.exec(attrs);
|
|
736
|
+
const sample = new RegExp(String.raw`\bdefaultValue=${LITERAL}`).exec(attrs);
|
|
737
|
+
if (!setter || /\bvalue=/.test(attrs)) return all;
|
|
738
|
+
const value = `value={${setter[1][0].toLowerCase()}${setter[1].slice(1)}}`;
|
|
739
|
+
const sep = attrs.includes("\n") ? `\n${/\n(\s*)onValueChange=/.exec(attrs)?.[1] ?? " "}` : " ";
|
|
740
|
+
return `<${tag}${sample ? attrs.replace(sample[0], value) : attrs.replace(setter[0], `${value}${sep}${setter[0]}`)}${close}>`;
|
|
741
|
+
});
|
|
742
|
+
}
|
|
743
|
+
const cap = (s) => s[0].toUpperCase() + s.slice(1);
|
|
744
|
+
const kebab = (s) => s.replace(/[A-Z]/g, (c) => `-${c.toLowerCase()}`);
|
|
745
|
+
|
|
746
|
+
/**
|
|
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.
|
|
750
|
+
*/
|
|
751
|
+
function fieldScope(node, ctx, attrs) {
|
|
752
|
+
const props = node.instance?.props ?? {};
|
|
753
|
+
const own = [props.label, props.title].find((v) => typeof v === "string" && /[A-Za-z]/.test(v));
|
|
754
|
+
if (own) return camelName(own);
|
|
755
|
+
const placeholder = new RegExp(String.raw`\bplaceholder=(${LITERAL})`).exec(attrs);
|
|
756
|
+
const hint = placeholder ? literalText(placeholder[1]) : "";
|
|
757
|
+
if (/^[^:]{1,32}:/.test(hint)) return camelName(hint.split(":")[0]);
|
|
758
|
+
const shown = (ctx.parent?.children ?? []).filter((c) => c.visible !== false);
|
|
759
|
+
const before = shown[shown.indexOf(node) - 1];
|
|
760
|
+
if (before?.type === "TEXT" && /[A-Za-z]/.test(before.text ?? "") && !/:\s*$/.test(before.text)) return camelName(before.text);
|
|
761
|
+
if (/^search\b/i.test(hint)) return "search";
|
|
762
|
+
const layer = camelName(node.name);
|
|
763
|
+
return layer === camelName(node.instance?.set ?? "") || !layer ? camelName(hint) || "field" : layer;
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
/**
|
|
767
|
+
* Every Input, Textarea and SelectField is controlled by the page: Figma's
|
|
768
|
+
* sample value (`defaultValue="Apex Labs Pvt Ltd"`) becomes the page's value,
|
|
769
|
+
* and a change calls back. A SelectField's id is its own, not the template's
|
|
770
|
+
* shared `id="select"`. The scope also names the template's own identifiers
|
|
771
|
+
* (a select's options), so two filters never share one.
|
|
772
|
+
*/
|
|
773
|
+
function liftFieldControls(code, node, ctx, lift) {
|
|
774
|
+
return code.replace(/<(Input|Textarea|SelectField|RadioGroup)\b((?:[^>"{]|"(?:[^"\\\n]|\\.)*"|\{[^{}]*(?:\{[^{}]*\}[^{}]*)*\})*?)(\s*\/?)>/g, (all, tag, attrs, close) => {
|
|
775
|
+
if (/\b(value|onChange|onValueChange)=/.test(attrs) || /\{\.\.\./.test(attrs)) return all;
|
|
776
|
+
const scope = fieldScope(node, ctx, attrs);
|
|
777
|
+
const sep = attrs.includes("\n") ? `\n${/\n(\s*)/.exec(attrs)[1]}` : " ";
|
|
778
|
+
const value = `value={${lift(scope, `${scope}Value`)}}`;
|
|
779
|
+
const change = `${FIELD_CONTROLS[tag]}={${lift(scope, `on${cap(scope)}Change`)}}`;
|
|
780
|
+
let next = attrs.replace(/\bid="select"/, `id="${kebab(scope)}"`);
|
|
781
|
+
const sample = new RegExp(String.raw`\bdefaultValue=${LITERAL}`).exec(next);
|
|
782
|
+
next = sample ? next.replace(sample[0], `${value}${sep}${change}`) : `${next}${sep}${value}${sep}${change}`;
|
|
783
|
+
return `<${tag}${next}${close}>`;
|
|
784
|
+
});
|
|
785
|
+
}
|
|
786
|
+
|
|
695
787
|
/** Tabs the page controls: its tab is a prop, and choosing one calls back (NODII-DEV-CLI-83). */
|
|
696
788
|
const CONTROLLED_TABS = (value, onChange) => `<Tabs panelless value={${value}} onValueChange={${onChange}}>`;
|
|
697
789
|
|
|
@@ -1062,8 +1154,9 @@ function emitNode(node, ctx) {
|
|
|
1062
1154
|
let own = rendered.code.trim().replace(/=\{<>\{([a-z][A-Za-z0-9]*)\}<\/>\}/g, "={$1}");
|
|
1063
1155
|
// A tab strip the page controls (tabOf reads the template's own strip first, to gather a run).
|
|
1064
1156
|
if (!ctx.tabProbe) own = own.replace(/<Tabs panelless(?: defaultValue="[^"]*")?>/g, CONTROLLED_TABS("tab", "onTabChange"));
|
|
1065
|
-
own = liftRecordData(own, node, ctx, path);
|
|
1066
|
-
const
|
|
1157
|
+
own = controlHalfControlled(liftRecordData(own, node, ctx, path));
|
|
1158
|
+
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;
|
|
1067
1160
|
// A Table part is valid only inside the DS Table. One the generator could not assemble
|
|
1068
1161
|
// into a Table stays reported, never passed off as mapped (MW8-17.3).
|
|
1069
1162
|
const tag = /^<([A-Za-z]+)/.exec(code)?.[1];
|
|
@@ -1091,7 +1184,15 @@ function emitNode(node, ctx) {
|
|
|
1091
1184
|
{ CENTER: "text-center", RIGHT: "text-right", JUSTIFIED: "text-justify" }[node.align],
|
|
1092
1185
|
node.maxLines === 1 ? "truncate" : node.maxLines ? `line-clamp-${node.maxLines}` : null,
|
|
1093
1186
|
]);
|
|
1094
|
-
|
|
1187
|
+
// Text naming a record's value (a date, an amount, a code) is Figma's sample: the page's own (NODII-DEV-CLI-82).
|
|
1188
|
+
let content = JSON.stringify(node.text);
|
|
1189
|
+
if (SAMPLE_VALUE.test(node.text) && !ctx.textOwner) {
|
|
1190
|
+
const scope = positionScope(node, ctx, "text");
|
|
1191
|
+
const name = mark(ctx, scope, scope);
|
|
1192
|
+
note(path, LIFTED, `text ${shown} names a record's value: lifted from Figma's sample into the page's props (NODII-DEV-CLI-82)`);
|
|
1193
|
+
content = name;
|
|
1194
|
+
}
|
|
1195
|
+
return indent(`<span${classes ? ` className="${classes}"` : ""}>{${content}}</span>`, depth);
|
|
1095
1196
|
}
|
|
1096
1197
|
|
|
1097
1198
|
// A shape is not a DS part: it is marked and reported, never drawn as a look-alike (MW2-37.2).
|
package/dist/watchdog.js
CHANGED
|
@@ -398,9 +398,23 @@ export async function sweepWatchdog({
|
|
|
398
398
|
|
|
399
399
|
const xml = (value) => String(value).replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll('"', """).replaceAll("'", "'");
|
|
400
400
|
|
|
401
|
-
|
|
401
|
+
/**
|
|
402
|
+
* hub-251: launchd starts a job with PATH=/usr/bin:/bin:/usr/sbin:/sbin, where
|
|
403
|
+
* a lane runtime such as `claude` (~/.local/bin) or `codex` is not found, so a
|
|
404
|
+
* resume-due lane's relaunch failed with `Executable not found in $PATH`. The
|
|
405
|
+
* plist carries the installing shell's PATH, plus the directory of the runtime
|
|
406
|
+
* that runs the CLI.
|
|
407
|
+
*/
|
|
408
|
+
export function watchdogPath(envPath = process.env.PATH, runtime = process.execPath) {
|
|
409
|
+
const dirs = [dirname(runtime), ...String(envPath ?? "").split(":"), "/usr/bin", "/bin", "/usr/sbin", "/sbin"];
|
|
410
|
+
// A package runner's own bins (npx's _npx cache, node_modules/.bin) are left out: they are temporary.
|
|
411
|
+
const kept = dirs.filter((dir) => dir && dir.startsWith("/") && !dir.includes("/node_modules/") && !dir.includes("/_npx/"));
|
|
412
|
+
return [...new Set(kept)].join(":");
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
export function launchdPlist({ runtime, entry, config, interval, stdoutPath, stderrPath, path = watchdogPath(undefined, runtime) }) {
|
|
402
416
|
const args = [runtime, entry, "watchdog", "sweep", "--json"].map((value) => `<string>${xml(value)}</string>`).join("");
|
|
403
|
-
return `<?xml version="1.0" encoding="UTF-8"?>\n<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">\n<plist version="1.0"><dict><key>Label</key><string>${WATCHDOG_LABEL}</string><key>ProgramArguments</key><array>${args}</array><key>EnvironmentVariables</key><dict><key>NODII_DEV_CONFIG_PATH</key><string>${xml(config)}</string></dict><key>RunAtLoad</key><true/><key>StartInterval</key><integer>${interval}</integer><key>ProcessType</key><string>Background</string><key>StandardOutPath</key><string>${xml(stdoutPath)}</string><key>StandardErrorPath</key><string>${xml(stderrPath)}</string></dict></plist>\n`;
|
|
417
|
+
return `<?xml version="1.0" encoding="UTF-8"?>\n<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">\n<plist version="1.0"><dict><key>Label</key><string>${WATCHDOG_LABEL}</string><key>ProgramArguments</key><array>${args}</array><key>EnvironmentVariables</key><dict><key>NODII_DEV_CONFIG_PATH</key><string>${xml(config)}</string><key>PATH</key><string>${xml(path)}</string></dict><key>RunAtLoad</key><true/><key>StartInterval</key><integer>${interval}</integer><key>ProcessType</key><string>Background</string><key>StandardOutPath</key><string>${xml(stdoutPath)}</string><key>StandardErrorPath</key><string>${xml(stderrPath)}</string></dict></plist>\n`;
|
|
404
418
|
}
|
|
405
419
|
|
|
406
420
|
export async function installWatchdog({
|