@nimtech/nimpress 2.3.8 → 2.3.9

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/cli.es.js CHANGED
@@ -1,46 +1,48 @@
1
- import { d as R, c as he, r as ge, s as Ue, p as Ve, a as Fe, b as Q, e as qe, f as Ke, g as le, h as De, i as Qe, j as Ce, k as Xe, l as Ye, m as et, n as Se, w as X, o as Oe, q as tt, t as st, u as nt, v as ot, x as rt } from "./plugin-C3C36uvj.js";
2
- import { join as h, dirname as z, relative as D, sep as U, extname as Y, resolve as T, basename as F } from "node:path";
3
- import { readdirSync as q, existsSync as b, writeFileSync as L, mkdirSync as ye, rmSync as ne, readFileSync as J, statSync as Ee } from "node:fs";
4
- import it from "gray-matter";
5
- import { readFile as ae, readdir as at, writeFile as Z, mkdir as me, copyFile as Ne } from "node:fs/promises";
6
- import { s as ct, r as oe } from "./typeMembers-CNvE92EX.js";
7
- import { createServer as We, build as Ae } from "vite";
8
- import { createHash as lt } from "node:crypto";
9
- import { createInterface as mt } from "node:readline/promises";
10
- function A(t, e) {
11
- return t.find((s) => s.startsWith(`--${e}=`))?.slice(e.length + 3);
12
- }
13
- function $e(t, e) {
14
- return t.includes(`--${e}`);
15
- }
16
- function se(t, e) {
17
- return t.filter((s) => !s.startsWith("--"))[e];
18
- }
19
- function ee(t, e = []) {
20
- let o;
1
+ import { d as z, c as ke, r as Se, s as rt, p as it, a as Ne, b as se, e as at, f as ct, g as $e, h as Pe, i as lt, j as Te, k as ut, l as mt, m as pt, n as Ee, w as ne, o as Ae, q as ft, t as dt, u as ht, v as gt, x as $t } from "./plugin-C3C36uvj.js";
2
+ import { join as d, dirname as L, relative as O, sep as q, extname as oe, resolve as F, basename as C } from "node:path";
3
+ import { readdirSync as Y, existsSync as b, writeFileSync as A, mkdirSync as Q, rmSync as ae, readFileSync as W, statSync as Me } from "node:fs";
4
+ import yt from "gray-matter";
5
+ import { readFile as fe, readdir as wt, writeFile as G, mkdir as ye, copyFile as Re } from "node:fs/promises";
6
+ import { s as bt, r as ce } from "./typeMembers-CNvE92EX.js";
7
+ import { createServer as Ie, build as ze } from "vite";
8
+ import { createHash as xt } from "node:crypto";
9
+ import { createInterface as vt } from "node:readline/promises";
10
+ import { fileURLToPath as kt } from "node:url";
11
+ import { homedir as Le } from "node:os";
12
+ function T(e, t) {
13
+ return e.find((s) => s.startsWith(`--${t}=`))?.slice(t.length + 3);
14
+ }
15
+ function X(e, t) {
16
+ return e.includes(`--${t}`);
17
+ }
18
+ function ee(e, t) {
19
+ return e.filter((s) => !s.startsWith("--"))[t];
20
+ }
21
+ function re(e, t = []) {
22
+ let n;
21
23
  try {
22
- o = q(t, { withFileTypes: !0 });
24
+ n = Y(e, { withFileTypes: !0 });
23
25
  } catch {
24
- return e;
26
+ return t;
25
27
  }
26
- for (const s of o) {
27
- const n = h(t, s.name);
28
+ for (const s of n) {
29
+ const o = d(e, s.name);
28
30
  if (s.isDirectory()) {
29
31
  if (s.name === "node_modules" || s.name.startsWith(".")) continue;
30
- ee(n, e);
31
- } else s.isFile() && e.push(n);
32
+ re(o, t);
33
+ } else s.isFile() && t.push(o);
32
34
  }
33
- return e;
35
+ return t;
34
36
  }
35
- function ue(t, e, o) {
36
- if (e.length) {
37
- console.error(`${t} failed with ${e.length} problems`);
38
- for (const s of e) console.error(` ${s}`);
37
+ function we(e, t, n) {
38
+ if (t.length) {
39
+ console.error(`${e} failed with ${t.length} problems`);
40
+ for (const s of t) console.error(` ${s}`);
39
41
  process.exit(1);
40
42
  }
41
- console.log(o);
43
+ console.log(n);
42
44
  }
43
- function ut() {
45
+ function St() {
44
46
  return `import { defineConfig } from '@nimtech/nimpress/plugin'
45
47
 
46
48
  /**
@@ -50,15 +52,15 @@ function ut() {
50
52
  */
51
53
  export default defineConfig({
52
54
  /** Site title shown in the header and the tab. */
53
- title: ${JSON.stringify(R.title)},
55
+ title: ${JSON.stringify(z.title)},
54
56
 
55
- /** Folder holding the markdown content. Default ${JSON.stringify(R.contentDir)}. */
57
+ /** Folder holding the markdown content. Default ${JSON.stringify(z.contentDir)}. */
56
58
  // contentDir: 'docs',
57
59
 
58
- /** Root assets folder copied into the build, never inside contentDir. Default ${JSON.stringify(R.assetsDir)}. */
60
+ /** Root assets folder copied into the build, never inside contentDir. Default ${JSON.stringify(z.assetsDir)}. */
59
61
  // assetsDir: 'assets',
60
62
 
61
- /** Url base the assets folder serves under. Default ${JSON.stringify(R.assetUrlBase)}. */
63
+ /** Url base the assets folder serves under. Default ${JSON.stringify(z.assetUrlBase)}. */
62
64
  // assetUrlBase: '/assets',
63
65
 
64
66
  /**
@@ -143,24 +145,24 @@ export default defineConfig({
143
145
  })
144
146
  `;
145
147
  }
146
- function ft() {
148
+ function jt() {
147
149
  return JSON.stringify(
148
150
  {
149
151
  $schema: "./node_modules/@nimtech/nimpress/config.schema.json",
150
- title: R.title,
151
- contentDir: R.contentDir,
152
- assetsDir: R.assetsDir,
153
- assetUrlBase: R.assetUrlBase
152
+ title: z.title,
153
+ contentDir: z.contentDir,
154
+ assetsDir: z.assetsDir,
155
+ assetUrlBase: z.assetUrlBase
154
156
  },
155
157
  null,
156
158
  2
157
159
  ) + `
158
160
  `;
159
161
  }
160
- function pt(t) {
162
+ function Ct(e) {
161
163
  return `# Nimpress project
162
164
 
163
- This site is built with @nimtech/nimpress. Content lives in \`${t}/\` as markdown with typed frontmatter.
165
+ This site is built with @nimtech/nimpress. Content lives in \`${e}/\` as markdown with typed frontmatter.
164
166
 
165
167
  The full documentation is at https://nimling.github.io/nimpress/.
166
168
 
@@ -199,12 +201,12 @@ The authoritative AI working rules ship inside the package at \`node_modules/@ni
199
201
  8. \`nimpress guard map\` and \`nimpress guard apply\` wire gated pages, marked with the \`gate:\` frontmatter field, to the auth provider artifacts.
200
202
  `;
201
203
  }
202
- function dt(t) {
203
- const e = h(t, "nimpress.config.ts"), o = h(t, "nimpress.config.json"), s = $e(process.argv.slice(2), "json");
204
- !b(e) && !b(o) && (s ? (L(o, ft()), console.log(`nimpress init: ${o} written, field descriptions come from the referenced config.schema.json`)) : (L(e, ut()), console.log(`nimpress init: ${e} written with every field documented, uncomment what you need`)));
205
- const n = h(t, R.contentDir);
206
- (!b(n) || q(n).length === 0) && (ye(n, { recursive: !0 }), L(
207
- h(n, "index.md"),
204
+ function Ft(e) {
205
+ const t = d(e, "nimpress.config.ts"), n = d(e, "nimpress.config.json"), s = X(process.argv.slice(2), "json");
206
+ !b(t) && !b(n) && (s ? (A(n, jt()), console.log(`nimpress init: ${n} written, field descriptions come from the referenced config.schema.json`)) : (A(t, St()), console.log(`nimpress init: ${t} written with every field documented, uncomment what you need`)));
207
+ const o = d(e, z.contentDir);
208
+ (!b(o) || Y(o).length === 0) && (Q(o, { recursive: !0 }), A(
209
+ d(o, "index.md"),
208
210
  `---
209
211
  title: Home
210
212
  ---
@@ -212,332 +214,332 @@ title: Home
212
214
  Welcome to your Nimpress site.
213
215
  `
214
216
  ));
215
- const r = pt(R.contentDir);
217
+ const i = Ct(z.contentDir);
216
218
  for (const a of ["CLAUDE.md", "AGENTS.md"]) {
217
- const l = h(t, a);
218
- b(l) || (L(l, r), console.log(`nimpress init: ${a} written, pointing at the packaged rules in node_modules/@nimtech/nimpress/.claude/rules/`));
219
+ const l = d(e, a);
220
+ b(l) || (A(l, i), console.log(`nimpress init: ${a} written, pointing at the packaged rules in node_modules/@nimtech/nimpress/.claude/rules/`));
219
221
  }
220
222
  }
221
- const ht = { vue: "vueStory", svelte: "svelteStory" }, gt = { vue: ".svelte", svelte: ".vue" };
222
- function V(t) {
223
- return `run nimpress modules update ${t}`;
223
+ const Ot = { vue: "vueStory", svelte: "svelteStory" }, Et = { vue: ".svelte", svelte: ".vue" };
224
+ function K(e) {
225
+ return `run nimpress modules update ${e}`;
224
226
  }
225
- async function yt(t) {
226
- let e;
227
+ async function Dt(e) {
228
+ let t;
227
229
  try {
228
- e = await at(t, { withFileTypes: !0 });
230
+ t = await wt(e, { withFileTypes: !0 });
229
231
  } catch {
230
232
  return [];
231
233
  }
232
- return e.filter((o) => o.isFile() && /\.story\.tsx?$/.test(o.name)).map((o) => o.name);
233
- }
234
- function $t(t, e) {
235
- const o = e === "integer" ? "number" : e;
236
- return t.every((s) => typeof s === o);
237
- }
238
- function wt(t, e, o, s, n) {
239
- const i = [], r = s.properties ?? {}, a = n.properties ?? {};
240
- for (const d of Object.keys(a))
241
- d in r || i.push(`${t}: prop ${d} is missing from the schema, ${V(e)}`);
242
- for (const d of Object.keys(r))
243
- d in a || i.push(`${t}: schema prop ${d} has no counterpart in ${o}, remove it or restore the prop`);
244
- for (const [d, f] of Object.entries(r)) {
245
- const p = a[d];
246
- if (p && (f.type && p.type && f.type !== p.type && !f.enum && i.push(
247
- `${t}: prop ${d} schema type ${f.type} conflicts with source type ${p.type}, ${V(e)}`
248
- ), f.enum && p.type && !$t(f.enum, p.type) && i.push(`${t}: prop ${d} enum values mismatch the source type ${p.type}`), f.enum && p.enum)) {
249
- const w = new Set(p.enum.map((S) => JSON.stringify(S))), y = f.enum.filter((S) => !w.has(JSON.stringify(S)));
250
- y.length && i.push(
251
- `${t}: prop ${d} enum carries ${y.map((S) => JSON.stringify(S)).join(", ")} outside the source union`
234
+ return t.filter((n) => n.isFile() && /\.story\.tsx?$/.test(n.name)).map((n) => n.name);
235
+ }
236
+ function _t(e, t) {
237
+ const n = t === "integer" ? "number" : t;
238
+ return e.every((s) => typeof s === n);
239
+ }
240
+ function Wt(e, t, n, s, o) {
241
+ const r = [], i = s.properties ?? {}, a = o.properties ?? {};
242
+ for (const h of Object.keys(a))
243
+ h in i || r.push(`${e}: prop ${h} is missing from the schema, ${K(t)}`);
244
+ for (const h of Object.keys(i))
245
+ h in a || r.push(`${e}: schema prop ${h} has no counterpart in ${n}, remove it or restore the prop`);
246
+ for (const [h, p] of Object.entries(i)) {
247
+ const f = a[h];
248
+ if (f && (p.type && f.type && p.type !== f.type && !p.enum && r.push(
249
+ `${e}: prop ${h} schema type ${p.type} conflicts with source type ${f.type}, ${K(t)}`
250
+ ), p.enum && f.type && !_t(p.enum, f.type) && r.push(`${e}: prop ${h} enum values mismatch the source type ${f.type}`), p.enum && f.enum)) {
251
+ const w = new Set(f.enum.map((k) => JSON.stringify(k))), $ = p.enum.filter((k) => !w.has(JSON.stringify(k)));
252
+ $.length && r.push(
253
+ `${e}: prop ${h} enum carries ${$.map((k) => JSON.stringify(k)).join(", ")} outside the source union`
252
254
  );
253
255
  }
254
256
  }
255
- const l = s.slots ?? {}, c = n.slots ?? {};
256
- for (const d of Object.keys(c))
257
- d in l || i.push(`${t}: slot ${d} is missing from the schema, ${V(e)}`);
258
- for (const d of Object.keys(l))
259
- d in c || i.push(`${t}: schema slot ${d} has no counterpart in ${o}`);
260
- const u = new Set(s.emits ?? []), m = new Set(n.emits ?? []);
261
- for (const d of m)
262
- u.has(d) || i.push(`${t}: emit ${d} is missing from the schema, ${V(e)}`);
263
- for (const d of u)
264
- m.has(d) || i.push(`${t}: schema emit ${d} has no counterpart in ${o}`);
265
- return i;
257
+ const l = s.slots ?? {}, c = o.slots ?? {};
258
+ for (const h of Object.keys(c))
259
+ h in l || r.push(`${e}: slot ${h} is missing from the schema, ${K(t)}`);
260
+ for (const h of Object.keys(l))
261
+ h in c || r.push(`${e}: schema slot ${h} has no counterpart in ${n}`);
262
+ const m = new Set(s.emits ?? []), u = new Set(o.emits ?? []);
263
+ for (const h of u)
264
+ m.has(h) || r.push(`${e}: emit ${h} is missing from the schema, ${K(t)}`);
265
+ for (const h of m)
266
+ u.has(h) || r.push(`${e}: schema emit ${h} has no counterpart in ${n}`);
267
+ return r;
266
268
  }
267
- async function Te(t, e, o) {
268
- const s = o ? [o] : Object.keys(e.modules.systems), n = [], i = await he(t, e.contentDir);
269
- for (const r of s) {
270
- const a = e.modules.systems[r];
269
+ async function Je(e, t, n) {
270
+ const s = n ? [n] : Object.keys(t.modules.systems), o = [], r = await ke(e, t.contentDir);
271
+ for (const i of s) {
272
+ const a = t.modules.systems[i];
271
273
  if (!a) {
272
- n.push(`${r}: not a configured system`);
274
+ o.push(`${i}: not a configured system`);
273
275
  continue;
274
276
  }
275
- const l = a.framework, c = ht[l === "vue" ? "svelte" : "vue"], u = gt[l];
276
- for (const m of i) {
277
- if (m.system !== r) continue;
278
- const d = z(m.pageFile), f = D(t, d).split(U).join("/"), p = await yt(d);
279
- p.length || n.push(`${f}: no story, run nimpress modules story --system=${r} ${m.component}`);
277
+ const l = a.framework, c = Ot[l === "vue" ? "svelte" : "vue"], m = Et[l];
278
+ for (const u of r) {
279
+ if (u.system !== i) continue;
280
+ const h = L(u.pageFile), p = O(e, h).split(q).join("/"), f = await Dt(h);
281
+ f.length || o.push(`${p}: no story, run nimpress modules story --system=${i} ${u.component}`);
280
282
  const w = /* @__PURE__ */ new Set();
281
- for (const k of p) {
282
- let O;
283
+ for (const S of f) {
284
+ let D;
283
285
  try {
284
- O = await ae(h(d, k), "utf-8");
286
+ D = await fe(d(h, S), "utf-8");
285
287
  } catch {
286
288
  continue;
287
289
  }
288
- (/\bharness\s*:/.test(O) || /\brender\s*:/.test(O)) && w.add(k), O.includes(c) && n.push(`${f}/${k}: uses ${c} inside the ${l} system ${r}`);
289
- for (const g of O.matchAll(/from\s+['"]([^'"]+)['"]/g))
290
- Y(g[1]) === u && n.push(`${f}/${k}: imports ${g[1]} inside the ${l} system ${r}`);
290
+ (/\bharness\s*:/.test(D) || /\brender\s*:/.test(D)) && w.add(S), D.includes(c) && o.push(`${p}/${S}: uses ${c} inside the ${l} system ${i}`);
291
+ for (const g of D.matchAll(/from\s+['"]([^'"]+)['"]/g))
292
+ oe(g[1]) === m && o.push(`${p}/${S}: imports ${g[1]} inside the ${l} system ${i}`);
291
293
  }
292
- const y = ge(t, e.modules, r, m.component, m.file);
293
- if (y && Y(y.componentFile) === u && n.push(
294
- `${f}: component file ${D(t, y.componentFile)} mismatches the ${l} system ${r}`
295
- ), b(h(d, "schema.json")) && b(h(d, "schema.yml"))) {
296
- n.push(`${f}: both schema.json and schema.yml exist, keep one`);
294
+ const $ = Se(e, t.modules, i, u.component, u.file);
295
+ if ($ && oe($.componentFile) === m && o.push(
296
+ `${p}: component file ${O(e, $.componentFile)} mismatches the ${l} system ${i}`
297
+ ), b(d(h, "schema.json")) && b(d(h, "schema.yml"))) {
298
+ o.push(`${p}: both schema.json and schema.yml exist, keep one`);
297
299
  continue;
298
300
  }
299
- const S = Ue(d);
300
- if (!S) {
301
- n.push(`${f}: schema file missing, ${V(m.component)}`);
301
+ const k = rt(h);
302
+ if (!k) {
303
+ o.push(`${p}: schema file missing, ${K(u.component)}`);
302
304
  continue;
303
305
  }
304
- let C;
306
+ let E;
305
307
  try {
306
- C = await ae(S.path, "utf-8");
308
+ E = await fe(k.path, "utf-8");
307
309
  } catch {
308
- n.push(`${f}: ${S.form} schema unreadable`);
310
+ o.push(`${p}: ${k.form} schema unreadable`);
309
311
  continue;
310
312
  }
311
313
  let j;
312
314
  try {
313
- j = Ve(C, S.form);
315
+ j = it(E, k.form);
314
316
  } catch {
315
- n.push(`${f}: schema is not valid ${S.form}, fix it by hand`);
317
+ o.push(`${p}: schema is not valid ${k.form}, fix it by hand`);
316
318
  continue;
317
319
  }
318
320
  const x = new Set(Object.keys(j.properties ?? {}));
319
- for (const k of await Fe(d))
320
- if (!w.has(k.file))
321
- for (const O of Object.keys(k.props ?? {}))
322
- x.has(O) || n.push(`${f}/${k.file}: prop ${O} is absent from the schema, ${V(m.component)}`);
323
- const N = y ? await ae(y.componentFile, "utf-8").catch(() => {
321
+ for (const S of await Ne(h))
322
+ if (!w.has(S.file))
323
+ for (const D of Object.keys(S.props ?? {}))
324
+ x.has(D) || o.push(`${p}/${S.file}: prop ${D} is absent from the schema, ${K(u.component)}`);
325
+ const N = $ ? await fe($.componentFile, "utf-8").catch(() => {
324
326
  }) : void 0;
325
- if (y) {
326
- const k = await Q(y.componentFile, l, m.component);
327
- if (k) {
328
- const O = ct(m.component, k.props, k.slots, k.emits);
329
- n.push(
330
- ...wt(f, m.component, D(t, y.componentFile), j, O)
327
+ if ($) {
328
+ const S = await se($.componentFile, l, u.component);
329
+ if (S) {
330
+ const D = bt(u.component, S.props, S.slots, S.emits);
331
+ o.push(
332
+ ...Wt(p, u.component, O(e, $.componentFile), j, D)
331
333
  );
332
334
  }
333
335
  }
334
- qe(Ke(m.component, j, { sourceFile: y?.componentFile, sourceText: N }));
336
+ at(ct(u.component, j, { sourceFile: $?.componentFile, sourceText: N }));
335
337
  }
336
338
  }
337
- return le(t), n;
339
+ return $e(e), o;
338
340
  }
339
- function Je(t) {
340
- return Object.entries(t.modules.systems).filter(([, e]) => e.visibility !== "dev-only").map(([e]) => e);
341
+ function Be(e) {
342
+ return Object.entries(e.modules.systems).filter(([, t]) => t.visibility !== "dev-only").map(([t]) => t);
341
343
  }
342
- async function Ie(t, e, o) {
343
- for (const s of o)
344
+ async function Ue(e, t, n) {
345
+ for (const s of n)
344
346
  try {
345
- await (await We(await Ce(t, e, s, "serve"))).listen(), console.log(`nimpress modules: ${s} harness on port ${Xe(e.modules, s)}`);
346
- } catch (n) {
347
- console.warn(`nimpress modules: harness for ${s} failed to start: ${String(n)}`);
347
+ await (await Ie(await Te(e, t, s, "serve"))).listen(), console.log(`nimpress modules: ${s} harness on port ${ut(t.modules, s)}`);
348
+ } catch (o) {
349
+ console.warn(`nimpress modules: harness for ${s} failed to start: ${String(o)}`);
348
350
  }
349
351
  }
350
- async function Pe(t, e, o) {
351
- for (const s of o)
352
- await Ae(await Ce(t, e, s, "build")), console.log(`nimpress modules: built ${s}`);
353
- }
354
- async function bt(t, e) {
355
- const o = await We(De({ cwd: t, command: "serve", resolved: e }));
356
- await o.listen(), await Ie(t, e, Object.keys(e.modules.systems)), o.printUrls(), o.bindCLIShortcuts({ print: !0 });
357
- }
358
- async function Me(t, e) {
359
- const o = h(t, "index.html"), s = !b(o);
360
- s && L(o, Qe(e));
361
- const n = () => {
362
- s && ne(o, { force: !0 });
363
- }, i = () => {
364
- n(), process.exit(130);
352
+ async function Ge(e, t, n) {
353
+ for (const s of n)
354
+ await ze(await Te(e, t, s, "build")), console.log(`nimpress modules: built ${s}`);
355
+ }
356
+ async function Nt(e, t) {
357
+ const n = await Ie(Pe({ cwd: e, command: "serve", resolved: t }));
358
+ await n.listen(), await Ue(e, t, Object.keys(t.modules.systems)), n.printUrls(), n.bindCLIShortcuts({ print: !0 });
359
+ }
360
+ async function He(e, t) {
361
+ const n = d(e, "index.html"), s = !b(n);
362
+ s && A(n, lt(t));
363
+ const o = () => {
364
+ s && ae(n, { force: !0 });
365
+ }, r = () => {
366
+ o(), process.exit(130);
365
367
  };
366
- process.once("SIGINT", i), process.once("SIGTERM", i);
368
+ process.once("SIGINT", r), process.once("SIGTERM", r);
367
369
  try {
368
- await Ae(De({ cwd: t, command: "build", resolved: e, htmlInput: o }));
370
+ await ze(Pe({ cwd: e, command: "build", resolved: t, htmlInput: n }));
369
371
  } finally {
370
- process.off("SIGINT", i), process.off("SIGTERM", i), n();
372
+ process.off("SIGINT", r), process.off("SIGTERM", r), o();
371
373
  }
372
- await Pe(t, e, Je(e));
373
- }
374
- const xt = [".ts", ".tsx", ".js", ".mjs", ".vue", ".svelte"], vt = ["", ".ts", ".tsx", ".js", ".mjs", ".vue", ".svelte", "/index.ts", "/index.js"], ke = /^[a-z0-9][a-z0-9.-]*$/, St = /^[A-Z][A-Za-z0-9]*$/;
375
- function kt(t) {
376
- const e = t.resolve;
377
- if (!e || typeof e != "object") return [];
378
- const o = e.alias;
379
- return !o || typeof o != "object" ? [] : Array.isArray(o) ? o.flatMap((s) => {
374
+ await Ge(e, t, Be(t));
375
+ }
376
+ const Pt = [".ts", ".tsx", ".js", ".mjs", ".vue", ".svelte"], Tt = ["", ".ts", ".tsx", ".js", ".mjs", ".vue", ".svelte", "/index.ts", "/index.js"], De = /^[a-z0-9][a-z0-9.-]*$/, At = /^[A-Z][A-Za-z0-9]*$/;
377
+ function Mt(e) {
378
+ const t = e.resolve;
379
+ if (!t || typeof t != "object") return [];
380
+ const n = t.alias;
381
+ return !n || typeof n != "object" ? [] : Array.isArray(n) ? n.flatMap((s) => {
380
382
  if (!s || typeof s != "object") return [];
381
- const { find: n, replacement: i } = s;
382
- return typeof n != "string" || typeof i != "string" ? [] : [{ find: n, replacement: i }];
383
- }) : Object.entries(o).flatMap(
384
- ([s, n]) => typeof n == "string" ? [{ find: s, replacement: n }] : []
383
+ const { find: o, replacement: r } = s;
384
+ return typeof o != "string" || typeof r != "string" ? [] : [{ find: o, replacement: r }];
385
+ }) : Object.entries(n).flatMap(
386
+ ([s, o]) => typeof o == "string" ? [{ find: s, replacement: o }] : []
385
387
  );
386
388
  }
387
- function jt(t) {
388
- const e = [], o = [
389
+ function Rt(e) {
390
+ const t = [], n = [
389
391
  /(?:^|\n)[ \t]*import[^'"\n]*?from[ \t]*['"]([^'"\n]+)['"]/g,
390
392
  /(?:^|\n)[ \t]*export[^'"\n]*?from[ \t]*['"]([^'"\n]+)['"]/g,
391
393
  /(?:^|\n)[ \t]*import[ \t]+['"]([^'"\n]+)['"]/g,
392
394
  /\bimport\(\s*['"]([^'"\n]+)['"]\s*\)/g
393
395
  ];
394
- for (const s of o) {
395
- let n;
396
- for (; n = s.exec(t); ) e.push(n[1]);
396
+ for (const s of n) {
397
+ let o;
398
+ for (; o = s.exec(e); ) t.push(o[1]);
397
399
  }
398
- return e;
400
+ return t;
399
401
  }
400
- function je(t) {
401
- return vt.some((e) => {
402
- const o = t + e;
403
- if (!b(o)) return !1;
402
+ function _e(e) {
403
+ return Tt.some((t) => {
404
+ const n = e + t;
405
+ if (!b(n)) return !1;
404
406
  try {
405
- return Ee(o).isFile();
407
+ return Me(n).isFile();
406
408
  } catch {
407
409
  return !1;
408
410
  }
409
411
  });
410
412
  }
411
- function Ft(t, e) {
412
- const o = T(t, e.contentDir), s = kt(e.vite), n = [];
413
- for (const i of ee(o)) {
414
- if (!xt.some((l) => i.endsWith(l))) continue;
415
- let r;
413
+ function It(e, t) {
414
+ const n = F(e, t.contentDir), s = Mt(t.vite), o = [];
415
+ for (const r of re(n)) {
416
+ if (!Pt.some((l) => r.endsWith(l))) continue;
417
+ let i;
416
418
  try {
417
- r = J(i, "utf-8");
419
+ i = W(r, "utf-8");
418
420
  } catch {
419
421
  continue;
420
422
  }
421
- const a = D(o, i).split(U).join("/");
422
- for (const l of jt(r)) {
423
+ const a = O(n, r).split(q).join("/");
424
+ for (const l of Rt(i)) {
423
425
  if (l.includes("_shared/") || l.startsWith("_shared")) {
424
- n.push(
426
+ o.push(
425
427
  `${a}: imports ${l}, shared fixture folders are forbidden, stories are self contained and shared setup lives in a group harness component`
426
428
  );
427
429
  continue;
428
430
  }
429
431
  const c = l.split("?")[0];
430
432
  if (c.startsWith("./") || c.startsWith("../")) {
431
- const m = T(z(i), c);
432
- je(m) || n.push(`${a}: unresolved import ${l}, fix the path or create the file`);
433
+ const u = F(L(r), c);
434
+ _e(u) || o.push(`${a}: unresolved import ${l}, fix the path or create the file`);
433
435
  continue;
434
436
  }
435
- const u = s.find((m) => c === m.find || c.startsWith(m.find + "/"));
436
- if (u) {
437
- const m = T(t, u.replacement + c.slice(u.find.length));
438
- je(m) || n.push(`${a}: unresolved import ${l} via alias ${u.find}`);
437
+ const m = s.find((u) => c === u.find || c.startsWith(u.find + "/"));
438
+ if (m) {
439
+ const u = F(e, m.replacement + c.slice(m.find.length));
440
+ _e(u) || o.push(`${a}: unresolved import ${l} via alias ${m.find}`);
439
441
  }
440
442
  }
441
443
  }
442
- return n;
444
+ return o;
443
445
  }
444
- function Dt(t, e) {
445
- const o = T(t, e.contentDir), s = [];
446
- if (!b(o)) return [`${e.contentDir}: contentDir does not exist`];
447
- const n = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Map();
448
- for (const a of ee(o)) {
449
- const l = D(o, a).split(U).join("/"), c = z(a), u = F(a);
450
- if (u.endsWith(".md")) {
451
- const m = i.get(c) ?? [];
452
- m.push(a), i.set(c, m);
453
- const d = u.slice(0, -3);
454
- ke.test(d) || s.push(`${l}: markdown file names are lowercase kebab case, rename to ${d.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase().replace(/[^a-z0-9.-]+/g, "-")}.md`);
455
- let f;
446
+ function zt(e, t) {
447
+ const n = F(e, t.contentDir), s = [];
448
+ if (!b(n)) return [`${t.contentDir}: contentDir does not exist`];
449
+ const o = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Map();
450
+ for (const a of re(n)) {
451
+ const l = O(n, a).split(q).join("/"), c = L(a), m = C(a);
452
+ if (m.endsWith(".md")) {
453
+ const u = r.get(c) ?? [];
454
+ u.push(a), r.set(c, u);
455
+ const h = m.slice(0, -3);
456
+ De.test(h) || s.push(`${l}: markdown file names are lowercase kebab case, rename to ${h.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase().replace(/[^a-z0-9.-]+/g, "-")}.md`);
457
+ let p;
456
458
  try {
457
- f = it(J(a, "utf-8")).data;
459
+ p = yt(W(a, "utf-8")).data;
458
460
  } catch {
459
461
  continue;
460
462
  }
461
- if (f?.type === "component") {
462
- const p = n.get(c);
463
- p ? s.push(`${l}: second type component page in one folder, ${D(o, p).split(U).join("/")} already owns it, one component per folder`) : n.set(c, a);
463
+ if (p?.type === "component") {
464
+ const f = o.get(c);
465
+ f ? s.push(`${l}: second type component page in one folder, ${O(n, f).split(q).join("/")} already owns it, one component per folder`) : o.set(c, a);
464
466
  }
465
- if (f?.type === "dbml") {
466
- const p = typeof f.spec == "string" ? f.spec : "";
467
- p ? b(T(c, p)) || s.push(`${l}: spec ${p} does not resolve, create the file or fix the path`) : s.push(`${l}: type dbml needs a spec field pointing at the .dbml file`);
467
+ if (p?.type === "dbml") {
468
+ const f = typeof p.spec == "string" ? p.spec : "";
469
+ f ? b(F(c, f)) || s.push(`${l}: spec ${f} does not resolve, create the file or fix the path`) : s.push(`${l}: type dbml needs a spec field pointing at the .dbml file`);
468
470
  }
469
- f?.type === "changelog" && typeof f.path == "string" && s.push(`${l}: changelog entries never set path, the collection mounts at the folder route, remove the path field`);
471
+ p?.type === "changelog" && typeof p.path == "string" && s.push(`${l}: changelog entries never set path, the collection mounts at the folder route, remove the path field`);
470
472
  }
471
- if (u.endsWith(".css") && !u.startsWith("_")) {
472
- const m = a.replace(/\.css$/, ".md");
473
- b(m) || s.push(`${l}: page css without a matching ${F(m)}, page styles are named after the page they scope`);
473
+ if (m.endsWith(".css") && !m.startsWith("_")) {
474
+ const u = a.replace(/\.css$/, ".md");
475
+ b(u) || s.push(`${l}: page css without a matching ${C(u)}, page styles are named after the page they scope`);
474
476
  }
475
477
  }
476
- for (const [a, l] of i) {
477
- const c = D(o, a).split(U).join("/") || ".", u = n.has(a);
478
- let m = [];
478
+ for (const [a, l] of r) {
479
+ const c = O(n, a).split(q).join("/") || ".", m = o.has(a);
480
+ let u = [];
479
481
  try {
480
- m = q(a);
482
+ u = Y(a);
481
483
  } catch {
482
484
  continue;
483
485
  }
484
- m.filter((f) => /\.story\.tsx?$/.test(f)).length && !u && s.push(`${c}: story files without a type component page, add the component index.md or move the stories`);
485
- for (const f of ["schema.json", "schema.yml"])
486
- m.includes(f) && !u && s.push(`${c}: ${f} without a type component page, it belongs beside the component index.md`);
487
- if (u && l.length > 1) {
488
- const f = l.filter((p) => p !== n.get(a)).map((p) => F(p));
489
- s.push(`${c}: a component folder holds exactly one md file, move ${f.join(", ")} out`);
486
+ u.filter((p) => /\.story\.tsx?$/.test(p)).length && !m && s.push(`${c}: story files without a type component page, add the component index.md or move the stories`);
487
+ for (const p of ["schema.json", "schema.yml"])
488
+ u.includes(p) && !m && s.push(`${c}: ${p} without a type component page, it belongs beside the component index.md`);
489
+ if (m && l.length > 1) {
490
+ const p = l.filter((f) => f !== o.get(a)).map((f) => C(f));
491
+ s.push(`${c}: a component folder holds exactly one md file, move ${p.join(", ")} out`);
490
492
  }
491
493
  }
492
- const r = (a) => {
494
+ const i = (a) => {
493
495
  let l;
494
496
  try {
495
- l = q(a, { withFileTypes: !0 });
497
+ l = Y(a, { withFileTypes: !0 });
496
498
  } catch {
497
499
  return;
498
500
  }
499
501
  for (const c of l)
500
502
  if (c.isDirectory() && !(c.name.startsWith(".") || c.name === "node_modules")) {
501
- if (!ke.test(c.name) && !St.test(c.name)) {
502
- const u = D(o, h(a, c.name)).split(U).join("/");
503
- s.push(`${u}/: folder names are lowercase kebab case, or PascalCase for component and group folders, rename it`);
503
+ if (!De.test(c.name) && !At.test(c.name)) {
504
+ const m = O(n, d(a, c.name)).split(q).join("/");
505
+ s.push(`${m}/: folder names are lowercase kebab case, or PascalCase for component and group folders, rename it`);
504
506
  }
505
- r(h(a, c.name));
507
+ i(d(a, c.name));
506
508
  }
507
509
  };
508
- return r(o), s;
510
+ return i(n), s;
509
511
  }
510
- async function Ct(t, e) {
511
- const o = et(t, e, "lint"), s = () => ne(o, { recursive: !0, force: !0 }), n = () => {
512
+ async function Lt(e, t) {
513
+ const n = pt(e, t, "lint"), s = () => ae(n, { recursive: !0, force: !0 }), o = () => {
512
514
  s(), process.exit(130);
513
515
  };
514
- process.once("SIGINT", n), process.once("SIGTERM", n);
516
+ process.once("SIGINT", o), process.once("SIGTERM", o);
515
517
  try {
516
- return await Me(t, { ...e, paths: { ...e.paths, out: o } }), [];
517
- } catch (i) {
518
- return (i instanceof Error ? i.message : String(i)).split(`
518
+ return await He(e, { ...t, paths: { ...t.paths, out: n } }), [];
519
+ } catch (r) {
520
+ return (r instanceof Error ? r.message : String(r)).split(`
519
521
  `).filter((a) => a.trim()).map((a) => `build: ${a.trim()}`);
520
522
  } finally {
521
- process.off("SIGINT", n), process.off("SIGTERM", n), s();
523
+ process.off("SIGINT", o), process.off("SIGTERM", o), s();
522
524
  }
523
525
  }
524
- async function Ot(t, e) {
525
- const o = process.argv.slice(2), s = [
526
- ...Dt(t, e),
527
- ...await Ye(t, e.contentDir),
528
- ...Ft(t, e),
529
- ...await Te(t, e)
526
+ async function Jt(e, t) {
527
+ const n = process.argv.slice(2), s = [
528
+ ...zt(e, t),
529
+ ...await mt(e, t.contentDir),
530
+ ...It(e, t),
531
+ ...await Je(e, t)
530
532
  ];
531
533
  if (s.length) {
532
- ue("nimpress lint", s, "");
534
+ we("nimpress lint", s, "");
533
535
  return;
534
536
  }
535
- if (console.log("nimpress lint: structure, frontmatter, imports, and modules ok"), $e(o, "no-build")) return;
537
+ if (console.log("nimpress lint: structure, frontmatter, imports, and modules ok"), X(n, "no-build")) return;
536
538
  console.log("nimpress lint: building to verify the output compiles");
537
- const n = await Ct(t, e);
538
- ue("nimpress lint", n, "nimpress lint: build ok, everything passes");
539
+ const o = await Lt(e, t);
540
+ we("nimpress lint", o, "nimpress lint: build ok, everything passes");
539
541
  }
540
- const Et = {
542
+ const Bt = {
541
543
  ".json": "application/json",
542
544
  ".xml": "application/rss+xml",
543
545
  ".html": "text/html",
@@ -550,105 +552,105 @@ const Et = {
550
552
  ".webp": "image/webp",
551
553
  ".pdf": "application/pdf"
552
554
  };
553
- function Nt(t, e, o) {
554
- const s = o[0], n = h(t, A(o, "dist") ?? e.paths.out), i = `/${e.paths.guarded}/`, r = h(n, "access.json");
555
- if (!b(r))
556
- throw new Error(`[nimpress] guard: ${r} not found, run a build first`);
557
- const a = JSON.parse(J(r, "utf-8"));
555
+ function Ut(e, t, n) {
556
+ const s = n[0], o = d(e, T(n, "dist") ?? t.paths.out), r = `/${t.paths.guarded}/`, i = d(o, "access.json");
557
+ if (!b(i))
558
+ throw new Error(`[nimpress] guard: ${i} not found, run a build first`);
559
+ const a = JSON.parse(W(i, "utf-8"));
558
560
  if (s === "map") {
559
- const l = Se(n, e), c = h(n, "guard.map.json"), u = b(c) ? JSON.parse(J(c, "utf-8")) : { prefix: a.prefix ?? i, routes: a.routes, bundles: {} }, m = b(l) ? ee(l) : [], d = u.prefix ?? i, f = m.map((y) => {
560
- const S = D(l, y).split("\\").join("/"), C = S.split("/")[0] ?? "", j = [
561
+ const l = Ee(o, t), c = d(o, "guard.map.json"), m = b(c) ? JSON.parse(W(c, "utf-8")) : { prefix: a.prefix ?? r, routes: a.routes, bundles: {} }, u = b(l) ? re(l) : [], h = m.prefix ?? r, p = u.map(($) => {
562
+ const k = O(l, $).split("\\").join("/"), E = k.split("/")[0] ?? "", j = [
561
563
  ...new Set(
562
- Object.values(u.routes ?? {}).filter((N) => N.bundle === C && N.gate).map((N) => N.gate)
564
+ Object.values(m.routes ?? {}).filter((N) => N.bundle === E && N.gate).map((N) => N.gate)
563
565
  )
564
- ], x = J(y);
566
+ ], x = W($);
565
567
  return {
566
- path: `${d}${S}`,
567
- file: S,
568
- bundle: C,
569
- sha256: lt("sha256").update(x).digest("hex"),
570
- size: Ee(y).size,
571
- mime: Et[Y(y).toLowerCase()] ?? "application/octet-stream",
568
+ path: `${h}${k}`,
569
+ file: k,
570
+ bundle: E,
571
+ sha256: xt("sha256").update(x).digest("hex"),
572
+ size: Me($).size,
573
+ mime: Bt[oe($).toLowerCase()] ?? "application/octet-stream",
572
574
  gates: j
573
575
  };
574
- }), p = A(o, "out"), w = p ? h(t, p) : c;
575
- L(
576
+ }), f = T(n, "out"), w = f ? d(e, f) : c;
577
+ A(
576
578
  w,
577
- JSON.stringify({ ...u, prefix: d, files: f }, null, 2) + `
579
+ JSON.stringify({ ...m, prefix: h, files: p }, null, 2) + `
578
580
  `
579
- ), console.log(`nimpress guard: mapped ${f.length} guarded files to ${w}`);
581
+ ), console.log(`nimpress guard: mapped ${p.length} guarded files to ${w}`);
580
582
  return;
581
583
  }
582
584
  if (s === "apply") {
583
- const l = A(o, "map");
585
+ const l = T(n, "map");
584
586
  if (!l) throw new Error("[nimpress] guard apply requires --map=<uploaded mapping json>");
585
- const c = JSON.parse(J(h(t, l), "utf-8"));
587
+ const c = JSON.parse(W(d(e, l), "utf-8"));
586
588
  if (!c.base) throw new Error("[nimpress] guard apply: mapping json carries no base url");
587
- a.base = c.base.replace(/\/$/, ""), a.files = (c.files ?? []).map((u) => ({
588
- path: u.path,
589
- file: u.file,
590
- bundle: u.bundle,
591
- asset_id: u.asset_id,
592
- url: u.url
593
- })), L(r, JSON.stringify(a, null, 2) + `
594
- `), ne(Se(n, e), { recursive: !0, force: !0 }), ne(h(n, "guard.map.json"), { force: !0 }), console.log(`nimpress guard: base ${a.base} applied, ${e.paths.guarded} removed from ${n}`);
589
+ a.base = c.base.replace(/\/$/, ""), a.files = (c.files ?? []).map((m) => ({
590
+ path: m.path,
591
+ file: m.file,
592
+ bundle: m.bundle,
593
+ asset_id: m.asset_id,
594
+ url: m.url
595
+ })), A(i, JSON.stringify(a, null, 2) + `
596
+ `), ae(Ee(o, t), { recursive: !0, force: !0 }), ae(d(o, "guard.map.json"), { force: !0 }), console.log(`nimpress guard: base ${a.base} applied, ${t.paths.guarded} removed from ${o}`);
595
597
  return;
596
598
  }
597
599
  throw new Error("[nimpress] guard expects map or apply");
598
600
  }
599
- function Re(t) {
600
- const e = Y(t);
601
- return e === ".vue" ? "vue" : e === ".svelte" ? "svelte" : null;
601
+ function Ze(e) {
602
+ const t = oe(e);
603
+ return t === ".vue" ? "vue" : t === ".svelte" ? "svelte" : null;
602
604
  }
603
- async function we(t, e, o, s, n) {
604
- const r = (await he(t, e.contentDir)).find((d) => d.system === o && d.component === s);
605
- if (!r)
606
- return console.warn(`[nimpress] modules story: no type component page found for ${o}/${s}`), null;
607
- const a = ge(t, e.modules, o, s, r.file);
605
+ async function je(e, t, n, s, o) {
606
+ const i = (await ke(e, t.contentDir)).find((h) => h.system === n && h.component === s);
607
+ if (!i)
608
+ return console.warn(`[nimpress] modules story: no type component page found for ${n}/${s}`), null;
609
+ const a = Se(e, t.modules, n, s, i.file);
608
610
  if (!a)
609
- return console.warn(`[nimpress] modules story: no source found for ${o}/${s}`), null;
610
- const l = n ?? Re(a.componentFile);
611
+ return console.warn(`[nimpress] modules story: no source found for ${n}/${s}`), null;
612
+ const l = o ?? Ze(a.componentFile);
611
613
  if (!l)
612
614
  throw new Error(
613
615
  `[nimpress] modules story: failed to detect framework for ${a.componentFile}, pass --framework=vue or --framework=svelte`
614
616
  );
615
- const c = l === "vue" ? "vueStory" : "svelteStory", u = `import { ${c} } from '@nimtech/nimpress/story'
617
+ const c = l === "vue" ? "vueStory" : "svelteStory", m = `import { ${c} } from '@nimtech/nimpress/story'
616
618
 
617
619
  // story: Default
618
620
  export default ${c}({
619
621
  name: "Default"
620
622
  })
621
- `, m = h(z(r.pageFile), "default.story.tsx");
622
- return b(m) ? (console.warn(`[nimpress] modules story: ${m} exists, not overwriting`), null) : (await Z(m, u), m);
623
- }
624
- async function Wt(t, e, o) {
625
- const s = await he(t, e.contentDir);
626
- let n = 0;
627
- for (const i of s)
628
- if (!(i.system !== o || (await Fe(z(i.pageFile))).length))
623
+ `, u = d(L(i.pageFile), "default.story.tsx");
624
+ return b(u) ? (console.warn(`[nimpress] modules story: ${u} exists, not overwriting`), null) : (await G(u, m), u);
625
+ }
626
+ async function Gt(e, t, n) {
627
+ const s = await ke(e, t.contentDir);
628
+ let o = 0;
629
+ for (const r of s)
630
+ if (!(r.system !== n || (await Ne(L(r.pageFile))).length))
629
631
  try {
630
- await we(t, e, o, i.component) && n++;
632
+ await je(e, t, n, r.component) && o++;
631
633
  } catch (a) {
632
634
  console.warn(String(a));
633
635
  }
634
- return n;
636
+ return o;
635
637
  }
636
- async function At(t, e, o, s, n) {
637
- const i = e.modules.systems[o];
638
- if (!i) throw new Error(`[nimpress] modules create: unknown system ${o}`);
639
- const r = h(t, e.contentDir, "components", "Components", s), a = h(r, "index.md");
638
+ async function Ht(e, t, n, s, o) {
639
+ const r = t.modules.systems[n];
640
+ if (!r) throw new Error(`[nimpress] modules create: unknown system ${n}`);
641
+ const i = d(e, t.contentDir, "components", "Components", s), a = d(i, "index.md");
640
642
  if (b(a))
641
643
  throw new Error(`[nimpress] modules create: ${a} exists`);
642
644
  const { mkdir: l } = await import("node:fs/promises");
643
- await l(r, { recursive: !0 });
644
- const c = i.package;
645
- await Z(
645
+ await l(i, { recursive: !0 });
646
+ const c = r.package;
647
+ await G(
646
648
  a,
647
649
  `---
648
650
  title: ${s}
649
651
  type: component
650
652
  data:
651
- system: ${o}
653
+ system: ${n}
652
654
  component: ${s}${c ? `
653
655
  package: "${c}"` : ""}
654
656
  ---
@@ -656,22 +658,22 @@ data:
656
658
  ## Usage
657
659
 
658
660
  \`\`\`ts
659
- import { ${s} } from "${c ?? o}";
661
+ import { ${s} } from "${c ?? n}";
660
662
  \`\`\`
661
663
  `
662
664
  );
663
- const u = ge(t, e.modules, o, s);
664
- if (u) {
665
- const m = n ?? Re(u.componentFile) ?? i.framework;
666
- await X(r, s, await Q(u.componentFile, m, s)), await we(t, e, o, s, n);
665
+ const m = Se(e, t.modules, n, s);
666
+ if (m) {
667
+ const u = o ?? Ze(m.componentFile) ?? r.framework;
668
+ await ne(i, s, await se(m.componentFile, u, s)), await je(e, t, n, s, o);
667
669
  } else {
668
- const m = i.framework === "vue" ? "vueStory" : "svelteStory";
669
- await Z(
670
- h(r, "default.story.tsx"),
671
- `import { ${m} } from '@nimtech/nimpress/story'
670
+ const u = r.framework === "vue" ? "vueStory" : "svelteStory";
671
+ await G(
672
+ d(i, "default.story.tsx"),
673
+ `import { ${u} } from '@nimtech/nimpress/story'
672
674
 
673
675
  // story: Default
674
- export default ${m}({
676
+ export default ${u}({
675
677
  name: "Default",
676
678
  props: {}
677
679
  })
@@ -680,586 +682,923 @@ export default ${m}({
680
682
  `nimpress modules: no source found for ${s}, wrote a stub story, schema.json follows once the component exists and import or create runs again`
681
683
  );
682
684
  }
683
- return r;
685
+ return i;
684
686
  }
685
- function re(t) {
687
+ function le(e) {
686
688
  try {
687
- return JSON.parse(JSON.stringify(t, (e, o) => typeof o == "function" ? void 0 : o));
689
+ return JSON.parse(JSON.stringify(e, (t, n) => typeof n == "function" ? void 0 : n));
688
690
  } catch {
689
691
  return {};
690
692
  }
691
693
  }
692
- function ie(t, e = []) {
693
- let o;
694
+ function ue(e, t = []) {
695
+ let n;
694
696
  try {
695
- o = q(t, { withFileTypes: !0 });
697
+ n = Y(e, { withFileTypes: !0 });
696
698
  } catch {
697
- return e;
699
+ return t;
698
700
  }
699
- for (const s of o) {
700
- const n = h(t, s.name);
701
+ for (const s of n) {
702
+ const o = d(e, s.name);
701
703
  if (s.isDirectory()) {
702
704
  if (s.name === "node_modules" || s.name.startsWith(".")) continue;
703
- ie(n, e);
704
- } else s.isFile() && e.push(n);
705
+ ue(o, t);
706
+ } else s.isFile() && t.push(o);
705
707
  }
706
- return e;
708
+ return t;
707
709
  }
708
- function fe(t) {
709
- return t.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase().replace(/[^a-z0-9-]/g, "");
710
+ function be(e) {
711
+ return e.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase().replace(/[^a-z0-9-]/g, "");
710
712
  }
711
- function pe(t) {
712
- const e = J(t, "utf-8"), o = e.split(`
713
+ function xe(e) {
714
+ const t = W(e, "utf-8"), n = t.split(`
713
715
  `), s = [];
714
- let n = 0;
715
- for (; n < o.length; ) {
716
- const f = o[n];
717
- if (/^\s*import\b/.test(f)) {
718
- let p = f;
719
- for (; !/from\s+["'][^"']+["'];?\s*$/.test(p) && !/^\s*import\s+["'][^"']+["'];?\s*$/.test(p) && n + 1 < o.length; )
720
- n++, p += `
721
- ` + o[n];
722
- s.push(p), n++;
716
+ let o = 0;
717
+ for (; o < n.length; ) {
718
+ const p = n[o];
719
+ if (/^\s*import\b/.test(p)) {
720
+ let f = p;
721
+ for (; !/from\s+["'][^"']+["'];?\s*$/.test(f) && !/^\s*import\s+["'][^"']+["'];?\s*$/.test(f) && o + 1 < n.length; )
722
+ o++, f += `
723
+ ` + n[o];
724
+ s.push(f), o++;
723
725
  continue;
724
726
  }
725
- if (/^\s*$/.test(f)) {
726
- n++;
727
+ if (/^\s*$/.test(p)) {
728
+ o++;
727
729
  continue;
728
730
  }
729
731
  break;
730
732
  }
731
- const i = z(t), r = [], a = (f) => {
732
- const p = T(i, f);
733
- return /\.(vue|svelte)$/.test(f) ? { kind: "source", abs: p } : f.endsWith(".ts") ? b(p) ? { kind: "data", abs: p } : null : b(`${p}.ts`) ? { kind: "data", abs: `${p}.ts` } : b(`${p}.vue`) || b(`${p}.svelte`) || b(h(p, "index.ts")) ? { kind: "source", abs: p } : null;
733
+ const r = L(e), i = [], a = (p) => {
734
+ const f = F(r, p);
735
+ return /\.(vue|svelte)$/.test(p) ? { kind: "source", abs: f } : p.endsWith(".ts") ? b(f) ? { kind: "data", abs: f } : null : b(`${f}.ts`) ? { kind: "data", abs: `${f}.ts` } : b(`${f}.vue`) || b(`${f}.svelte`) || b(d(f, "index.ts")) ? { kind: "source", abs: f } : null;
734
736
  };
735
- for (const f of s) {
736
- const p = f.match(/from\s+["'](\.\.?\/[^"']+)["']/)?.[1];
737
- if (!p) continue;
738
- const w = a(p);
739
- w?.kind === "data" && r.push(w.abs);
737
+ for (const p of s) {
738
+ const f = p.match(/from\s+["'](\.\.?\/[^"']+)["']/)?.[1];
739
+ if (!f) continue;
740
+ const w = a(f);
741
+ w?.kind === "data" && i.push(w.abs);
740
742
  }
741
- const l = s.filter((f) => !f.includes("@storybook")).map(
742
- (f) => f.replace(/from\s+["'](\.\.?\/[^"']+)["']/g, (p, w) => {
743
- const y = a(w);
744
- return y?.kind === "source" ? `from ${JSON.stringify(y.abs)}` : `from "./${F(w).replace(/\.ts$/, "")}"`;
743
+ const l = s.filter((p) => !p.includes("@storybook")).map(
744
+ (p) => p.replace(/from\s+["'](\.\.?\/[^"']+)["']/g, (f, w) => {
745
+ const $ = a(w);
746
+ return $?.kind === "source" ? `from ${JSON.stringify($.abs)}` : `from "./${C(w).replace(/\.ts$/, "")}"`;
745
747
  })
746
748
  ).join(`
747
749
  `);
748
- let c = e.slice(o.slice(0, n).join(`
750
+ let c = t.slice(n.slice(0, o).join(`
749
751
  `).length);
750
- const u = (f) => {
751
- const p = c.search(f);
752
- if (p < 0) return;
753
- const w = c.indexOf("{", p);
752
+ const m = (p) => {
753
+ const f = c.search(p);
754
+ if (f < 0) return;
755
+ const w = c.indexOf("{", f);
754
756
  if (w < 0) {
755
- c = c.slice(0, p) + c.slice(c.indexOf(`
756
- `, p) + 1);
757
+ c = c.slice(0, f) + c.slice(c.indexOf(`
758
+ `, f) + 1);
757
759
  return;
758
760
  }
759
- const y = oe(c, w + 1), S = w + 1 + y.length + 1, C = c.slice(S).match(/^[^\n]*/)?.[0] ?? "";
760
- c = c.slice(0, p) + c.slice(S + C.length);
761
+ const $ = ce(c, w + 1), k = w + 1 + $.length + 1, E = c.slice(k).match(/^[^\n]*/)?.[0] ?? "";
762
+ c = c.slice(0, f) + c.slice(k + E.length);
761
763
  };
762
- u(/^const meta\b[^\n]*/m), c = c.replace(/^export default meta;?\s*$/m, ""), c = c.replace(/^(?:export )?type \w+[^\n]*\n(?:[ \t]+[^\n]*\n?)*/gm, "");
763
- let m = 0;
764
- for (; /^(?:export )?interface \w+/m.test(c) && m < 50; )
765
- u(/^(?:export )?interface \w+[^\n]*/m), m++;
766
- let d = 0;
767
- for (; /^export const \w+/m.test(c) && d < 200; )
768
- u(/^export const \w+[^\n]*/m), d++;
764
+ m(/^const meta\b[^\n]*/m), c = c.replace(/^export default meta;?\s*$/m, ""), c = c.replace(/^(?:export )?type \w+[^\n]*\n(?:[ \t]+[^\n]*\n?)*/gm, "");
765
+ let u = 0;
766
+ for (; /^(?:export )?interface \w+/m.test(c) && u < 50; )
767
+ m(/^(?:export )?interface \w+[^\n]*/m), u++;
768
+ let h = 0;
769
+ for (; /^export const \w+/m.test(c) && h < 200; )
770
+ m(/^export const \w+[^\n]*/m), h++;
769
771
  return {
770
- file: t,
771
- text: e,
772
- title: e.match(/\btitle:\s*["']([^"']+)["']/)?.[1],
773
- metaComponent: e.match(/\bcomponent:\s*([A-Za-z_$][\w$]*)\s*[,\n}]/)?.[1],
772
+ file: e,
773
+ text: t,
774
+ title: t.match(/\btitle:\s*["']([^"']+)["']/)?.[1],
775
+ metaComponent: t.match(/\bcomponent:\s*([A-Za-z_$][\w$]*)\s*[,\n}]/)?.[1],
774
776
  imports: l,
775
777
  declarations: c.trim(),
776
- dataModules: r
778
+ dataModules: i
777
779
  };
778
780
  }
779
- function Tt(t, e) {
780
- const o = t.indexOf(":", e) + 1;
781
- let s = 0, n = null;
782
- for (let i = o; i < t.length; i++) {
783
- const r = t[i], a = t[i - 1];
784
- if (n) {
785
- r === n && a !== "\\" && (n = null);
781
+ function Zt(e, t) {
782
+ const n = e.indexOf(":", t) + 1;
783
+ let s = 0, o = null;
784
+ for (let r = n; r < e.length; r++) {
785
+ const i = e[r], a = e[r - 1];
786
+ if (o) {
787
+ i === o && a !== "\\" && (o = null);
786
788
  continue;
787
789
  }
788
- if (r === "'" || r === '"' || r === "`") {
789
- n = r;
790
+ if (i === "'" || i === '"' || i === "`") {
791
+ o = i;
790
792
  continue;
791
793
  }
792
- if (r === "{" || r === "(" || r === "[") s++;
793
- else if (r === "}" || r === ")" || r === "]") s--;
794
- else if (r === "," && s === 0) return t.slice(o, i).trim();
794
+ if (i === "{" || i === "(" || i === "[") s++;
795
+ else if (i === "}" || i === ")" || i === "]") s--;
796
+ else if (i === "," && s === 0) return e.slice(n, r).trim();
795
797
  }
796
- return t.slice(o).trim();
798
+ return e.slice(n).trim();
797
799
  }
798
- function _e(t) {
799
- return t.replace(/\bsatisfies\s+[A-Za-z_$][\w$.]*(?:<[^>]*>)?/g, "").replace(/\bas\s+const\b/g, "").replace(/\)\s*:\s*[A-Za-z_$][\w$<>\[\], .|&]*\s*=>/g, ") =>").replace(/\(\s*([A-Za-z_$][\w$]*)\s*:\s*[A-Za-z_$][\w$<>\[\], .|&]*\)/g, "($1)");
800
+ function Ve(e) {
801
+ return e.replace(/\bsatisfies\s+[A-Za-z_$][\w$.]*(?:<[^>]*>)?/g, "").replace(/\bas\s+const\b/g, "").replace(/\)\s*:\s*[A-Za-z_$][\w$<>\[\], .|&]*\s*=>/g, ") =>").replace(/\(\s*([A-Za-z_$][\w$]*)\s*:\s*[A-Za-z_$][\w$<>\[\], .|&]*\)/g, "($1)");
800
802
  }
801
- function Be(t) {
802
- const e = [], o = /export const (\w+)\s*(?::[^=]*)?=\s*\{/g;
803
+ function qe(e) {
804
+ const t = [], n = /export const (\w+)\s*(?::[^=]*)?=\s*\{/g;
803
805
  let s;
804
- for (; s = o.exec(t.text); ) {
805
- const n = s[1];
806
- if (n === "default" || n === "meta") continue;
807
- const i = oe(t.text, o.lastIndex), r = i.search(/\brender\s*:/);
808
- if (r >= 0) {
809
- const c = Tt(i, r);
806
+ for (; s = n.exec(e.text); ) {
807
+ const o = s[1];
808
+ if (o === "default" || o === "meta") continue;
809
+ const r = ce(e.text, n.lastIndex), i = r.search(/\brender\s*:/);
810
+ if (i >= 0) {
811
+ const c = Zt(r, i);
810
812
  if (c) {
811
- e.push({ name: n, renderFn: c });
813
+ t.push({ name: o, renderFn: c });
812
814
  continue;
813
815
  }
814
816
  }
815
- const a = i.search(/\bargs\s*:/);
817
+ const a = r.search(/\bargs\s*:/);
816
818
  let l = {};
817
819
  if (a >= 0) {
818
- const c = i.indexOf("{", a);
820
+ const c = r.indexOf("{", a);
819
821
  if (c >= 0) {
820
- const u = oe(i, c + 1);
822
+ const m = ce(r, c + 1);
821
823
  try {
822
- l = re(new Function(`${_e(t.declarations)}
823
- return {${u}}`)());
824
+ l = le(new Function(`${Ve(e.declarations)}
825
+ return {${m}}`)());
824
826
  } catch {
825
827
  try {
826
- l = re(new Function(`return {${u}}`)());
828
+ l = le(new Function(`return {${m}}`)());
827
829
  } catch {
828
830
  l = {};
829
831
  }
830
832
  }
831
833
  }
832
834
  }
833
- e.push({ name: n, props: l });
835
+ t.push({ name: o, props: l });
834
836
  }
835
- return e;
837
+ return t;
836
838
  }
837
- function Le(t) {
838
- const e = t.text.search(/\bargTypes\s*:\s*\{/);
839
- if (e < 0) return;
840
- const o = t.text.indexOf("{", e), s = oe(t.text, o + 1);
841
- let n;
839
+ function Ke(e) {
840
+ const t = e.text.search(/\bargTypes\s*:\s*\{/);
841
+ if (t < 0) return;
842
+ const n = e.text.indexOf("{", t), s = ce(e.text, n + 1);
843
+ let o;
842
844
  try {
843
- n = re(new Function(`return {${s}}`)());
845
+ o = le(new Function(`return {${s}}`)());
844
846
  } catch {
845
847
  try {
846
- n = re(
847
- new Function(`${_e(t.declarations)}
848
+ o = le(
849
+ new Function(`${Ve(e.declarations)}
848
850
  return {${s}}`)()
849
851
  );
850
852
  } catch {
851
853
  return;
852
854
  }
853
855
  }
854
- const i = {};
855
- for (const [r, a] of Object.entries(n)) {
856
+ const r = {};
857
+ for (const [i, a] of Object.entries(o)) {
856
858
  if (!a || typeof a != "object") continue;
857
- const l = a.control, c = typeof l == "string" ? l : String(l?.type ?? ""), u = a.options ?? (typeof l == "object" ? l?.options : void 0), m = {};
858
- typeof a.description == "string" && (m.description = a.description), Array.isArray(u) ? m.enum = u : c === "boolean" ? m.type = "boolean" : c === "number" || c === "range" ? m.type = "number" : c === "text" || c === "color" || c === "date" ? m.type = "string" : c === "object" && (m.type = "object"), a.defaultValue !== void 0 && (m.default = a.defaultValue), Object.keys(m).length && (i[r] = m);
859
+ const l = a.control, c = typeof l == "string" ? l : String(l?.type ?? ""), m = a.options ?? (typeof l == "object" ? l?.options : void 0), u = {};
860
+ typeof a.description == "string" && (u.description = a.description), Array.isArray(m) ? u.enum = m : c === "boolean" ? u.type = "boolean" : c === "number" || c === "range" ? u.type = "number" : c === "text" || c === "color" || c === "date" ? u.type = "string" : c === "object" && (u.type = "object"), a.defaultValue !== void 0 && (u.default = a.defaultValue), Object.keys(u).length && (r[i] = u);
859
861
  }
860
- return Object.keys(i).length ? i : void 0;
862
+ return Object.keys(r).length ? r : void 0;
861
863
  }
862
- async function ze(t) {
863
- const e = [...t].sort();
864
- for (let r = 0; r < e.length; r++)
865
- console.log(`${String(r + 1).padStart(4)} ${e[r]}`);
866
- const o = mt({ input: process.stdin, output: process.stdout }), s = await o.question(
864
+ async function Ye(e) {
865
+ const t = [...e].sort();
866
+ for (let i = 0; i < t.length; i++)
867
+ console.log(`${String(i + 1).padStart(4)} ${t[i]}`);
868
+ const n = vt({ input: process.stdin, output: process.stdout }), s = await n.question(
867
869
  "select components to import, comma separated numbers, names, or /regex/, empty imports all: "
868
870
  );
869
- o.close();
870
- const n = s.trim();
871
- if (!n) return new Set(e);
872
- const i = /* @__PURE__ */ new Set();
873
- for (const r of n.split(",").map((a) => a.trim()).filter(Boolean)) {
874
- const a = r.match(/^\/(.+)\/$/);
871
+ n.close();
872
+ const o = s.trim();
873
+ if (!o) return new Set(t);
874
+ const r = /* @__PURE__ */ new Set();
875
+ for (const i of o.split(",").map((a) => a.trim()).filter(Boolean)) {
876
+ const a = i.match(/^\/(.+)\/$/);
875
877
  if (a) {
876
878
  const l = new RegExp(a[1]);
877
- for (const c of e) l.test(c) && i.add(c);
879
+ for (const c of t) l.test(c) && r.add(c);
878
880
  continue;
879
881
  }
880
- if (/^\d+$/.test(r)) {
881
- const l = e[Number(r) - 1];
882
- l && i.add(l);
882
+ if (/^\d+$/.test(i)) {
883
+ const l = t[Number(i) - 1];
884
+ l && r.add(l);
883
885
  continue;
884
886
  }
885
- for (const l of e) l === r && i.add(l);
887
+ for (const l of t) l === i && r.add(l);
886
888
  }
887
- return i;
889
+ return r;
888
890
  }
889
- function Ge(t, e) {
890
- const o = /* @__PURE__ */ new Map(), s = h(t, "node_modules", e, "index.mjs");
891
- if (!b(s)) return o;
892
- const n = J(s, "utf-8");
893
- for (const i of n.matchAll(/export \{ default as ([A-Za-z]+) \}/g))
894
- o.set(i[1].toLowerCase(), i[1]);
895
- return o;
891
+ function Qe(e, t) {
892
+ const n = /* @__PURE__ */ new Map(), s = d(e, "node_modules", t, "index.mjs");
893
+ if (!b(s)) return n;
894
+ const o = W(s, "utf-8");
895
+ for (const r of o.matchAll(/export \{ default as ([A-Za-z]+) \}/g))
896
+ n.set(r[1].toLowerCase(), r[1]);
897
+ return n;
896
898
  }
897
- async function Jt(t, e, o, s) {
898
- const n = e.modules.systems[o];
899
- if (!n) throw new Error(`[nimpress] modules import: unknown system ${o}`);
900
- const i = n.framework, r = i === "vue" ? ".vue" : ".svelte", a = h(t, e.contentDir, "components"), l = n.package, c = s.match ? new RegExp(s.match) : null;
899
+ async function Vt(e, t, n, s) {
900
+ const o = t.modules.systems[n];
901
+ if (!o) throw new Error(`[nimpress] modules import: unknown system ${n}`);
902
+ const r = o.framework, i = r === "vue" ? ".vue" : ".svelte", a = d(e, t.contentDir, "components"), l = o.package, c = s.match ? new RegExp(s.match) : null;
901
903
  if (s.file) {
902
- const g = T(t, s.file);
904
+ const g = F(e, s.file);
903
905
  if (!b(g)) throw new Error(`[nimpress] modules import: ${g} not found`);
904
- if (Y(g) !== r)
905
- throw new Error(`[nimpress] modules import: ${g} does not match system framework ${i}`);
906
- const $ = s.name ?? F(g, r), _ = n.source ? T(t, n.source) : t, E = h(a, "Components", $);
907
- await me(E, { recursive: !0 });
908
- const W = D(_, g);
909
- await Z(h(E, "index.md"), de(o, $, l, W)), await X(E, $, await Q(g, i, $)), console.log(`nimpress modules: imported ${$} at ${D(t, E)}`);
906
+ if (oe(g) !== i)
907
+ throw new Error(`[nimpress] modules import: ${g} does not match system framework ${r}`);
908
+ const y = s.name ?? C(g, i), J = o.source ? F(e, o.source) : e, _ = d(a, "Components", y);
909
+ await ye(_, { recursive: !0 });
910
+ const P = O(J, g);
911
+ await G(d(_, "index.md"), ve(n, y, l, P)), await ne(_, y, await se(g, r, y)), console.log(`nimpress modules: imported ${y} at ${O(e, _)}`);
910
912
  return;
911
913
  }
912
914
  if (s.fromStories) {
913
- await It(t, e, o, s);
915
+ await qt(e, t, n, s);
914
916
  return;
915
917
  }
916
- const u = T(t, s.source ?? n.source ?? "");
917
- if (!b(u))
918
- throw new Error(`[nimpress] modules import: source ${u} not found`);
919
- const m = ie(u), d = /* @__PURE__ */ new Map(), f = /* @__PURE__ */ new Map(), p = m.filter((g) => g.endsWith(".stories.ts")), w = s.stories ? [T(t, s.stories)] : [];
918
+ const m = F(e, s.source ?? o.source ?? "");
919
+ if (!b(m))
920
+ throw new Error(`[nimpress] modules import: source ${m} not found`);
921
+ const u = ue(m), h = /* @__PURE__ */ new Map(), p = /* @__PURE__ */ new Map(), f = u.filter((g) => g.endsWith(".stories.ts")), w = s.stories ? [F(e, s.stories)] : [];
920
922
  for (const g of w)
921
- for (const $ of ie(g))
922
- $.endsWith(".stories.ts") && p.push($);
923
- const y = m.filter(
924
- (g) => g.endsWith(r) && /^[A-Z][A-Za-z0-9]*$/.test(F(g, r))
925
- ), S = new Set(y.map((g) => F(g, r))), C = l && !n.source ? Ge(t, l) : null;
926
- for (const g of p) {
927
- const $ = pe(g);
928
- if ($.title?.includes("/")) {
929
- const [P, I] = $.title.split("/");
930
- d.set(I, P.replace(/\s+/g, ""));
923
+ for (const y of ue(g))
924
+ y.endsWith(".stories.ts") && f.push(y);
925
+ const $ = u.filter(
926
+ (g) => g.endsWith(i) && /^[A-Z][A-Za-z0-9]*$/.test(C(g, i))
927
+ ), k = new Set($.map((g) => C(g, i))), E = l && !o.source ? Qe(e, l) : null;
928
+ for (const g of f) {
929
+ const y = xe(g);
930
+ if (y.title?.includes("/")) {
931
+ const [R, M] = y.title.split("/");
932
+ h.set(M, R.replace(/\s+/g, ""));
931
933
  }
932
- const _ = F(g, ".stories.ts");
933
- let W = b(h(z(g), `${_}${r}`)) ? _ : $.metaComponent ?? _;
934
- if (!S.has(W)) {
935
- let P = "";
936
- for (const I of S)
937
- _.startsWith(I) && I.length > P.length && (P = I);
938
- P ? W = P : console.warn(`nimpress modules: ${F(g)} targets ${W} which has no component page`);
934
+ const J = C(g, ".stories.ts");
935
+ let P = b(d(L(g), `${J}${i}`)) ? J : y.metaComponent ?? J;
936
+ if (!k.has(P)) {
937
+ let R = "";
938
+ for (const M of k)
939
+ J.startsWith(M) && M.length > R.length && (R = M);
940
+ R ? P = R : console.warn(`nimpress modules: ${C(g)} targets ${P} which has no component page`);
939
941
  }
940
- const v = C?.get(W.toLowerCase()) ?? W, B = f.get(v) ?? [];
941
- B.push($), f.set(v, B);
942
+ const v = E?.get(P.toLowerCase()) ?? P, B = p.get(v) ?? [];
943
+ B.push(y), p.set(v, B);
942
944
  }
943
945
  const j = /* @__PURE__ */ new Map();
944
946
  let x = 0, N = 0;
945
- const k = y.filter((g) => !c || c.test(F(g, r))), O = s.select ? await ze(k.map((g) => F(g, r))) : null;
946
- for (const g of k) {
947
- const $ = F(g, r);
948
- if (O && !O.has($)) continue;
949
- if (j.has($)) {
950
- console.warn(`nimpress modules: skip duplicate ${$}, kept ${j.get($)}`);
947
+ const S = $.filter((g) => !c || c.test(C(g, i))), D = s.select ? await Ye(S.map((g) => C(g, i))) : null;
948
+ for (const g of S) {
949
+ const y = C(g, i);
950
+ if (D && !D.has(y)) continue;
951
+ if (j.has(y)) {
952
+ console.warn(`nimpress modules: skip duplicate ${y}, kept ${j.get(y)}`);
951
953
  continue;
952
954
  }
953
- j.set($, D(u, g));
954
- const _ = d.get($) ?? "Components", E = h(a, _, $);
955
- await me(E, { recursive: !0 });
956
- const W = D(u, g), v = W === `${$}/${$}${r}` || W === `${$}${r}`, B = (f.get($) ?? []).map((M) => Le(M)).reduce(
957
- (M, H) => H ? { ...M ?? {}, ...H } : M,
955
+ j.set(y, O(m, g));
956
+ const J = h.get(y) ?? "Components", _ = d(a, J, y);
957
+ await ye(_, { recursive: !0 });
958
+ const P = O(m, g), v = P === `${y}/${y}${i}` || P === `${y}${i}`, B = (p.get(y) ?? []).map((I) => Ke(I)).reduce(
959
+ (I, Z) => Z ? { ...I ?? {}, ...Z } : I,
958
960
  void 0
959
961
  );
960
- await Z(h(E, "index.md"), de(o, $, l, v ? void 0 : W)), await X(E, $, await Q(g, i, $)), B && await Oe(E, { properties: B }), x++;
961
- const P = f.get($) ?? [], I = /* @__PURE__ */ new Set();
962
- for (const M of P) {
963
- const H = F(M.file, ".stories.ts"), be = Be(M);
964
- be.length || console.warn(`nimpress modules: no stories mined from ${F(M.file)}`);
965
- for (const G of M.dataModules)
966
- await Ne(G, h(E, F(G)));
967
- for (const G of be) {
968
- const xe = G.name === $ ? "Default" : H === $ ? G.name : `${H} ${G.name}`;
969
- let te = fe(xe);
970
- I.has(te) && (te = fe(`${H}-${G.name}`));
971
- const ve = h(E, `${te}.story.tsx`);
972
- I.add(te), !b(ve) && (await Z(ve, Ze(i, xe, H, G, M)), N++);
962
+ await G(d(_, "index.md"), ve(n, y, l, v ? void 0 : P)), await ne(_, y, await se(g, r, y)), B && await Ae(_, { properties: B }), x++;
963
+ const R = p.get(y) ?? [], M = /* @__PURE__ */ new Set();
964
+ for (const I of R) {
965
+ const Z = C(I.file, ".stories.ts"), Ce = qe(I);
966
+ Ce.length || console.warn(`nimpress modules: no stories mined from ${C(I.file)}`);
967
+ for (const U of I.dataModules)
968
+ await Re(U, d(_, C(U)));
969
+ for (const U of Ce) {
970
+ const Fe = U.name === y ? "Default" : Z === y ? U.name : `${Z} ${U.name}`;
971
+ let ie = be(Fe);
972
+ M.has(ie) && (ie = be(`${Z}-${U.name}`));
973
+ const Oe = d(_, `${ie}.story.tsx`);
974
+ M.add(ie), !b(Oe) && (await G(Oe, Xe(r, Fe, Z, U, I)), N++);
973
975
  }
974
976
  }
975
977
  }
976
- console.log(`nimpress modules: imported ${x} components with ${N} stories for ${o}`);
978
+ console.log(`nimpress modules: imported ${x} components with ${N} stories for ${n}`);
977
979
  }
978
- async function It(t, e, o, s) {
979
- const n = e.modules.systems[o], i = n.framework, r = h(t, e.contentDir, "components"), a = T(t, s.stories ?? "");
980
+ async function qt(e, t, n, s) {
981
+ const o = t.modules.systems[n], r = o.framework, i = d(e, t.contentDir, "components"), a = F(e, s.stories ?? "");
980
982
  if (!s.stories || !b(a))
981
983
  throw new Error("[nimpress] modules import --from-stories requires --stories=<csf dir>");
982
- const l = n.source ? T(t, n.source) : t, c = s.match ? new RegExp(s.match) : null, u = /* @__PURE__ */ new Set();
983
- let m = 0, d = 0;
984
- const f = ie(a).filter((w) => w.endsWith(".stories.ts")), p = s.select ? await ze(
985
- f.map((w) => pe(w).metaComponent ?? F(w, ".stories.ts"))
984
+ const l = o.source ? F(e, o.source) : e, c = s.match ? new RegExp(s.match) : null, m = /* @__PURE__ */ new Set();
985
+ let u = 0, h = 0;
986
+ const p = ue(a).filter((w) => w.endsWith(".stories.ts")), f = s.select ? await Ye(
987
+ p.map((w) => xe(w).metaComponent ?? C(w, ".stories.ts"))
986
988
  ) : null;
987
- for (const w of f) {
988
- const y = pe(w), S = F(w, ".stories.ts"), C = y.metaComponent ?? S;
989
- if (p && !p.has(C)) continue;
990
- const j = y.text.match(
991
- new RegExp(`import\\s+(?:\\{\\s*)?${C}(?:\\s*\\})?\\s+from\\s+["']([^"']+)["']`)
989
+ for (const w of p) {
990
+ const $ = xe(w), k = C(w, ".stories.ts"), E = $.metaComponent ?? k;
991
+ if (f && !f.has(E)) continue;
992
+ const j = $.text.match(
993
+ new RegExp(`import\\s+(?:\\{\\s*)?${E}(?:\\s*\\})?\\s+from\\s+["']([^"']+)["']`)
992
994
  )?.[1];
993
- let x = C, N = n.package, k;
995
+ let x = E, N = o.package, S;
994
996
  if (j && !j.startsWith(".") && !j.startsWith("@/")) {
995
997
  const v = j.split("/")[0].startsWith("@") ? j.split("/").slice(0, 2).join("/") : j.split("/")[0];
996
- N = v, x = Ge(t, v).get(C.toLowerCase()) ?? C;
998
+ N = v, x = Qe(e, v).get(E.toLowerCase()) ?? E;
997
999
  } else if (j?.startsWith("@/components/")) {
998
1000
  const v = j.slice(13);
999
- v === x || v === `${x}/${x}.vue` || (k = v.endsWith(".vue") || v.endsWith(".svelte") ? v : `${v}/${x}.vue`);
1001
+ v === x || v === `${x}/${x}.vue` || (S = v.endsWith(".vue") || v.endsWith(".svelte") ? v : `${v}/${x}.vue`);
1000
1002
  } else if (j?.startsWith(".")) {
1001
- const v = T(z(w), j);
1002
- k = D(l, v);
1003
+ const v = F(L(w), j);
1004
+ S = O(l, v);
1003
1005
  }
1004
1006
  if (c && !c.test(x)) continue;
1005
- if (u.has(x)) {
1006
- console.warn(`nimpress modules: skip duplicate ${x} from ${F(w)}`);
1007
+ if (m.has(x)) {
1008
+ console.warn(`nimpress modules: skip duplicate ${x} from ${C(w)}`);
1007
1009
  continue;
1008
1010
  }
1009
- u.add(x);
1010
- const O = y.title?.includes("/") ? y.title.split("/")[0].replace(/\s+/g, "") : "Components", g = h(r, O, x);
1011
- await me(g, { recursive: !0 }), await Z(h(g, "index.md"), de(o, x, N, k));
1012
- const $ = i === "vue" ? ".vue" : ".svelte", E = (k ? [T(l, k)] : [
1013
- h(l, x, `${x}${$}`),
1014
- h(l, `${x}${$}`)
1011
+ m.add(x);
1012
+ const D = $.title?.includes("/") ? $.title.split("/")[0].replace(/\s+/g, "") : "Components", g = d(i, D, x);
1013
+ await ye(g, { recursive: !0 }), await G(d(g, "index.md"), ve(n, x, N, S));
1014
+ const y = r === "vue" ? ".vue" : ".svelte", _ = (S ? [F(l, S)] : [
1015
+ d(l, x, `${x}${y}`),
1016
+ d(l, `${x}${y}`)
1015
1017
  ]).find((v) => b(v));
1016
- if (E)
1017
- await X(g, x, await Q(E, i, x));
1018
+ if (_)
1019
+ await ne(g, x, await se(_, r, x));
1018
1020
  else if (N) {
1019
- const v = tt(t, N, x);
1020
- v ? await X(g, x, st(J(v, "utf-8"), x)) : console.warn(`nimpress modules: no source or d.ts found for ${x}, the schema seed is skipped`);
1021
+ const v = ft(e, N, x);
1022
+ v ? await ne(g, x, dt(W(v, "utf-8"), x)) : console.warn(`nimpress modules: no source or d.ts found for ${x}, the schema seed is skipped`);
1021
1023
  }
1022
- const W = Le(y);
1023
- W && await Oe(g, { properties: W }), m++;
1024
- for (const v of y.dataModules)
1025
- await Ne(v, h(g, F(v)));
1026
- for (const v of Be(y)) {
1027
- const B = v.name === x ? "Default" : v.name, P = fe(B), I = h(g, `${P}.story.tsx`);
1028
- b(I) || (await Z(I, Ze(i, B, S, v, y)), d++);
1024
+ const P = Ke($);
1025
+ P && await Ae(g, { properties: P }), u++;
1026
+ for (const v of $.dataModules)
1027
+ await Re(v, d(g, C(v)));
1028
+ for (const v of qe($)) {
1029
+ const B = v.name === x ? "Default" : v.name, R = be(B), M = d(g, `${R}.story.tsx`);
1030
+ b(M) || (await G(M, Xe(r, B, k, v, $)), h++);
1029
1031
  }
1030
1032
  }
1031
- console.log(`nimpress modules: imported ${m} components with ${d} stories for ${o} from stories`);
1033
+ console.log(`nimpress modules: imported ${u} components with ${h} stories for ${n} from stories`);
1032
1034
  }
1033
- function de(t, e, o, s) {
1034
- const n = o ? `
1035
- package: "${o}"` : "", i = s ? `
1035
+ function ve(e, t, n, s) {
1036
+ const o = n ? `
1037
+ package: "${n}"` : "", r = s ? `
1036
1038
  file: ${JSON.stringify(s)}` : "";
1037
1039
  return `---
1038
- title: ${e}
1040
+ title: ${t}
1039
1041
  type: component
1040
1042
  data:
1041
- system: ${t}
1042
- component: ${e}${n}${i}
1043
+ system: ${e}
1044
+ component: ${t}${o}${r}
1043
1045
  ---
1044
1046
 
1045
1047
  ## Usage
1046
1048
 
1047
1049
  \`\`\`ts
1048
- import { ${e} } from "${o ?? t}";
1050
+ import { ${t} } from "${n ?? e}";
1049
1051
  \`\`\`
1050
1052
  `;
1051
1053
  }
1052
- function Ze(t, e, o, s, n) {
1053
- const i = t === "vue" ? "vueStory" : "svelteStory";
1054
- return s.renderFn ? `import { ${i} } from '@nimtech/nimpress/story'
1055
- ${n.imports}
1054
+ function Xe(e, t, n, s, o) {
1055
+ const r = e === "vue" ? "vueStory" : "svelteStory";
1056
+ return s.renderFn ? `import { ${r} } from '@nimtech/nimpress/story'
1057
+ ${o.imports}
1056
1058
 
1057
- ${n.declarations}
1059
+ ${o.declarations}
1058
1060
 
1059
- // story: ${e}
1060
- export default ${i}({
1061
- name: ${JSON.stringify(e)},
1062
- description: ${JSON.stringify(`Scenario from ${o}`)},
1061
+ // story: ${t}
1062
+ export default ${r}({
1063
+ name: ${JSON.stringify(t)},
1064
+ description: ${JSON.stringify(`Scenario from ${n}`)},
1063
1065
  render: ${s.renderFn}
1064
1066
  })
1065
- ` : `import { ${i} } from '@nimtech/nimpress/story'
1067
+ ` : `import { ${r} } from '@nimtech/nimpress/story'
1066
1068
 
1067
- // story: ${e}
1068
- export default ${i}({
1069
- name: ${JSON.stringify(e)},
1069
+ // story: ${t}
1070
+ export default ${r}({
1071
+ name: ${JSON.stringify(t)},
1070
1072
  props: ${JSON.stringify(s.props ?? {}, null, 2)}
1071
1073
  })
1072
1074
  `;
1073
1075
  }
1074
- function K(t, e) {
1075
- const o = A(e, "system");
1076
- if (o === void 0) return;
1077
- const s = Object.keys(t.modules.systems);
1078
- if (!s.includes(o))
1079
- throw new Error(`[nimpress] modules: unknown system ${o}, configured: ${s.join(", ") || "none"}`);
1080
- return o;
1076
+ function te(e, t) {
1077
+ const n = T(t, "system");
1078
+ if (n === void 0) return;
1079
+ const s = Object.keys(e.modules.systems);
1080
+ if (!s.includes(n))
1081
+ throw new Error(`[nimpress] modules: unknown system ${n}, configured: ${s.join(", ") || "none"}`);
1082
+ return n;
1081
1083
  }
1082
- function ce(t, e, o) {
1083
- const s = K(t, e);
1084
+ function de(e, t, n) {
1085
+ const s = te(e, t);
1084
1086
  if (s) return s;
1085
- const n = Object.keys(t.modules.systems);
1086
- if (n.length === 1) return n[0];
1087
- throw n.length ? new Error(
1088
- `[nimpress] modules ${o}: several systems configured (${n.join(", ")}), pass --system=<name>`
1089
- ) : new Error(`[nimpress] modules ${o}: no systems configured`);
1090
- }
1091
- async function Pt(t, e, o) {
1092
- const s = o[0], n = o.slice(1), i = Object.keys(e.modules.systems);
1087
+ const o = Object.keys(e.modules.systems);
1088
+ if (o.length === 1) return o[0];
1089
+ throw o.length ? new Error(
1090
+ `[nimpress] modules ${n}: several systems configured (${o.join(", ")}), pass --system=<name>`
1091
+ ) : new Error(`[nimpress] modules ${n}: no systems configured`);
1092
+ }
1093
+ async function Kt(e, t, n) {
1094
+ const s = n[0], o = n.slice(1), r = Object.keys(t.modules.systems);
1093
1095
  if (s === "init") {
1094
- Mt(t, e);
1096
+ Yt(e, t);
1095
1097
  return;
1096
1098
  }
1097
1099
  if (s === "dev") {
1098
- const r = K(e, n), a = r ? [r] : i;
1100
+ const i = te(t, o), a = i ? [i] : r;
1099
1101
  if (!a.length) throw new Error("[nimpress] modules dev: no systems configured");
1100
- await Ie(t, e, a), await new Promise(() => {
1102
+ await Ue(e, t, a), await new Promise(() => {
1101
1103
  });
1102
1104
  }
1103
1105
  if (s === "build") {
1104
- const r = K(e, n), a = r ? [r] : Je(e);
1106
+ const i = te(t, o), a = i ? [i] : Be(t);
1105
1107
  if (!a.length) throw new Error("[nimpress] modules build: no systems configured");
1106
- await Pe(t, e, a);
1108
+ await Ge(e, t, a);
1107
1109
  return;
1108
1110
  }
1109
1111
  if (s === "lint") {
1110
- const r = await Te(t, e, K(e, n));
1111
- ue("nimpress modules lint", r, "nimpress modules lint: systems, schemas, and stories ok");
1112
+ const i = await Je(e, t, te(t, o));
1113
+ we("nimpress modules lint", i, "nimpress modules lint: systems, schemas, and stories ok");
1112
1114
  return;
1113
1115
  }
1114
1116
  if (s === "story") {
1115
- const r = ce(e, n, "story"), a = se(n, 0), l = A(n, "framework");
1117
+ const i = de(t, o, "story"), a = ee(o, 0), l = T(o, "framework");
1116
1118
  if (a) {
1117
- const u = await we(t, e, r, a, l);
1118
- u && console.log(`nimpress modules: story written to ${u}`);
1119
+ const m = await je(e, t, i, a, l);
1120
+ m && console.log(`nimpress modules: story written to ${m}`);
1119
1121
  return;
1120
1122
  }
1121
- const c = await Wt(t, e, r);
1122
- console.log(`nimpress modules: ${c} auto stories written for ${r}`);
1123
+ const c = await Gt(e, t, i);
1124
+ console.log(`nimpress modules: ${c} auto stories written for ${i}`);
1123
1125
  return;
1124
1126
  }
1125
1127
  if (s === "import") {
1126
- const r = ce(e, n, "import"), a = se(n, 0);
1127
- await Jt(t, e, r, {
1128
+ const i = de(t, o, "import"), a = ee(o, 0);
1129
+ await Vt(e, t, i, {
1128
1130
  file: a,
1129
- name: A(n, "name"),
1130
- source: A(n, "source"),
1131
- stories: A(n, "stories"),
1132
- match: A(n, "match"),
1133
- fromStories: n.includes("--from-stories"),
1134
- select: n.includes("--select")
1135
- }), le(t);
1131
+ name: T(o, "name"),
1132
+ source: T(o, "source"),
1133
+ stories: T(o, "stories"),
1134
+ match: T(o, "match"),
1135
+ fromStories: o.includes("--from-stories"),
1136
+ select: o.includes("--select")
1137
+ }), $e(e);
1136
1138
  return;
1137
1139
  }
1138
1140
  if (s === "update") {
1139
- const r = A(n, "component") ?? se(n, 0), a = await nt(t, e, { ref: r, system: K(e, n) });
1140
- console.log(`nimpress modules: ${a} schema${a === 1 ? "" : "s"} upserted`), le(t);
1141
+ const i = T(o, "component") ?? ee(o, 0), a = await ht(e, t, { ref: i, system: te(t, o) });
1142
+ console.log(`nimpress modules: ${a} schema${a === 1 ? "" : "s"} upserted`), $e(e);
1141
1143
  return;
1142
1144
  }
1143
1145
  if (s === "create") {
1144
- const r = A(n, "component");
1145
- if (r) {
1146
- if (!$e(n, "schema"))
1146
+ const i = T(o, "component");
1147
+ if (i) {
1148
+ if (!X(o, "schema"))
1147
1149
  throw new Error("[nimpress] modules create --component expects --schema to upsert the schema");
1148
- const m = await ot(t, e, r);
1149
- console.log(`nimpress modules: schema upserted at ${m}`);
1150
+ const u = await gt(e, t, i);
1151
+ console.log(`nimpress modules: schema upserted at ${u}`);
1150
1152
  return;
1151
1153
  }
1152
- const a = se(n, 0);
1154
+ const a = ee(o, 0);
1153
1155
  if (!a)
1154
1156
  throw new Error("[nimpress] modules create expects: nimpress modules create <Component> [--system=<name>], or --component=<ref> --schema");
1155
- const l = ce(e, n, "create"), c = A(n, "framework"), u = await At(t, e, l, a, c);
1156
- console.log(`nimpress modules: created ${a} at ${D(t, u)}`);
1157
+ const l = de(t, o, "create"), c = T(o, "framework"), m = await Ht(e, t, l, a, c);
1158
+ console.log(`nimpress modules: created ${a} at ${O(e, m)}`);
1157
1159
  return;
1158
1160
  }
1159
1161
  throw new Error("[nimpress] modules expects init, dev, build, lint, story, import, create or update");
1160
1162
  }
1161
- function Mt(t, e) {
1162
- const o = h(t, e.modules.dir);
1163
- ye(o, { recursive: !0 });
1164
- const s = h(t, "nimpress.config.json");
1163
+ function Yt(e, t) {
1164
+ const n = d(e, t.modules.dir);
1165
+ Q(n, { recursive: !0 });
1166
+ const s = d(e, "nimpress.config.json");
1165
1167
  if (b(s)) {
1166
- const n = JSON.parse(J(s, "utf-8"));
1167
- n.modules || (n.modules = { dir: e.modules.dir, route: e.modules.route, systems: {} }, L(s, JSON.stringify(n, null, 2) + `
1168
+ const o = JSON.parse(W(s, "utf-8"));
1169
+ o.modules || (o.modules = { dir: t.modules.dir, route: t.modules.route, systems: {} }, A(s, JSON.stringify(o, null, 2) + `
1168
1170
  `), console.log(`nimpress modules: modules block added to ${s}`));
1169
1171
  } else
1170
1172
  console.log("nimpress modules: add a modules block with systems entries to your nimpress config");
1171
- console.log(`nimpress modules: folder ready at ${o}`);
1173
+ console.log(`nimpress modules: folder ready at ${n}`);
1172
1174
  }
1173
- function He(t) {
1174
- if (!t.startsWith(`---
1175
+ function et(e) {
1176
+ if (!e.startsWith(`---
1175
1177
  `)) return null;
1176
- const e = t.indexOf(`
1178
+ const t = e.indexOf(`
1177
1179
  ---`, 4);
1178
- return e < 0 ? null : t.slice(4, e);
1180
+ return t < 0 ? null : e.slice(4, t);
1179
1181
  }
1180
- function Rt(t) {
1181
- for (const e of t.split(`
1182
+ function Qt(e) {
1183
+ for (const t of e.split(`
1182
1184
  `)) {
1183
- if (!e.startsWith("export:")) continue;
1184
- const o = e.slice(7).trim().replace(/^["']|["']$/g, "");
1185
- return o === "" || o === "false" ? null : o;
1185
+ if (!t.startsWith("export:")) continue;
1186
+ const n = t.slice(7).trim().replace(/^["']|["']$/g, "");
1187
+ return n === "" || n === "false" ? null : n;
1186
1188
  }
1187
1189
  return null;
1188
1190
  }
1189
- function _t(t, e) {
1190
- const o = He(t);
1191
- if (o === null) return t;
1192
- const s = o.split(`
1193
- `).filter((i) => !i.startsWith("export:") && !i.startsWith(" file:")), n = s.findIndex((i) => i.startsWith(" package:"));
1194
- return e && n >= 0 && !s.some((i) => i.startsWith(" version:")) && s.splice(n + 1, 0, ` version: ${JSON.stringify(e)}`), `---
1191
+ function Xt(e, t) {
1192
+ const n = et(e);
1193
+ if (n === null) return e;
1194
+ const s = n.split(`
1195
+ `).filter((r) => !r.startsWith("export:") && !r.startsWith(" file:")), o = s.findIndex((r) => r.startsWith(" package:"));
1196
+ return t && o >= 0 && !s.some((r) => r.startsWith(" version:")) && s.splice(o + 1, 0, ` version: ${JSON.stringify(t)}`), `---
1195
1197
  ${s.join(`
1196
- `)}${t.slice(4 + o.length)}`;
1198
+ `)}${e.slice(4 + n.length)}`;
1197
1199
  }
1198
- function Bt(t, e, o) {
1199
- const s = A(o, "target") ?? "", n = h(t, A(o, "out") ?? e.paths.export), i = h(t, e.contentDir);
1200
- let r = "";
1200
+ function es(e, t, n) {
1201
+ const s = T(n, "target") ?? "", o = d(e, T(n, "out") ?? t.paths.export), r = d(e, t.contentDir);
1202
+ let i = "";
1201
1203
  try {
1202
- r = JSON.parse(J(h(t, "package.json"), "utf-8")).version ?? "";
1204
+ i = JSON.parse(W(d(e, "package.json"), "utf-8")).version ?? "";
1203
1205
  } catch {
1204
- r = "";
1206
+ i = "";
1205
1207
  }
1206
1208
  let a = 0;
1207
- for (const l of ee(i)) {
1209
+ for (const l of re(r)) {
1208
1210
  if (!l.endsWith(".md")) continue;
1209
- const c = J(l, "utf-8"), u = He(c);
1210
- if (u === null) continue;
1211
- const m = Rt(u);
1212
- if (m === null || s && m !== s && m !== "true") continue;
1213
- const d = z(l), f = h(n, D(i, d));
1214
- ye(f, { recursive: !0 });
1215
- for (const p of q(d, { withFileTypes: !0 })) {
1216
- if (!p.isFile()) continue;
1217
- const w = J(h(d, p.name), "utf-8");
1218
- L(
1219
- h(f, p.name),
1220
- p.name.endsWith(".md") ? _t(w, r) : w
1211
+ const c = W(l, "utf-8"), m = et(c);
1212
+ if (m === null) continue;
1213
+ const u = Qt(m);
1214
+ if (u === null || s && u !== s && u !== "true") continue;
1215
+ const h = L(l), p = d(o, O(r, h));
1216
+ Q(p, { recursive: !0 });
1217
+ for (const f of Y(h, { withFileTypes: !0 })) {
1218
+ if (!f.isFile()) continue;
1219
+ const w = W(d(h, f.name), "utf-8");
1220
+ A(
1221
+ d(p, f.name),
1222
+ f.name.endsWith(".md") ? Xt(w, i) : w
1221
1223
  );
1222
1224
  }
1223
1225
  a++;
1224
1226
  }
1225
- console.log(`nimpress export: ${a} pages collected into ${n}`);
1227
+ console.log(`nimpress export: ${a} pages collected into ${o}`);
1228
+ }
1229
+ const he = d(".claude", "skills", "nimpress", "SKILL.md");
1230
+ function tt() {
1231
+ const e = L(kt(import.meta.url)), t = [
1232
+ F(e, he),
1233
+ F(e, "..", he),
1234
+ F(e, "..", "..", he)
1235
+ ];
1236
+ for (const n of t)
1237
+ try {
1238
+ return W(n, "utf-8");
1239
+ } catch {
1240
+ }
1241
+ throw new Error(`[nimpress] skill: SKILL.md not found, looked in ${t.join(", ")}`);
1242
+ }
1243
+ function st(e, t) {
1244
+ const n = t ? d(Le(), ".claude") : d(e, ".claude"), s = d(n, "skills", "nimpress");
1245
+ Q(s, { recursive: !0 });
1246
+ const o = d(s, "SKILL.md");
1247
+ return A(o, tt()), console.log(`wrote ${o}`), o;
1248
+ }
1249
+ function ts(e, t) {
1250
+ const n = t[0];
1251
+ if (n === "get") {
1252
+ process.stdout.write(tt());
1253
+ return;
1254
+ }
1255
+ if (n === "put") {
1256
+ st(e, !X(t, "project"));
1257
+ return;
1258
+ }
1259
+ throw new Error("[nimpress] skill expects get or put");
1226
1260
  }
1227
- async function Xt(t) {
1228
- const e = t[0] ?? "dev", o = t.slice(1), s = process.cwd();
1229
- if (e === "init") {
1230
- dt(s);
1261
+ const V = {
1262
+ name: "--system",
1263
+ value: !0,
1264
+ describe: "the configured component system to act on"
1265
+ }, We = {
1266
+ name: "--framework",
1267
+ value: !0,
1268
+ describe: "vue or svelte, overriding the framework of the system"
1269
+ }, H = [
1270
+ {
1271
+ name: "init",
1272
+ describe: "Write the config, the content folder, and the agent guide",
1273
+ flags: [{ name: "--json", value: !1, describe: "write nimpress.config.json instead of nimpress.config.ts" }],
1274
+ subs: []
1275
+ },
1276
+ {
1277
+ name: "dev",
1278
+ describe: "Serve the site and every component harness",
1279
+ flags: [],
1280
+ subs: []
1281
+ },
1282
+ {
1283
+ name: "build",
1284
+ describe: "Build the static site and the harness bundles",
1285
+ flags: [],
1286
+ subs: []
1287
+ },
1288
+ {
1289
+ name: "lint",
1290
+ describe: "Check structure, frontmatter, imports, and modules, then build to verify",
1291
+ flags: [{ name: "--no-build", value: !1, describe: "stop after the checks and skip the verification build" }],
1292
+ subs: []
1293
+ },
1294
+ {
1295
+ name: "modules",
1296
+ describe: "Drive the component workshop",
1297
+ flags: [],
1298
+ subs: [
1299
+ { name: "init", describe: "Create the modules folder and the config block", flags: [], subs: [] },
1300
+ { name: "dev", describe: "Serve the harnesses and stay running", flags: [V], subs: [] },
1301
+ { name: "build", describe: "Build the harness bundles", flags: [V], subs: [] },
1302
+ { name: "lint", describe: "Check the systems, the schemas, and the stories", flags: [V], subs: [] },
1303
+ { name: "story", describe: "Write auto stories for one component or for every component", flags: [V, We], subs: [] },
1304
+ {
1305
+ name: "import",
1306
+ describe: "Import components and storybook stories into component pages",
1307
+ flags: [
1308
+ V,
1309
+ { name: "--name", value: !0, describe: "the component name when a single file is imported" },
1310
+ { name: "--source", value: !0, describe: "the component source root, overriding the system source" },
1311
+ { name: "--stories", value: !0, describe: "an extra folder of storybook csf files" },
1312
+ { name: "--match", value: !0, describe: "a regular expression the component name must match" },
1313
+ { name: "--from-stories", value: !1, describe: "take the component list from the csf files instead of the source" },
1314
+ { name: "--select", value: !1, describe: "pick the components to import interactively" }
1315
+ ],
1316
+ subs: []
1317
+ },
1318
+ {
1319
+ name: "create",
1320
+ describe: "Create a component page, or upsert one schema",
1321
+ flags: [
1322
+ V,
1323
+ We,
1324
+ { name: "--component", value: !0, describe: "the component reference whose schema is upserted" },
1325
+ { name: "--schema", value: !1, describe: "required with --component, upserts the schema" }
1326
+ ],
1327
+ subs: []
1328
+ },
1329
+ {
1330
+ name: "update",
1331
+ describe: "Upsert the component schemas from the component types",
1332
+ flags: [V, { name: "--component", value: !0, describe: "limit the upsert to one component reference" }],
1333
+ subs: []
1334
+ }
1335
+ ]
1336
+ },
1337
+ {
1338
+ name: "export",
1339
+ describe: "Collect the pages marked with the export frontmatter field",
1340
+ flags: [
1341
+ { name: "--target", value: !0, describe: "the export target name matched against the frontmatter value" },
1342
+ { name: "--out", value: !0, describe: "the folder the pages are collected into" }
1343
+ ],
1344
+ subs: []
1345
+ },
1346
+ {
1347
+ name: "guard",
1348
+ describe: "Wire the gated pages to the auth provider artifacts",
1349
+ flags: [],
1350
+ subs: [
1351
+ {
1352
+ name: "map",
1353
+ describe: "Map the guarded files into guard.map.json",
1354
+ flags: [
1355
+ { name: "--dist", value: !0, describe: "the build folder to read" },
1356
+ { name: "--out", value: !0, describe: "where the mapping json is written" }
1357
+ ],
1358
+ subs: []
1359
+ },
1360
+ {
1361
+ name: "apply",
1362
+ describe: "Apply the uploaded mapping and strip the guarded folder",
1363
+ flags: [
1364
+ { name: "--dist", value: !0, describe: "the build folder to read" },
1365
+ { name: "--map", value: !0, describe: "the uploaded mapping json" }
1366
+ ],
1367
+ subs: []
1368
+ }
1369
+ ]
1370
+ },
1371
+ {
1372
+ name: "skill",
1373
+ describe: "The claude skill that teaches an agent to drive this cli",
1374
+ flags: [],
1375
+ subs: [
1376
+ { name: "get", describe: "Print the skill document", flags: [], subs: [] },
1377
+ {
1378
+ name: "put",
1379
+ describe: "Install the skill under ~/.claude/skills, or into the current project with --project",
1380
+ flags: [{ name: "--project", value: !1, describe: "install into .claude of the current directory instead of the home directory" }],
1381
+ subs: []
1382
+ }
1383
+ ]
1384
+ },
1385
+ {
1386
+ name: "completion",
1387
+ describe: "Print the shell completion script, or wire it up with --auto",
1388
+ flags: [
1389
+ { name: "--auto", value: !1, describe: "detect the shell and install completion into the rc file" },
1390
+ { name: "--skill", value: !1, describe: "install the claude skill globally in the same step" }
1391
+ ],
1392
+ subs: [
1393
+ { name: "bash", describe: "the bash completion script", flags: [], subs: [] },
1394
+ { name: "zsh", describe: "the zsh completion script", flags: [], subs: [] },
1395
+ { name: "fish", describe: "the fish completion script", flags: [], subs: [] },
1396
+ { name: "powershell", describe: "the powershell completion script", flags: [], subs: [] }
1397
+ ]
1398
+ }
1399
+ ], nt = ["bash", "zsh", "fish", "powershell"];
1400
+ function me(e) {
1401
+ const t = [];
1402
+ for (const n of [...e.flags, ...e.subs.flatMap((s) => s.flags)])
1403
+ t.some((s) => s.name === n.name) || t.push(n);
1404
+ return t;
1405
+ }
1406
+ function pe(e, t) {
1407
+ return t && e.value ? `${e.name}=` : e.name;
1408
+ }
1409
+ function ss() {
1410
+ const e = ["_nimpress() {", ' local cur="${COMP_WORDS[COMP_CWORD]}"'];
1411
+ e.push(` local words="${H.map((t) => t.name).join(" ")}"`), e.push(' if [ "$COMP_CWORD" -gt 1 ]; then'), e.push(' case "${COMP_WORDS[1]}" in');
1412
+ for (const t of H) {
1413
+ const n = [...t.subs.map((s) => s.name), ...me(t).map((s) => pe(s, !1))];
1414
+ e.push(` ${t.name}) words="${n.join(" ")}" ;;`);
1415
+ }
1416
+ return e.push(' *) words="" ;;'), e.push(" esac"), e.push(" fi"), e.push(' COMPREPLY=( $(compgen -W "$words" -- "$cur") )'), e.push("}"), e.push("complete -o default -F _nimpress nimpress"), e.join(`
1417
+ `) + `
1418
+ `;
1419
+ }
1420
+ function ge(e, t, n) {
1421
+ const s = [`${e}entries=(`];
1422
+ for (const o of n) s.push(`${e} ${o}`);
1423
+ return s.push(`${e})`), s.push(`${e}_describe '${t}' entries`), s.push(`${e}return`), s;
1424
+ }
1425
+ function ns() {
1426
+ const e = ["#compdef nimpress", "", "_nimpress() {", " local -a entries", " if (( CURRENT == 2 )); then"];
1427
+ e.push(
1428
+ ...ge(
1429
+ " ",
1430
+ "nimpress command",
1431
+ H.map((t) => `'${t.name}:${t.describe}'`)
1432
+ )
1433
+ ), e.push(" fi"), e.push(' case "$words[2]" in');
1434
+ for (const t of H) {
1435
+ e.push(` ${t.name})`), t.subs.length && (e.push(" if (( CURRENT == 3 )); then"), e.push(
1436
+ ...ge(
1437
+ " ",
1438
+ `${t.name} argument`,
1439
+ t.subs.map((s) => `'${s.name}:${s.describe}'`)
1440
+ )
1441
+ ), e.push(" fi"));
1442
+ const n = me(t);
1443
+ n.length ? e.push(
1444
+ ...ge(
1445
+ " ",
1446
+ "nimpress flag",
1447
+ n.map((s) => `'${pe(s, !0)}:${s.describe}'`)
1448
+ )
1449
+ ) : e.push(" return"), e.push(" ;;");
1450
+ }
1451
+ return e.push(" esac"), e.push("}"), e.push(""), e.push('if [ "$funcstack[1]" = "_nimpress" ]; then'), e.push(' _nimpress "$@"'), e.push("else"), e.push(" compdef _nimpress nimpress"), e.push("fi"), e.join(`
1452
+ `) + `
1453
+ `;
1454
+ }
1455
+ function os() {
1456
+ const e = ["complete -c nimpress -f"];
1457
+ for (const t of H)
1458
+ e.push(
1459
+ `complete -c nimpress -n '__fish_use_subcommand' -a '${t.name}' -d '${t.describe}'`
1460
+ );
1461
+ for (const t of H) {
1462
+ const n = `__fish_seen_subcommand_from ${t.name}`;
1463
+ for (const s of t.subs)
1464
+ e.push(`complete -c nimpress -n '${n}' -a '${s.name}' -d '${s.describe}'`);
1465
+ for (const s of me(t))
1466
+ e.push(
1467
+ `complete -c nimpress -n '${n}' -a '${pe(s, !0)}' -d '${s.describe}'`
1468
+ );
1469
+ }
1470
+ return e.join(`
1471
+ `) + `
1472
+ `;
1473
+ }
1474
+ function rs() {
1475
+ const e = [
1476
+ "Register-ArgumentCompleter -Native -CommandName nimpress -ScriptBlock {",
1477
+ " param($wordToComplete, $commandAst, $cursorPosition)",
1478
+ " $words = @($commandAst.CommandElements | ForEach-Object { $_.ToString() })",
1479
+ " $candidates = @()",
1480
+ " if ($words.Count -le 2) {",
1481
+ ` $candidates = @(${H.map((t) => `'${t.name}'`).join(", ")})`,
1482
+ " } else {",
1483
+ " switch ($words[1]) {"
1484
+ ];
1485
+ for (const t of H) {
1486
+ const n = [...t.subs.map((s) => s.name), ...me(t).map((s) => pe(s, !0))];
1487
+ e.push(` '${t.name}' { $candidates = @(${n.map((s) => `'${s}'`).join(", ")}) }`);
1488
+ }
1489
+ return e.push(" }"), e.push(" }"), e.push(' $candidates | Where-Object { $_ -like "$wordToComplete*" } | ForEach-Object {'), e.push(" [System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_)"), e.push(" }"), e.push("}"), e.join(`
1490
+ `) + `
1491
+ `;
1492
+ }
1493
+ function ot(e) {
1494
+ if (e === "bash") return ss();
1495
+ if (e === "zsh") return ns();
1496
+ if (e === "fish") return os();
1497
+ if (e === "powershell") return rs();
1498
+ throw new Error(`[nimpress] completion: unsupported shell ${e}, use ${nt.join(", ")}`);
1499
+ }
1500
+ function is() {
1501
+ const e = C(process.env.SHELL ?? "");
1502
+ for (const t of ["zsh", "bash", "fish"])
1503
+ if (e.includes(t)) return t;
1504
+ return "";
1505
+ }
1506
+ function as(e, t) {
1507
+ const n = "# >>> nimpress completion >>>", s = "# <<< nimpress completion <<<", o = `${n}
1508
+ ${t}
1509
+ ${s}`, r = e.indexOf(n), i = e.indexOf(s);
1510
+ return r >= 0 && i > r ? e.slice(0, r) + o + e.slice(i + s.length) : r >= 0 ? e.replace(/\n+$/, "") + `
1511
+ ` + o + `
1512
+ ` : (e === "" || e.endsWith(`
1513
+ `) ? e : e + `
1514
+ `) + o + `
1515
+ `;
1516
+ }
1517
+ function cs(e, t) {
1518
+ let n = "";
1519
+ try {
1520
+ n = W(e, "utf-8");
1521
+ } catch {
1522
+ n = "";
1523
+ }
1524
+ A(e, as(n, t));
1525
+ }
1526
+ function ls(e) {
1527
+ const t = e || is();
1528
+ if (!t)
1529
+ throw new Error("[nimpress] completion: could not detect the shell from $SHELL, name it: nimpress completion <shell> --auto");
1530
+ const n = ot(t), s = Le();
1531
+ if (t === "fish") {
1532
+ const l = d(s, ".config", "fish", "completions");
1533
+ Q(l, { recursive: !0 });
1534
+ const c = d(l, "nimpress.fish");
1535
+ A(c, n), console.log(`wrote ${c}`), console.log("fish loads it on the next shell");
1536
+ return;
1537
+ }
1538
+ if (t !== "bash" && t !== "zsh")
1539
+ throw new Error(`[nimpress] completion: auto install covers bash, zsh, and fish, for ${t} run: nimpress completion ${t}`);
1540
+ const o = d(s, ".config", "nimpress", "completions");
1541
+ Q(o, { recursive: !0 });
1542
+ const r = d(o, t === "zsh" ? "_nimpress" : "nimpress.bash");
1543
+ A(r, n), console.log(`wrote ${r}`);
1544
+ const i = d(s, t === "zsh" ? ".zshrc" : ".bashrc"), a = t === "zsh" ? `fpath=("${o}" $fpath)
1545
+ autoload -Uz compinit && compinit -u` : `[ -f "${r}" ] && source "${r}"`;
1546
+ cs(i, a), console.log(`wired ${i}`), console.log(`start a new shell or run: source ${i}`);
1547
+ }
1548
+ function us(e, t) {
1549
+ const n = ee(t, 0) ?? "", s = X(t, "auto"), o = X(t, "skill");
1550
+ if (!s) {
1551
+ if (o) throw new Error("[nimpress] completion: --skill installs alongside --auto");
1552
+ if (!n) throw new Error(`[nimpress] completion: name a shell (${nt.join(", ")}) or pass --auto`);
1553
+ process.stdout.write(ot(n));
1554
+ return;
1555
+ }
1556
+ ls(n), o && st(e, !0);
1557
+ }
1558
+ async function ks(e) {
1559
+ const t = e[0] ?? "dev", n = e.slice(1), s = process.cwd();
1560
+ if (t === "init") {
1561
+ Ft(s);
1562
+ return;
1563
+ }
1564
+ if (t === "skill") {
1565
+ ts(s, n);
1566
+ return;
1567
+ }
1568
+ if (t === "completion") {
1569
+ us(s, n);
1231
1570
  return;
1232
1571
  }
1233
- const { resolved: n } = await rt(s);
1234
- if (e === "lint") {
1235
- await Ot(s, n);
1572
+ const { resolved: o } = await $t(s);
1573
+ if (t === "lint") {
1574
+ await Jt(s, o);
1236
1575
  return;
1237
1576
  }
1238
- if (e === "dev") {
1239
- await bt(s, n);
1577
+ if (t === "dev") {
1578
+ await Nt(s, o);
1240
1579
  return;
1241
1580
  }
1242
- if (e === "build") {
1243
- await Me(s, n);
1581
+ if (t === "build") {
1582
+ await He(s, o);
1244
1583
  return;
1245
1584
  }
1246
- if (e === "guard") {
1247
- Nt(s, n, o);
1585
+ if (t === "guard") {
1586
+ Ut(s, o, n);
1248
1587
  return;
1249
1588
  }
1250
- if (e === "modules") {
1251
- await Pt(s, n, o);
1589
+ if (t === "modules") {
1590
+ await Kt(s, o, n);
1252
1591
  return;
1253
1592
  }
1254
- if (e === "export") {
1255
- Bt(s, n, o);
1593
+ if (t === "export") {
1594
+ es(s, o, n);
1256
1595
  return;
1257
1596
  }
1258
- throw new Error(`[nimpress] unknown command: ${e}`);
1597
+ throw new Error(`[nimpress] unknown command: ${t}`);
1259
1598
  }
1260
1599
  export {
1261
- De as buildViteConfig,
1262
- Qe as indexHtml,
1263
- rt as loadNimpressConfig,
1264
- Xt as run
1600
+ Pe as buildViteConfig,
1601
+ lt as indexHtml,
1602
+ $t as loadNimpressConfig,
1603
+ ks as run
1265
1604
  };