@nodii/dev 0.6.164 → 0.6.165
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 +32 -5
- 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.165";
|
|
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
|
@@ -27,12 +27,12 @@
|
|
|
27
27
|
import { execFileSync } from "node:child_process";
|
|
28
28
|
import { existsSync, mkdirSync, readFileSync, readdirSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
29
29
|
import { tmpdir } from "node:os";
|
|
30
|
-
import { dirname, join, relative, resolve } from "node:path";
|
|
30
|
+
import { basename, 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 =
|
|
35
|
+
export const GENERATOR_FORMAT = 34;
|
|
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). */
|
|
@@ -505,6 +505,31 @@ export function mergeImports(statements, body = null) {
|
|
|
505
505
|
return [...lines, ...[...other].sort()];
|
|
506
506
|
}
|
|
507
507
|
|
|
508
|
+
/** The registry is the authority for block aliases used by Code Connect. */
|
|
509
|
+
export function blockImportPaths(items) {
|
|
510
|
+
const paths = new Map();
|
|
511
|
+
for (const item of items) {
|
|
512
|
+
if (item.type !== "registry:block") continue;
|
|
513
|
+
const files = item.files ?? [];
|
|
514
|
+
for (const file of files) {
|
|
515
|
+
const name = files.length === 1 ? item.name : basename(file.path).replace(/-block(\.tsx?)$/, "$1").replace(/\.[^.]+$/, "");
|
|
516
|
+
paths.set(`@/components/ui/${name}`, file.path);
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
return paths;
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
/** Generated pages live in blocks itself, so use the registry's source, not a consumer alias. */
|
|
523
|
+
export function resolveBlockImports(imports, sourcePath, paths = new Map()) {
|
|
524
|
+
if (!sourcePath) return imports;
|
|
525
|
+
return imports.map(statement => statement.replace(/\bfrom\s+(["'])(@\/components\/ui\/[^"']+)\1/, (all, quote, alias) => {
|
|
526
|
+
const target = paths.get(alias);
|
|
527
|
+
if (!target) return all;
|
|
528
|
+
const path = relative(dirname(sourcePath), target).replaceAll("\\", "/").replace(/\.tsx?$/, "");
|
|
529
|
+
return `from ${quote}${path.startsWith(".") ? path : `./${path}`}${quote}`;
|
|
530
|
+
}));
|
|
531
|
+
}
|
|
532
|
+
|
|
508
533
|
/** The design system's inputs to emitting: templates, the key index, tokens and text utilities. */
|
|
509
534
|
export function loadDesignSystem(root, { exec = execFileSync, docs } = {}) {
|
|
510
535
|
const dsFileKey = readJson(join(root, DS_FILE_META)).fileKey;
|
|
@@ -527,7 +552,9 @@ export function loadDesignSystem(root, { exec = execFileSync, docs } = {}) {
|
|
|
527
552
|
const set = optionalProps.get(doc.component) ?? optionalProps.set(doc.component, new Set()).get(doc.component);
|
|
528
553
|
for (const name of listed) set.add(name);
|
|
529
554
|
}
|
|
530
|
-
|
|
555
|
+
const registryPath = join(root, "apps/web/public/registry.json");
|
|
556
|
+
const registry = existsSync(registryPath) ? readJson(registryPath) : [];
|
|
557
|
+
return { dsFileKey, renderer, byKey, colours, textStyles, optionalProps, blockImports: blockImportPaths(registry.items ?? registry) };
|
|
531
558
|
}
|
|
532
559
|
|
|
533
560
|
/** `figma connect parse`, the repository's own Code Connect compile, into memory. */
|
|
@@ -602,7 +629,7 @@ export function emitSurface(tree, row, ds) {
|
|
|
602
629
|
];
|
|
603
630
|
const lines = [
|
|
604
631
|
...header,
|
|
605
|
-
...mergeImports([...imports, ...(reactTypes.length ? [`import type { ${reactTypes.join(", ")} } from "react";`] : [])], [...views.map((v) => v.body), reactTypes.join(" ")].join("\n")),
|
|
632
|
+
...mergeImports(resolveBlockImports([...imports, ...(reactTypes.length ? [`import type { ${reactTypes.join(", ")} } from "react";`] : [])], row.sourcePath, ds.blockImports), [...views.map((v) => v.body), reactTypes.join(" ")].join("\n")),
|
|
606
633
|
"",
|
|
607
634
|
`export type ${stateType} = ${views.map((v) => JSON.stringify(v.state)).join(" | ")};`,
|
|
608
635
|
"",
|
|
@@ -989,7 +1016,7 @@ function liftRecordData(code, node, ctx, path, scope = scopeName(node)) {
|
|
|
989
1016
|
const scope = nameOf(label ? literalText(label[1]) : node.name, node.name);
|
|
990
1017
|
return `<DescriptionItem${attrs.replace(value[0], `value={${lift(scope, "value")}}`)}/>`;
|
|
991
1018
|
});
|
|
992
|
-
out = rewriteTags(out, "DetailFact", (attrs) => {
|
|
1019
|
+
out = rewriteTags(out, "DetailFact|RightPaneRow", (attrs) => {
|
|
993
1020
|
const parsed = tagAttributes(`${attrs}>`, 0);
|
|
994
1021
|
if (!parsed?.literals.has("value")) return attrs;
|
|
995
1022
|
const label = parsed.literals.get("label");
|