@nimtech/nimpress 2.6.13 → 2.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.es.js CHANGED
@@ -1,30 +1,30 @@
1
- import { d as z, c as Ae, r as Me, s as Gt, p as Ht, a as st, b as pe, e as Ut, f as Zt, g as De, h as nt, i as Vt, j as ot, k as Kt, l as Yt, m as Qt, C as ge, n as Xt, o as rt, q as Ge, w as me, t as it, u as qt, v as es, x as He, y as ts, z as ss, A as ns, B as os, D as we, E as rs } from "./plugin-CnifGnSA.js";
2
- import { join as d, dirname as N, relative as F, sep as L, extname as fe, resolve as x, basename as D } from "node:path";
3
- import { readdirSync as ie, existsSync as b, writeFileSync as W, mkdirSync as B, rmSync as ee, readFileSync as C, statSync as at, watch as Ue } from "node:fs";
1
+ import { d as B, c as Me, r as Ie, s as Zt, p as Vt, a as rt, b as pe, e as Kt, f as Yt, g as _e, h as it, i as Qt, j as at, k as Xt, l as qt, m as es, C as ge, n as ts, o as Le, q as He, w as me, t as ct, u as ss, v as ns, x as we, y as os, z as rs, A as is, B as as, D as cs, E as Ue, F as ls, G as us } from "./plugin-C8OdcVeq.js";
2
+ import { join as d, dirname as N, relative as E, sep as L, extname as fe, resolve as x, basename as D } from "node:path";
3
+ import { readdirSync as ae, existsSync as b, writeFileSync as W, mkdirSync as J, rmSync as te, readFileSync as C, statSync as lt, watch as Ze, openSync as ps } from "node:fs";
4
4
  import ue from "gray-matter";
5
- import { readFile as Se, readdir as is, writeFile as q, mkdir as _e, copyFile as ct } from "node:fs/promises";
6
- import { s as as, r as $e } from "./typeMembers-CNvE92EX.js";
7
- import { createServer as lt, build as ut } from "vite";
8
- import { createHash as pt } from "node:crypto";
9
- import { createInterface as mt } from "node:readline/promises";
10
- import { fileURLToPath as ft } from "node:url";
11
- import { homedir as K, platform as cs } from "node:os";
12
- import { spawnSync as te, spawn as Ie } from "node:child_process";
13
- import { createInterface as ls } from "node:readline";
14
- import { parse as us } from "yaml";
5
+ import { readFile as je, readdir as ms, writeFile as ee, mkdir as Ne, copyFile as ut } from "node:fs/promises";
6
+ import { s as fs, r as $e } from "./typeMembers-CNvE92EX.js";
7
+ import { createServer as pt, build as mt } from "vite";
8
+ import { createHash as ft } from "node:crypto";
9
+ import { spawnSync as se, spawn as ke } from "node:child_process";
10
+ import { createInterface as dt } from "node:readline/promises";
11
+ import { homedir as Q, platform as ds } from "node:os";
12
+ import { parse as hs } from "yaml";
13
+ import { fileURLToPath as ht } from "node:url";
14
+ import { createInterface as gs } from "node:readline";
15
15
  function _(e, t) {
16
16
  return e.find((n) => n.startsWith(`--${t}=`))?.slice(t.length + 3);
17
17
  }
18
18
  function M(e, t) {
19
19
  return e.includes(`--${t}`);
20
20
  }
21
- function ne(e, t) {
21
+ function K(e, t) {
22
22
  return e.filter((n) => !n.startsWith("--"))[t];
23
23
  }
24
- function Y(e, t = []) {
24
+ function X(e, t = []) {
25
25
  let s;
26
26
  try {
27
- s = ie(e, { withFileTypes: !0 });
27
+ s = ae(e, { withFileTypes: !0 });
28
28
  } catch {
29
29
  return t;
30
30
  }
@@ -32,12 +32,12 @@ function Y(e, t = []) {
32
32
  const o = d(e, n.name);
33
33
  if (n.isDirectory()) {
34
34
  if (n.name === "node_modules" || n.name.startsWith(".")) continue;
35
- Y(o, t);
35
+ X(o, t);
36
36
  } else n.isFile() && t.push(o);
37
37
  }
38
38
  return t;
39
39
  }
40
- function Ne(e, t, s) {
40
+ function We(e, t, s) {
41
41
  if (t.length) {
42
42
  console.error(`${e} failed with ${t.length} problems`);
43
43
  for (const n of t) console.error(` ${n}`);
@@ -45,7 +45,7 @@ function Ne(e, t, s) {
45
45
  }
46
46
  console.log(s);
47
47
  }
48
- function ps() {
48
+ function ws() {
49
49
  return `import { defineConfig } from '@nimtech/nimpress/plugin'
50
50
 
51
51
  /**
@@ -55,15 +55,15 @@ function ps() {
55
55
  */
56
56
  export default defineConfig({
57
57
  /** Site title shown in the header and the tab. */
58
- title: ${JSON.stringify(z.title)},
58
+ title: ${JSON.stringify(B.title)},
59
59
 
60
- /** Folder holding the markdown content. Default ${JSON.stringify(z.contentDir)}. */
60
+ /** Folder holding the markdown content. Default ${JSON.stringify(B.contentDir)}. */
61
61
  // contentDir: 'docs',
62
62
 
63
- /** Root assets folder copied into the build, never inside contentDir. Default ${JSON.stringify(z.assetsDir)}. */
63
+ /** Root assets folder copied into the build, never inside contentDir. Default ${JSON.stringify(B.assetsDir)}. */
64
64
  // assetsDir: 'assets',
65
65
 
66
- /** Url base the assets folder serves under. Default ${JSON.stringify(z.assetUrlBase)}. */
66
+ /** Url base the assets folder serves under. Default ${JSON.stringify(B.assetUrlBase)}. */
67
67
  // assetUrlBase: '/assets',
68
68
 
69
69
  /**
@@ -181,21 +181,21 @@ export default defineConfig({
181
181
  })
182
182
  `;
183
183
  }
184
- function ms() {
184
+ function $s() {
185
185
  return JSON.stringify(
186
186
  {
187
187
  $schema: "./node_modules/@nimtech/nimpress/config.schema.json",
188
- title: z.title,
189
- contentDir: z.contentDir,
190
- assetsDir: z.assetsDir,
191
- assetUrlBase: z.assetUrlBase
188
+ title: B.title,
189
+ contentDir: B.contentDir,
190
+ assetsDir: B.assetsDir,
191
+ assetUrlBase: B.assetUrlBase
192
192
  },
193
193
  null,
194
194
  2
195
195
  ) + `
196
196
  `;
197
197
  }
198
- function fs(e) {
198
+ function ys(e) {
199
199
  return `# Nimpress project
200
200
 
201
201
  This site is built with @nimtech/nimpress. Content lives in \`${e}/\` as markdown with typed frontmatter.
@@ -237,11 +237,11 @@ The authoritative AI working rules ship inside the package at \`node_modules/@ni
237
237
  8. \`nimpress guard map\` and \`nimpress guard apply\` wire gated pages, marked with the \`gate:\` frontmatter field, to the auth provider artifacts.
238
238
  `;
239
239
  }
240
- function ds(e) {
240
+ function bs(e) {
241
241
  const t = d(e, "nimpress.config.ts"), s = d(e, "nimpress.config.json"), n = M(process.argv.slice(2), "json");
242
- !b(t) && !b(s) && (n ? (W(s, ms()), console.log(`nimpress init: ${s} written, field descriptions come from the referenced config.schema.json`)) : (W(t, ps()), console.log(`nimpress init: ${t} written with every field documented, uncomment what you need`)));
243
- const o = d(e, z.contentDir);
244
- (!b(o) || ie(o).length === 0) && (B(o, { recursive: !0 }), W(
242
+ !b(t) && !b(s) && (n ? (W(s, $s()), console.log(`nimpress init: ${s} written, field descriptions come from the referenced config.schema.json`)) : (W(t, ws()), console.log(`nimpress init: ${t} written with every field documented, uncomment what you need`)));
243
+ const o = d(e, B.contentDir);
244
+ (!b(o) || ae(o).length === 0) && (J(o, { recursive: !0 }), W(
245
245
  d(o, "index.md"),
246
246
  `---
247
247
  title: Home
@@ -250,30 +250,30 @@ title: Home
250
250
  Welcome to your Nimpress site.
251
251
  `
252
252
  ));
253
- const i = fs(z.contentDir);
253
+ const i = ys(B.contentDir);
254
254
  for (const c of ["CLAUDE.md", "AGENTS.md"]) {
255
- const p = d(e, c);
256
- b(p) || (W(p, i), console.log(`nimpress init: ${c} written, pointing at the packaged rules in node_modules/@nimtech/nimpress/.claude/rules/`));
255
+ const l = d(e, c);
256
+ b(l) || (W(l, i), console.log(`nimpress init: ${c} written, pointing at the packaged rules in node_modules/@nimtech/nimpress/.claude/rules/`));
257
257
  }
258
258
  }
259
- const hs = { vue: "vueStory", svelte: "svelteStory" }, gs = { vue: ".svelte", svelte: ".vue" };
259
+ const vs = { vue: "vueStory", svelte: "svelteStory" }, ks = { vue: ".svelte", svelte: ".vue" };
260
260
  function ce(e) {
261
261
  return `run nimpress modules update ${e}`;
262
262
  }
263
- async function ws(e) {
263
+ async function xs(e) {
264
264
  let t;
265
265
  try {
266
- t = await is(e, { withFileTypes: !0 });
266
+ t = await ms(e, { withFileTypes: !0 });
267
267
  } catch {
268
268
  return [];
269
269
  }
270
270
  return t.filter((s) => s.isFile() && /\.story\.tsx?$/.test(s.name)).map((s) => s.name);
271
271
  }
272
- function $s(e, t) {
272
+ function Ss(e, t) {
273
273
  const s = t === "integer" ? "number" : t;
274
274
  return e.every((n) => typeof n === s);
275
275
  }
276
- function ys(e, t, s, n, o) {
276
+ function js(e, t, s, n, o) {
277
277
  const r = [], i = n.properties ?? {}, c = o.properties ?? {};
278
278
  for (const m of Object.keys(c))
279
279
  m in i || r.push(`${e}: prop ${m} is missing from the schema, ${ce(t)}`);
@@ -283,134 +283,134 @@ function ys(e, t, s, n, o) {
283
283
  const h = c[m];
284
284
  if (h && (f.type && h.type && f.type !== h.type && !f.enum && r.push(
285
285
  `${e}: prop ${m} schema type ${f.type} conflicts with source type ${h.type}, ${ce(t)}`
286
- ), f.enum && h.type && !$s(f.enum, h.type) && r.push(`${e}: prop ${m} enum values mismatch the source type ${h.type}`), f.enum && h.enum)) {
286
+ ), f.enum && h.type && !Ss(f.enum, h.type) && r.push(`${e}: prop ${m} enum values mismatch the source type ${h.type}`), f.enum && h.enum)) {
287
287
  const g = new Set(h.enum.map((k) => JSON.stringify(k))), w = f.enum.filter((k) => !g.has(JSON.stringify(k)));
288
288
  w.length && r.push(
289
289
  `${e}: prop ${m} enum carries ${w.map((k) => JSON.stringify(k)).join(", ")} outside the source union`
290
290
  );
291
291
  }
292
292
  }
293
- const p = n.slots ?? {}, a = o.slots ?? {};
293
+ const l = n.slots ?? {}, a = o.slots ?? {};
294
294
  for (const m of Object.keys(a))
295
- m in p || r.push(`${e}: slot ${m} is missing from the schema, ${ce(t)}`);
296
- for (const m of Object.keys(p))
295
+ m in l || r.push(`${e}: slot ${m} is missing from the schema, ${ce(t)}`);
296
+ for (const m of Object.keys(l))
297
297
  m in a || r.push(`${e}: schema slot ${m} has no counterpart in ${s}`);
298
- const l = new Set(n.emits ?? []), u = new Set(o.emits ?? []);
298
+ const u = new Set(n.emits ?? []), p = new Set(o.emits ?? []);
299
+ for (const m of p)
300
+ u.has(m) || r.push(`${e}: emit ${m} is missing from the schema, ${ce(t)}`);
299
301
  for (const m of u)
300
- l.has(m) || r.push(`${e}: emit ${m} is missing from the schema, ${ce(t)}`);
301
- for (const m of l)
302
- u.has(m) || r.push(`${e}: schema emit ${m} has no counterpart in ${s}`);
302
+ p.has(m) || r.push(`${e}: schema emit ${m} has no counterpart in ${s}`);
303
303
  return r;
304
304
  }
305
- async function dt(e, t, s) {
306
- const n = s ? [s] : Object.keys(t.modules.systems), o = [], r = await Ae(e, t.contentDir);
305
+ async function gt(e, t, s) {
306
+ const n = s ? [s] : Object.keys(t.modules.systems), o = [], r = await Me(e, t.contentDir);
307
307
  for (const i of n) {
308
308
  const c = t.modules.systems[i];
309
309
  if (!c) {
310
310
  o.push(`${i}: not a configured system`);
311
311
  continue;
312
312
  }
313
- const p = c.framework, a = hs[p === "vue" ? "svelte" : "vue"], l = gs[p];
314
- for (const u of r) {
315
- if (u.system !== i) continue;
316
- const m = N(u.pageFile), f = F(e, m).split(L).join("/"), h = await ws(m);
317
- h.length || o.push(`${f}: no story, run nimpress modules story --system=${i} ${u.component}`);
313
+ const l = c.framework, a = vs[l === "vue" ? "svelte" : "vue"], u = ks[l];
314
+ for (const p of r) {
315
+ if (p.system !== i) continue;
316
+ const m = N(p.pageFile), f = E(e, m).split(L).join("/"), h = await xs(m);
317
+ h.length || o.push(`${f}: no story, run nimpress modules story --system=${i} ${p.component}`);
318
318
  const g = /* @__PURE__ */ new Set();
319
- for (const O of h) {
319
+ for (const F of h) {
320
320
  let T;
321
321
  try {
322
- T = await Se(d(m, O), "utf-8");
322
+ T = await je(d(m, F), "utf-8");
323
323
  } catch {
324
324
  continue;
325
325
  }
326
- (/\bharness\s*:/.test(T) || /\brender\s*:/.test(T)) && g.add(O), T.includes(a) && o.push(`${f}/${O}: uses ${a} inside the ${p} system ${i}`);
326
+ (/\bharness\s*:/.test(T) || /\brender\s*:/.test(T)) && g.add(F), T.includes(a) && o.push(`${f}/${F}: uses ${a} inside the ${l} system ${i}`);
327
327
  for (const $ of T.matchAll(/from\s+['"]([^'"]+)['"]/g))
328
- fe($[1]) === l && o.push(`${f}/${O}: imports ${$[1]} inside the ${p} system ${i}`);
328
+ fe($[1]) === u && o.push(`${f}/${F}: imports ${$[1]} inside the ${l} system ${i}`);
329
329
  }
330
- const w = Me(e, t.modules, i, u.component, u.file);
331
- if (w && fe(w.componentFile) === l && o.push(
332
- `${f}: component file ${F(e, w.componentFile)} mismatches the ${p} system ${i}`
330
+ const w = Ie(e, t.modules, i, p.component, p.file);
331
+ if (w && fe(w.componentFile) === u && o.push(
332
+ `${f}: component file ${E(e, w.componentFile)} mismatches the ${l} system ${i}`
333
333
  ), b(d(m, "schema.json")) && b(d(m, "schema.yml"))) {
334
334
  o.push(`${f}: both schema.json and schema.yml exist, keep one`);
335
335
  continue;
336
336
  }
337
- const k = Gt(m);
337
+ const k = Zt(m);
338
338
  if (!k) {
339
- o.push(`${f}: schema file missing, ${ce(u.component)}`);
339
+ o.push(`${f}: schema file missing, ${ce(p.component)}`);
340
340
  continue;
341
341
  }
342
342
  let j;
343
343
  try {
344
- j = await Se(k.path, "utf-8");
344
+ j = await je(k.path, "utf-8");
345
345
  } catch {
346
346
  o.push(`${f}: ${k.form} schema unreadable`);
347
347
  continue;
348
348
  }
349
- let E;
349
+ let O;
350
350
  try {
351
- E = Ht(j, k.form);
351
+ O = Vt(j, k.form);
352
352
  } catch {
353
353
  o.push(`${f}: schema is not valid ${k.form}, fix it by hand`);
354
354
  continue;
355
355
  }
356
- const v = new Set(Object.keys(E.properties ?? {}));
357
- for (const O of await st(m))
358
- if (!g.has(O.file))
359
- for (const T of Object.keys(O.props ?? {}))
360
- v.has(T) || o.push(`${f}/${O.file}: prop ${T} is absent from the schema, ${ce(u.component)}`);
361
- const R = w ? await Se(w.componentFile, "utf-8").catch(() => {
356
+ const v = new Set(Object.keys(O.properties ?? {}));
357
+ for (const F of await rt(m))
358
+ if (!g.has(F.file))
359
+ for (const T of Object.keys(F.props ?? {}))
360
+ v.has(T) || o.push(`${f}/${F.file}: prop ${T} is absent from the schema, ${ce(p.component)}`);
361
+ const R = w ? await je(w.componentFile, "utf-8").catch(() => {
362
362
  }) : void 0;
363
363
  if (w) {
364
- const O = await pe(w.componentFile, p, u.component);
365
- if (O) {
366
- const T = as(u.component, O.props, O.slots, O.emits);
364
+ const F = await pe(w.componentFile, l, p.component);
365
+ if (F) {
366
+ const T = fs(p.component, F.props, F.slots, F.emits);
367
367
  o.push(
368
- ...ys(f, u.component, F(e, w.componentFile), E, T)
368
+ ...js(f, p.component, E(e, w.componentFile), O, T)
369
369
  );
370
370
  }
371
371
  }
372
- Ut(Zt(u.component, E, { sourceFile: w?.componentFile, sourceText: R }));
372
+ Kt(Yt(p.component, O, { sourceFile: w?.componentFile, sourceText: R }));
373
373
  }
374
374
  }
375
- return De(e), o;
375
+ return _e(e), o;
376
376
  }
377
- function ht(e) {
377
+ function wt(e) {
378
378
  return Object.entries(e.modules.systems).filter(([, t]) => t.visibility !== "dev-only").map(([t]) => t);
379
379
  }
380
- async function gt(e, t, s) {
380
+ async function $t(e, t, s) {
381
381
  for (const n of s)
382
382
  try {
383
- await (await lt(await ot(e, t, n, "serve"))).listen(), console.log(`nimpress modules: ${n} harness on port ${Kt(t.modules, n)}`);
383
+ await (await pt(await at(e, t, n, "serve"))).listen(), console.log(`nimpress modules: ${n} harness on port ${Xt(t.modules, n)}`);
384
384
  } catch (o) {
385
385
  console.warn(`nimpress modules: harness for ${n} failed to start: ${String(o)}`);
386
386
  }
387
387
  }
388
- async function wt(e, t, s) {
388
+ async function yt(e, t, s) {
389
389
  for (const n of s)
390
- await ut(await ot(e, t, n, "build")), console.log(`nimpress modules: built ${n}`);
390
+ await mt(await at(e, t, n, "build")), console.log(`nimpress modules: built ${n}`);
391
391
  }
392
- async function bs(e, t) {
393
- const s = await lt(await nt({ cwd: e, command: "serve", resolved: t }));
394
- await s.listen(), await gt(e, t, Object.keys(t.modules.systems)), s.printUrls(), s.bindCLIShortcuts({ print: !0 });
392
+ async function Cs(e, t) {
393
+ const s = await pt(await it({ cwd: e, command: "serve", resolved: t }));
394
+ await s.listen(), await $t(e, t, Object.keys(t.modules.systems)), s.printUrls(), s.bindCLIShortcuts({ print: !0 });
395
395
  }
396
- async function $t(e, t) {
396
+ async function bt(e, t) {
397
397
  const s = d(e, "index.html"), n = !b(s);
398
- n && W(s, Vt(t));
398
+ n && W(s, Qt(t));
399
399
  const o = () => {
400
- n && ee(s, { force: !0 });
400
+ n && te(s, { force: !0 });
401
401
  }, r = () => {
402
402
  o(), process.exit(130);
403
403
  };
404
404
  process.once("SIGINT", r), process.once("SIGTERM", r);
405
405
  try {
406
- await ut(await nt({ cwd: e, command: "build", resolved: t, htmlInput: s }));
406
+ await mt(await it({ cwd: e, command: "build", resolved: t, htmlInput: s }));
407
407
  } finally {
408
408
  process.off("SIGINT", r), process.off("SIGTERM", r), o();
409
409
  }
410
- await wt(e, t, ht(t));
410
+ await yt(e, t, wt(t));
411
411
  }
412
- const vs = [".ts", ".tsx", ".js", ".mjs", ".vue", ".svelte"], ks = ["", ".ts", ".tsx", ".js", ".mjs", ".vue", ".svelte", "/index.ts", "/index.js"], Ze = /^[a-z0-9][a-z0-9.-]*$/, xs = /^[A-Z][A-Za-z0-9]*$/;
413
- function Ss(e) {
412
+ const Es = [".ts", ".tsx", ".js", ".mjs", ".vue", ".svelte"], Os = ["", ".ts", ".tsx", ".js", ".mjs", ".vue", ".svelte", "/index.ts", "/index.js"], Ve = /^[a-z0-9][a-z0-9.-]*$/, Fs = /^[A-Z][A-Za-z0-9]*$/;
413
+ function Ds(e) {
414
414
  const t = e.resolve;
415
415
  if (!t || typeof t != "object") return [];
416
416
  const s = t.alias;
@@ -422,7 +422,7 @@ function Ss(e) {
422
422
  ([n, o]) => typeof o == "string" ? [{ find: n, replacement: o }] : []
423
423
  );
424
424
  }
425
- function js(e) {
425
+ function _s(e) {
426
426
  const t = [], s = [
427
427
  /(?:^|\n)[ \t]*import[^'"\n]*?from[ \t]*['"]([^'"\n]+)['"]/g,
428
428
  /(?:^|\n)[ \t]*export[^'"\n]*?from[ \t]*['"]([^'"\n]+)['"]/g,
@@ -435,137 +435,137 @@ function js(e) {
435
435
  }
436
436
  return t;
437
437
  }
438
- function Ve(e) {
439
- return ks.some((t) => {
438
+ function Ke(e) {
439
+ return Os.some((t) => {
440
440
  const s = e + t;
441
441
  if (!b(s)) return !1;
442
442
  try {
443
- return at(s).isFile();
443
+ return lt(s).isFile();
444
444
  } catch {
445
445
  return !1;
446
446
  }
447
447
  });
448
448
  }
449
- function Cs(e, t) {
450
- const s = x(e, t.contentDir), n = Ss(t.vite), o = [];
451
- for (const r of Y(s)) {
452
- if (!vs.some((p) => r.endsWith(p))) continue;
449
+ function Ns(e, t) {
450
+ const s = x(e, t.contentDir), n = Ds(t.vite), o = [];
451
+ for (const r of X(s)) {
452
+ if (!Es.some((l) => r.endsWith(l))) continue;
453
453
  let i;
454
454
  try {
455
455
  i = C(r, "utf-8");
456
456
  } catch {
457
457
  continue;
458
458
  }
459
- const c = F(s, r).split(L).join("/");
460
- for (const p of js(i)) {
461
- if (p.includes("_shared/") || p.startsWith("_shared")) {
459
+ const c = E(s, r).split(L).join("/");
460
+ for (const l of _s(i)) {
461
+ if (l.includes("_shared/") || l.startsWith("_shared")) {
462
462
  o.push(
463
- `${c}: imports ${p}, shared fixture folders are forbidden, stories are self contained and shared setup lives in a group harness component`
463
+ `${c}: imports ${l}, shared fixture folders are forbidden, stories are self contained and shared setup lives in a group harness component`
464
464
  );
465
465
  continue;
466
466
  }
467
- const a = p.split("?")[0];
467
+ const a = l.split("?")[0];
468
468
  if (a.startsWith("./") || a.startsWith("../")) {
469
- const u = x(N(r), a);
470
- Ve(u) || o.push(`${c}: unresolved import ${p}, fix the path or create the file`);
469
+ const p = x(N(r), a);
470
+ Ke(p) || o.push(`${c}: unresolved import ${l}, fix the path or create the file`);
471
471
  continue;
472
472
  }
473
- const l = n.find((u) => a === u.find || a.startsWith(u.find + "/"));
474
- if (l) {
475
- const u = x(e, l.replacement + a.slice(l.find.length));
476
- Ve(u) || o.push(`${c}: unresolved import ${p} via alias ${l.find}`);
473
+ const u = n.find((p) => a === p.find || a.startsWith(p.find + "/"));
474
+ if (u) {
475
+ const p = x(e, u.replacement + a.slice(u.find.length));
476
+ Ke(p) || o.push(`${c}: unresolved import ${l} via alias ${u.find}`);
477
477
  }
478
478
  }
479
479
  }
480
480
  return o;
481
481
  }
482
- function Es(e, t) {
482
+ function Ws(e, t) {
483
483
  const s = x(e, t.contentDir), n = [];
484
484
  if (!b(s)) return [`${t.contentDir}: contentDir does not exist`];
485
485
  const o = /* @__PURE__ */ new Map();
486
486
  let r, i;
487
487
  const c = /* @__PURE__ */ new Map();
488
- for (const a of Y(s)) {
489
- const l = F(s, a).split(L).join("/"), u = N(a), m = D(a);
488
+ for (const a of X(s)) {
489
+ const u = E(s, a).split(L).join("/"), p = N(a), m = D(a);
490
490
  if (m.endsWith(".md")) {
491
- const f = c.get(u) ?? [];
492
- f.push(a), c.set(u, f);
491
+ const f = c.get(p) ?? [];
492
+ f.push(a), c.set(p, f);
493
493
  const h = m.slice(0, -3);
494
- Ze.test(h) || n.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`);
494
+ Ve.test(h) || n.push(`${u}: 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`);
495
495
  let g;
496
496
  try {
497
497
  g = ue(C(a, "utf-8")).data, typeof g.type == "number" && (g.type = String(g.type));
498
498
  } catch {
499
499
  continue;
500
500
  }
501
- if (g?.type === "glossary" && (i ? n.push(`${l}: second type glossary page in the site, ${F(s, i).split(L).join("/")} already owns it, one glossary per site`) : i = a, /^: /m.test(ue(C(a, "utf-8")).content) || n.push(`${l}: type glossary needs a definition list body, term lines followed by lines starting with a colon`)), g?.type === "section" && !a.endsWith(`${L}index.md`) && n.push(`${l}: type section belongs on a folder index.md, move the page or drop the type`), g?.type === "404" && (r ? n.push(`${l}: second type 404 page in the site, ${F(s, r).split(L).join("/")} already owns it, one not found page per site`) : r = a), g?.type === "component") {
502
- const w = o.get(u);
503
- w ? n.push(`${l}: second type component page in one folder, ${F(s, w).split(L).join("/")} already owns it, one component per folder`) : o.set(u, a);
501
+ if (g?.type === "glossary" && (i ? n.push(`${u}: second type glossary page in the site, ${E(s, i).split(L).join("/")} already owns it, one glossary per site`) : i = a, /^: /m.test(ue(C(a, "utf-8")).content) || n.push(`${u}: type glossary needs a definition list body, term lines followed by lines starting with a colon`)), g?.type === "section" && !a.endsWith(`${L}index.md`) && n.push(`${u}: type section belongs on a folder index.md, move the page or drop the type`), g?.type === "404" && (r ? n.push(`${u}: second type 404 page in the site, ${E(s, r).split(L).join("/")} already owns it, one not found page per site`) : r = a), g?.type === "component") {
502
+ const w = o.get(p);
503
+ w ? n.push(`${u}: second type component page in one folder, ${E(s, w).split(L).join("/")} already owns it, one component per folder`) : o.set(p, a);
504
504
  }
505
505
  if (g?.type === "dbml") {
506
506
  const w = typeof g.spec == "string" ? g.spec : "";
507
- w ? b(x(u, w)) || n.push(`${l}: spec ${w} does not resolve, create the file or fix the path`) : n.push(`${l}: type dbml needs a spec field pointing at the .dbml file`);
507
+ w ? b(x(p, w)) || n.push(`${u}: spec ${w} does not resolve, create the file or fix the path`) : n.push(`${u}: type dbml needs a spec field pointing at the .dbml file`);
508
508
  }
509
- g?.type === "changelog" && typeof g.path == "string" && n.push(`${l}: changelog entries never set path, the collection mounts at the folder route, remove the path field`);
509
+ g?.type === "changelog" && typeof g.path == "string" && n.push(`${u}: changelog entries never set path, the collection mounts at the folder route, remove the path field`);
510
510
  }
511
511
  if (m.endsWith(".css") && !m.startsWith("_") && D(N(a)) === "styles" && N(N(a)) === s) {
512
512
  const f = m.replace(/\.css$/, "");
513
- ge.includes(f) || n.push(`${l}: ${f} is not a component class root, name the file after one of ${ge.join(", ")}`);
513
+ ge.includes(f) || n.push(`${u}: ${f} is not a component class root, name the file after one of ${ge.join(", ")}`);
514
514
  continue;
515
515
  }
516
516
  if (m.endsWith(".css") && !m.startsWith("_") && m.split(".").length > 2) {
517
- const f = m.split(".")[0], h = Xt(m, f);
517
+ const f = m.split(".")[0], h = ts(m, f);
518
518
  if (h && b(d(N(a), `${f}.md`))) {
519
- ge.includes(h) || n.push(`${l}: ${h} is not a component class root, name the file after one of ${ge.join(", ")}`);
519
+ ge.includes(h) || n.push(`${u}: ${h} is not a component class root, name the file after one of ${ge.join(", ")}`);
520
520
  continue;
521
521
  }
522
522
  }
523
523
  if (m.endsWith(".css") && !m.startsWith("_")) {
524
524
  const f = a.replace(/\.css$/, ".md");
525
- b(f) || n.push(`${l}: page css without a matching ${D(f)}, page styles are named after the page they scope`);
525
+ b(f) || n.push(`${u}: page css without a matching ${D(f)}, page styles are named after the page they scope`);
526
526
  }
527
527
  }
528
- for (const [a, l] of c) {
529
- const u = F(s, a).split(L).join("/") || ".", m = o.has(a);
528
+ for (const [a, u] of c) {
529
+ const p = E(s, a).split(L).join("/") || ".", m = o.has(a);
530
530
  let f = [];
531
531
  try {
532
- f = ie(a);
532
+ f = ae(a);
533
533
  } catch {
534
534
  continue;
535
535
  }
536
- f.filter((g) => /\.story\.tsx?$/.test(g)).length && !m && n.push(`${u}: story files without a type component page, add the component index.md or move the stories`);
536
+ f.filter((g) => /\.story\.tsx?$/.test(g)).length && !m && n.push(`${p}: story files without a type component page, add the component index.md or move the stories`);
537
537
  for (const g of ["schema.json", "schema.yml"])
538
- f.includes(g) && !m && n.push(`${u}: ${g} without a type component page, it belongs beside the component index.md`);
539
- if (m && l.length > 1) {
540
- const g = l.filter((w) => w !== o.get(a)).map((w) => D(w));
541
- n.push(`${u}: a component folder holds exactly one md file, move ${g.join(", ")} out`);
538
+ f.includes(g) && !m && n.push(`${p}: ${g} without a type component page, it belongs beside the component index.md`);
539
+ if (m && u.length > 1) {
540
+ const g = u.filter((w) => w !== o.get(a)).map((w) => D(w));
541
+ n.push(`${p}: a component folder holds exactly one md file, move ${g.join(", ")} out`);
542
542
  }
543
543
  }
544
- const p = (a) => {
545
- let l;
544
+ const l = (a) => {
545
+ let u;
546
546
  try {
547
- l = ie(a, { withFileTypes: !0 });
547
+ u = ae(a, { withFileTypes: !0 });
548
548
  } catch {
549
549
  return;
550
550
  }
551
- for (const u of l)
552
- if (u.isDirectory() && !(u.name.startsWith(".") || u.name === "node_modules")) {
553
- if (!Ze.test(u.name) && !xs.test(u.name)) {
554
- const m = F(s, d(a, u.name)).split(L).join("/");
551
+ for (const p of u)
552
+ if (p.isDirectory() && !(p.name.startsWith(".") || p.name === "node_modules")) {
553
+ if (!Ve.test(p.name) && !Fs.test(p.name)) {
554
+ const m = E(s, d(a, p.name)).split(L).join("/");
555
555
  n.push(`${m}/: folder names are lowercase kebab case, or PascalCase for component and group folders, rename it`);
556
556
  }
557
- p(d(a, u.name));
557
+ l(d(a, p.name));
558
558
  }
559
559
  };
560
- return p(s), n;
560
+ return l(s), n;
561
561
  }
562
- async function Os(e, t) {
563
- const s = rt(e, t, "lint"), n = () => ee(s, { recursive: !0, force: !0 }), o = () => {
562
+ async function Ts(e, t) {
563
+ const s = Le(e, t, "lint"), n = () => te(s, { recursive: !0, force: !0 }), o = () => {
564
564
  n(), process.exit(130);
565
565
  };
566
566
  process.once("SIGINT", o), process.once("SIGTERM", o);
567
567
  try {
568
- return await $t(e, { ...t, paths: { ...t.paths, out: s } }), [];
568
+ return await bt(e, { ...t, paths: { ...t.paths, out: s } }), [];
569
569
  } catch (r) {
570
570
  return (r instanceof Error ? r.message : String(r)).split(`
571
571
  `).filter((c) => c.trim()).map((c) => `build: ${c.trim()}`);
@@ -573,23 +573,23 @@ async function Os(e, t) {
573
573
  process.off("SIGINT", o), process.off("SIGTERM", o), n();
574
574
  }
575
575
  }
576
- async function Fs(e, t) {
576
+ async function Ps(e, t) {
577
577
  const s = process.argv.slice(2), n = [
578
- ...Es(e, t),
579
- ...(Yt(e, t.pageTypes ?? {}), await Qt(e, t.contentDir)),
580
- ...Cs(e, t),
581
- ...await dt(e, t)
578
+ ...Ws(e, t),
579
+ ...(qt(e, t.pageTypes ?? {}), await es(e, t.contentDir)),
580
+ ...Ns(e, t),
581
+ ...await gt(e, t)
582
582
  ];
583
583
  if (n.length) {
584
- Ne("nimpress lint", n, "");
584
+ We("nimpress lint", n, "");
585
585
  return;
586
586
  }
587
587
  if (console.log("nimpress lint: structure, frontmatter, imports, and modules ok"), M(s, "no-build")) return;
588
588
  console.log("nimpress lint: building to verify the output compiles");
589
- const o = await Os(e, t);
590
- Ne("nimpress lint", o, "nimpress lint: build ok, everything passes");
589
+ const o = await Ts(e, t);
590
+ We("nimpress lint", o, "nimpress lint: build ok, everything passes");
591
591
  }
592
- const Ds = {
592
+ const Rs = {
593
593
  ".json": "application/json",
594
594
  ".xml": "application/rss+xml",
595
595
  ".html": "text/html",
@@ -602,99 +602,99 @@ const Ds = {
602
602
  ".webp": "image/webp",
603
603
  ".pdf": "application/pdf"
604
604
  };
605
- function _s(e, t, s) {
605
+ function As(e, t, s) {
606
606
  const n = s[0], o = d(e, _(s, "dist") ?? t.paths.out), r = `/${t.paths.guarded}/`, i = d(o, "access.json");
607
607
  if (!b(i))
608
608
  throw new Error(`[nimpress] guard: ${i} not found, run a build first`);
609
609
  const c = JSON.parse(C(i, "utf-8"));
610
610
  if (n === "map") {
611
- const p = Ge(o, t), a = d(o, "guard.map.json"), l = b(a) ? JSON.parse(C(a, "utf-8")) : { prefix: c.prefix ?? r, routes: c.routes, bundles: {} }, u = b(p) ? Y(p) : [], m = l.prefix ?? r, f = u.map((w) => {
612
- const k = F(p, w).split("\\").join("/"), j = k.split("/")[0] ?? "", E = [
611
+ const l = He(o, t), a = d(o, "guard.map.json"), u = b(a) ? JSON.parse(C(a, "utf-8")) : { prefix: c.prefix ?? r, routes: c.routes, bundles: {} }, p = b(l) ? X(l) : [], m = u.prefix ?? r, f = p.map((w) => {
612
+ const k = E(l, w).split("\\").join("/"), j = k.split("/")[0] ?? "", O = [
613
613
  ...new Set(
614
- Object.values(l.routes ?? {}).filter((R) => R.bundle === j && R.gate).map((R) => R.gate)
614
+ Object.values(u.routes ?? {}).filter((R) => R.bundle === j && R.gate).map((R) => R.gate)
615
615
  )
616
616
  ], v = C(w);
617
617
  return {
618
618
  path: `${m}${k}`,
619
619
  file: k,
620
620
  bundle: j,
621
- sha256: pt("sha256").update(v).digest("hex"),
622
- size: at(w).size,
623
- mime: Ds[fe(w).toLowerCase()] ?? "application/octet-stream",
624
- gates: E
621
+ sha256: ft("sha256").update(v).digest("hex"),
622
+ size: lt(w).size,
623
+ mime: Rs[fe(w).toLowerCase()] ?? "application/octet-stream",
624
+ gates: O
625
625
  };
626
626
  }), h = _(s, "out"), g = h ? d(e, h) : a;
627
627
  W(
628
628
  g,
629
- JSON.stringify({ ...l, prefix: m, files: f }, null, 2) + `
629
+ JSON.stringify({ ...u, prefix: m, files: f }, null, 2) + `
630
630
  `
631
631
  ), console.log(`nimpress guard: mapped ${f.length} guarded files to ${g}`);
632
632
  return;
633
633
  }
634
634
  if (n === "apply") {
635
- const p = _(s, "map");
636
- if (!p) throw new Error("[nimpress] guard apply requires --map=<uploaded mapping json>");
637
- const a = JSON.parse(C(d(e, p), "utf-8"));
635
+ const l = _(s, "map");
636
+ if (!l) throw new Error("[nimpress] guard apply requires --map=<uploaded mapping json>");
637
+ const a = JSON.parse(C(d(e, l), "utf-8"));
638
638
  if (!a.base) throw new Error("[nimpress] guard apply: mapping json carries no base url");
639
- c.base = a.base.replace(/\/$/, ""), c.files = (a.files ?? []).map((l) => ({
640
- path: l.path,
641
- file: l.file,
642
- bundle: l.bundle,
643
- asset_id: l.asset_id,
644
- url: l.url
639
+ c.base = a.base.replace(/\/$/, ""), c.files = (a.files ?? []).map((u) => ({
640
+ path: u.path,
641
+ file: u.file,
642
+ bundle: u.bundle,
643
+ asset_id: u.asset_id,
644
+ url: u.url
645
645
  })), W(i, JSON.stringify(c, null, 2) + `
646
- `), ee(Ge(o, t), { recursive: !0, force: !0 }), ee(d(o, "guard.map.json"), { force: !0 }), console.log(`nimpress guard: base ${c.base} applied, ${t.paths.guarded} removed from ${o}`);
646
+ `), te(He(o, t), { recursive: !0, force: !0 }), te(d(o, "guard.map.json"), { force: !0 }), console.log(`nimpress guard: base ${c.base} applied, ${t.paths.guarded} removed from ${o}`);
647
647
  return;
648
648
  }
649
649
  throw new Error("[nimpress] guard expects map or apply");
650
650
  }
651
- function yt(e) {
651
+ function vt(e) {
652
652
  const t = fe(e);
653
653
  return t === ".vue" ? "vue" : t === ".svelte" ? "svelte" : null;
654
654
  }
655
- async function Le(e, t, s, n, o) {
656
- const i = (await Ae(e, t.contentDir)).find((m) => m.system === s && m.component === n);
655
+ async function Je(e, t, s, n, o) {
656
+ const i = (await Me(e, t.contentDir)).find((m) => m.system === s && m.component === n);
657
657
  if (!i)
658
658
  return console.warn(`[nimpress] modules story: no type component page found for ${s}/${n}`), null;
659
- const c = Me(e, t.modules, s, n, i.file);
659
+ const c = Ie(e, t.modules, s, n, i.file);
660
660
  if (!c)
661
661
  return console.warn(`[nimpress] modules story: no source found for ${s}/${n}`), null;
662
- const p = o ?? yt(c.componentFile);
663
- if (!p)
662
+ const l = o ?? vt(c.componentFile);
663
+ if (!l)
664
664
  throw new Error(
665
665
  `[nimpress] modules story: failed to detect framework for ${c.componentFile}, pass --framework=vue or --framework=svelte`
666
666
  );
667
- const a = p === "vue" ? "vueStory" : "svelteStory", l = `import { ${a} } from '@nimtech/nimpress/story'
667
+ const a = l === "vue" ? "vueStory" : "svelteStory", u = `import { ${a} } from '@nimtech/nimpress/story'
668
668
 
669
669
  // story: Default
670
670
  export default ${a}({
671
671
  name: "Default"
672
672
  })
673
- `, u = d(N(i.pageFile), "default.story.tsx");
674
- return b(u) ? (console.warn(`[nimpress] modules story: ${u} exists, not overwriting`), null) : (await q(u, l), u);
673
+ `, p = d(N(i.pageFile), "default.story.tsx");
674
+ return b(p) ? (console.warn(`[nimpress] modules story: ${p} exists, not overwriting`), null) : (await ee(p, u), p);
675
675
  }
676
- async function Ns(e, t, s) {
677
- const n = await Ae(e, t.contentDir);
676
+ async function Ms(e, t, s) {
677
+ const n = await Me(e, t.contentDir);
678
678
  let o = 0;
679
679
  for (const r of n)
680
- if (!(r.system !== s || (await st(N(r.pageFile))).length))
680
+ if (!(r.system !== s || (await rt(N(r.pageFile))).length))
681
681
  try {
682
- await Le(e, t, s, r.component) && o++;
682
+ await Je(e, t, s, r.component) && o++;
683
683
  } catch (c) {
684
684
  console.warn(String(c));
685
685
  }
686
686
  return o;
687
687
  }
688
- async function Ws(e, t, s, n, o) {
688
+ async function Is(e, t, s, n, o) {
689
689
  const r = t.modules.systems[s];
690
690
  if (!r) throw new Error(`[nimpress] modules create: unknown system ${s}`);
691
691
  const i = d(e, t.contentDir, "components", "Components", n), c = d(i, "index.md");
692
692
  if (b(c))
693
693
  throw new Error(`[nimpress] modules create: ${c} exists`);
694
- const { mkdir: p } = await import("node:fs/promises");
695
- await p(i, { recursive: !0 });
694
+ const { mkdir: l } = await import("node:fs/promises");
695
+ await l(i, { recursive: !0 });
696
696
  const a = r.package;
697
- await q(
697
+ await ee(
698
698
  c,
699
699
  `---
700
700
  title: ${n}
@@ -712,18 +712,18 @@ import { ${n} } from "${a ?? s}";
712
712
  \`\`\`
713
713
  `
714
714
  );
715
- const l = Me(e, t.modules, s, n);
716
- if (l) {
717
- const u = o ?? yt(l.componentFile) ?? r.framework;
718
- await me(i, n, await pe(l.componentFile, u, n)), await Le(e, t, s, n, o);
715
+ const u = Ie(e, t.modules, s, n);
716
+ if (u) {
717
+ const p = o ?? vt(u.componentFile) ?? r.framework;
718
+ await me(i, n, await pe(u.componentFile, p, n)), await Je(e, t, s, n, o);
719
719
  } else {
720
- const u = r.framework === "vue" ? "vueStory" : "svelteStory";
721
- await q(
720
+ const p = r.framework === "vue" ? "vueStory" : "svelteStory";
721
+ await ee(
722
722
  d(i, "default.story.tsx"),
723
- `import { ${u} } from '@nimtech/nimpress/story'
723
+ `import { ${p} } from '@nimtech/nimpress/story'
724
724
 
725
725
  // story: Default
726
- export default ${u}({
726
+ export default ${p}({
727
727
  name: "Default",
728
728
  props: {}
729
729
  })
@@ -744,7 +744,7 @@ function ye(e) {
744
744
  function be(e, t = []) {
745
745
  let s;
746
746
  try {
747
- s = ie(e, { withFileTypes: !0 });
747
+ s = ae(e, { withFileTypes: !0 });
748
748
  } catch {
749
749
  return t;
750
750
  }
@@ -757,10 +757,10 @@ function be(e, t = []) {
757
757
  }
758
758
  return t;
759
759
  }
760
- function We(e) {
760
+ function Te(e) {
761
761
  return e.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase().replace(/[^a-z0-9-]/g, "");
762
762
  }
763
- function Te(e) {
763
+ function Pe(e) {
764
764
  const t = C(e, "utf-8"), s = t.split(`
765
765
  `), n = [];
766
766
  let o = 0;
@@ -790,7 +790,7 @@ function Te(e) {
790
790
  const g = c(h);
791
791
  g?.kind === "data" && i.push(g.abs);
792
792
  }
793
- const p = n.filter((f) => !f.includes("@storybook")).map(
793
+ const l = n.filter((f) => !f.includes("@storybook")).map(
794
794
  (f) => f.replace(/from\s+["'](\.\.?\/[^"']+)["']/g, (h, g) => {
795
795
  const w = c(g);
796
796
  return w?.kind === "source" ? `from ${JSON.stringify(w.abs)}` : `from "./${D(g).replace(/\.ts$/, "")}"`;
@@ -799,7 +799,7 @@ function Te(e) {
799
799
  `);
800
800
  let a = t.slice(s.slice(0, o).join(`
801
801
  `).length);
802
- const l = (f) => {
802
+ const u = (f) => {
803
803
  const h = a.search(f);
804
804
  if (h < 0) return;
805
805
  const g = a.indexOf("{", h);
@@ -811,24 +811,24 @@ function Te(e) {
811
811
  const w = $e(a, g + 1), k = g + 1 + w.length + 1, j = a.slice(k).match(/^[^\n]*/)?.[0] ?? "";
812
812
  a = a.slice(0, h) + a.slice(k + j.length);
813
813
  };
814
- l(/^const meta\b[^\n]*/m), a = a.replace(/^export default meta;?\s*$/m, ""), a = a.replace(/^(?:export )?type \w+[^\n]*\n(?:[ \t]+[^\n]*\n?)*/gm, "");
815
- let u = 0;
816
- for (; /^(?:export )?interface \w+/m.test(a) && u < 50; )
817
- l(/^(?:export )?interface \w+[^\n]*/m), u++;
814
+ u(/^const meta\b[^\n]*/m), a = a.replace(/^export default meta;?\s*$/m, ""), a = a.replace(/^(?:export )?type \w+[^\n]*\n(?:[ \t]+[^\n]*\n?)*/gm, "");
815
+ let p = 0;
816
+ for (; /^(?:export )?interface \w+/m.test(a) && p < 50; )
817
+ u(/^(?:export )?interface \w+[^\n]*/m), p++;
818
818
  let m = 0;
819
819
  for (; /^export const \w+/m.test(a) && m < 200; )
820
- l(/^export const \w+[^\n]*/m), m++;
820
+ u(/^export const \w+[^\n]*/m), m++;
821
821
  return {
822
822
  file: e,
823
823
  text: t,
824
824
  title: t.match(/\btitle:\s*["']([^"']+)["']/)?.[1],
825
825
  metaComponent: t.match(/\bcomponent:\s*([A-Za-z_$][\w$]*)\s*[,\n}]/)?.[1],
826
- imports: p,
826
+ imports: l,
827
827
  declarations: a.trim(),
828
828
  dataModules: i
829
829
  };
830
830
  }
831
- function Ts(e, t) {
831
+ function Ls(e, t) {
832
832
  const s = e.indexOf(":", t) + 1;
833
833
  let n = 0, o = null;
834
834
  for (let r = s; r < e.length; r++) {
@@ -847,10 +847,10 @@ function Ts(e, t) {
847
847
  }
848
848
  return e.slice(s).trim();
849
849
  }
850
- function bt(e) {
850
+ function kt(e) {
851
851
  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)");
852
852
  }
853
- function vt(e) {
853
+ function xt(e) {
854
854
  const t = [], s = /export const (\w+)\s*(?::[^=]*)?=\s*\{/g;
855
855
  let n;
856
856
  for (; n = s.exec(e.text); ) {
@@ -858,35 +858,35 @@ function vt(e) {
858
858
  if (o === "default" || o === "meta") continue;
859
859
  const r = $e(e.text, s.lastIndex), i = r.search(/\brender\s*:/);
860
860
  if (i >= 0) {
861
- const a = Ts(r, i);
861
+ const a = Ls(r, i);
862
862
  if (a) {
863
863
  t.push({ name: o, renderFn: a });
864
864
  continue;
865
865
  }
866
866
  }
867
867
  const c = r.search(/\bargs\s*:/);
868
- let p = {};
868
+ let l = {};
869
869
  if (c >= 0) {
870
870
  const a = r.indexOf("{", c);
871
871
  if (a >= 0) {
872
- const l = $e(r, a + 1);
872
+ const u = $e(r, a + 1);
873
873
  try {
874
- p = ye(new Function(`${bt(e.declarations)}
875
- return {${l}}`)());
874
+ l = ye(new Function(`${kt(e.declarations)}
875
+ return {${u}}`)());
876
876
  } catch {
877
877
  try {
878
- p = ye(new Function(`return {${l}}`)());
878
+ l = ye(new Function(`return {${u}}`)());
879
879
  } catch {
880
- p = {};
880
+ l = {};
881
881
  }
882
882
  }
883
883
  }
884
884
  }
885
- t.push({ name: o, props: p });
885
+ t.push({ name: o, props: l });
886
886
  }
887
887
  return t;
888
888
  }
889
- function kt(e) {
889
+ function St(e) {
890
890
  const t = e.text.search(/\bargTypes\s*:\s*\{/);
891
891
  if (t < 0) return;
892
892
  const s = e.text.indexOf("{", t), n = $e(e.text, s + 1);
@@ -896,7 +896,7 @@ function kt(e) {
896
896
  } catch {
897
897
  try {
898
898
  o = ye(
899
- new Function(`${bt(e.declarations)}
899
+ new Function(`${kt(e.declarations)}
900
900
  return {${n}}`)()
901
901
  );
902
902
  } catch {
@@ -906,16 +906,16 @@ return {${n}}`)()
906
906
  const r = {};
907
907
  for (const [i, c] of Object.entries(o)) {
908
908
  if (!c || typeof c != "object") continue;
909
- const p = c.control, a = typeof p == "string" ? p : String(p?.type ?? ""), l = c.options ?? (typeof p == "object" ? p?.options : void 0), u = {};
910
- typeof c.description == "string" && (u.description = c.description), Array.isArray(l) ? u.enum = l : a === "boolean" ? u.type = "boolean" : a === "number" || a === "range" ? u.type = "number" : a === "text" || a === "color" || a === "date" ? u.type = "string" : a === "object" && (u.type = "object"), c.defaultValue !== void 0 && (u.default = c.defaultValue), Object.keys(u).length && (r[i] = u);
909
+ const l = c.control, a = typeof l == "string" ? l : String(l?.type ?? ""), u = c.options ?? (typeof l == "object" ? l?.options : void 0), p = {};
910
+ typeof c.description == "string" && (p.description = c.description), Array.isArray(u) ? p.enum = u : a === "boolean" ? p.type = "boolean" : a === "number" || a === "range" ? p.type = "number" : a === "text" || a === "color" || a === "date" ? p.type = "string" : a === "object" && (p.type = "object"), c.defaultValue !== void 0 && (p.default = c.defaultValue), Object.keys(p).length && (r[i] = p);
911
911
  }
912
912
  return Object.keys(r).length ? r : void 0;
913
913
  }
914
- async function xt(e) {
914
+ async function jt(e) {
915
915
  const t = [...e].sort();
916
916
  for (let i = 0; i < t.length; i++)
917
917
  console.log(`${String(i + 1).padStart(4)} ${t[i]}`);
918
- const s = mt({ input: process.stdin, output: process.stdout }), n = await s.question(
918
+ const s = dt({ input: process.stdin, output: process.stdout }), n = await s.question(
919
919
  "select components to import, comma separated numbers, names, or /regex/, empty imports all: "
920
920
  );
921
921
  s.close();
@@ -925,20 +925,20 @@ async function xt(e) {
925
925
  for (const i of o.split(",").map((c) => c.trim()).filter(Boolean)) {
926
926
  const c = i.match(/^\/(.+)\/$/);
927
927
  if (c) {
928
- const p = new RegExp(c[1]);
929
- for (const a of t) p.test(a) && r.add(a);
928
+ const l = new RegExp(c[1]);
929
+ for (const a of t) l.test(a) && r.add(a);
930
930
  continue;
931
931
  }
932
932
  if (/^\d+$/.test(i)) {
933
- const p = t[Number(i) - 1];
934
- p && r.add(p);
933
+ const l = t[Number(i) - 1];
934
+ l && r.add(l);
935
935
  continue;
936
936
  }
937
- for (const p of t) p === i && r.add(p);
937
+ for (const l of t) l === i && r.add(l);
938
938
  }
939
939
  return r;
940
940
  }
941
- function St(e, t) {
941
+ function Ct(e, t) {
942
942
  const s = /* @__PURE__ */ new Map(), n = d(e, "node_modules", t, "index.mjs");
943
943
  if (!b(n)) return s;
944
944
  const o = C(n, "utf-8");
@@ -946,143 +946,143 @@ function St(e, t) {
946
946
  s.set(r[1].toLowerCase(), r[1]);
947
947
  return s;
948
948
  }
949
- async function Ps(e, t, s, n) {
949
+ async function Js(e, t, s, n) {
950
950
  const o = t.modules.systems[s];
951
951
  if (!o) throw new Error(`[nimpress] modules import: unknown system ${s}`);
952
- const r = o.framework, i = r === "vue" ? ".vue" : ".svelte", c = d(e, t.contentDir, "components"), p = o.package, a = n.match ? new RegExp(n.match) : null;
952
+ const r = o.framework, i = r === "vue" ? ".vue" : ".svelte", c = d(e, t.contentDir, "components"), l = o.package, a = n.match ? new RegExp(n.match) : null;
953
953
  if (n.file) {
954
954
  const $ = x(e, n.file);
955
955
  if (!b($)) throw new Error(`[nimpress] modules import: ${$} not found`);
956
956
  if (fe($) !== i)
957
957
  throw new Error(`[nimpress] modules import: ${$} does not match system framework ${r}`);
958
958
  const y = n.name ?? D($, i), I = o.source ? x(e, o.source) : e, P = d(c, "Components", y);
959
- await _e(P, { recursive: !0 });
960
- const A = F(I, $);
961
- await q(d(P, "index.md"), Pe(s, y, p, A)), await me(P, y, await pe($, r, y)), console.log(`nimpress modules: imported ${y} at ${F(e, P)}`);
959
+ await Ne(P, { recursive: !0 });
960
+ const A = E(I, $);
961
+ await ee(d(P, "index.md"), Re(s, y, l, A)), await me(P, y, await pe($, r, y)), console.log(`nimpress modules: imported ${y} at ${E(e, P)}`);
962
962
  return;
963
963
  }
964
964
  if (n.fromStories) {
965
- await Rs(e, t, s, n);
965
+ await zs(e, t, s, n);
966
966
  return;
967
967
  }
968
- const l = x(e, n.source ?? o.source ?? "");
969
- if (!b(l))
970
- throw new Error(`[nimpress] modules import: source ${l} not found`);
971
- const u = be(l), m = /* @__PURE__ */ new Map(), f = /* @__PURE__ */ new Map(), h = u.filter(($) => $.endsWith(".stories.ts")), g = n.stories ? [x(e, n.stories)] : [];
968
+ const u = x(e, n.source ?? o.source ?? "");
969
+ if (!b(u))
970
+ throw new Error(`[nimpress] modules import: source ${u} not found`);
971
+ const p = be(u), m = /* @__PURE__ */ new Map(), f = /* @__PURE__ */ new Map(), h = p.filter(($) => $.endsWith(".stories.ts")), g = n.stories ? [x(e, n.stories)] : [];
972
972
  for (const $ of g)
973
973
  for (const y of be($))
974
974
  y.endsWith(".stories.ts") && h.push(y);
975
- const w = u.filter(
975
+ const w = p.filter(
976
976
  ($) => $.endsWith(i) && /^[A-Z][A-Za-z0-9]*$/.test(D($, i))
977
- ), k = new Set(w.map(($) => D($, i))), j = p && !o.source ? St(e, p) : null;
977
+ ), k = new Set(w.map(($) => D($, i))), j = l && !o.source ? Ct(e, l) : null;
978
978
  for (const $ of h) {
979
- const y = Te($);
979
+ const y = Pe($);
980
980
  if (y.title?.includes("/")) {
981
- const [G, J] = y.title.split("/");
982
- m.set(J, G.replace(/\s+/g, ""));
981
+ const [G, z] = y.title.split("/");
982
+ m.set(z, G.replace(/\s+/g, ""));
983
983
  }
984
984
  const I = D($, ".stories.ts");
985
985
  let A = b(d(N($), `${I}${i}`)) ? I : y.metaComponent ?? I;
986
986
  if (!k.has(A)) {
987
987
  let G = "";
988
- for (const J of k)
989
- I.startsWith(J) && J.length > G.length && (G = J);
988
+ for (const z of k)
989
+ I.startsWith(z) && z.length > G.length && (G = z);
990
990
  G ? A = G : console.warn(`nimpress modules: ${D($)} targets ${A} which has no component page`);
991
991
  }
992
992
  const S = j?.get(A.toLowerCase()) ?? A, Z = f.get(S) ?? [];
993
993
  Z.push(y), f.set(S, Z);
994
994
  }
995
- const E = /* @__PURE__ */ new Map();
995
+ const O = /* @__PURE__ */ new Map();
996
996
  let v = 0, R = 0;
997
- const O = w.filter(($) => !a || a.test(D($, i))), T = n.select ? await xt(O.map(($) => D($, i))) : null;
998
- for (const $ of O) {
997
+ const F = w.filter(($) => !a || a.test(D($, i))), T = n.select ? await jt(F.map(($) => D($, i))) : null;
998
+ for (const $ of F) {
999
999
  const y = D($, i);
1000
1000
  if (T && !T.has(y)) continue;
1001
- if (E.has(y)) {
1002
- console.warn(`nimpress modules: skip duplicate ${y}, kept ${E.get(y)}`);
1001
+ if (O.has(y)) {
1002
+ console.warn(`nimpress modules: skip duplicate ${y}, kept ${O.get(y)}`);
1003
1003
  continue;
1004
1004
  }
1005
- E.set(y, F(l, $));
1005
+ O.set(y, E(u, $));
1006
1006
  const I = m.get(y) ?? "Components", P = d(c, I, y);
1007
- await _e(P, { recursive: !0 });
1008
- const A = F(l, $), S = A === `${y}/${y}${i}` || A === `${y}${i}`, Z = (f.get(y) ?? []).map((H) => kt(H)).reduce(
1009
- (H, se) => se ? { ...H ?? {}, ...se } : H,
1007
+ await Ne(P, { recursive: !0 });
1008
+ const A = E(u, $), S = A === `${y}/${y}${i}` || A === `${y}${i}`, Z = (f.get(y) ?? []).map((H) => St(H)).reduce(
1009
+ (H, ne) => ne ? { ...H ?? {}, ...ne } : H,
1010
1010
  void 0
1011
1011
  );
1012
- await q(d(P, "index.md"), Pe(s, y, p, S ? void 0 : A)), await me(P, y, await pe($, r, y)), Z && await it(P, { properties: Z }), v++;
1013
- const G = f.get(y) ?? [], J = /* @__PURE__ */ new Set();
1012
+ await ee(d(P, "index.md"), Re(s, y, l, S ? void 0 : A)), await me(P, y, await pe($, r, y)), Z && await ct(P, { properties: Z }), v++;
1013
+ const G = f.get(y) ?? [], z = /* @__PURE__ */ new Set();
1014
1014
  for (const H of G) {
1015
- const se = D(H.file, ".stories.ts"), Je = vt(H);
1016
- Je.length || console.warn(`nimpress modules: no stories mined from ${D(H.file)}`);
1017
- for (const Q of H.dataModules)
1018
- await ct(Q, d(P, D(Q)));
1019
- for (const Q of Je) {
1020
- const ze = Q.name === y ? "Default" : se === y ? Q.name : `${se} ${Q.name}`;
1021
- let he = We(ze);
1022
- J.has(he) && (he = We(`${se}-${Q.name}`));
1023
- const Be = d(P, `${he}.story.tsx`);
1024
- J.add(he), !b(Be) && (await q(Be, jt(r, ze, se, Q, H)), R++);
1015
+ const ne = D(H.file, ".stories.ts"), ze = xt(H);
1016
+ ze.length || console.warn(`nimpress modules: no stories mined from ${D(H.file)}`);
1017
+ for (const q of H.dataModules)
1018
+ await ut(q, d(P, D(q)));
1019
+ for (const q of ze) {
1020
+ const Be = q.name === y ? "Default" : ne === y ? q.name : `${ne} ${q.name}`;
1021
+ let he = Te(Be);
1022
+ z.has(he) && (he = Te(`${ne}-${q.name}`));
1023
+ const Ge = d(P, `${he}.story.tsx`);
1024
+ z.add(he), !b(Ge) && (await ee(Ge, Et(r, Be, ne, q, H)), R++);
1025
1025
  }
1026
1026
  }
1027
1027
  }
1028
1028
  console.log(`nimpress modules: imported ${v} components with ${R} stories for ${s}`);
1029
1029
  }
1030
- async function Rs(e, t, s, n) {
1030
+ async function zs(e, t, s, n) {
1031
1031
  const o = t.modules.systems[s], r = o.framework, i = d(e, t.contentDir, "components"), c = x(e, n.stories ?? "");
1032
1032
  if (!n.stories || !b(c))
1033
1033
  throw new Error("[nimpress] modules import --from-stories requires --stories=<csf dir>");
1034
- const p = o.source ? x(e, o.source) : e, a = n.match ? new RegExp(n.match) : null, l = /* @__PURE__ */ new Set();
1035
- let u = 0, m = 0;
1036
- const f = be(c).filter((g) => g.endsWith(".stories.ts")), h = n.select ? await xt(
1037
- f.map((g) => Te(g).metaComponent ?? D(g, ".stories.ts"))
1034
+ const l = o.source ? x(e, o.source) : e, a = n.match ? new RegExp(n.match) : null, u = /* @__PURE__ */ new Set();
1035
+ let p = 0, m = 0;
1036
+ const f = be(c).filter((g) => g.endsWith(".stories.ts")), h = n.select ? await jt(
1037
+ f.map((g) => Pe(g).metaComponent ?? D(g, ".stories.ts"))
1038
1038
  ) : null;
1039
1039
  for (const g of f) {
1040
- const w = Te(g), k = D(g, ".stories.ts"), j = w.metaComponent ?? k;
1040
+ const w = Pe(g), k = D(g, ".stories.ts"), j = w.metaComponent ?? k;
1041
1041
  if (h && !h.has(j)) continue;
1042
- const E = w.text.match(
1042
+ const O = w.text.match(
1043
1043
  new RegExp(`import\\s+(?:\\{\\s*)?${j}(?:\\s*\\})?\\s+from\\s+["']([^"']+)["']`)
1044
1044
  )?.[1];
1045
- let v = j, R = o.package, O;
1046
- if (E && !E.startsWith(".") && !E.startsWith("@/")) {
1047
- const S = E.split("/")[0].startsWith("@") ? E.split("/").slice(0, 2).join("/") : E.split("/")[0];
1048
- R = S, v = St(e, S).get(j.toLowerCase()) ?? j;
1049
- } else if (E?.startsWith("@/components/")) {
1050
- const S = E.slice(13);
1051
- S === v || S === `${v}/${v}.vue` || (O = S.endsWith(".vue") || S.endsWith(".svelte") ? S : `${S}/${v}.vue`);
1052
- } else if (E?.startsWith(".")) {
1053
- const S = x(N(g), E);
1054
- O = F(p, S);
1045
+ let v = j, R = o.package, F;
1046
+ if (O && !O.startsWith(".") && !O.startsWith("@/")) {
1047
+ const S = O.split("/")[0].startsWith("@") ? O.split("/").slice(0, 2).join("/") : O.split("/")[0];
1048
+ R = S, v = Ct(e, S).get(j.toLowerCase()) ?? j;
1049
+ } else if (O?.startsWith("@/components/")) {
1050
+ const S = O.slice(13);
1051
+ S === v || S === `${v}/${v}.vue` || (F = S.endsWith(".vue") || S.endsWith(".svelte") ? S : `${S}/${v}.vue`);
1052
+ } else if (O?.startsWith(".")) {
1053
+ const S = x(N(g), O);
1054
+ F = E(l, S);
1055
1055
  }
1056
1056
  if (a && !a.test(v)) continue;
1057
- if (l.has(v)) {
1057
+ if (u.has(v)) {
1058
1058
  console.warn(`nimpress modules: skip duplicate ${v} from ${D(g)}`);
1059
1059
  continue;
1060
1060
  }
1061
- l.add(v);
1061
+ u.add(v);
1062
1062
  const T = w.title?.includes("/") ? w.title.split("/")[0].replace(/\s+/g, "") : "Components", $ = d(i, T, v);
1063
- await _e($, { recursive: !0 }), await q(d($, "index.md"), Pe(s, v, R, O));
1064
- const y = r === "vue" ? ".vue" : ".svelte", P = (O ? [x(p, O)] : [
1065
- d(p, v, `${v}${y}`),
1066
- d(p, `${v}${y}`)
1063
+ await Ne($, { recursive: !0 }), await ee(d($, "index.md"), Re(s, v, R, F));
1064
+ const y = r === "vue" ? ".vue" : ".svelte", P = (F ? [x(l, F)] : [
1065
+ d(l, v, `${v}${y}`),
1066
+ d(l, `${v}${y}`)
1067
1067
  ]).find((S) => b(S));
1068
1068
  if (P)
1069
1069
  await me($, v, await pe(P, r, v));
1070
1070
  else if (R) {
1071
- const S = qt(e, R, v);
1072
- S ? await me($, v, es(C(S, "utf-8"), v)) : console.warn(`nimpress modules: no source or d.ts found for ${v}, the schema seed is skipped`);
1071
+ const S = ss(e, R, v);
1072
+ S ? await me($, v, ns(C(S, "utf-8"), v)) : console.warn(`nimpress modules: no source or d.ts found for ${v}, the schema seed is skipped`);
1073
1073
  }
1074
- const A = kt(w);
1075
- A && await it($, { properties: A }), u++;
1074
+ const A = St(w);
1075
+ A && await ct($, { properties: A }), p++;
1076
1076
  for (const S of w.dataModules)
1077
- await ct(S, d($, D(S)));
1078
- for (const S of vt(w)) {
1079
- const Z = S.name === v ? "Default" : S.name, G = We(Z), J = d($, `${G}.story.tsx`);
1080
- b(J) || (await q(J, jt(r, Z, k, S, w)), m++);
1077
+ await ut(S, d($, D(S)));
1078
+ for (const S of xt(w)) {
1079
+ const Z = S.name === v ? "Default" : S.name, G = Te(Z), z = d($, `${G}.story.tsx`);
1080
+ b(z) || (await ee(z, Et(r, Z, k, S, w)), m++);
1081
1081
  }
1082
1082
  }
1083
- console.log(`nimpress modules: imported ${u} components with ${m} stories for ${s} from stories`);
1083
+ console.log(`nimpress modules: imported ${p} components with ${m} stories for ${s} from stories`);
1084
1084
  }
1085
- function Pe(e, t, s, n) {
1085
+ function Re(e, t, s, n) {
1086
1086
  const o = s ? `
1087
1087
  package: "${s}"` : "", r = n ? `
1088
1088
  file: ${JSON.stringify(n)}` : "";
@@ -1101,7 +1101,7 @@ import { ${t} } from "${s ?? e}";
1101
1101
  \`\`\`
1102
1102
  `;
1103
1103
  }
1104
- function jt(e, t, s, n, o) {
1104
+ function Et(e, t, s, n, o) {
1105
1105
  const r = e === "vue" ? "vueStory" : "svelteStory";
1106
1106
  return n.renderFn ? `import { ${r} } from '@nimtech/nimpress/story'
1107
1107
  ${o.imports}
@@ -1123,7 +1123,378 @@ export default ${r}({
1123
1123
  })
1124
1124
  `;
1125
1125
  }
1126
- function ae(e, t) {
1126
+ function Ot(e) {
1127
+ if (!e.startsWith(`---
1128
+ `)) return null;
1129
+ const t = e.indexOf(`
1130
+ ---`, 4);
1131
+ return t < 0 ? null : e.slice(4, t);
1132
+ }
1133
+ function Bs(e) {
1134
+ for (const t of e.split(`
1135
+ `)) {
1136
+ if (!t.startsWith("export:")) continue;
1137
+ const s = t.slice(7).trim().replace(/^["']|["']$/g, "");
1138
+ return s === "" || s === "false" ? null : s;
1139
+ }
1140
+ return null;
1141
+ }
1142
+ function Gs(e, t) {
1143
+ const s = Ot(e);
1144
+ if (s === null) return e;
1145
+ const n = s.split(`
1146
+ `).filter((r) => !r.startsWith("export:") && !r.startsWith(" file:")), o = n.findIndex((r) => r.startsWith(" package:"));
1147
+ return t && o >= 0 && !n.some((r) => r.startsWith(" version:")) && n.splice(o + 1, 0, ` version: ${JSON.stringify(t)}`), `---
1148
+ ${n.join(`
1149
+ `)}${e.slice(4 + s.length)}`;
1150
+ }
1151
+ function Ae(e, t, s) {
1152
+ const n = _(s, "target") ?? "", o = d(e, _(s, "out") ?? t.paths.export), r = d(e, t.contentDir);
1153
+ let i = "";
1154
+ try {
1155
+ i = JSON.parse(C(d(e, "package.json"), "utf-8")).version ?? "";
1156
+ } catch {
1157
+ i = "";
1158
+ }
1159
+ let c = 0;
1160
+ for (const l of X(r)) {
1161
+ if (!l.endsWith(".md")) continue;
1162
+ const a = C(l, "utf-8"), u = Ot(a);
1163
+ if (u === null) continue;
1164
+ const p = Bs(u);
1165
+ if (p === null || n && p !== n && p !== "true") continue;
1166
+ const m = N(l), f = d(o, E(r, m));
1167
+ J(f, { recursive: !0 });
1168
+ for (const h of ae(m, { withFileTypes: !0 })) {
1169
+ if (!h.isFile()) continue;
1170
+ const g = C(d(m, h.name), "utf-8");
1171
+ W(
1172
+ d(f, h.name),
1173
+ h.name.endsWith(".md") ? Gs(g, i) : g
1174
+ );
1175
+ }
1176
+ c++;
1177
+ }
1178
+ console.log(`nimpress export: ${c} pages collected into ${o}`);
1179
+ }
1180
+ function Ft(e = Q()) {
1181
+ return d(e, ".nimpress", "config.json");
1182
+ }
1183
+ function Dt(e = Q()) {
1184
+ return d(e, ".tide", "nimpress", "sites");
1185
+ }
1186
+ function _t(e = Q()) {
1187
+ const t = Ft(e);
1188
+ return b(t) ? { links: JSON.parse(C(t, "utf-8")).links ?? {} } : { links: {} };
1189
+ }
1190
+ function Nt(e, t = Q()) {
1191
+ const s = Ft(t);
1192
+ J(N(s), { recursive: !0 }), W(s, `${JSON.stringify(e, null, 2)}
1193
+ `);
1194
+ }
1195
+ function ve(e) {
1196
+ const t = e.trim().replace(/\.git$/, "").replace(/\/+$/, ""), s = t.match(/[:/]([^/:]+)\/([^/]+)$/);
1197
+ if (s && t.includes("github.com")) return `${s[1]}/${s[2]}`;
1198
+ const n = t.match(/^([^/\s]+)\/([^/\s]+)$/);
1199
+ if (n) return `${n[1]}/${n[2]}`;
1200
+ throw new Error(`[nimpress] view: cannot read owner/repo from ${e}`);
1201
+ }
1202
+ function Ce(e) {
1203
+ const t = e.trim();
1204
+ return /^(https?:\/\/|git@|ssh:\/\/)/.test(t) ? t : `https://github.com/${ve(t)}.git`;
1205
+ }
1206
+ function Wt(e) {
1207
+ const t = d(e, ".github", "workflows");
1208
+ return b(t) ? ae(t).filter((s) => s.endsWith(".yml") || s.endsWith(".yaml")).sort().map((s) => d(t, s)) : [];
1209
+ }
1210
+ function Tt(e) {
1211
+ try {
1212
+ const t = hs(C(e, "utf-8"));
1213
+ return typeof t == "object" && t !== null ? t : null;
1214
+ } catch {
1215
+ return null;
1216
+ }
1217
+ }
1218
+ function le(e, t) {
1219
+ return String(e ?? "").replace(/\$\{\{\s*env\.([A-Za-z_][A-Za-z0-9_]*)\s*\}\}/g, (n, o) => {
1220
+ for (const r of t)
1221
+ if (r && r[o] !== void 0) return String(r[o]);
1222
+ return "";
1223
+ }).trim();
1224
+ }
1225
+ function Pt(e, t) {
1226
+ const s = [];
1227
+ for (const n of Object.values(e.jobs ?? {}))
1228
+ for (const o of n.steps ?? [])
1229
+ typeof o.uses == "string" && o.uses.includes(`/actions/${t}@`) && s.push({ step: o, scopes: [o.env, n.env, e.env] });
1230
+ return s;
1231
+ }
1232
+ function Hs(e) {
1233
+ const t = /* @__PURE__ */ new Map();
1234
+ for (const s of Wt(e)) {
1235
+ const n = Tt(s);
1236
+ if (n)
1237
+ for (const { step: o, scopes: r } of Pt(n, "docs-notify")) {
1238
+ const i = le(o.with?.["docs-repo"], r);
1239
+ if (!i) continue;
1240
+ const c = le(o.with?.["export-dir"], r) || ".nimpress";
1241
+ t.set(i, { repo: i, exportDir: c });
1242
+ }
1243
+ }
1244
+ return [...t.values()];
1245
+ }
1246
+ function Ye(e) {
1247
+ return e.replace(/\$\{\{\s*github\.workspace\s*\}\}\/?/g, "").replace(/^\.\//, "");
1248
+ }
1249
+ function Us(e, t) {
1250
+ const s = {
1251
+ contentRoot: t,
1252
+ mapping: b(d(e, "nimpress.sources.json")) ? "nimpress.sources.json" : "",
1253
+ defaults: {}
1254
+ };
1255
+ for (const n of Wt(e)) {
1256
+ const o = Tt(n);
1257
+ if (o)
1258
+ for (const { step: r, scopes: i } of Pt(o, "docs-sync")) {
1259
+ const c = Ye(le(r.with?.["docs-dir"], i)), l = (m) => {
1260
+ const f = Ye(m);
1261
+ return (c && f.startsWith(`${c}/`) ? f.slice(c.length + 1) : f).replace(/\/+$/, "");
1262
+ }, a = le(r.with?.["content-root"], i);
1263
+ a && (s.contentRoot = l(a));
1264
+ const u = le(r.with?.mapping, i);
1265
+ u && (s.mapping = l(u));
1266
+ const p = le(r.with?.defaults, i);
1267
+ return p && (s.defaults = JSON.parse(p)), s;
1268
+ }
1269
+ }
1270
+ return s;
1271
+ }
1272
+ function Zs(e, t) {
1273
+ const s = { ...e };
1274
+ return t.target && (s.target = t.target), t.targets?.length && (s.targets = t.targets), t.mode && (s.mode = t.mode), s;
1275
+ }
1276
+ function Vs(e) {
1277
+ const t = e.mode || "mirror";
1278
+ return e.targets?.length ? e.targets.map((s) => ({ from: s.from ?? "", to: s.to, mode: s.mode || t })) : e.target ? [{ from: "", to: e.target, mode: t }] : [];
1279
+ }
1280
+ function Ks(e, t, s) {
1281
+ let n = t.defaults;
1282
+ const o = t.mapping ? d(e, t.mapping) : "";
1283
+ if (o && b(o)) {
1284
+ const i = JSON.parse(C(o, "utf-8")).sources?.[s];
1285
+ i && (n = Zs(n, i));
1286
+ }
1287
+ return n;
1288
+ }
1289
+ function Qe(e) {
1290
+ const t = /* @__PURE__ */ new Map();
1291
+ if (!b(e)) return t;
1292
+ for (const s of X(e))
1293
+ t.set(E(e, s).split(L).join("/"), C(s));
1294
+ return t;
1295
+ }
1296
+ function Ys(e, t, s) {
1297
+ const n = { added: [], modified: [], deleted: [] }, o = Qe(e), r = Qe(t);
1298
+ for (const [i, c] of o) {
1299
+ const l = r.get(i);
1300
+ if (l && l.equals(c)) continue;
1301
+ const a = d(t, ...i.split("/"));
1302
+ J(N(a), { recursive: !0 }), W(a, c), l ? n.modified.push(i) : n.added.push(i);
1303
+ }
1304
+ if (s === "mirror")
1305
+ for (const i of r.keys())
1306
+ o.has(i) || (te(d(t, ...i.split("/")), { force: !0 }), n.deleted.push(i));
1307
+ return n;
1308
+ }
1309
+ function Qs(e, t) {
1310
+ const s = /* @__PURE__ */ new Map();
1311
+ for (const o of X(e)) {
1312
+ if (!o.endsWith(".md")) continue;
1313
+ const r = ue(C(o, "utf-8")).data.path, i = os(e, o, typeof r == "string" ? r : void 0);
1314
+ s.set(i, [...s.get(i) ?? [], o]);
1315
+ }
1316
+ const n = [];
1317
+ for (const o of s.values())
1318
+ o.some((r) => t.has(r)) && n.push(...o.filter((r) => !t.has(r)));
1319
+ return n.sort();
1320
+ }
1321
+ function ie(e, t, s) {
1322
+ const n = se("git", e, { cwd: t, encoding: "utf-8", env: { ...process.env, ...s } });
1323
+ return { ok: n.status === 0, out: `${n.stdout ?? ""}${n.stderr ?? ""}`.trim() };
1324
+ }
1325
+ function Rt(e) {
1326
+ const t = ie(["rev-parse", "--show-toplevel"], e);
1327
+ return t.ok ? t.out : e;
1328
+ }
1329
+ function Xs(e) {
1330
+ const t = ie(["remote", "get-url", "origin"], e);
1331
+ if (!t.ok) throw new Error(`[nimpress] view: ${e} has no origin remote, so its docs site mapping cannot be looked up`);
1332
+ return ve(t.out);
1333
+ }
1334
+ function qs() {
1335
+ return se("gh", ["--version"], { encoding: "utf-8" }).status === 0;
1336
+ }
1337
+ function At(e) {
1338
+ return e?.method === "ssh" && e.key ? { GIT_SSH_COMMAND: `ssh -i ${e.key} -o IdentitiesOnly=yes` } : {};
1339
+ }
1340
+ function Ee(e) {
1341
+ return e.login?.method === "gh" ? se("gh", ["repo", "view", e.repo, "--json", "name"], { encoding: "utf-8" }).status === 0 : ie(["ls-remote", "--exit-code", "-h", e.url], void 0, At(e.login)).ok;
1342
+ }
1343
+ async function Mt(e) {
1344
+ const t = dt({ input: process.stdin, output: process.stdout });
1345
+ try {
1346
+ return (await t.question(e)).trim();
1347
+ } finally {
1348
+ t.close();
1349
+ }
1350
+ }
1351
+ async function en(e) {
1352
+ if (Ee(e)) return e;
1353
+ if (console.log(`nimpress view: ${e.url} refused the connection`), qs()) {
1354
+ if (console.log("nimpress view: logging in through gh"), se("gh", ["auth", "login"], { stdio: "inherit" }).status !== 0) throw new Error("[nimpress] view: gh auth login did not complete");
1355
+ const o = { ...e, login: { method: "gh" } };
1356
+ if (Ee(o)) return o;
1357
+ throw new Error(`[nimpress] view: ${e.repo} is still unreachable after the gh login, ask for access to it`);
1358
+ }
1359
+ const t = await Mt("nimpress view: path to the ssh key with access to the repo: ");
1360
+ if (!t) throw new Error("[nimpress] view: no ssh key given and gh is not installed");
1361
+ const s = { ...e, login: { method: "ssh", key: x(t.replace(/^~/, Q())) } };
1362
+ if (Ee(s)) return s;
1363
+ throw new Error(`[nimpress] view: ${e.repo} is still unreachable with ${s.login.key}, ask for access to it`);
1364
+ }
1365
+ async function tn(e, t, s = Q()) {
1366
+ const n = Rt(e), o = _t(s), r = o.links[n] ?? [], i = Hs(n), c = _(t, "docs-repo");
1367
+ let l;
1368
+ if (c) {
1369
+ const u = ve(c), p = i.find((m) => m.repo === u)?.exportDir ?? _(t, "export-dir") ?? ".nimpress";
1370
+ l = [{ repo: u, url: Ce(c), exportDir: p, login: r.find((m) => m.repo === u)?.login }];
1371
+ } else if (i.length)
1372
+ l = i.map((u) => ({
1373
+ repo: u.repo,
1374
+ url: r.find((p) => p.repo === u.repo)?.url ?? Ce(u.repo),
1375
+ exportDir: u.exportDir,
1376
+ login: r.find((p) => p.repo === u.repo)?.login
1377
+ }));
1378
+ else if (r.length)
1379
+ l = r;
1380
+ else {
1381
+ console.log(`nimpress view: no workflow under ${n} names a docs site`);
1382
+ const u = await Mt("nimpress view: docs site repo, owner/repo or a url, http or ssh: ");
1383
+ if (!u) throw new Error("[nimpress] view: no docs site given");
1384
+ l = [{ repo: ve(u), url: Ce(u), exportDir: _(t, "export-dir") ?? ".nimpress" }];
1385
+ }
1386
+ const a = [];
1387
+ for (const u of l) a.push(await en(u));
1388
+ return o.links[n] = a, Nt(o, s), a;
1389
+ }
1390
+ function sn(e, t = Q()) {
1391
+ return d(Dt(t), e.repo.replace("/", "__"));
1392
+ }
1393
+ function nn(e, t, s) {
1394
+ const n = At(e.login);
1395
+ if (!b(d(t, ".git"))) {
1396
+ J(N(t), { recursive: !0 }), console.log(`nimpress view: cloning ${e.repo}`);
1397
+ const r = e.login?.method === "gh" ? se("gh", ["repo", "clone", e.repo, t, "--", "--depth", "1"], { encoding: "utf-8" }) : se("git", ["clone", "--depth", "1", e.url, t], { encoding: "utf-8", env: { ...process.env, ...n } });
1398
+ if (r.status !== 0) throw new Error(`[nimpress] view: clone of ${e.repo} failed
1399
+ ${r.stderr ?? ""}`);
1400
+ return;
1401
+ }
1402
+ if (s) return;
1403
+ const o = ie(["fetch", "--depth", "1", "origin", "HEAD"], t, n);
1404
+ if (!o.ok) throw new Error(`[nimpress] view: fetch of ${e.repo} failed
1405
+ ${o.out}`);
1406
+ ie(["reset", "--hard", "FETCH_HEAD"], t), ie(["clean", "-fd"], t);
1407
+ }
1408
+ function on(e) {
1409
+ const t = ["pnpm-lock.yaml", "package.json"].map((s) => d(e, s)).find((s) => b(s));
1410
+ return t ? ft("sha256").update(C(t)).digest("hex") : "";
1411
+ }
1412
+ function rn(e) {
1413
+ const t = d(e, B.paths.cache, "view", "lockfile.sha256"), s = on(e);
1414
+ if (b(d(e, "node_modules")) && b(t) && C(t, "utf-8").trim() === s) return;
1415
+ if (console.log("nimpress view: installing the docs site dependencies"), se("pnpm", ["install"], { cwd: e, stdio: "inherit" }).status !== 0) throw new Error("[nimpress] view: pnpm install failed in the docs site clone");
1416
+ J(N(t), { recursive: !0 }), W(t, `${s}
1417
+ `);
1418
+ }
1419
+ function It(e, t) {
1420
+ const s = ds(), n = s === "darwin" ? ["open", ...t ? ["-a", t] : [], e] : s === "win32" ? ["cmd", "/c", "start", "", ...t ? [t] : [], e] : t ? [t, e] : ["xdg-open", e], o = ke(n[0], n.slice(1), { stdio: "ignore", detached: !0 });
1421
+ o.on("error", () => console.log(`nimpress: open ${e} in ${t ?? "a browser"}`)), o.unref();
1422
+ }
1423
+ function Xe(e, t) {
1424
+ let s;
1425
+ return () => {
1426
+ s && clearTimeout(s), s = setTimeout(e, t);
1427
+ };
1428
+ }
1429
+ function an(e, t) {
1430
+ t.added.length + t.modified.length + t.deleted.length !== 0 && console.log(`nimpress view: ${e} ${t.added.length} added, ${t.modified.length} modified, ${t.deleted.length} deleted`);
1431
+ }
1432
+ function cn(e) {
1433
+ const t = ke("pnpm", ["exec", "nimpress", "dev"], { cwd: e, stdio: ["ignore", "pipe", "inherit"] }), s = new Promise((n, o) => {
1434
+ let r = !1;
1435
+ t.stdout?.on("data", (i) => {
1436
+ const c = i.toString();
1437
+ if (process.stdout.write(c), r) return;
1438
+ const l = c.replace(/\x1b\[[0-9;]*m/g, "").match(/Local\s*:?\s+(https?:\/\/\S+)/);
1439
+ l && (r = !0, n(l[1]));
1440
+ }), t.on("exit", (i) => {
1441
+ r || o(new Error(`[nimpress] view: the docs site dev server exited with ${i ?? "a signal"} before it printed a url`));
1442
+ }), t.on("error", (i) => o(new Error(`[nimpress] view: cannot run the docs site dev server, ${i.message}`)));
1443
+ });
1444
+ return { child: t, origin: s };
1445
+ }
1446
+ async function ln(e, t) {
1447
+ const s = M(t, "offline"), n = await tn(e, t), o = Xs(e), r = Rt(e), i = await we(e), c = _(t, "target") ? [`--target=${_(t, "target")}`] : [], l = [];
1448
+ for (const u of n) {
1449
+ const p = x(r, u.exportDir);
1450
+ if (i.configFile && Ae(e, i.resolved, [...c, `--out=${p}`]), !b(p))
1451
+ throw new Error(`[nimpress] view: no export folder at ${p}, write the pages there or mark pages with export: and add a config`);
1452
+ const m = sn(u);
1453
+ nn(u, m, s), rn(m);
1454
+ const f = await we(m);
1455
+ if (!f.configFile) throw new Error(`[nimpress] view: ${u.repo} carries no nimpress config, so it is not a docs site`);
1456
+ const h = Us(m, f.resolved.contentDir), g = Vs(Ks(m, h, o));
1457
+ if (!g.length)
1458
+ throw new Error(
1459
+ `[nimpress] view: ${u.repo} has no target for ${o}, add it to nimpress.sources.json or the receiver defaults`
1460
+ );
1461
+ const w = x(m, h.contentRoot), k = x(m, f.resolved.contentDir);
1462
+ let j = [];
1463
+ const O = () => {
1464
+ j.length && ie(["checkout", "--", ...j], m);
1465
+ const $ = /* @__PURE__ */ new Set();
1466
+ for (const y of g) {
1467
+ const I = d(p, ...y.from.split("/").filter(Boolean)), P = d(w, ...y.to.split("/"));
1468
+ an(y.to, Ys(I, P, y.mode));
1469
+ for (const A of X(I)) $.add(d(P, E(I, A)));
1470
+ }
1471
+ j = Qs(k, $);
1472
+ for (const y of j) te(y);
1473
+ j.length && console.log(`nimpress view: the local pages replace ${j.map((y) => E(m, y)).join(", ")}`);
1474
+ };
1475
+ O();
1476
+ const v = Ze(p, { recursive: !0 }, Xe(O, 150));
1477
+ if (l.push(() => v.close()), i.configFile) {
1478
+ const $ = Ze(
1479
+ x(e, i.resolved.contentDir),
1480
+ { recursive: !0 },
1481
+ Xe(() => Ae(e, i.resolved, [...c, `--out=${p}`]), 150)
1482
+ );
1483
+ l.push(() => $.close());
1484
+ }
1485
+ const { child: R, origin: F } = cn(m);
1486
+ l.push(() => R.kill());
1487
+ const T = `${(await F).replace(/\/$/, "")}/${g[0].to}`;
1488
+ console.log(`nimpress view: ${o} inside ${u.repo} at ${T}`), M(t, "no-browser") || It(T);
1489
+ }
1490
+ const a = () => {
1491
+ for (const u of l) u();
1492
+ process.exit(0);
1493
+ };
1494
+ process.on("SIGINT", a), process.on("SIGTERM", a);
1495
+ }
1496
+ const un = 6e4;
1497
+ function oe(e, t) {
1127
1498
  const s = _(t, "system");
1128
1499
  if (s === void 0) return;
1129
1500
  const n = Object.keys(e.modules.systems);
@@ -1131,8 +1502,8 @@ function ae(e, t) {
1131
1502
  throw new Error(`[nimpress] modules: unknown system ${s}, configured: ${n.join(", ") || "none"}`);
1132
1503
  return s;
1133
1504
  }
1134
- function je(e, t, s) {
1135
- const n = ae(e, t);
1505
+ function Oe(e, t, s) {
1506
+ const n = oe(e, t);
1136
1507
  if (n) return n;
1137
1508
  const o = Object.keys(e.modules.systems);
1138
1509
  if (o.length === 1) return o[0];
@@ -1140,64 +1511,74 @@ function je(e, t, s) {
1140
1511
  `[nimpress] modules ${s}: several systems configured (${o.join(", ")}), pass --system=<name>`
1141
1512
  ) : new Error(`[nimpress] modules ${s}: no systems configured`);
1142
1513
  }
1143
- async function As(e, t, s) {
1514
+ async function pn(e, t, s) {
1144
1515
  const n = s[0], o = s.slice(1), r = Object.keys(t.modules.systems);
1145
1516
  if (n === "init") {
1146
- Ms(e, t);
1517
+ fn(e, t);
1147
1518
  return;
1148
1519
  }
1149
1520
  if (n === "dev") {
1150
- const i = ae(t, o), c = i ? [i] : r;
1521
+ const i = oe(t, o), c = i ? [i] : r;
1151
1522
  if (!c.length) throw new Error("[nimpress] modules dev: no systems configured");
1152
- await gt(e, t, c), await new Promise(() => {
1523
+ await $t(e, t, c), await new Promise(() => {
1153
1524
  });
1154
1525
  }
1155
1526
  if (n === "build") {
1156
- const i = ae(t, o), c = i ? [i] : ht(t);
1527
+ const i = oe(t, o), c = i ? [i] : wt(t);
1157
1528
  if (!c.length) throw new Error("[nimpress] modules build: no systems configured");
1158
- await wt(e, t, c);
1529
+ await yt(e, t, c);
1159
1530
  return;
1160
1531
  }
1161
1532
  if (n === "lint") {
1162
- const i = await dt(e, t, ae(t, o));
1163
- Ne("nimpress modules lint", i, "nimpress modules lint: systems, schemas, and stories ok");
1533
+ const i = await gt(e, t, oe(t, o));
1534
+ We("nimpress modules lint", i, "nimpress modules lint: systems, schemas, and stories ok");
1164
1535
  return;
1165
1536
  }
1166
1537
  if (n === "story") {
1167
- const i = je(t, o, "story"), c = ne(o, 0), p = _(o, "framework");
1538
+ const i = Oe(t, o, "story"), c = K(o, 0), l = _(o, "framework");
1168
1539
  if (c) {
1169
- const l = await Le(e, t, i, c, p);
1170
- l && console.log(`nimpress modules: story written to ${l}`);
1540
+ const u = await Je(e, t, i, c, l);
1541
+ u && console.log(`nimpress modules: story written to ${u}`);
1171
1542
  return;
1172
1543
  }
1173
- const a = await Ns(e, t, i);
1544
+ const a = await Ms(e, t, i);
1174
1545
  console.log(`nimpress modules: ${a} auto stories written for ${i}`);
1175
1546
  return;
1176
1547
  }
1177
1548
  if (n === "stories") {
1178
- const i = ne(o, 0), c = ae(t, o), p = await He(e, t, { component: i, system: c });
1179
- if (i && !p.length) {
1180
- const a = (await He(e, t, { system: c })).map((l) => `${l.system}/${l.component}`).filter((l, u, m) => m.indexOf(l) === u && l.toLowerCase().includes(i.toLowerCase()));
1181
- throw new Error(
1182
- `[nimpress] modules stories: no stories for ${i}${c ? ` in ${c}` : ""}` + (a.length ? `, did you mean ${a.slice(0, 8).join(", ")}` : "")
1183
- );
1184
- }
1549
+ const i = K(o, 0), c = await qe(e, t, "stories", i, oe(t, o));
1185
1550
  if (M(o, "json")) {
1186
- console.log(JSON.stringify(p, null, 2));
1551
+ console.log(JSON.stringify(c, null, 2));
1187
1552
  return;
1188
1553
  }
1189
1554
  if (!i) {
1190
- const a = /* @__PURE__ */ new Map();
1191
- for (const l of p) a.set(`${l.system} ${l.component}`, (a.get(`${l.system} ${l.component}`) ?? 0) + 1);
1192
- for (const [l, u] of a) console.log(`${l} ${u}`);
1555
+ const l = /* @__PURE__ */ new Map();
1556
+ for (const a of c) l.set(`${a.system} ${a.component}`, (l.get(`${a.system} ${a.component}`) ?? 0) + 1);
1557
+ for (const [a, u] of l) console.log(`${a} ${u}`);
1193
1558
  return;
1194
1559
  }
1195
- for (const a of p) console.log(`${a.system} ${a.component} ${a.story} ${a.route}`);
1560
+ for (const l of c) console.log(`${l.system} ${l.component} ${l.story} ${l.route}`);
1561
+ return;
1562
+ }
1563
+ if (n === "open") {
1564
+ const i = K(o, 0);
1565
+ if (!i)
1566
+ throw new Error("[nimpress] modules open expects: nimpress modules open <Component> [story] [--system=<name>] [--browser=<app>]");
1567
+ const c = await qe(e, t, "open", i, oe(t, o)), l = c.map((m) => m.system).filter((m, f, h) => h.indexOf(m) === f);
1568
+ if (l.length > 1)
1569
+ throw new Error(`[nimpress] modules open: ${i} is in several systems (${l.join(", ")}), pass --system=<name>`);
1570
+ const a = K(o, 1), u = rs(c, a);
1571
+ if (!u)
1572
+ throw new Error(
1573
+ `[nimpress] modules open: no story ${a} for ${c[0].system}/${c[0].component}, stories: ${c.map((m) => m.story).join(", ")}`
1574
+ );
1575
+ const p = is(t, u);
1576
+ await mn(e, t, u, p), It(p, _(o, "browser")), console.log(`nimpress modules open: ${u.system}/${u.component} ${u.story} at ${p}`);
1196
1577
  return;
1197
1578
  }
1198
1579
  if (n === "import") {
1199
- const i = je(t, o, "import"), c = ne(o, 0);
1200
- await Ps(e, t, i, {
1580
+ const i = Oe(t, o, "import"), c = K(o, 0);
1581
+ await Js(e, t, i, {
1201
1582
  file: c,
1202
1583
  name: _(o, "name"),
1203
1584
  source: _(o, "source"),
@@ -1205,12 +1586,12 @@ async function As(e, t, s) {
1205
1586
  match: _(o, "match"),
1206
1587
  fromStories: o.includes("--from-stories"),
1207
1588
  select: o.includes("--select")
1208
- }), De(e);
1589
+ }), _e(e);
1209
1590
  return;
1210
1591
  }
1211
1592
  if (n === "update") {
1212
- const i = _(o, "component") ?? ne(o, 0), c = await ts(e, t, { ref: i, system: ae(t, o) });
1213
- console.log(`nimpress modules: ${c} schema${c === 1 ? "" : "s"} upserted`), De(e);
1593
+ const i = _(o, "component") ?? K(o, 0), c = await as(e, t, { ref: i, system: oe(t, o) });
1594
+ console.log(`nimpress modules: ${c} schema${c === 1 ? "" : "s"} upserted`), _e(e);
1214
1595
  return;
1215
1596
  }
1216
1597
  if (n === "create") {
@@ -1218,22 +1599,59 @@ async function As(e, t, s) {
1218
1599
  if (i) {
1219
1600
  if (!M(o, "schema"))
1220
1601
  throw new Error("[nimpress] modules create --component expects --schema to upsert the schema");
1221
- const u = await ss(e, t, i);
1222
- console.log(`nimpress modules: schema upserted at ${u}`);
1602
+ const p = await cs(e, t, i);
1603
+ console.log(`nimpress modules: schema upserted at ${p}`);
1223
1604
  return;
1224
1605
  }
1225
- const c = ne(o, 0);
1606
+ const c = K(o, 0);
1226
1607
  if (!c)
1227
1608
  throw new Error("[nimpress] modules create expects: nimpress modules create <Component> [--system=<name>], or --component=<ref> --schema");
1228
- const p = je(t, o, "create"), a = _(o, "framework"), l = await Ws(e, t, p, c, a);
1229
- console.log(`nimpress modules: created ${c} at ${F(e, l)}`);
1609
+ const l = Oe(t, o, "create"), a = _(o, "framework"), u = await Is(e, t, l, c, a);
1610
+ console.log(`nimpress modules: created ${c} at ${E(e, u)}`);
1230
1611
  return;
1231
1612
  }
1232
- throw new Error("[nimpress] modules expects init, dev, build, lint, story, stories, import, create or update");
1613
+ throw new Error("[nimpress] modules expects init, dev, build, lint, story, stories, open, import, create or update");
1233
1614
  }
1234
- function Ms(e, t) {
1615
+ async function qe(e, t, s, n, o) {
1616
+ const r = await Ue(e, t, { component: n, system: o });
1617
+ if (n && !r.length) {
1618
+ const i = (await Ue(e, t, { system: o })).map((c) => `${c.system}/${c.component}`).filter((c, l, a) => a.indexOf(c) === l && c.toLowerCase().includes(n.toLowerCase()));
1619
+ throw new Error(
1620
+ `[nimpress] modules ${s}: no stories for ${n}${o ? ` in ${o}` : ""}` + (i.length ? `, did you mean ${i.slice(0, 8).join(", ")}` : "")
1621
+ );
1622
+ }
1623
+ return r;
1624
+ }
1625
+ async function et(e) {
1626
+ try {
1627
+ return (await fetch(e, { signal: AbortSignal.timeout(2e3) })).status;
1628
+ } catch {
1629
+ return;
1630
+ }
1631
+ }
1632
+ async function mn(e, t, s, n) {
1633
+ let o = await et(n);
1634
+ if (o === void 0) {
1635
+ const r = Le(e, t, "modules", "dev.log");
1636
+ J(N(r), { recursive: !0 });
1637
+ const i = ps(r, "a"), c = ke(process.execPath, [process.argv[1], "dev"], { cwd: e, detached: !0, stdio: ["ignore", i, i] });
1638
+ c.unref();
1639
+ let l = !1;
1640
+ c.on("exit", () => l = !0), console.log(`nimpress modules open: started nimpress dev in the background, pid ${c.pid}, log ${E(e, r)}`);
1641
+ const a = Date.now() + un;
1642
+ for (; o === void 0 && !l && Date.now() < a; )
1643
+ await new Promise((u) => setTimeout(u, 500)), o = await et(n);
1644
+ if (o === void 0)
1645
+ throw new Error(`[nimpress] modules open: the ${s.system} harness did not answer on ${n}, see ${E(e, r)}`);
1646
+ }
1647
+ if (o !== 200)
1648
+ throw new Error(
1649
+ `[nimpress] modules open: the ${s.system} harness answers ${o} for ${s.component}, restart nimpress dev so it picks the component up`
1650
+ );
1651
+ }
1652
+ function fn(e, t) {
1235
1653
  const s = d(e, t.modules.dir);
1236
- B(s, { recursive: !0 });
1654
+ J(s, { recursive: !0 });
1237
1655
  const n = d(e, "nimpress.config.json");
1238
1656
  if (b(n)) {
1239
1657
  const o = JSON.parse(C(n, "utf-8"));
@@ -1243,66 +1661,12 @@ function Ms(e, t) {
1243
1661
  console.log("nimpress modules: add a modules block with systems entries to your nimpress config");
1244
1662
  console.log(`nimpress modules: folder ready at ${s}`);
1245
1663
  }
1246
- function Ct(e) {
1247
- if (!e.startsWith(`---
1248
- `)) return null;
1249
- const t = e.indexOf(`
1250
- ---`, 4);
1251
- return t < 0 ? null : e.slice(4, t);
1252
- }
1253
- function Is(e) {
1254
- for (const t of e.split(`
1255
- `)) {
1256
- if (!t.startsWith("export:")) continue;
1257
- const s = t.slice(7).trim().replace(/^["']|["']$/g, "");
1258
- return s === "" || s === "false" ? null : s;
1259
- }
1260
- return null;
1261
- }
1262
- function Ls(e, t) {
1263
- const s = Ct(e);
1264
- if (s === null) return e;
1265
- const n = s.split(`
1266
- `).filter((r) => !r.startsWith("export:") && !r.startsWith(" file:")), o = n.findIndex((r) => r.startsWith(" package:"));
1267
- return t && o >= 0 && !n.some((r) => r.startsWith(" version:")) && n.splice(o + 1, 0, ` version: ${JSON.stringify(t)}`), `---
1268
- ${n.join(`
1269
- `)}${e.slice(4 + s.length)}`;
1270
- }
1271
- function Re(e, t, s) {
1272
- const n = _(s, "target") ?? "", o = d(e, _(s, "out") ?? t.paths.export), r = d(e, t.contentDir);
1273
- let i = "";
1274
- try {
1275
- i = JSON.parse(C(d(e, "package.json"), "utf-8")).version ?? "";
1276
- } catch {
1277
- i = "";
1278
- }
1279
- let c = 0;
1280
- for (const p of Y(r)) {
1281
- if (!p.endsWith(".md")) continue;
1282
- const a = C(p, "utf-8"), l = Ct(a);
1283
- if (l === null) continue;
1284
- const u = Is(l);
1285
- if (u === null || n && u !== n && u !== "true") continue;
1286
- const m = N(p), f = d(o, F(r, m));
1287
- B(f, { recursive: !0 });
1288
- for (const h of ie(m, { withFileTypes: !0 })) {
1289
- if (!h.isFile()) continue;
1290
- const g = C(d(m, h.name), "utf-8");
1291
- W(
1292
- d(f, h.name),
1293
- h.name.endsWith(".md") ? Ls(g, i) : g
1294
- );
1295
- }
1296
- c++;
1297
- }
1298
- console.log(`nimpress export: ${c} pages collected into ${o}`);
1299
- }
1300
- const Ce = d(".claude", "skills", "nimpress", "SKILL.md");
1301
- function Et() {
1302
- const e = N(ft(import.meta.url)), t = [
1303
- x(e, Ce),
1304
- x(e, "..", Ce),
1305
- x(e, "..", "..", Ce)
1664
+ const Fe = d(".claude", "skills", "nimpress", "SKILL.md");
1665
+ function Lt() {
1666
+ const e = N(ht(import.meta.url)), t = [
1667
+ x(e, Fe),
1668
+ x(e, "..", Fe),
1669
+ x(e, "..", "..", Fe)
1306
1670
  ];
1307
1671
  for (const s of t)
1308
1672
  try {
@@ -1311,51 +1675,51 @@ function Et() {
1311
1675
  }
1312
1676
  throw new Error(`[nimpress] skill: SKILL.md not found, looked in ${t.join(", ")}`);
1313
1677
  }
1314
- function Ot(e, t) {
1315
- const s = t ? d(K(), ".claude") : d(e, ".claude"), n = d(s, "skills", "nimpress");
1316
- B(n, { recursive: !0 });
1678
+ function Jt(e, t) {
1679
+ const s = t ? d(Q(), ".claude") : d(e, ".claude"), n = d(s, "skills", "nimpress");
1680
+ J(n, { recursive: !0 });
1317
1681
  const o = d(n, "SKILL.md");
1318
- return W(o, Et()), console.log(`wrote ${o}`), o;
1682
+ return W(o, Lt()), console.log(`wrote ${o}`), o;
1319
1683
  }
1320
- function Js(e, t) {
1684
+ function dn(e, t) {
1321
1685
  const s = t[0];
1322
1686
  if (s === "get") {
1323
- process.stdout.write(Et());
1687
+ process.stdout.write(Lt());
1324
1688
  return;
1325
1689
  }
1326
1690
  if (s === "put") {
1327
- Ot(e, !M(t, "project"));
1691
+ Jt(e, !M(t, "project"));
1328
1692
  return;
1329
1693
  }
1330
1694
  throw new Error("[nimpress] skill expects get or put");
1331
1695
  }
1332
- const zs = "nimling/nimpress", Bs = "nimpress@nimpress";
1333
- function Ke(e, t) {
1696
+ const hn = "nimling/nimpress", gn = "nimpress@nimpress";
1697
+ function tt(e, t) {
1334
1698
  console.log(`claude ${t.join(" ")}`);
1335
- const s = te("claude", t, { cwd: e, stdio: "inherit" });
1699
+ const s = se("claude", t, { cwd: e, stdio: "inherit" });
1336
1700
  if (s.error) throw new Error(`[nimpress] plugin: could not run claude, install Claude Code first: ${s.error.message}`);
1337
1701
  if (s.status !== 0) throw new Error(`[nimpress] plugin: claude ${t.join(" ")} exited with ${s.status}`);
1338
1702
  }
1339
- function Gs(e, t) {
1703
+ function wn(e, t) {
1340
1704
  const s = t ? "user" : "project";
1341
- Ke(e, ["plugin", "marketplace", "add", zs, "--scope", s]), Ke(e, ["plugin", "install", Bs, "--scope", s]);
1705
+ tt(e, ["plugin", "marketplace", "add", hn, "--scope", s]), tt(e, ["plugin", "install", gn, "--scope", s]);
1342
1706
  }
1343
- function Hs(e, t) {
1707
+ function $n(e, t) {
1344
1708
  if (t[0] === "put") {
1345
- Gs(e, !M(t, "project"));
1709
+ wn(e, !M(t, "project"));
1346
1710
  return;
1347
1711
  }
1348
1712
  throw new Error("[nimpress] plugin expects put");
1349
1713
  }
1350
- const X = {
1714
+ const V = {
1351
1715
  name: "--system",
1352
1716
  value: !0,
1353
1717
  describe: "the configured component system to act on"
1354
- }, Ye = {
1718
+ }, st = {
1355
1719
  name: "--framework",
1356
1720
  value: !0,
1357
1721
  describe: "vue or svelte, overriding the framework of the system"
1358
- }, V = [
1722
+ }, Y = [
1359
1723
  {
1360
1724
  name: "init",
1361
1725
  describe: "Write the config, the content folder, and the agent guide",
@@ -1392,21 +1756,27 @@ const X = {
1392
1756
  flags: [],
1393
1757
  subs: [
1394
1758
  { name: "init", describe: "Create the modules folder and the config block", flags: [], subs: [] },
1395
- { name: "dev", describe: "Serve the harnesses and stay running", flags: [X], subs: [] },
1396
- { name: "build", describe: "Build the harness bundles", flags: [X], subs: [] },
1397
- { name: "lint", describe: "Check the systems, the schemas, and the stories", flags: [X], subs: [] },
1398
- { name: "story", describe: "Write auto stories for one component or for every component", flags: [X, Ye], subs: [] },
1759
+ { name: "dev", describe: "Serve the harnesses and stay running", flags: [V], subs: [] },
1760
+ { name: "build", describe: "Build the harness bundles", flags: [V], subs: [] },
1761
+ { name: "lint", describe: "Check the systems, the schemas, and the stories", flags: [V], subs: [] },
1762
+ { name: "story", describe: "Write auto stories for one component or for every component", flags: [V, st], subs: [] },
1399
1763
  {
1400
1764
  name: "stories",
1401
1765
  describe: "List the stories of one component in every system that carries it, with the harness route that renders each story alone, or every component and its story count",
1402
- flags: [X, { name: "--json", value: !1, describe: "print the routes as json" }],
1766
+ flags: [V, { name: "--json", value: !1, describe: "print the routes as json" }],
1767
+ subs: []
1768
+ },
1769
+ {
1770
+ name: "open",
1771
+ describe: "Open one story of a component alone in the browser, the default story when none is named, starting nimpress dev in the background when no harness answers",
1772
+ flags: [V, { name: "--browser", value: !0, describe: "the browser application to open the story in instead of the default browser" }],
1403
1773
  subs: []
1404
1774
  },
1405
1775
  {
1406
1776
  name: "import",
1407
1777
  describe: "Import components and storybook stories into component pages",
1408
1778
  flags: [
1409
- X,
1779
+ V,
1410
1780
  { name: "--name", value: !0, describe: "the component name when a single file is imported" },
1411
1781
  { name: "--source", value: !0, describe: "the component source root, overriding the system source" },
1412
1782
  { name: "--stories", value: !0, describe: "an extra folder of storybook csf files" },
@@ -1420,8 +1790,8 @@ const X = {
1420
1790
  name: "create",
1421
1791
  describe: "Create a component page, or upsert one schema",
1422
1792
  flags: [
1423
- X,
1424
- Ye,
1793
+ V,
1794
+ st,
1425
1795
  { name: "--component", value: !0, describe: "the component reference whose schema is upserted" },
1426
1796
  { name: "--schema", value: !1, describe: "required with --component, upserts the schema" }
1427
1797
  ],
@@ -1430,7 +1800,7 @@ const X = {
1430
1800
  {
1431
1801
  name: "update",
1432
1802
  describe: "Upsert the component schemas from the component types",
1433
- flags: [X, { name: "--component", value: !0, describe: "limit the upsert to one component reference" }],
1803
+ flags: [V, { name: "--component", value: !0, describe: "limit the upsert to one component reference" }],
1434
1804
  subs: []
1435
1805
  }
1436
1806
  ]
@@ -1545,55 +1915,55 @@ const X = {
1545
1915
  { name: "powershell", describe: "the powershell completion script", flags: [], subs: [] }
1546
1916
  ]
1547
1917
  }
1548
- ], Ft = ["bash", "zsh", "fish", "powershell"];
1549
- function ke(e) {
1918
+ ], zt = ["bash", "zsh", "fish", "powershell"];
1919
+ function xe(e) {
1550
1920
  const t = [];
1551
1921
  for (const s of [...e.flags, ...e.subs.flatMap((n) => n.flags)])
1552
1922
  t.some((n) => n.name === s.name) || t.push(s);
1553
1923
  return t;
1554
1924
  }
1555
- function xe(e, t) {
1925
+ function Se(e, t) {
1556
1926
  return t && e.value ? `${e.name}=` : e.name;
1557
1927
  }
1558
- function Us() {
1928
+ function yn() {
1559
1929
  const e = ["_nimpress() {", ' local cur="${COMP_WORDS[COMP_CWORD]}"'];
1560
- e.push(` local words="${V.map((t) => t.name).join(" ")}"`), e.push(' if [ "$COMP_CWORD" -gt 1 ]; then'), e.push(' case "${COMP_WORDS[1]}" in');
1561
- for (const t of V) {
1562
- const s = [...t.subs.map((n) => n.name), ...ke(t).map((n) => xe(n, !1))];
1930
+ e.push(` local words="${Y.map((t) => t.name).join(" ")}"`), e.push(' if [ "$COMP_CWORD" -gt 1 ]; then'), e.push(' case "${COMP_WORDS[1]}" in');
1931
+ for (const t of Y) {
1932
+ const s = [...t.subs.map((n) => n.name), ...xe(t).map((n) => Se(n, !1))];
1563
1933
  e.push(` ${t.name}) words="${s.join(" ")}" ;;`);
1564
1934
  }
1565
1935
  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(`
1566
1936
  `) + `
1567
1937
  `;
1568
1938
  }
1569
- function Ee(e, t, s) {
1939
+ function De(e, t, s) {
1570
1940
  const n = [`${e}entries=(`];
1571
1941
  for (const o of s) n.push(`${e} ${o}`);
1572
1942
  return n.push(`${e})`), n.push(`${e}_describe '${t}' entries`), n.push(`${e}return`), n;
1573
1943
  }
1574
- function Zs() {
1944
+ function bn() {
1575
1945
  const e = ["#compdef nimpress", "", "_nimpress() {", " local -a entries", " if (( CURRENT == 2 )); then"];
1576
1946
  e.push(
1577
- ...Ee(
1947
+ ...De(
1578
1948
  " ",
1579
1949
  "nimpress command",
1580
- V.map((t) => `'${t.name}:${t.describe}'`)
1950
+ Y.map((t) => `'${t.name}:${t.describe}'`)
1581
1951
  )
1582
1952
  ), e.push(" fi"), e.push(' case "$words[2]" in');
1583
- for (const t of V) {
1953
+ for (const t of Y) {
1584
1954
  e.push(` ${t.name})`), t.subs.length && (e.push(" if (( CURRENT == 3 )); then"), e.push(
1585
- ...Ee(
1955
+ ...De(
1586
1956
  " ",
1587
1957
  `${t.name} argument`,
1588
1958
  t.subs.map((n) => `'${n.name}:${n.describe}'`)
1589
1959
  )
1590
1960
  ), e.push(" fi"));
1591
- const s = ke(t);
1961
+ const s = xe(t);
1592
1962
  s.length ? e.push(
1593
- ...Ee(
1963
+ ...De(
1594
1964
  " ",
1595
1965
  "nimpress flag",
1596
- s.map((n) => `'${xe(n, !0)}:${n.describe}'`)
1966
+ s.map((n) => `'${Se(n, !0)}:${n.describe}'`)
1597
1967
  )
1598
1968
  ) : e.push(" return"), e.push(" ;;");
1599
1969
  }
@@ -1601,52 +1971,52 @@ function Zs() {
1601
1971
  `) + `
1602
1972
  `;
1603
1973
  }
1604
- function Vs() {
1974
+ function vn() {
1605
1975
  const e = ["complete -c nimpress -f"];
1606
- for (const t of V)
1976
+ for (const t of Y)
1607
1977
  e.push(
1608
1978
  `complete -c nimpress -n '__fish_use_subcommand' -a '${t.name}' -d '${t.describe}'`
1609
1979
  );
1610
- for (const t of V) {
1980
+ for (const t of Y) {
1611
1981
  const s = `__fish_seen_subcommand_from ${t.name}`;
1612
1982
  for (const n of t.subs)
1613
1983
  e.push(`complete -c nimpress -n '${s}' -a '${n.name}' -d '${n.describe}'`);
1614
- for (const n of ke(t))
1984
+ for (const n of xe(t))
1615
1985
  e.push(
1616
- `complete -c nimpress -n '${s}' -a '${xe(n, !0)}' -d '${n.describe}'`
1986
+ `complete -c nimpress -n '${s}' -a '${Se(n, !0)}' -d '${n.describe}'`
1617
1987
  );
1618
1988
  }
1619
1989
  return e.join(`
1620
1990
  `) + `
1621
1991
  `;
1622
1992
  }
1623
- function Ks() {
1993
+ function kn() {
1624
1994
  const e = [
1625
1995
  "Register-ArgumentCompleter -Native -CommandName nimpress -ScriptBlock {",
1626
1996
  " param($wordToComplete, $commandAst, $cursorPosition)",
1627
1997
  " $words = @($commandAst.CommandElements | ForEach-Object { $_.ToString() })",
1628
1998
  " $candidates = @()",
1629
1999
  " if ($words.Count -le 2) {",
1630
- ` $candidates = @(${V.map((t) => `'${t.name}'`).join(", ")})`,
2000
+ ` $candidates = @(${Y.map((t) => `'${t.name}'`).join(", ")})`,
1631
2001
  " } else {",
1632
2002
  " switch ($words[1]) {"
1633
2003
  ];
1634
- for (const t of V) {
1635
- const s = [...t.subs.map((n) => n.name), ...ke(t).map((n) => xe(n, !0))];
2004
+ for (const t of Y) {
2005
+ const s = [...t.subs.map((n) => n.name), ...xe(t).map((n) => Se(n, !0))];
1636
2006
  e.push(` '${t.name}' { $candidates = @(${s.map((n) => `'${n}'`).join(", ")}) }`);
1637
2007
  }
1638
2008
  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(`
1639
2009
  `) + `
1640
2010
  `;
1641
2011
  }
1642
- function Dt(e) {
1643
- if (e === "bash") return Us();
1644
- if (e === "zsh") return Zs();
1645
- if (e === "fish") return Vs();
1646
- if (e === "powershell") return Ks();
1647
- throw new Error(`[nimpress] completion: unsupported shell ${e}, use ${Ft.join(", ")}`);
2012
+ function Bt(e) {
2013
+ if (e === "bash") return yn();
2014
+ if (e === "zsh") return bn();
2015
+ if (e === "fish") return vn();
2016
+ if (e === "powershell") return kn();
2017
+ throw new Error(`[nimpress] completion: unsupported shell ${e}, use ${zt.join(", ")}`);
1648
2018
  }
1649
- function Qe(e) {
2019
+ function nt(e) {
1650
2020
  return e === "fish" ? [
1651
2021
  "function nimpress",
1652
2022
  " if test -x node_modules/.bin/nimpress",
@@ -1668,13 +2038,13 @@ function Qe(e) {
1668
2038
  ].join(`
1669
2039
  `);
1670
2040
  }
1671
- function Ys() {
2041
+ function xn() {
1672
2042
  const e = D(process.env.SHELL ?? "");
1673
2043
  for (const t of ["zsh", "bash", "fish"])
1674
2044
  if (e.includes(t)) return t;
1675
2045
  return "";
1676
2046
  }
1677
- function Qs(e, t) {
2047
+ function Sn(e, t) {
1678
2048
  const s = "# >>> nimpress completion >>>", n = "# <<< nimpress completion <<<", o = `${s}
1679
2049
  ${t}
1680
2050
  ${n}`, r = e.indexOf(s), i = e.indexOf(n);
@@ -1685,68 +2055,68 @@ ${n}`, r = e.indexOf(s), i = e.indexOf(n);
1685
2055
  `) + o + `
1686
2056
  `;
1687
2057
  }
1688
- function Xs(e, t) {
2058
+ function jn(e, t) {
1689
2059
  let s = "";
1690
2060
  try {
1691
2061
  s = C(e, "utf-8");
1692
2062
  } catch {
1693
2063
  s = "";
1694
2064
  }
1695
- W(e, Qs(s, t));
2065
+ W(e, Sn(s, t));
1696
2066
  }
1697
- function qs(e) {
1698
- const t = e || Ys();
2067
+ function Cn(e) {
2068
+ const t = e || xn();
1699
2069
  if (!t)
1700
2070
  throw new Error("[nimpress] completion: could not detect the shell from $SHELL, name it: nimpress completion <shell> --auto");
1701
- const s = Dt(t), n = K();
2071
+ const s = Bt(t), n = Q();
1702
2072
  if (t === "fish") {
1703
2073
  const a = d(n, ".config", "fish", "completions");
1704
- B(a, { recursive: !0 });
1705
- const l = d(a, "nimpress.fish");
1706
- W(l, s), console.log(`wrote ${l}`);
1707
- const u = d(n, ".config", "fish", "functions");
1708
- B(u, { recursive: !0 });
1709
- const m = d(u, "nimpress.fish");
1710
- W(m, Qe(t)), console.log(`wrote ${m}`), console.log("fish loads them on the next shell");
2074
+ J(a, { recursive: !0 });
2075
+ const u = d(a, "nimpress.fish");
2076
+ W(u, s), console.log(`wrote ${u}`);
2077
+ const p = d(n, ".config", "fish", "functions");
2078
+ J(p, { recursive: !0 });
2079
+ const m = d(p, "nimpress.fish");
2080
+ W(m, nt(t)), console.log(`wrote ${m}`), console.log("fish loads them on the next shell");
1711
2081
  return;
1712
2082
  }
1713
2083
  if (t !== "bash" && t !== "zsh")
1714
2084
  throw new Error(`[nimpress] completion: auto install covers bash, zsh, and fish, for ${t} run: nimpress completion ${t}`);
1715
2085
  const o = d(n, ".config", "nimpress", "completions");
1716
- B(o, { recursive: !0 });
2086
+ J(o, { recursive: !0 });
1717
2087
  const r = d(o, t === "zsh" ? "_nimpress" : "nimpress.bash");
1718
2088
  W(r, s), console.log(`wrote ${r}`);
1719
2089
  const i = d(n, t === "zsh" ? ".zshrc" : ".bashrc"), c = t === "zsh" ? `fpath=("${o}" $fpath)
1720
- autoload -Uz compinit && compinit -u` : `[ -f "${r}" ] && source "${r}"`, p = `${Qe(t)}
2090
+ autoload -Uz compinit && compinit -u` : `[ -f "${r}" ] && source "${r}"`, l = `${nt(t)}
1721
2091
  ${c}`;
1722
- Xs(i, p), console.log(`wired ${i}`), console.log(`start a new shell or run: source ${i}`);
2092
+ jn(i, l), console.log(`wired ${i}`), console.log(`start a new shell or run: source ${i}`);
1723
2093
  }
1724
- function en(e, t) {
1725
- const s = ne(t, 0) ?? "", n = M(t, "auto"), o = M(t, "skill");
2094
+ function En(e, t) {
2095
+ const s = K(t, 0) ?? "", n = M(t, "auto"), o = M(t, "skill");
1726
2096
  if (!n) {
1727
2097
  if (o) throw new Error("[nimpress] completion: --skill installs alongside --auto");
1728
- if (!s) throw new Error(`[nimpress] completion: name a shell (${Ft.join(", ")}) or pass --auto`);
1729
- process.stdout.write(Dt(s));
2098
+ if (!s) throw new Error(`[nimpress] completion: name a shell (${zt.join(", ")}) or pass --auto`);
2099
+ process.stdout.write(Bt(s));
1730
2100
  return;
1731
2101
  }
1732
- qs(s), o && Ot(e, !0);
2102
+ Cn(s), o && Jt(e, !0);
1733
2103
  }
1734
- const tn = /* @__PURE__ */ new Set(["skill", "plugin", "mcp", "completion"]), sn = /* @__PURE__ */ new Set(["dev", "view", "modules dev"]), nn = 2e4, de = /* @__PURE__ */ new Map();
1735
- function _t(e, t) {
2104
+ const On = /* @__PURE__ */ new Set(["skill", "plugin", "mcp", "completion"]), Fn = /* @__PURE__ */ new Set(["dev", "view", "modules dev"]), Dn = 2e4, de = /* @__PURE__ */ new Map();
2105
+ function Gt(e, t) {
1736
2106
  const s = [...t, e.name];
1737
- return e.subs.length ? e.subs.flatMap((n) => _t(n, s)) : [
2107
+ return e.subs.length ? e.subs.flatMap((n) => Gt(n, s)) : [
1738
2108
  {
1739
2109
  name: s.join("_"),
1740
2110
  argv: s,
1741
2111
  describe: e.describe,
1742
2112
  flags: e.flags,
1743
- serves: sn.has(s.join(" "))
2113
+ serves: Fn.has(s.join(" "))
1744
2114
  }
1745
2115
  ];
1746
2116
  }
1747
- const Nt = V.filter((e) => !tn.has(e.name)).flatMap((e) => _t(e, []));
1748
- function on() {
1749
- const e = N(ft(import.meta.url));
2117
+ const Ht = Y.filter((e) => !On.has(e.name)).flatMap((e) => Gt(e, []));
2118
+ function _n() {
2119
+ const e = N(ht(import.meta.url));
1750
2120
  for (const t of [x(e, "..", "package.json"), x(e, "..", "..", "package.json")])
1751
2121
  try {
1752
2122
  return JSON.parse(C(t, "utf-8")).version;
@@ -1754,7 +2124,7 @@ function on() {
1754
2124
  }
1755
2125
  return "0.0.0";
1756
2126
  }
1757
- function rn(e) {
2127
+ function Nn(e) {
1758
2128
  const t = {};
1759
2129
  for (const s of e.flags)
1760
2130
  t[s.name.slice(2)] = { type: s.value ? "string" : "boolean", description: s.describe };
@@ -1768,12 +2138,12 @@ function rn(e) {
1768
2138
  additionalProperties: !1
1769
2139
  };
1770
2140
  }
1771
- function an() {
2141
+ function Wn() {
1772
2142
  return [
1773
- ...Nt.map((e) => ({
2143
+ ...Ht.map((e) => ({
1774
2144
  name: e.name,
1775
2145
  description: `nimpress ${e.argv.join(" ")}: ${e.describe}${e.serves ? ". Keeps running in the background and returns its pid with the first output" : ""}`,
1776
- inputSchema: rn(e)
2146
+ inputSchema: Nn(e)
1777
2147
  })),
1778
2148
  {
1779
2149
  name: "stop",
@@ -1787,7 +2157,7 @@ function an() {
1787
2157
  }
1788
2158
  ];
1789
2159
  }
1790
- function cn(e, t) {
2160
+ function Tn(e, t) {
1791
2161
  const s = [...e.argv, ...t.args ?? []];
1792
2162
  for (const [n, o] of Object.entries(t.flags ?? {}))
1793
2163
  o === !0 ? s.push(`--${n}`) : typeof o == "string" && s.push(`--${n}=${o}`);
@@ -1796,89 +2166,89 @@ function cn(e, t) {
1796
2166
  function U(e, t = !1) {
1797
2167
  return { content: [{ type: "text", text: e || "(no output)" }], ...t ? { isError: t } : {} };
1798
2168
  }
1799
- function Wt(e, t, s) {
1800
- return Ie(process.execPath, [process.argv[1], ...cn(t, s)], {
2169
+ function Ut(e, t, s) {
2170
+ return ke(process.execPath, [process.argv[1], ...Tn(t, s)], {
1801
2171
  cwd: x(e, s.cwd ?? "."),
1802
2172
  env: { ...process.env, NO_COLOR: "1", FORCE_COLOR: "0" },
1803
2173
  stdio: ["ignore", "pipe", "pipe"]
1804
2174
  });
1805
2175
  }
1806
- function ln(e, t, s) {
1807
- const n = Wt(e, t, s);
2176
+ function Pn(e, t, s) {
2177
+ const n = Ut(e, t, s);
1808
2178
  let o = "";
1809
2179
  return n.stdout?.on("data", (r) => o += r), n.stderr?.on("data", (r) => o += r), new Promise((r) => {
1810
2180
  n.on("error", (i) => r(U(`${o}${i.message}`, !0))), n.on("close", (i) => r(U(o, i !== 0)));
1811
2181
  });
1812
2182
  }
1813
- function un(e, t, s) {
1814
- const n = Wt(e, t, s);
2183
+ function Rn(e, t, s) {
2184
+ const n = Ut(e, t, s);
1815
2185
  let o = "";
1816
2186
  return new Promise((r) => {
1817
2187
  const i = (a) => {
1818
- clearTimeout(p), n.stdout?.removeAllListeners("data"), n.stderr?.removeAllListeners("data"), n.stdout?.resume(), n.stderr?.resume(), r(a);
2188
+ clearTimeout(l), n.stdout?.removeAllListeners("data"), n.stderr?.removeAllListeners("data"), n.stdout?.resume(), n.stderr?.resume(), r(a);
1819
2189
  }, c = (a) => {
1820
2190
  o += a, /https?:\/\/\S+/.test(o) && i(U(`pid ${n.pid}
1821
2191
  ${o}`));
1822
- }, p = setTimeout(() => i(U(`pid ${n.pid}
1823
- ${o}`)), nn);
2192
+ }, l = setTimeout(() => i(U(`pid ${n.pid}
2193
+ ${o}`)), Dn);
1824
2194
  n.stdout?.on("data", c), n.stderr?.on("data", c), n.on("error", (a) => i(U(`${o}${a.message}`, !0))), n.on("exit", (a) => {
1825
2195
  de.delete(n.pid ?? -1), i(U(o, a !== 0));
1826
2196
  }), n.pid && de.set(n.pid, n);
1827
2197
  });
1828
2198
  }
1829
- function pn(e) {
2199
+ function An(e) {
1830
2200
  const t = de.get(e);
1831
2201
  return t ? (t.kill("SIGTERM"), de.delete(e), U(`stopped ${e}`)) : U(`no server with pid ${e} was started by this session`, !0);
1832
2202
  }
1833
- async function mn(e, t) {
2203
+ async function Mn(e, t) {
1834
2204
  const s = String(t.name ?? ""), n = t.arguments ?? {};
1835
- if (s === "stop") return pn(Number(n.pid));
1836
- const o = Nt.find((r) => r.name === s);
1837
- return o ? b(x(e, n.cwd ?? ".")) ? o.serves ? un(e, o, n) : ln(e, o, n) : U(`no folder ${n.cwd} under ${e}`, !0) : U(`unknown tool ${s}`, !0);
2205
+ if (s === "stop") return An(Number(n.pid));
2206
+ const o = Ht.find((r) => r.name === s);
2207
+ return o ? b(x(e, n.cwd ?? ".")) ? o.serves ? Rn(e, o, n) : Pn(e, o, n) : U(`no folder ${n.cwd} under ${e}`, !0) : U(`unknown tool ${s}`, !0);
1838
2208
  }
1839
- function oe(e, t) {
2209
+ function re(e, t) {
1840
2210
  process.stdout.write(JSON.stringify({ jsonrpc: "2.0", id: e, ...t }) + `
1841
2211
  `);
1842
2212
  }
1843
- async function fn(e, t) {
2213
+ async function In(e, t) {
1844
2214
  if (t.id !== void 0) {
1845
2215
  if (t.method === "initialize") {
1846
- oe(t.id, {
2216
+ re(t.id, {
1847
2217
  result: {
1848
2218
  protocolVersion: t.params?.protocolVersion ?? "2025-06-18",
1849
2219
  capabilities: { tools: {} },
1850
- serverInfo: { name: "nimpress", version: on() }
2220
+ serverInfo: { name: "nimpress", version: _n() }
1851
2221
  }
1852
2222
  });
1853
2223
  return;
1854
2224
  }
1855
2225
  if (t.method === "ping") {
1856
- oe(t.id, { result: {} });
2226
+ re(t.id, { result: {} });
1857
2227
  return;
1858
2228
  }
1859
2229
  if (t.method === "tools/list") {
1860
- oe(t.id, { result: { tools: an() } });
2230
+ re(t.id, { result: { tools: Wn() } });
1861
2231
  return;
1862
2232
  }
1863
2233
  if (t.method === "tools/call") {
1864
- oe(t.id, { result: await mn(e, t.params ?? {}) });
2234
+ re(t.id, { result: await Mn(e, t.params ?? {}) });
1865
2235
  return;
1866
2236
  }
1867
- oe(t.id, { error: { code: -32601, message: `method not found: ${t.method}` } });
2237
+ re(t.id, { error: { code: -32601, message: `method not found: ${t.method}` } });
1868
2238
  }
1869
2239
  }
1870
- function dn(e) {
1871
- const t = ls({ input: process.stdin }), s = /* @__PURE__ */ new Set();
2240
+ function Ln(e) {
2241
+ const t = gs({ input: process.stdin }), s = /* @__PURE__ */ new Set();
1872
2242
  t.on("line", (n) => {
1873
2243
  if (!n.trim()) return;
1874
2244
  let o;
1875
2245
  try {
1876
2246
  o = JSON.parse(n);
1877
2247
  } catch {
1878
- oe(null, { error: { code: -32700, message: "parse error" } });
2248
+ re(null, { error: { code: -32700, message: "parse error" } });
1879
2249
  return;
1880
2250
  }
1881
- const r = fn(e, o).catch((i) => oe(o.id, { error: { code: -32603, message: String(i?.message ?? i) } })).finally(() => s.delete(r));
2251
+ const r = In(e, o).catch((i) => re(o.id, { error: { code: -32603, message: String(i?.message ?? i) } })).finally(() => s.delete(r));
1882
2252
  s.add(r);
1883
2253
  }), t.on("close", async () => {
1884
2254
  await Promise.all(s);
@@ -1886,464 +2256,148 @@ function dn(e) {
1886
2256
  process.exit(0);
1887
2257
  });
1888
2258
  }
1889
- function hn(e, t, s) {
2259
+ function Jn(e, t, s) {
1890
2260
  if (typeof s.path == "string") return s.path.startsWith("/") ? s.path : `/${s.path}`;
1891
- const n = F(e, t).split(L).join("/").replace(/\.md$/, "");
2261
+ const n = E(e, t).split(L).join("/").replace(/\.md$/, "");
1892
2262
  return n === "index" ? "/" : `/${n.replace(/\/index$/, "")}`;
1893
2263
  }
1894
- function Xe(e) {
2264
+ function ot(e) {
1895
2265
  return e ? (Array.isArray(e) ? e : String(e).split(",")).map((s) => String(s).trim()).filter(Boolean) : [];
1896
2266
  }
1897
- function gn(e) {
2267
+ function zn(e) {
1898
2268
  return e.split(`
1899
2269
  `).filter((t) => /^#{1,6}\s/.test(t)).map((t) => t.replace(/^#{1,6}\s+/, "").trim());
1900
2270
  }
1901
- function wn(e, t) {
1902
- const s = x(e, t.contentDir), o = Y(s).filter((a) => a.endsWith(".md")).map((a) => {
1903
- const { data: l, content: u } = ue(C(a, "utf-8"));
1904
- return { file: a, data: l, content: u };
2271
+ function Bn(e, t) {
2272
+ const s = x(e, t.contentDir), o = X(s).filter((a) => a.endsWith(".md")).map((a) => {
2273
+ const { data: u, content: p } = ue(C(a, "utf-8"));
2274
+ return { file: a, data: u, content: p };
1905
2275
  }).filter((a) => typeof a.data.title == "string" && a.data.visibility !== "hidden" && !a.data.link), r = o.map((a) => ({
1906
2276
  slug: a.file,
1907
2277
  title: String(a.data.title),
1908
- headings: gn(a.content),
1909
- tags: Xe(a.data.tags),
2278
+ headings: zn(a.content),
2279
+ tags: ot(a.data.tags),
1910
2280
  body: a.content
1911
- })), i = ns(r), c = t.site?.url?.replace(/\/$/, "") ?? "", p = t.base.replace(/\/$/, "");
2281
+ })), i = ls(r), c = t.site?.url?.replace(/\/$/, "") ?? "", l = t.base.replace(/\/$/, "");
1912
2282
  return o.map((a) => {
1913
- const l = i.get(a.file) ?? { keywords: [], description: "" }, u = a.data.meta ?? {}, m = Array.isArray(u.keywords) ? u.keywords : typeof u.keywords == "string" ? [u.keywords] : void 0, f = typeof u.description == "string" ? u.description : typeof a.data.description == "string" ? a.data.description : void 0, h = u.override === !0, g = t.seo?.auto === !0, w = g ? h && m ? m : l.keywords.length ? l.keywords : m ?? [] : m ?? Xe(a.data.tags), k = g ? h && f ? f : l.description || f || "" : f ?? "", j = hn(s, a.file, a.data);
2283
+ const u = i.get(a.file) ?? { keywords: [], description: "" }, p = a.data.meta ?? {}, m = Array.isArray(p.keywords) ? p.keywords : typeof p.keywords == "string" ? [p.keywords] : void 0, f = typeof p.description == "string" ? p.description : typeof a.data.description == "string" ? a.data.description : void 0, h = p.override === !0, g = t.seo?.auto === !0, w = g ? h && m ? m : u.keywords.length ? u.keywords : m ?? [] : m ?? ot(a.data.tags), k = g ? h && f ? f : u.description || f || "" : f ?? "", j = Jn(s, a.file, a.data);
1914
2284
  return {
1915
2285
  path: j,
1916
- file: F(e, a.file).split(L).join("/"),
2286
+ file: E(e, a.file).split(L).join("/"),
1917
2287
  title: String(a.data.title),
1918
2288
  keywords: w,
1919
2289
  description: k,
1920
- robots: os(typeof u.robots == "string" ? u.robots : "index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1", t.seo?.ai?.index, typeof u.ai == "boolean" ? u.ai : void 0),
1921
- canonical: typeof u.canonical == "string" ? u.canonical : c ? `${c}${p}${j === "/" ? "/" : j}` : "",
1922
- generated: l,
1923
- authored: { keywords: m, description: f, override: h, ai: typeof u.ai == "boolean" ? u.ai : void 0 }
2290
+ robots: us(typeof p.robots == "string" ? p.robots : "index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1", t.seo?.ai?.index, typeof p.ai == "boolean" ? p.ai : void 0),
2291
+ canonical: typeof p.canonical == "string" ? p.canonical : c ? `${c}${l}${j === "/" ? "/" : j}` : "",
2292
+ generated: u,
2293
+ authored: { keywords: m, description: f, override: h, ai: typeof p.ai == "boolean" ? p.ai : void 0 }
1924
2294
  };
1925
2295
  });
1926
2296
  }
1927
- function $n(e, t) {
2297
+ function Gn(e, t) {
1928
2298
  let s = 0;
1929
2299
  for (const n of t) {
1930
2300
  const o = x(e, n.file), { data: r, content: i } = ue(C(o, "utf-8")), c = { ...r.meta ?? {} };
1931
- let p = !1;
1932
- c.keywords === void 0 && n.generated.keywords.length && (c.keywords = n.generated.keywords, p = !0), c.description === void 0 && n.generated.description && (c.description = n.generated.description, p = !0), p && (W(o, ue.stringify(i, { ...r, meta: c })), s += 1);
2301
+ let l = !1;
2302
+ c.keywords === void 0 && n.generated.keywords.length && (c.keywords = n.generated.keywords, l = !0), c.description === void 0 && n.generated.description && (c.description = n.generated.description, l = !0), l && (W(o, ue.stringify(i, { ...r, meta: c })), s += 1);
1933
2303
  }
1934
2304
  return s;
1935
2305
  }
1936
- function yn(e, t, s) {
1937
- const n = wn(e, t), o = _(s, "out") ?? "seo.map.json";
2306
+ function Hn(e, t, s) {
2307
+ const n = Bn(e, t), o = _(s, "out") ?? "seo.map.json";
1938
2308
  for (const r of n) {
1939
2309
  const i = t.seo?.auto ? r.authored.override ? "authored" : "generated" : "authored";
1940
2310
  console.log(`${r.path.padEnd(40)} ${String(r.keywords.length).padStart(2)} keywords ${String(r.description.length).padStart(3)} chars ${r.robots.includes("noai") ? "noai" : "ai ok"} ${i}`);
1941
2311
  }
1942
2312
  if (W(x(e, o), JSON.stringify(n, null, 2) + `
1943
2313
  `), console.log(`nimpress seo: ${n.length} pages, map written to ${o}`), s.includes("--write")) {
1944
- const r = $n(e, n);
2314
+ const r = Gn(e, n);
1945
2315
  console.log(`nimpress seo: generated fields written into ${r} pages`);
1946
2316
  }
1947
2317
  }
1948
- function Tt(e = K()) {
1949
- return d(e, ".nimpress", "config.json");
1950
- }
1951
- function Pt(e = K()) {
1952
- return d(e, ".tide", "nimpress", "sites");
1953
- }
1954
- function Rt(e = K()) {
1955
- const t = Tt(e);
1956
- return b(t) ? { links: JSON.parse(C(t, "utf-8")).links ?? {} } : { links: {} };
1957
- }
1958
- function At(e, t = K()) {
1959
- const s = Tt(t);
1960
- B(N(s), { recursive: !0 }), W(s, `${JSON.stringify(e, null, 2)}
1961
- `);
1962
- }
1963
- function ve(e) {
1964
- const t = e.trim().replace(/\.git$/, "").replace(/\/+$/, ""), s = t.match(/[:/]([^/:]+)\/([^/]+)$/);
1965
- if (s && t.includes("github.com")) return `${s[1]}/${s[2]}`;
1966
- const n = t.match(/^([^/\s]+)\/([^/\s]+)$/);
1967
- if (n) return `${n[1]}/${n[2]}`;
1968
- throw new Error(`[nimpress] view: cannot read owner/repo from ${e}`);
1969
- }
1970
- function Oe(e) {
1971
- const t = e.trim();
1972
- return /^(https?:\/\/|git@|ssh:\/\/)/.test(t) ? t : `https://github.com/${ve(t)}.git`;
1973
- }
1974
- function Mt(e) {
1975
- const t = d(e, ".github", "workflows");
1976
- return b(t) ? ie(t).filter((s) => s.endsWith(".yml") || s.endsWith(".yaml")).sort().map((s) => d(t, s)) : [];
1977
- }
1978
- function It(e) {
1979
- try {
1980
- const t = us(C(e, "utf-8"));
1981
- return typeof t == "object" && t !== null ? t : null;
1982
- } catch {
1983
- return null;
1984
- }
1985
- }
1986
- function le(e, t) {
1987
- return String(e ?? "").replace(/\$\{\{\s*env\.([A-Za-z_][A-Za-z0-9_]*)\s*\}\}/g, (n, o) => {
1988
- for (const r of t)
1989
- if (r && r[o] !== void 0) return String(r[o]);
1990
- return "";
1991
- }).trim();
1992
- }
1993
- function Lt(e, t) {
1994
- const s = [];
1995
- for (const n of Object.values(e.jobs ?? {}))
1996
- for (const o of n.steps ?? [])
1997
- typeof o.uses == "string" && o.uses.includes(`/actions/${t}@`) && s.push({ step: o, scopes: [o.env, n.env, e.env] });
1998
- return s;
1999
- }
2000
- function bn(e) {
2001
- const t = /* @__PURE__ */ new Map();
2002
- for (const s of Mt(e)) {
2003
- const n = It(s);
2004
- if (n)
2005
- for (const { step: o, scopes: r } of Lt(n, "docs-notify")) {
2006
- const i = le(o.with?.["docs-repo"], r);
2007
- if (!i) continue;
2008
- const c = le(o.with?.["export-dir"], r) || ".nimpress";
2009
- t.set(i, { repo: i, exportDir: c });
2010
- }
2011
- }
2012
- return [...t.values()];
2013
- }
2014
- function qe(e) {
2015
- return e.replace(/\$\{\{\s*github\.workspace\s*\}\}\/?/g, "").replace(/^\.\//, "");
2016
- }
2017
- function vn(e, t) {
2018
- const s = {
2019
- contentRoot: t,
2020
- mapping: b(d(e, "nimpress.sources.json")) ? "nimpress.sources.json" : "",
2021
- defaults: {}
2022
- };
2023
- for (const n of Mt(e)) {
2024
- const o = It(n);
2025
- if (o)
2026
- for (const { step: r, scopes: i } of Lt(o, "docs-sync")) {
2027
- const c = qe(le(r.with?.["docs-dir"], i)), p = (m) => {
2028
- const f = qe(m);
2029
- return (c && f.startsWith(`${c}/`) ? f.slice(c.length + 1) : f).replace(/\/+$/, "");
2030
- }, a = le(r.with?.["content-root"], i);
2031
- a && (s.contentRoot = p(a));
2032
- const l = le(r.with?.mapping, i);
2033
- l && (s.mapping = p(l));
2034
- const u = le(r.with?.defaults, i);
2035
- return u && (s.defaults = JSON.parse(u)), s;
2036
- }
2037
- }
2038
- return s;
2039
- }
2040
- function kn(e, t) {
2041
- const s = { ...e };
2042
- return t.target && (s.target = t.target), t.targets?.length && (s.targets = t.targets), t.mode && (s.mode = t.mode), s;
2043
- }
2044
- function xn(e) {
2045
- const t = e.mode || "mirror";
2046
- return e.targets?.length ? e.targets.map((s) => ({ from: s.from ?? "", to: s.to, mode: s.mode || t })) : e.target ? [{ from: "", to: e.target, mode: t }] : [];
2047
- }
2048
- function Sn(e, t, s) {
2049
- let n = t.defaults;
2050
- const o = t.mapping ? d(e, t.mapping) : "";
2051
- if (o && b(o)) {
2052
- const i = JSON.parse(C(o, "utf-8")).sources?.[s];
2053
- i && (n = kn(n, i));
2054
- }
2055
- return n;
2056
- }
2057
- function et(e) {
2058
- const t = /* @__PURE__ */ new Map();
2059
- if (!b(e)) return t;
2060
- for (const s of Y(e))
2061
- t.set(F(e, s).split(L).join("/"), C(s));
2062
- return t;
2063
- }
2064
- function jn(e, t, s) {
2065
- const n = { added: [], modified: [], deleted: [] }, o = et(e), r = et(t);
2066
- for (const [i, c] of o) {
2067
- const p = r.get(i);
2068
- if (p && p.equals(c)) continue;
2069
- const a = d(t, ...i.split("/"));
2070
- B(N(a), { recursive: !0 }), W(a, c), p ? n.modified.push(i) : n.added.push(i);
2071
- }
2072
- if (s === "mirror")
2073
- for (const i of r.keys())
2074
- o.has(i) || (ee(d(t, ...i.split("/")), { force: !0 }), n.deleted.push(i));
2075
- return n;
2076
- }
2077
- function Cn(e, t) {
2078
- const s = /* @__PURE__ */ new Map();
2079
- for (const o of Y(e)) {
2080
- if (!o.endsWith(".md")) continue;
2081
- const r = ue(C(o, "utf-8")).data.path, i = rs(e, o, typeof r == "string" ? r : void 0);
2082
- s.set(i, [...s.get(i) ?? [], o]);
2083
- }
2084
- const n = [];
2085
- for (const o of s.values())
2086
- o.some((r) => t.has(r)) && n.push(...o.filter((r) => !t.has(r)));
2087
- return n.sort();
2088
- }
2089
- function re(e, t, s) {
2090
- const n = te("git", e, { cwd: t, encoding: "utf-8", env: { ...process.env, ...s } });
2091
- return { ok: n.status === 0, out: `${n.stdout ?? ""}${n.stderr ?? ""}`.trim() };
2092
- }
2093
- function Jt(e) {
2094
- const t = re(["rev-parse", "--show-toplevel"], e);
2095
- return t.ok ? t.out : e;
2096
- }
2097
- function En(e) {
2098
- const t = re(["remote", "get-url", "origin"], e);
2099
- if (!t.ok) throw new Error(`[nimpress] view: ${e} has no origin remote, so its docs site mapping cannot be looked up`);
2100
- return ve(t.out);
2101
- }
2102
- function On() {
2103
- return te("gh", ["--version"], { encoding: "utf-8" }).status === 0;
2104
- }
2105
- function zt(e) {
2106
- return e?.method === "ssh" && e.key ? { GIT_SSH_COMMAND: `ssh -i ${e.key} -o IdentitiesOnly=yes` } : {};
2107
- }
2108
- function Fe(e) {
2109
- return e.login?.method === "gh" ? te("gh", ["repo", "view", e.repo, "--json", "name"], { encoding: "utf-8" }).status === 0 : re(["ls-remote", "--exit-code", "-h", e.url], void 0, zt(e.login)).ok;
2110
- }
2111
- async function Bt(e) {
2112
- const t = mt({ input: process.stdin, output: process.stdout });
2113
- try {
2114
- return (await t.question(e)).trim();
2115
- } finally {
2116
- t.close();
2117
- }
2118
- }
2119
- async function Fn(e) {
2120
- if (Fe(e)) return e;
2121
- if (console.log(`nimpress view: ${e.url} refused the connection`), On()) {
2122
- if (console.log("nimpress view: logging in through gh"), te("gh", ["auth", "login"], { stdio: "inherit" }).status !== 0) throw new Error("[nimpress] view: gh auth login did not complete");
2123
- const o = { ...e, login: { method: "gh" } };
2124
- if (Fe(o)) return o;
2125
- throw new Error(`[nimpress] view: ${e.repo} is still unreachable after the gh login, ask for access to it`);
2126
- }
2127
- const t = await Bt("nimpress view: path to the ssh key with access to the repo: ");
2128
- if (!t) throw new Error("[nimpress] view: no ssh key given and gh is not installed");
2129
- const s = { ...e, login: { method: "ssh", key: x(t.replace(/^~/, K())) } };
2130
- if (Fe(s)) return s;
2131
- throw new Error(`[nimpress] view: ${e.repo} is still unreachable with ${s.login.key}, ask for access to it`);
2132
- }
2133
- async function Dn(e, t, s = K()) {
2134
- const n = Jt(e), o = Rt(s), r = o.links[n] ?? [], i = bn(n), c = _(t, "docs-repo");
2135
- let p;
2136
- if (c) {
2137
- const l = ve(c), u = i.find((m) => m.repo === l)?.exportDir ?? _(t, "export-dir") ?? ".nimpress";
2138
- p = [{ repo: l, url: Oe(c), exportDir: u, login: r.find((m) => m.repo === l)?.login }];
2139
- } else if (i.length)
2140
- p = i.map((l) => ({
2141
- repo: l.repo,
2142
- url: r.find((u) => u.repo === l.repo)?.url ?? Oe(l.repo),
2143
- exportDir: l.exportDir,
2144
- login: r.find((u) => u.repo === l.repo)?.login
2145
- }));
2146
- else if (r.length)
2147
- p = r;
2148
- else {
2149
- console.log(`nimpress view: no workflow under ${n} names a docs site`);
2150
- const l = await Bt("nimpress view: docs site repo, owner/repo or a url, http or ssh: ");
2151
- if (!l) throw new Error("[nimpress] view: no docs site given");
2152
- p = [{ repo: ve(l), url: Oe(l), exportDir: _(t, "export-dir") ?? ".nimpress" }];
2153
- }
2154
- const a = [];
2155
- for (const l of p) a.push(await Fn(l));
2156
- return o.links[n] = a, At(o, s), a;
2157
- }
2158
- function _n(e, t = K()) {
2159
- return d(Pt(t), e.repo.replace("/", "__"));
2160
- }
2161
- function Nn(e, t, s) {
2162
- const n = zt(e.login);
2163
- if (!b(d(t, ".git"))) {
2164
- B(N(t), { recursive: !0 }), console.log(`nimpress view: cloning ${e.repo}`);
2165
- const r = e.login?.method === "gh" ? te("gh", ["repo", "clone", e.repo, t, "--", "--depth", "1"], { encoding: "utf-8" }) : te("git", ["clone", "--depth", "1", e.url, t], { encoding: "utf-8", env: { ...process.env, ...n } });
2166
- if (r.status !== 0) throw new Error(`[nimpress] view: clone of ${e.repo} failed
2167
- ${r.stderr ?? ""}`);
2168
- return;
2169
- }
2170
- if (s) return;
2171
- const o = re(["fetch", "--depth", "1", "origin", "HEAD"], t, n);
2172
- if (!o.ok) throw new Error(`[nimpress] view: fetch of ${e.repo} failed
2173
- ${o.out}`);
2174
- re(["reset", "--hard", "FETCH_HEAD"], t), re(["clean", "-fd"], t);
2175
- }
2176
- function Wn(e) {
2177
- const t = ["pnpm-lock.yaml", "package.json"].map((s) => d(e, s)).find((s) => b(s));
2178
- return t ? pt("sha256").update(C(t)).digest("hex") : "";
2179
- }
2180
- function Tn(e) {
2181
- const t = d(e, z.paths.cache, "view", "lockfile.sha256"), s = Wn(e);
2182
- if (b(d(e, "node_modules")) && b(t) && C(t, "utf-8").trim() === s) return;
2183
- if (console.log("nimpress view: installing the docs site dependencies"), te("pnpm", ["install"], { cwd: e, stdio: "inherit" }).status !== 0) throw new Error("[nimpress] view: pnpm install failed in the docs site clone");
2184
- B(N(t), { recursive: !0 }), W(t, `${s}
2185
- `);
2186
- }
2187
- function Pn(e) {
2188
- const t = cs(), s = t === "darwin" ? ["open", e] : t === "win32" ? ["cmd", "/c", "start", "", e] : ["xdg-open", e], n = Ie(s[0], s.slice(1), { stdio: "ignore", detached: !0 });
2189
- n.on("error", () => console.log(`nimpress view: open ${e} in a browser`)), n.unref();
2190
- }
2191
- function tt(e, t) {
2192
- let s;
2193
- return () => {
2194
- s && clearTimeout(s), s = setTimeout(e, t);
2195
- };
2196
- }
2197
- function Rn(e, t) {
2198
- t.added.length + t.modified.length + t.deleted.length !== 0 && console.log(`nimpress view: ${e} ${t.added.length} added, ${t.modified.length} modified, ${t.deleted.length} deleted`);
2199
- }
2200
- function An(e) {
2201
- const t = Ie("pnpm", ["exec", "nimpress", "dev"], { cwd: e, stdio: ["ignore", "pipe", "inherit"] }), s = new Promise((n, o) => {
2202
- let r = !1;
2203
- t.stdout?.on("data", (i) => {
2204
- const c = i.toString();
2205
- if (process.stdout.write(c), r) return;
2206
- const p = c.replace(/\x1b\[[0-9;]*m/g, "").match(/Local\s*:?\s+(https?:\/\/\S+)/);
2207
- p && (r = !0, n(p[1]));
2208
- }), t.on("exit", (i) => {
2209
- r || o(new Error(`[nimpress] view: the docs site dev server exited with ${i ?? "a signal"} before it printed a url`));
2210
- }), t.on("error", (i) => o(new Error(`[nimpress] view: cannot run the docs site dev server, ${i.message}`)));
2211
- });
2212
- return { child: t, origin: s };
2213
- }
2214
- async function Mn(e, t) {
2215
- const s = M(t, "offline"), n = await Dn(e, t), o = En(e), r = Jt(e), i = await we(e), c = _(t, "target") ? [`--target=${_(t, "target")}`] : [], p = [];
2216
- for (const l of n) {
2217
- const u = x(r, l.exportDir);
2218
- if (i.configFile && Re(e, i.resolved, [...c, `--out=${u}`]), !b(u))
2219
- throw new Error(`[nimpress] view: no export folder at ${u}, write the pages there or mark pages with export: and add a config`);
2220
- const m = _n(l);
2221
- Nn(l, m, s), Tn(m);
2222
- const f = await we(m);
2223
- if (!f.configFile) throw new Error(`[nimpress] view: ${l.repo} carries no nimpress config, so it is not a docs site`);
2224
- const h = vn(m, f.resolved.contentDir), g = xn(Sn(m, h, o));
2225
- if (!g.length)
2226
- throw new Error(
2227
- `[nimpress] view: ${l.repo} has no target for ${o}, add it to nimpress.sources.json or the receiver defaults`
2228
- );
2229
- const w = x(m, h.contentRoot), k = x(m, f.resolved.contentDir);
2230
- let j = [];
2231
- const E = () => {
2232
- j.length && re(["checkout", "--", ...j], m);
2233
- const $ = /* @__PURE__ */ new Set();
2234
- for (const y of g) {
2235
- const I = d(u, ...y.from.split("/").filter(Boolean)), P = d(w, ...y.to.split("/"));
2236
- Rn(y.to, jn(I, P, y.mode));
2237
- for (const A of Y(I)) $.add(d(P, F(I, A)));
2238
- }
2239
- j = Cn(k, $);
2240
- for (const y of j) ee(y);
2241
- j.length && console.log(`nimpress view: the local pages replace ${j.map((y) => F(m, y)).join(", ")}`);
2242
- };
2243
- E();
2244
- const v = Ue(u, { recursive: !0 }, tt(E, 150));
2245
- if (p.push(() => v.close()), i.configFile) {
2246
- const $ = Ue(
2247
- x(e, i.resolved.contentDir),
2248
- { recursive: !0 },
2249
- tt(() => Re(e, i.resolved, [...c, `--out=${u}`]), 150)
2250
- );
2251
- p.push(() => $.close());
2252
- }
2253
- const { child: R, origin: O } = An(m);
2254
- p.push(() => R.kill());
2255
- const T = `${(await O).replace(/\/$/, "")}/${g[0].to}`;
2256
- console.log(`nimpress view: ${o} inside ${l.repo} at ${T}`), M(t, "no-browser") || Pn(T);
2257
- }
2258
- const a = () => {
2259
- for (const l of p) l();
2260
- process.exit(0);
2261
- };
2262
- process.on("SIGINT", a), process.on("SIGTERM", a);
2263
- }
2264
- async function In(e, t) {
2265
- const s = ne(t, 0);
2318
+ async function Un(e, t) {
2319
+ const s = K(t, 0);
2266
2320
  if (s !== "clear") throw new Error(`[nimpress] cache: unknown subcommand ${s ?? ""}, use clear`);
2267
2321
  const n = M(t, "links"), o = M(t, "sites"), r = M(t, "local"), i = !n && !o && !r;
2268
2322
  if (n || i) {
2269
- const c = Rt(), p = Object.keys(c.links).length;
2270
- At({ links: {} }), console.log(`nimpress cache: cleared ${p} links`);
2323
+ const c = _t(), l = Object.keys(c.links).length;
2324
+ Nt({ links: {} }), console.log(`nimpress cache: cleared ${l} links`);
2271
2325
  }
2272
2326
  if (o || i) {
2273
- const c = Pt();
2274
- ee(c, { recursive: !0, force: !0 }), console.log(`nimpress cache: cleared the docs site clones under ${c}`);
2327
+ const c = Dt();
2328
+ te(c, { recursive: !0, force: !0 }), console.log(`nimpress cache: cleared the docs site clones under ${c}`);
2275
2329
  }
2276
2330
  if (r) {
2277
- const { resolved: c, configFile: p } = await we(e);
2278
- if (!p) throw new Error(`[nimpress] cache: --local needs a nimpress config in ${e}`);
2279
- const a = rt(e, c);
2280
- b(a) && ee(a, { recursive: !0, force: !0 }), console.log(`nimpress cache: cleared ${a}`);
2331
+ const { resolved: c, configFile: l } = await we(e);
2332
+ if (!l) throw new Error(`[nimpress] cache: --local needs a nimpress config in ${e}`);
2333
+ const a = Le(e, c);
2334
+ b(a) && te(a, { recursive: !0, force: !0 }), console.log(`nimpress cache: cleared ${a}`);
2281
2335
  }
2282
2336
  }
2283
- async function to(e) {
2337
+ async function co(e) {
2284
2338
  const t = e[0] ?? "dev", s = e.slice(1), n = process.cwd();
2285
2339
  if (t === "init") {
2286
- ds(n);
2340
+ bs(n);
2287
2341
  return;
2288
2342
  }
2289
2343
  if (t === "skill") {
2290
- Js(n, s);
2344
+ dn(n, s);
2291
2345
  return;
2292
2346
  }
2293
2347
  if (t === "plugin") {
2294
- Hs(n, s);
2348
+ $n(n, s);
2295
2349
  return;
2296
2350
  }
2297
2351
  if (t === "mcp") {
2298
- dn(n);
2352
+ Ln(n);
2299
2353
  return;
2300
2354
  }
2301
2355
  if (t === "completion") {
2302
- en(n, s);
2356
+ En(n, s);
2303
2357
  return;
2304
2358
  }
2305
2359
  if (t === "view" || t === "dev" && M(s, "view")) {
2306
- await Mn(n, s);
2360
+ await ln(n, s);
2307
2361
  return;
2308
2362
  }
2309
2363
  if (t === "cache") {
2310
- await In(n, s);
2364
+ await Un(n, s);
2311
2365
  return;
2312
2366
  }
2313
2367
  const { resolved: o } = await we(n);
2314
2368
  if (t === "seo") {
2315
- yn(n, o, s);
2369
+ Hn(n, o, s);
2316
2370
  return;
2317
2371
  }
2318
2372
  if (t === "lint") {
2319
- await Fs(n, o);
2373
+ await Ps(n, o);
2320
2374
  return;
2321
2375
  }
2322
2376
  if (t === "dev") {
2323
- await bs(n, o);
2377
+ await Cs(n, o);
2324
2378
  return;
2325
2379
  }
2326
2380
  if (t === "build") {
2327
- await $t(n, o);
2381
+ await bt(n, o);
2328
2382
  return;
2329
2383
  }
2330
2384
  if (t === "guard") {
2331
- _s(n, o, s);
2385
+ As(n, o, s);
2332
2386
  return;
2333
2387
  }
2334
2388
  if (t === "modules") {
2335
- await As(n, o, s);
2389
+ await pn(n, o, s);
2336
2390
  return;
2337
2391
  }
2338
2392
  if (t === "export") {
2339
- Re(n, o, s);
2393
+ Ae(n, o, s);
2340
2394
  return;
2341
2395
  }
2342
2396
  throw new Error(`[nimpress] unknown command: ${t}`);
2343
2397
  }
2344
2398
  export {
2345
- nt as buildViteConfig,
2346
- Vt as indexHtml,
2399
+ it as buildViteConfig,
2400
+ Qt as indexHtml,
2347
2401
  we as loadNimpressConfig,
2348
- to as run
2402
+ co as run
2349
2403
  };