@marver-design/marver 0.10.2 → 0.11.0
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/CHANGELOG.md +143 -0
- package/dist/auth-B5yuwnOq.mjs +494 -0
- package/dist/{build-zUf_kwKp.mjs → build-Cr_ZLMdq.mjs} +3 -2
- package/dist/cli.mjs +6 -6
- package/dist/{collab-s3k5byM1.mjs → collab-C-n-uQdm.mjs} +67 -11
- package/dist/{comments-J06jqCVV.mjs → comments-CRqaO2MH.mjs} +26 -11
- package/dist/{comments-BZBKhKRO.mjs → comments-DZyobpxG.mjs} +8 -2
- package/dist/{manifest-DIsp3ldB.mjs → config-t9coJ-Pq.mjs} +3 -233
- package/dist/{daemon-BpKBJZee.mjs → daemon-DSmaS453.mjs} +23 -5
- package/dist/{dev-D2PG6igI.mjs → dev-CLBjRs0J.mjs} +117 -13
- package/dist/{init-DwV0_d9G.mjs → init-BSclDg4I.mjs} +2 -1
- package/dist/manifest-C2tzkNaC.mjs +233 -0
- package/dist/marver-id-B8-3WiHk.mjs +411 -0
- package/dist/marver-id-gate-BDzW6ahN.mjs +728 -0
- package/dist/{plugin-C1sDewZ3.mjs → plugin-vE7sxEeT.mjs} +12 -84
- package/dist/{profile-BkiWglVE.mjs → profile-DcsJyppw.mjs} +9 -6
- package/dist/{serve-CZqPnj19.mjs → serve-CZ1KEQxd.mjs} +194 -42
- package/dist/sync-DELGomPk.mjs +397 -0
- package/dist/update-DuWDj5nR.mjs +77 -0
- package/dist/utm-CxC3QN5X.mjs +20 -0
- package/package.json +1 -1
- package/src/shared/utm.ts +2 -2
- package/templates/instructions/configure.md +4 -0
- package/templates/instructions/publish.md +84 -15
- package/dist/auth-KQ9Aj-nB.mjs +0 -245
- package/dist/events-BMtBvvgU.mjs +0 -101
- package/dist/sync-BJKKmy1n.mjs +0 -150
- package/dist/{shot-D7I0MCLu.mjs → shot-Cyv3GN79.mjs} +1 -1
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { n as NAME, r as PKG } from "./cli.mjs";
|
|
2
|
-
import {
|
|
3
|
-
import { n as tailwind3Css, r as tailwind4Plugin, t as marverPlugin } from "./plugin-
|
|
4
|
-
import {
|
|
2
|
+
import { i as detectHost, n as loadConfig } from "./config-t9coJ-Pq.mjs";
|
|
3
|
+
import { n as tailwind3Css, r as tailwind4Plugin, t as marverPlugin } from "./plugin-vE7sxEeT.mjs";
|
|
4
|
+
import { realpathSync } from "node:fs";
|
|
5
|
+
import { basename, dirname, isAbsolute, join, relative, resolve } from "node:path";
|
|
5
6
|
import { fileURLToPath } from "node:url";
|
|
6
7
|
import { createLogger, createServer, searchForWorkspaceRoot } from "vite";
|
|
7
8
|
import react from "@vitejs/plugin-react";
|
|
@@ -44,6 +45,106 @@ async function pickPort(root, desired) {
|
|
|
44
45
|
fellBack: true
|
|
45
46
|
};
|
|
46
47
|
}
|
|
48
|
+
/**
|
|
49
|
+
* What the dev server must never hand out, however deep in the repo it sits.
|
|
50
|
+
*
|
|
51
|
+
* `marver dev` puts the whole repository on the web so frames can import from it.
|
|
52
|
+
* The collaboration credential no longer lives in there - it moved to
|
|
53
|
+
* ~/.marver/canvases/ precisely because guarding it here could not be finished -
|
|
54
|
+
* but design/.local still holds the local profile and whatever a previous version
|
|
55
|
+
* left behind, and none of that is anybody's business but the author's.
|
|
56
|
+
*
|
|
57
|
+
* Vite's own defaults are restated rather than assumed. `fs.deny` REPLACES the
|
|
58
|
+
* default list, so an array containing only our own rule quietly re-exposes
|
|
59
|
+
* `.env`, private keys, `.npmrc` and `.git` - a much larger hole than the one
|
|
60
|
+
* being closed, opened by closing it. Kept as an exported constant so a test can
|
|
61
|
+
* hold both halves.
|
|
62
|
+
*/
|
|
63
|
+
const FS_DENY = [
|
|
64
|
+
".env",
|
|
65
|
+
".env.*",
|
|
66
|
+
"*.{crt,pem,key,p12,pfx,cer,der}",
|
|
67
|
+
".npmrc",
|
|
68
|
+
".yarnrc.yml",
|
|
69
|
+
"**/.git/**",
|
|
70
|
+
".dev.vars",
|
|
71
|
+
".dev.vars.*",
|
|
72
|
+
"**/design/.local/**"
|
|
73
|
+
];
|
|
74
|
+
/**
|
|
75
|
+
* The half of the credential guard that globs cannot do.
|
|
76
|
+
*
|
|
77
|
+
* `fs.deny` matches the REQUEST path, lexically, and then Vite stats and streams
|
|
78
|
+
* whatever that path resolves to. So a repository containing
|
|
79
|
+
* `leak.json -> design/.local/anything` serves that file at `/leak.json` to any
|
|
80
|
+
* authored frame that asks - the deny rule never sees the name it is looking for.
|
|
81
|
+
* Verified against a real dev server before this existed.
|
|
82
|
+
*
|
|
83
|
+
* More patterns cannot fix that; only resolving can. This runs BEFORE Vite's own
|
|
84
|
+
* middlewares (a `configureServer` hook that does not return a function is
|
|
85
|
+
* installed first) and refuses any request whose real file lands inside
|
|
86
|
+
* design/.local, whatever route it took to get there.
|
|
87
|
+
*
|
|
88
|
+
* "Whatever route" means every place Vite would look, not just the project root.
|
|
89
|
+
* `public/` is mapped onto `/`, so `public/leak.json -> ../design/.local/x` is
|
|
90
|
+
* served at `/leak.json` - and Vite skips its own deny checks entirely for public
|
|
91
|
+
* files, so that spelling was reachable even with the root candidate guarded.
|
|
92
|
+
* Each candidate is resolved; if any lands in design/.local, the request is
|
|
93
|
+
* refused.
|
|
94
|
+
*
|
|
95
|
+
* The boundary this does NOT claim: a repository that can write symlinks can also
|
|
96
|
+
* write `design/config.ts`, which `marver dev` imports and RUNS in this process
|
|
97
|
+
* before any of the above exists. Running `dev` on a repository you do not trust
|
|
98
|
+
* hands it your machine long before it hands it a file, so a symlink is not the
|
|
99
|
+
* interesting way in. What this closes is the frame-in-a-trusted-repo case: a
|
|
100
|
+
* component that runs in the browser, same-origin, that can only ask for URLs and
|
|
101
|
+
* cannot create a file to ask for.
|
|
102
|
+
*/
|
|
103
|
+
function denyLocalSecrets(root) {
|
|
104
|
+
const guardedAt = join(root, "design", ".local");
|
|
105
|
+
const publicAt = join(root, "public");
|
|
106
|
+
const inside = (real, dir) => {
|
|
107
|
+
const rel = relative(dir, real);
|
|
108
|
+
return rel === "" || !rel.startsWith("..") && !isAbsolute(rel);
|
|
109
|
+
};
|
|
110
|
+
return {
|
|
111
|
+
name: "marver:deny-local-secrets",
|
|
112
|
+
configureServer(server) {
|
|
113
|
+
server.middlewares.use((req, res, next) => {
|
|
114
|
+
let pathname;
|
|
115
|
+
try {
|
|
116
|
+
pathname = decodeURIComponent((req.url ?? "/").split("?")[0].split("#")[0]);
|
|
117
|
+
} catch {
|
|
118
|
+
return next();
|
|
119
|
+
}
|
|
120
|
+
const rel = "." + (pathname.startsWith("/") ? pathname : `/${pathname}`);
|
|
121
|
+
const derived = (base) => [
|
|
122
|
+
base,
|
|
123
|
+
`${base}.html`,
|
|
124
|
+
join(base, "index"),
|
|
125
|
+
join(base, "index.html")
|
|
126
|
+
];
|
|
127
|
+
const candidates = pathname.startsWith("/@fs/") ? derived(pathname.slice(4)) : [...derived(resolve(root, rel)), ...derived(resolve(publicAt, rel))];
|
|
128
|
+
let guarded;
|
|
129
|
+
try {
|
|
130
|
+
guarded = realpathSync(guardedAt);
|
|
131
|
+
} catch {
|
|
132
|
+
return next();
|
|
133
|
+
}
|
|
134
|
+
if (!candidates.some((c) => {
|
|
135
|
+
try {
|
|
136
|
+
return inside(realpathSync(c), guarded);
|
|
137
|
+
} catch {
|
|
138
|
+
return false;
|
|
139
|
+
}
|
|
140
|
+
})) return next();
|
|
141
|
+
res.statusCode = 403;
|
|
142
|
+
res.setHeader("content-type", "text/plain; charset=utf-8");
|
|
143
|
+
res.end("design/.local holds this canvas's credentials and is never served");
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
}
|
|
47
148
|
async function dev(root, portFlag) {
|
|
48
149
|
const config = await loadConfig(root);
|
|
49
150
|
const host = detectHost(root);
|
|
@@ -52,7 +153,7 @@ async function dev(root, portFlag) {
|
|
|
52
153
|
const projectName = basename(root);
|
|
53
154
|
const desiredPort = portFlag ?? (config.port !== 5199 ? config.port : void 0) ?? projectPort(root);
|
|
54
155
|
const picked = await pickPort(root, desiredPort);
|
|
55
|
-
const plugins = [react()];
|
|
156
|
+
const plugins = [denyLocalSecrets(root), react()];
|
|
56
157
|
if (host.tailwind === 4) {
|
|
57
158
|
const tw = await tailwind4Plugin(root);
|
|
58
159
|
if (tw) plugins.push(...tw);
|
|
@@ -85,11 +186,14 @@ async function dev(root, portFlag) {
|
|
|
85
186
|
server: {
|
|
86
187
|
port: picked.port,
|
|
87
188
|
strictPort: false,
|
|
88
|
-
fs: {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
189
|
+
fs: {
|
|
190
|
+
allow: [.../* @__PURE__ */ new Set([
|
|
191
|
+
root,
|
|
192
|
+
pkgDir,
|
|
193
|
+
searchForWorkspaceRoot(root)
|
|
194
|
+
])],
|
|
195
|
+
deny: FS_DENY
|
|
196
|
+
},
|
|
93
197
|
watch: { ignored: [
|
|
94
198
|
"**/design/manifest.json",
|
|
95
199
|
"**/design/boards/**",
|
|
@@ -143,7 +247,7 @@ async function dev(root, portFlag) {
|
|
|
143
247
|
console.log(`\n ${NAME} · ${projectName} → http://localhost:${port}/\n`);
|
|
144
248
|
try {
|
|
145
249
|
const { staleManagedInstructions } = await import("./managed-HwHVNI3h.mjs");
|
|
146
|
-
const { installedVersion } = await import("./
|
|
250
|
+
const { installedVersion } = await import("./update-DuWDj5nR.mjs").then((n) => n.r);
|
|
147
251
|
const stale = staleManagedInstructions(root);
|
|
148
252
|
if (stale.length) {
|
|
149
253
|
const shown = stale.slice(0, 4).join(", ") + (stale.length > 4 ? `, +${stale.length - 4} more` : "");
|
|
@@ -151,8 +255,8 @@ async function dev(root, portFlag) {
|
|
|
151
255
|
console.log(` instructions predate ${v ? NAME + " " + v : "the installed version"} (${shown}) - run: npx ${NAME} init\n`);
|
|
152
256
|
}
|
|
153
257
|
} catch {}
|
|
154
|
-
const { loadCollab, syncOnce } = await import("./sync-
|
|
155
|
-
if (loadCollab(root)) console.log(` comments: syncing with the published canvas
|
|
258
|
+
const { loadCollab, syncOnce } = await import("./sync-DELGomPk.mjs").then((n) => n.o);
|
|
259
|
+
if (loadCollab(root)) console.log(` comments: syncing with the published canvas\n`);
|
|
156
260
|
let syncing = false;
|
|
157
261
|
const tick = async () => {
|
|
158
262
|
if (syncing) return;
|
|
@@ -181,7 +285,7 @@ async function dev(root, portFlag) {
|
|
|
181
285
|
});
|
|
182
286
|
}
|
|
183
287
|
if (config.jam) {
|
|
184
|
-
const { startJam } = await import("./daemon-
|
|
288
|
+
const { startJam } = await import("./daemon-DSmaS453.mjs");
|
|
185
289
|
const jam = startJam(root, config.jam, (m) => console.log(m), (board) => server.ws.send("sh:jam-comment", { board }));
|
|
186
290
|
if (jam) {
|
|
187
291
|
const close = server.close.bind(server);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { n as NAME } from "./cli.mjs";
|
|
2
|
-
import { a as
|
|
2
|
+
import { a as readJson, i as detectHost, r as detectAgent, t as DEFAULTS } from "./config-t9coJ-Pq.mjs";
|
|
3
|
+
import { a as writeManifest, r as scanFrames } from "./manifest-C2tzkNaC.mjs";
|
|
3
4
|
import { MANAGED_PREFIX, enumerateInstructionTemplates, hashBody, managedFile, pkgDir } from "./managed-HwHVNI3h.mjs";
|
|
4
5
|
import { cpSync, existsSync, mkdirSync, readFileSync, readdirSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
5
6
|
import { dirname, join, relative } from "node:path";
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
import { r as PKG, t as CONTENT_WIDTH } from "./cli.mjs";
|
|
2
|
+
import { existsSync, mkdirSync, readFileSync, readdirSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { join, relative, sep } from "node:path";
|
|
4
|
+
import { createHash } from "node:crypto";
|
|
5
|
+
//#region src/server/manifest.ts
|
|
6
|
+
const FRAME_EXT = /\.(tsx|jsx|html)$/;
|
|
7
|
+
const RESERVED_SCENES = /* @__PURE__ */ new Set(["components", "screens"]);
|
|
8
|
+
/** Extract `export const meta = {...}` with literal string values only. Anything else is silently omitted. */
|
|
9
|
+
function extractMeta(src) {
|
|
10
|
+
const m = /export\s+const\s+meta\s*=\s*\{([\s\S]*?)\}/.exec(src);
|
|
11
|
+
if (!m) return {};
|
|
12
|
+
const body = m[1];
|
|
13
|
+
const pick = (key) => {
|
|
14
|
+
const r = new RegExp(`(?:^|[{,])\\s*${key}\\s*:\\s*(['"\`])([^'"\`]*)\\1`).exec(body);
|
|
15
|
+
return r ? r[2] : void 0;
|
|
16
|
+
};
|
|
17
|
+
const out = {};
|
|
18
|
+
const title = pick("title");
|
|
19
|
+
if (title) out.title = title;
|
|
20
|
+
const viewport = pick("viewport");
|
|
21
|
+
if (viewport) out.viewport = viewport;
|
|
22
|
+
const theme = pick("theme");
|
|
23
|
+
if (theme) out.theme = theme;
|
|
24
|
+
const of = pick("of");
|
|
25
|
+
if (of) out.of = of;
|
|
26
|
+
const variant = pick("variant");
|
|
27
|
+
if (variant) out.variant = variant;
|
|
28
|
+
const intent = pick("intent");
|
|
29
|
+
if (intent) out.intent = intent;
|
|
30
|
+
return out;
|
|
31
|
+
}
|
|
32
|
+
/** Content-frame detection: LEXICAL by convention - the frame file
|
|
33
|
+
* itself imports PKG/content (an import specifier scan, so "<Diagram" inside a
|
|
34
|
+
* string in a UI frame can never misbadge it; barrels/re-exports are not
|
|
35
|
+
* detected - meta.intent is the taught path and always works). Returns the
|
|
36
|
+
* inferred intent + natural width, or null for UI frames. */
|
|
37
|
+
const CONTENT_IMPORT = new RegExp(`from\\s+['"]${PKG}/content['"]`);
|
|
38
|
+
const WIDE_DOC = /<Doc\b[^>]*\blayout\s*=\s*["']wide["']/;
|
|
39
|
+
const contentWidthOf = (src) => WIDE_DOC.test(src) ? CONTENT_WIDTH.wide : CONTENT_WIDTH.document;
|
|
40
|
+
function contentScan(src) {
|
|
41
|
+
if (!CONTENT_IMPORT.test(src)) return null;
|
|
42
|
+
const count = (re) => (src.match(re) ?? []).length;
|
|
43
|
+
const diagrams = count(/<Diagram[\s>/]/g);
|
|
44
|
+
const imgs = count(/<Img[\s>/]/g);
|
|
45
|
+
const mds = count(/<Md[\s>/]/g);
|
|
46
|
+
return {
|
|
47
|
+
intent: diagrams > 0 ? "diagram" : imgs > mds ? "moodboard" : "spec",
|
|
48
|
+
width: contentWidthOf(src)
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
/** id = path relative to design/, extension dropped, `scenes/` prefix dropped. Always `/`-separated. */
|
|
52
|
+
function toFrameId(designRelPath) {
|
|
53
|
+
const noExt = designRelPath.split(sep).join("/").replace(FRAME_EXT, "");
|
|
54
|
+
return noExt.startsWith("scenes/") ? noExt.slice(7) : noExt;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* A7: which frames does a changed `design/**` file affect? Manifest + directory conventions,
|
|
58
|
+
* NOT a module-graph walk (deterministic, cheap, may over-reload but never misses a
|
|
59
|
+
* conventionally-affected frame). Returns:
|
|
60
|
+
* null -> uncontrolled: leave to default Vite HMR (src/** deps, theme.css, config, assets)
|
|
61
|
+
* [] -> controlled but affects no current frame (e.g. a layout in an empty dir)
|
|
62
|
+
* [ids] -> controlled: the shell drives a rev-stamped reload of these frames
|
|
63
|
+
*/
|
|
64
|
+
function affectedFrameIds(absFile, root, manifest) {
|
|
65
|
+
const design = join(root, "design");
|
|
66
|
+
if (absFile !== design && !absFile.startsWith(design + sep)) return null;
|
|
67
|
+
const rel = relative(design, absFile).split(sep).join("/");
|
|
68
|
+
const name = rel.split("/").pop() ?? rel;
|
|
69
|
+
const designRel = `design/${rel}`;
|
|
70
|
+
const tsxFrames = manifest.frames.filter((f) => f.kind === "tsx");
|
|
71
|
+
if (name === "theme.css") return null;
|
|
72
|
+
if (rel === "providers.tsx" || rel === "providers.jsx") return tsxFrames.map((f) => f.id);
|
|
73
|
+
if (/(^|\/)(_layout\.(tsx|jsx)|_fixtures\.(ts|tsx|js|jsx|json))$/.test(rel)) {
|
|
74
|
+
const prefix = `design/${rel.slice(0, rel.length - name.length)}`;
|
|
75
|
+
return tsxFrames.filter((f) => f.file.startsWith(prefix)).map((f) => f.id);
|
|
76
|
+
}
|
|
77
|
+
const direct = manifest.frames.find((f) => f.file === designRel);
|
|
78
|
+
if (direct) return [direct.id];
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
function walk(dir, out = []) {
|
|
82
|
+
if (!existsSync(dir)) return out;
|
|
83
|
+
for (const e of readdirSync(dir, { withFileTypes: true })) {
|
|
84
|
+
if (e.name.startsWith(".")) continue;
|
|
85
|
+
const p = join(dir, e.name);
|
|
86
|
+
if (e.isDirectory()) walk(p, out);
|
|
87
|
+
else out.push(p);
|
|
88
|
+
}
|
|
89
|
+
return out;
|
|
90
|
+
}
|
|
91
|
+
function scanFrames(root) {
|
|
92
|
+
const design = join(root, "design");
|
|
93
|
+
const frames = [];
|
|
94
|
+
for (const base of ["scenes", "components"]) for (const abs of walk(join(design, base))) {
|
|
95
|
+
const name = abs.split(sep).pop();
|
|
96
|
+
if (name.startsWith("_") || !FRAME_EXT.test(name)) continue;
|
|
97
|
+
const rel = relative(design, abs).split(sep).join("/");
|
|
98
|
+
const id = toFrameId(rel);
|
|
99
|
+
const scene = id.includes("/") ? id.split("/")[0] : "";
|
|
100
|
+
if (base === "scenes" && RESERVED_SCENES.has(scene)) {
|
|
101
|
+
console.error(`[marver] scene "${scene}" is a reserved name - "${rel}" skipped. Rename the scene.`);
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
const kind = name.endsWith(".html") ? "html" : "tsx";
|
|
105
|
+
const entry = {
|
|
106
|
+
id,
|
|
107
|
+
file: `design/${rel}`,
|
|
108
|
+
kind,
|
|
109
|
+
scene
|
|
110
|
+
};
|
|
111
|
+
if (kind === "tsx") {
|
|
112
|
+
const src = readFileSync(abs, "utf8");
|
|
113
|
+
const meta = extractMeta(src);
|
|
114
|
+
if (meta.title) entry.title = meta.title;
|
|
115
|
+
if (meta.viewport) entry.viewport = meta.viewport;
|
|
116
|
+
if (meta.theme) entry.theme = meta.theme;
|
|
117
|
+
if (meta.of) entry.variantGroup = meta.of;
|
|
118
|
+
if (meta.variant) entry.variant = meta.variant;
|
|
119
|
+
const content = contentScan(src);
|
|
120
|
+
if (content || meta.intent) {
|
|
121
|
+
entry.intent = meta.intent ?? content.intent;
|
|
122
|
+
entry.contentWidth = content?.width ?? contentWidthOf(src);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
frames.push(entry);
|
|
126
|
+
}
|
|
127
|
+
const extRank = (file) => file.endsWith(".tsx") ? 0 : file.endsWith(".jsx") ? 1 : 2;
|
|
128
|
+
frames.sort((a, b) => a.id.localeCompare(b.id) || extRank(a.file) - extRank(b.file) || a.file.localeCompare(b.file));
|
|
129
|
+
const seen = /* @__PURE__ */ new Map();
|
|
130
|
+
const deduped = frames.filter((f) => {
|
|
131
|
+
const prev = seen.get(f.id);
|
|
132
|
+
if (prev) {
|
|
133
|
+
console.error(`[marver] duplicate frame id "${f.id}" (${prev} vs ${f.file}) - keeping ${prev}.`);
|
|
134
|
+
return false;
|
|
135
|
+
}
|
|
136
|
+
seen.set(f.id, f.file);
|
|
137
|
+
return true;
|
|
138
|
+
});
|
|
139
|
+
frames.length = 0;
|
|
140
|
+
frames.push(...deduped);
|
|
141
|
+
inferVariantGroups(frames);
|
|
142
|
+
const sceneCounts = /* @__PURE__ */ new Map();
|
|
143
|
+
for (const f of frames) sceneCounts.set(f.scene, (sceneCounts.get(f.scene) ?? 0) + 1);
|
|
144
|
+
return {
|
|
145
|
+
frames,
|
|
146
|
+
scenes: [...sceneCounts.entries()].map(([name, n]) => ({
|
|
147
|
+
name,
|
|
148
|
+
frames: n
|
|
149
|
+
})).sort((a, b) => a.name.localeCompare(b.name))
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
/** Variant groups. A group = 2+ frames in one DIRECTORY whose basenames
|
|
153
|
+
* are letter-prefixed (`a-terminal`), or frames declaring `meta.of`. Group id = the
|
|
154
|
+
* directory's id prefix (or meta.of); variant key = the letter (or meta.variant).
|
|
155
|
+
* Nested directories scope alternatives inside a busy scene (checkout/payment/a-card).
|
|
156
|
+
* States (empty.tsx, error.tsx) never letter-prefix, so they never misgroup.
|
|
157
|
+
* Mutates entries in place: only frames whose group materializes keep the fields. */
|
|
158
|
+
function inferVariantGroups(frames) {
|
|
159
|
+
const dirOf = (id) => {
|
|
160
|
+
const i = id.lastIndexOf("/");
|
|
161
|
+
return i >= 0 ? id.slice(0, i) : "";
|
|
162
|
+
};
|
|
163
|
+
const candidates = /* @__PURE__ */ new Map();
|
|
164
|
+
for (const f of frames) {
|
|
165
|
+
if (f.kind !== "tsx") {
|
|
166
|
+
delete f.variantGroup;
|
|
167
|
+
delete f.variant;
|
|
168
|
+
continue;
|
|
169
|
+
}
|
|
170
|
+
let group = f.variantGroup;
|
|
171
|
+
let key = f.variant;
|
|
172
|
+
if (!group) {
|
|
173
|
+
const base = f.id.slice(f.id.lastIndexOf("/") + 1);
|
|
174
|
+
const m = /^([a-z])-.+$/.exec(base);
|
|
175
|
+
if (!m) continue;
|
|
176
|
+
group = dirOf(f.id);
|
|
177
|
+
if (!group) continue;
|
|
178
|
+
key = key ?? m[1];
|
|
179
|
+
} else if (!key) {
|
|
180
|
+
const m = /^([a-z])-.+$/.exec(f.id.slice(f.id.lastIndexOf("/") + 1));
|
|
181
|
+
if (!m) {
|
|
182
|
+
console.warn(`[marver] ${f.file} declares of:"${group}" but no variant key (add meta.variant or a letter prefix) - not grouped.`);
|
|
183
|
+
delete f.variantGroup;
|
|
184
|
+
delete f.variant;
|
|
185
|
+
continue;
|
|
186
|
+
}
|
|
187
|
+
key = m[1];
|
|
188
|
+
}
|
|
189
|
+
f.variantGroup = group;
|
|
190
|
+
f.variant = key;
|
|
191
|
+
candidates.set(group, [...candidates.get(group) ?? [], f]);
|
|
192
|
+
}
|
|
193
|
+
for (const [group, members] of candidates) {
|
|
194
|
+
if (new Set(members.map((m) => dirOf(m.id))).size > 1) {
|
|
195
|
+
console.warn(`[marver] group "${group}" spans directories - variants must be siblings; not grouped.`);
|
|
196
|
+
for (const m of members) {
|
|
197
|
+
delete m.variantGroup;
|
|
198
|
+
delete m.variant;
|
|
199
|
+
}
|
|
200
|
+
continue;
|
|
201
|
+
}
|
|
202
|
+
const seen = /* @__PURE__ */ new Set();
|
|
203
|
+
const kept = [];
|
|
204
|
+
for (const m of members.sort((a, b) => (a.variant ?? "").localeCompare(b.variant ?? ""))) {
|
|
205
|
+
if (seen.has(m.variant)) {
|
|
206
|
+
console.warn(`[marver] duplicate variant "${m.variant}" in group "${group}" (${m.file}) - not grouped.`);
|
|
207
|
+
delete m.variantGroup;
|
|
208
|
+
delete m.variant;
|
|
209
|
+
continue;
|
|
210
|
+
}
|
|
211
|
+
seen.add(m.variant);
|
|
212
|
+
kept.push(m);
|
|
213
|
+
}
|
|
214
|
+
if (kept.length < 2) for (const m of kept) {
|
|
215
|
+
delete m.variantGroup;
|
|
216
|
+
delete m.variant;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
for (const f of frames) if (f.variant && !f.variantGroup) delete f.variant;
|
|
220
|
+
}
|
|
221
|
+
/** Write design/manifest.json only when content changed. Returns the manifest either way. */
|
|
222
|
+
function writeManifest(root, manifest) {
|
|
223
|
+
const file = join(root, "design", "manifest.json");
|
|
224
|
+
const next = JSON.stringify(manifest, null, 2) + "\n";
|
|
225
|
+
const prev = existsSync(file) ? readFileSync(file, "utf8") : "";
|
|
226
|
+
if (hash(prev) === hash(next)) return false;
|
|
227
|
+
mkdirSync(join(root, "design"), { recursive: true });
|
|
228
|
+
writeFileSync(file, next);
|
|
229
|
+
return true;
|
|
230
|
+
}
|
|
231
|
+
const hash = (s) => createHash("sha256").update(s).digest("hex");
|
|
232
|
+
//#endregion
|
|
233
|
+
export { writeManifest as a, toFrameId as i, hash as n, scanFrames as r, affectedFrameIds as t };
|