@nimtech/nimpress 2.3.9 → 2.4.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.
Files changed (61) hide show
  1. package/.claude/rules/doc-pages.md +2 -2
  2. package/.claude/rules/docs-authoring.md +40 -4
  3. package/.claude/rules/frontmatter.md +30 -2
  4. package/.claude/rules/page-types.md +52 -0
  5. package/.claude/rules/style.md +4 -0
  6. package/.claude/skills/nimpress/SKILL.md +48 -7
  7. package/dist/cli.es.js +1244 -776
  8. package/dist/katex-BHBbz4bq.js +11283 -0
  9. package/dist/nimpress.es.js +7121 -5674
  10. package/dist/plugin-DOmbMyy0.js +6743 -0
  11. package/dist/plugin.es.js +11 -3
  12. package/dist/src/cli/cache.d.ts +2 -0
  13. package/dist/src/cli/cache.d.ts.map +1 -0
  14. package/dist/src/cli/completion.d.ts.map +1 -1
  15. package/dist/src/cli/init.d.ts.map +1 -1
  16. package/dist/src/cli/lint.d.ts.map +1 -1
  17. package/dist/src/cli/seo.d.ts +25 -0
  18. package/dist/src/cli/seo.d.ts.map +1 -0
  19. package/dist/src/cli/view.d.ts +53 -0
  20. package/dist/src/cli/view.d.ts.map +1 -0
  21. package/dist/src/cli.d.ts.map +1 -1
  22. package/dist/src/config/defaults.d.ts.map +1 -1
  23. package/dist/src/config/load.d.ts +8 -1
  24. package/dist/src/config/load.d.ts.map +1 -1
  25. package/dist/src/config/schema.d.ts +486 -3
  26. package/dist/src/config/schema.d.ts.map +1 -1
  27. package/dist/src/feedback/feedback.d.ts +5 -0
  28. package/dist/src/feedback/feedback.d.ts.map +1 -0
  29. package/dist/src/framework/configStore.d.ts +3 -1
  30. package/dist/src/framework/configStore.d.ts.map +1 -1
  31. package/dist/src/framework/createNimpressApp.d.ts +2 -1
  32. package/dist/src/framework/createNimpressApp.d.ts.map +1 -1
  33. package/dist/src/framework/gated.d.ts.map +1 -1
  34. package/dist/src/framework/hashSpy.d.ts.map +1 -1
  35. package/dist/src/framework/pageMeta.d.ts.map +1 -1
  36. package/dist/src/framework/stores/tabs.d.ts +3 -0
  37. package/dist/src/framework/stores/tabs.d.ts.map +1 -0
  38. package/dist/src/index.d.ts +15 -7
  39. package/dist/src/index.d.ts.map +1 -1
  40. package/dist/src/markdown/GlossaryPage.svelte.d.ts +1 -0
  41. package/dist/src/markdown/Lightbox.svelte.d.ts +1 -0
  42. package/dist/src/markdown/MathBlock.svelte.d.ts +1 -0
  43. package/dist/src/markdown/NotFoundPage.svelte.d.ts +1 -0
  44. package/dist/src/markdown/PricingPage.svelte.d.ts +1 -0
  45. package/dist/src/markdown/SectionPage.svelte.d.ts +1 -0
  46. package/dist/src/markdown/Tabs.svelte.d.ts +1 -0
  47. package/dist/src/markdown/TagsPage.svelte.d.ts +1 -0
  48. package/dist/src/markdown/TeamPage.svelte.d.ts +1 -0
  49. package/dist/src/types.d.ts +149 -7
  50. package/dist/src/types.d.ts.map +1 -1
  51. package/dist/style.css +1 -1
  52. package/package.json +11 -2
  53. package/src/styles/preflight.css +247 -46
  54. package/src/styles/theme.css +7 -6
  55. package/src/styles/tokens.css +25 -0
  56. package/dist/plugin-C3C36uvj.js +0 -3851
  57. /package/dist/src/{markdown/CalloutCheck.svelte.d.ts → layout/Announce.svelte.d.ts} +0 -0
  58. /package/dist/src/{markdown/CalloutInfo.svelte.d.ts → layout/Footer.svelte.d.ts} +0 -0
  59. /package/dist/src/markdown/{CalloutNote.svelte.d.ts → Callout.svelte.d.ts} +0 -0
  60. /package/dist/src/markdown/{CalloutTip.svelte.d.ts → Feedback.svelte.d.ts} +0 -0
  61. /package/dist/src/markdown/{CalloutWarning.svelte.d.ts → FullPage.svelte.d.ts} +0 -0
package/dist/cli.es.js CHANGED
@@ -1,48 +1,50 @@
1
- import { d as z, c as ke, r as Se, s as rt, p as it, a as Ne, b as se, e as at, f as ct, g as $e, h as Pe, i as lt, j as Te, k as ut, l as mt, m as pt, n as Ee, w as ne, o as Ae, q as ft, t as dt, u as ht, v as gt, x as $t } from "./plugin-C3C36uvj.js";
2
- import { join as d, dirname as L, relative as O, sep as q, extname as oe, resolve as F, basename as C } from "node:path";
3
- import { readdirSync as Y, existsSync as b, writeFileSync as A, mkdirSync as Q, rmSync as ae, readFileSync as W, statSync as Me } from "node:fs";
4
- import yt from "gray-matter";
5
- import { readFile as fe, readdir as wt, writeFile as G, mkdir as ye, copyFile as Re } from "node:fs/promises";
6
- import { s as bt, r as ce } from "./typeMembers-CNvE92EX.js";
7
- import { createServer as Ie, build as ze } from "vite";
8
- import { createHash as xt } from "node:crypto";
9
- import { createInterface as vt } from "node:readline/promises";
10
- import { fileURLToPath as kt } from "node:url";
11
- import { homedir as Le } from "node:os";
12
- function T(e, t) {
13
- return e.find((s) => s.startsWith(`--${t}=`))?.slice(t.length + 3);
14
- }
15
- function X(e, t) {
1
+ import { d as J, c as Te, r as Ae, s as Tt, p as At, a as qe, b as ce, e as Rt, f as Pt, g as Ee, h as Ke, i as It, j as Ye, k as Mt, l as zt, m as Jt, C as fe, n as Lt, o as Qe, q as ze, w as le, t as Xe, u as Bt, v as Gt, x as Ht, y as Ut, z as Zt, A as Vt, B as de } from "./plugin-DOmbMyy0.js";
2
+ import { join as d, dirname as _, relative as D, sep as I, extname as ue, resolve as j, basename as O } from "node:path";
3
+ import { readdirSync as X, existsSync as $, writeFileSync as N, mkdirSync as G, rmSync as ee, readFileSync as C, statSync as et, watch as Je } from "node:fs";
4
+ import pe from "gray-matter";
5
+ import { readFile as ve, readdir as qt, writeFile as q, mkdir as Fe, copyFile as tt } from "node:fs/promises";
6
+ import { s as Kt, r as he } from "./typeMembers-CNvE92EX.js";
7
+ import { createServer as st, build as nt } from "vite";
8
+ import { createHash as ot } from "node:crypto";
9
+ import { createInterface as rt } from "node:readline/promises";
10
+ import { fileURLToPath as Yt } from "node:url";
11
+ import { homedir as Z, platform as Qt } from "node:os";
12
+ import { spawnSync as te, spawn as it } from "node:child_process";
13
+ import { parse as Xt } from "yaml";
14
+ function W(e, t) {
15
+ return e.find((n) => n.startsWith(`--${t}=`))?.slice(t.length + 3);
16
+ }
17
+ function M(e, t) {
16
18
  return e.includes(`--${t}`);
17
19
  }
18
- function ee(e, t) {
19
- return e.filter((s) => !s.startsWith("--"))[t];
20
+ function ne(e, t) {
21
+ return e.filter((n) => !n.startsWith("--"))[t];
20
22
  }
21
- function re(e, t = []) {
22
- let n;
23
+ function se(e, t = []) {
24
+ let s;
23
25
  try {
24
- n = Y(e, { withFileTypes: !0 });
26
+ s = X(e, { withFileTypes: !0 });
25
27
  } catch {
26
28
  return t;
27
29
  }
28
- for (const s of n) {
29
- const o = d(e, s.name);
30
- if (s.isDirectory()) {
31
- if (s.name === "node_modules" || s.name.startsWith(".")) continue;
32
- re(o, t);
33
- } else s.isFile() && t.push(o);
30
+ for (const n of s) {
31
+ const o = d(e, n.name);
32
+ if (n.isDirectory()) {
33
+ if (n.name === "node_modules" || n.name.startsWith(".")) continue;
34
+ se(o, t);
35
+ } else n.isFile() && t.push(o);
34
36
  }
35
37
  return t;
36
38
  }
37
- function we(e, t, n) {
39
+ function Oe(e, t, s) {
38
40
  if (t.length) {
39
41
  console.error(`${e} failed with ${t.length} problems`);
40
- for (const s of t) console.error(` ${s}`);
42
+ for (const n of t) console.error(` ${n}`);
41
43
  process.exit(1);
42
44
  }
43
- console.log(n);
45
+ console.log(s);
44
46
  }
45
- function St() {
47
+ function es() {
46
48
  return `import { defineConfig } from '@nimtech/nimpress/plugin'
47
49
 
48
50
  /**
@@ -52,15 +54,15 @@ function St() {
52
54
  */
53
55
  export default defineConfig({
54
56
  /** Site title shown in the header and the tab. */
55
- title: ${JSON.stringify(z.title)},
57
+ title: ${JSON.stringify(J.title)},
56
58
 
57
- /** Folder holding the markdown content. Default ${JSON.stringify(z.contentDir)}. */
59
+ /** Folder holding the markdown content. Default ${JSON.stringify(J.contentDir)}. */
58
60
  // contentDir: 'docs',
59
61
 
60
- /** Root assets folder copied into the build, never inside contentDir. Default ${JSON.stringify(z.assetsDir)}. */
62
+ /** Root assets folder copied into the build, never inside contentDir. Default ${JSON.stringify(J.assetsDir)}. */
61
63
  // assetsDir: 'assets',
62
64
 
63
- /** Url base the assets folder serves under. Default ${JSON.stringify(z.assetUrlBase)}. */
65
+ /** Url base the assets folder serves under. Default ${JSON.stringify(J.assetUrlBase)}. */
64
66
  // assetUrlBase: '/assets',
65
67
 
66
68
  /**
@@ -81,8 +83,41 @@ export default defineConfig({
81
83
  /** Brand colors written onto the theme tokens --np-brand and --np-brand-hover. */
82
84
  // brand: { primary: '#CC785C', primaryHover: '#B86A52' },
83
85
 
84
- /** Site wide footer line, overridable per page with the footer frontmatter field. */
85
- // footer: 'Made with nimpress',
86
+ /** Footer: text is the site wide line, overridable per page with the footer frontmatter field, beside a copyright, social links, previous and next links, and the generator notice. */
87
+ // footer: { text: 'Made with nimpress', copyright: '© 2026 Nimling', social: [{ icon: '/assets/github.svg', link: 'https://github.com/nimling', name: 'Nimling on GitHub' }], navigation: true },
88
+
89
+ /** Announcement bar above the header. text is one markdown line, link wraps it, dismiss adds a close button remembered per text. */
90
+ // announce: { text: 'v2.4 is out', link: '/changelog', dismiss: true },
91
+
92
+ /** Repository actions on every doc page. url defaults to github, editUri to edit/main/<contentDir>/, actions lists edit and view. */
93
+ // repo: { actions: ['edit', 'view'] },
94
+
95
+ /** The was this page helpful widget, shown on pages with feedback: true. Each rating carries an icon, a name, the data, and a markdown note shown after the click; endpoint receives every click as a json post. */
96
+ // feedback: { title: 'Was this page helpful?', endpoint: 'https://auth.example.io/api/feedback', ratings: [{ icon: '👍', name: 'This page was helpful', data: '1', note: 'Thanks for your feedback!' }] },
97
+
98
+ /** Page status identifiers mapped to the label the sidebar mark carries. new and deprecated are present without configuration. */
99
+ // status: { beta: 'Beta' },
100
+
101
+ /** Content tab groups. linked selects the same label in every tab group on the site when one is clicked, remembered across pages. */
102
+ // tabs: { linked: true },
103
+
104
+ /** Image behavior in the prose. lightbox opens every image full size on click; without it only images carrying the zoom class open. */
105
+ // images: { lightbox: true },
106
+
107
+ /** Folder of custom svg icons a :name: shortcode resolves in, beside the lucide set. */
108
+ // icons: './assets/icons',
109
+
110
+ /** Math syntax in the prose. false turns off $...$ and $$...$$ for sites that write dollar signs. */
111
+ // math: false,
112
+
113
+ /** Tag icons by identifier, default for every tag without one, and the tag to identifier map so a group shares an icon. */
114
+ // tags: { icons: { default: ':lucide-tag:', api: ':lucide-plug:' }, map: { OpenAPI: 'api' } },
115
+
116
+ /** Custom page types: a type name to a Svelte component file. A new name registers a type, a built in name such as hero replaces its renderer. */
117
+ // pageTypes: { spotlight: './docs/types/Spotlight.svelte' },
118
+
119
+ /** Generated metadata: auto fills keywords and a description on every page without authored ones, ai.index false blocks every known ai crawler. */
120
+ // seo: { auto: true, ai: { index: false } },
86
121
 
87
122
  /** Extra header navigation routes. gate hides an entry from viewers that fail the check. */
88
123
  // navRoutes: [{ text: 'API', link: '/api' }],
@@ -105,7 +140,7 @@ export default defineConfig({
105
140
  // guard: (frontmatter, filePath, relatedFiles) => frontmatter.gate ?? 'default'
106
141
  // },
107
142
 
108
- /** Path to a client module exporting authFunctions and subscribeFunctions. */
143
+ /** Path to a client module exporting authFunctions, subscribeFunctions, and feedbackFunctions. */
109
144
  // client: './docs/client.ts',
110
145
 
111
146
  /** Changelog subscription wiring. */
@@ -145,21 +180,21 @@ export default defineConfig({
145
180
  })
146
181
  `;
147
182
  }
148
- function jt() {
183
+ function ts() {
149
184
  return JSON.stringify(
150
185
  {
151
186
  $schema: "./node_modules/@nimtech/nimpress/config.schema.json",
152
- title: z.title,
153
- contentDir: z.contentDir,
154
- assetsDir: z.assetsDir,
155
- assetUrlBase: z.assetUrlBase
187
+ title: J.title,
188
+ contentDir: J.contentDir,
189
+ assetsDir: J.assetsDir,
190
+ assetUrlBase: J.assetUrlBase
156
191
  },
157
192
  null,
158
193
  2
159
194
  ) + `
160
195
  `;
161
196
  }
162
- function Ct(e) {
197
+ function ss(e) {
163
198
  return `# Nimpress project
164
199
 
165
200
  This site is built with @nimtech/nimpress. Content lives in \`${e}/\` as markdown with typed frontmatter.
@@ -201,11 +236,11 @@ The authoritative AI working rules ship inside the package at \`node_modules/@ni
201
236
  8. \`nimpress guard map\` and \`nimpress guard apply\` wire gated pages, marked with the \`gate:\` frontmatter field, to the auth provider artifacts.
202
237
  `;
203
238
  }
204
- function Ft(e) {
205
- const t = d(e, "nimpress.config.ts"), n = d(e, "nimpress.config.json"), s = X(process.argv.slice(2), "json");
206
- !b(t) && !b(n) && (s ? (A(n, jt()), console.log(`nimpress init: ${n} written, field descriptions come from the referenced config.schema.json`)) : (A(t, St()), console.log(`nimpress init: ${t} written with every field documented, uncomment what you need`)));
207
- const o = d(e, z.contentDir);
208
- (!b(o) || Y(o).length === 0) && (Q(o, { recursive: !0 }), A(
239
+ function ns(e) {
240
+ const t = d(e, "nimpress.config.ts"), s = d(e, "nimpress.config.json"), n = M(process.argv.slice(2), "json");
241
+ !$(t) && !$(s) && (n ? (N(s, ts()), console.log(`nimpress init: ${s} written, field descriptions come from the referenced config.schema.json`)) : (N(t, es()), console.log(`nimpress init: ${t} written with every field documented, uncomment what you need`)));
242
+ const o = d(e, J.contentDir);
243
+ (!$(o) || X(o).length === 0) && (G(o, { recursive: !0 }), N(
209
244
  d(o, "index.md"),
210
245
  `---
211
246
  title: Home
@@ -214,332 +249,346 @@ title: Home
214
249
  Welcome to your Nimpress site.
215
250
  `
216
251
  ));
217
- const i = Ct(z.contentDir);
218
- for (const a of ["CLAUDE.md", "AGENTS.md"]) {
219
- const l = d(e, a);
220
- b(l) || (A(l, i), console.log(`nimpress init: ${a} written, pointing at the packaged rules in node_modules/@nimtech/nimpress/.claude/rules/`));
252
+ const i = ss(J.contentDir);
253
+ for (const c of ["CLAUDE.md", "AGENTS.md"]) {
254
+ const u = d(e, c);
255
+ $(u) || (N(u, i), console.log(`nimpress init: ${c} written, pointing at the packaged rules in node_modules/@nimtech/nimpress/.claude/rules/`));
221
256
  }
222
257
  }
223
- const Ot = { vue: "vueStory", svelte: "svelteStory" }, Et = { vue: ".svelte", svelte: ".vue" };
224
- function K(e) {
258
+ const os = { vue: "vueStory", svelte: "svelteStory" }, rs = { vue: ".svelte", svelte: ".vue" };
259
+ function oe(e) {
225
260
  return `run nimpress modules update ${e}`;
226
261
  }
227
- async function Dt(e) {
262
+ async function is(e) {
228
263
  let t;
229
264
  try {
230
- t = await wt(e, { withFileTypes: !0 });
265
+ t = await qt(e, { withFileTypes: !0 });
231
266
  } catch {
232
267
  return [];
233
268
  }
234
- return t.filter((n) => n.isFile() && /\.story\.tsx?$/.test(n.name)).map((n) => n.name);
235
- }
236
- function _t(e, t) {
237
- const n = t === "integer" ? "number" : t;
238
- return e.every((s) => typeof s === n);
239
- }
240
- function Wt(e, t, n, s, o) {
241
- const r = [], i = s.properties ?? {}, a = o.properties ?? {};
242
- for (const h of Object.keys(a))
243
- h in i || r.push(`${e}: prop ${h} is missing from the schema, ${K(t)}`);
244
- for (const h of Object.keys(i))
245
- h in a || r.push(`${e}: schema prop ${h} has no counterpart in ${n}, remove it or restore the prop`);
246
- for (const [h, p] of Object.entries(i)) {
247
- const f = a[h];
248
- if (f && (p.type && f.type && p.type !== f.type && !p.enum && r.push(
249
- `${e}: prop ${h} schema type ${p.type} conflicts with source type ${f.type}, ${K(t)}`
250
- ), p.enum && f.type && !_t(p.enum, f.type) && r.push(`${e}: prop ${h} enum values mismatch the source type ${f.type}`), p.enum && f.enum)) {
251
- const w = new Set(f.enum.map((k) => JSON.stringify(k))), $ = p.enum.filter((k) => !w.has(JSON.stringify(k)));
252
- $.length && r.push(
253
- `${e}: prop ${h} enum carries ${$.map((k) => JSON.stringify(k)).join(", ")} outside the source union`
269
+ return t.filter((s) => s.isFile() && /\.story\.tsx?$/.test(s.name)).map((s) => s.name);
270
+ }
271
+ function as(e, t) {
272
+ const s = t === "integer" ? "number" : t;
273
+ return e.every((n) => typeof n === s);
274
+ }
275
+ function cs(e, t, s, n, o) {
276
+ const r = [], i = n.properties ?? {}, c = o.properties ?? {};
277
+ for (const m of Object.keys(c))
278
+ m in i || r.push(`${e}: prop ${m} is missing from the schema, ${oe(t)}`);
279
+ for (const m of Object.keys(i))
280
+ m in c || r.push(`${e}: schema prop ${m} has no counterpart in ${s}, remove it or restore the prop`);
281
+ for (const [m, f] of Object.entries(i)) {
282
+ const h = c[m];
283
+ if (h && (f.type && h.type && f.type !== h.type && !f.enum && r.push(
284
+ `${e}: prop ${m} schema type ${f.type} conflicts with source type ${h.type}, ${oe(t)}`
285
+ ), f.enum && h.type && !as(f.enum, h.type) && r.push(`${e}: prop ${m} enum values mismatch the source type ${h.type}`), f.enum && h.enum)) {
286
+ const g = new Set(h.enum.map((v) => JSON.stringify(v))), w = f.enum.filter((v) => !g.has(JSON.stringify(v)));
287
+ w.length && r.push(
288
+ `${e}: prop ${m} enum carries ${w.map((v) => JSON.stringify(v)).join(", ")} outside the source union`
254
289
  );
255
290
  }
256
291
  }
257
- const l = s.slots ?? {}, c = o.slots ?? {};
258
- for (const h of Object.keys(c))
259
- h in l || r.push(`${e}: slot ${h} is missing from the schema, ${K(t)}`);
260
- for (const h of Object.keys(l))
261
- h in c || r.push(`${e}: schema slot ${h} has no counterpart in ${n}`);
262
- const m = new Set(s.emits ?? []), u = new Set(o.emits ?? []);
263
- for (const h of u)
264
- m.has(h) || r.push(`${e}: emit ${h} is missing from the schema, ${K(t)}`);
265
- for (const h of m)
266
- u.has(h) || r.push(`${e}: schema emit ${h} has no counterpart in ${n}`);
292
+ const u = n.slots ?? {}, a = o.slots ?? {};
293
+ for (const m of Object.keys(a))
294
+ m in u || r.push(`${e}: slot ${m} is missing from the schema, ${oe(t)}`);
295
+ for (const m of Object.keys(u))
296
+ m in a || r.push(`${e}: schema slot ${m} has no counterpart in ${s}`);
297
+ const p = new Set(n.emits ?? []), l = new Set(o.emits ?? []);
298
+ for (const m of l)
299
+ p.has(m) || r.push(`${e}: emit ${m} is missing from the schema, ${oe(t)}`);
300
+ for (const m of p)
301
+ l.has(m) || r.push(`${e}: schema emit ${m} has no counterpart in ${s}`);
267
302
  return r;
268
303
  }
269
- async function Je(e, t, n) {
270
- const s = n ? [n] : Object.keys(t.modules.systems), o = [], r = await ke(e, t.contentDir);
271
- for (const i of s) {
272
- const a = t.modules.systems[i];
273
- if (!a) {
304
+ async function at(e, t, s) {
305
+ const n = s ? [s] : Object.keys(t.modules.systems), o = [], r = await Te(e, t.contentDir);
306
+ for (const i of n) {
307
+ const c = t.modules.systems[i];
308
+ if (!c) {
274
309
  o.push(`${i}: not a configured system`);
275
310
  continue;
276
311
  }
277
- const l = a.framework, c = Ot[l === "vue" ? "svelte" : "vue"], m = Et[l];
278
- for (const u of r) {
279
- if (u.system !== i) continue;
280
- const h = L(u.pageFile), p = O(e, h).split(q).join("/"), f = await Dt(h);
281
- f.length || o.push(`${p}: no story, run nimpress modules story --system=${i} ${u.component}`);
282
- const w = /* @__PURE__ */ new Set();
283
- for (const S of f) {
284
- let D;
312
+ const u = c.framework, a = os[u === "vue" ? "svelte" : "vue"], p = rs[u];
313
+ for (const l of r) {
314
+ if (l.system !== i) continue;
315
+ const m = _(l.pageFile), f = D(e, m).split(I).join("/"), h = await is(m);
316
+ h.length || o.push(`${f}: no story, run nimpress modules story --system=${i} ${l.component}`);
317
+ const g = /* @__PURE__ */ new Set();
318
+ for (const x of h) {
319
+ let A;
285
320
  try {
286
- D = await fe(d(h, S), "utf-8");
321
+ A = await ve(d(m, x), "utf-8");
287
322
  } catch {
288
323
  continue;
289
324
  }
290
- (/\bharness\s*:/.test(D) || /\brender\s*:/.test(D)) && w.add(S), D.includes(c) && o.push(`${p}/${S}: uses ${c} inside the ${l} system ${i}`);
291
- for (const g of D.matchAll(/from\s+['"]([^'"]+)['"]/g))
292
- oe(g[1]) === m && o.push(`${p}/${S}: imports ${g[1]} inside the ${l} system ${i}`);
325
+ (/\bharness\s*:/.test(A) || /\brender\s*:/.test(A)) && g.add(x), A.includes(a) && o.push(`${f}/${x}: uses ${a} inside the ${u} system ${i}`);
326
+ for (const y of A.matchAll(/from\s+['"]([^'"]+)['"]/g))
327
+ ue(y[1]) === p && o.push(`${f}/${x}: imports ${y[1]} inside the ${u} system ${i}`);
293
328
  }
294
- const $ = Se(e, t.modules, i, u.component, u.file);
295
- if ($ && oe($.componentFile) === m && o.push(
296
- `${p}: component file ${O(e, $.componentFile)} mismatches the ${l} system ${i}`
297
- ), b(d(h, "schema.json")) && b(d(h, "schema.yml"))) {
298
- o.push(`${p}: both schema.json and schema.yml exist, keep one`);
329
+ const w = Ae(e, t.modules, i, l.component, l.file);
330
+ if (w && ue(w.componentFile) === p && o.push(
331
+ `${f}: component file ${D(e, w.componentFile)} mismatches the ${u} system ${i}`
332
+ ), $(d(m, "schema.json")) && $(d(m, "schema.yml"))) {
333
+ o.push(`${f}: both schema.json and schema.yml exist, keep one`);
299
334
  continue;
300
335
  }
301
- const k = rt(h);
302
- if (!k) {
303
- o.push(`${p}: schema file missing, ${K(u.component)}`);
336
+ const v = Tt(m);
337
+ if (!v) {
338
+ o.push(`${f}: schema file missing, ${oe(l.component)}`);
304
339
  continue;
305
340
  }
306
- let E;
341
+ let F;
307
342
  try {
308
- E = await fe(k.path, "utf-8");
343
+ F = await ve(v.path, "utf-8");
309
344
  } catch {
310
- o.push(`${p}: ${k.form} schema unreadable`);
345
+ o.push(`${f}: ${v.form} schema unreadable`);
311
346
  continue;
312
347
  }
313
- let j;
348
+ let E;
314
349
  try {
315
- j = it(E, k.form);
350
+ E = At(F, v.form);
316
351
  } catch {
317
- o.push(`${p}: schema is not valid ${k.form}, fix it by hand`);
352
+ o.push(`${f}: schema is not valid ${v.form}, fix it by hand`);
318
353
  continue;
319
354
  }
320
- const x = new Set(Object.keys(j.properties ?? {}));
321
- for (const S of await Ne(h))
322
- if (!w.has(S.file))
323
- for (const D of Object.keys(S.props ?? {}))
324
- x.has(D) || o.push(`${p}/${S.file}: prop ${D} is absent from the schema, ${K(u.component)}`);
325
- const N = $ ? await fe($.componentFile, "utf-8").catch(() => {
355
+ const k = new Set(Object.keys(E.properties ?? {}));
356
+ for (const x of await qe(m))
357
+ if (!g.has(x.file))
358
+ for (const A of Object.keys(x.props ?? {}))
359
+ k.has(A) || o.push(`${f}/${x.file}: prop ${A} is absent from the schema, ${oe(l.component)}`);
360
+ const T = w ? await ve(w.componentFile, "utf-8").catch(() => {
326
361
  }) : void 0;
327
- if ($) {
328
- const S = await se($.componentFile, l, u.component);
329
- if (S) {
330
- const D = bt(u.component, S.props, S.slots, S.emits);
362
+ if (w) {
363
+ const x = await ce(w.componentFile, u, l.component);
364
+ if (x) {
365
+ const A = Kt(l.component, x.props, x.slots, x.emits);
331
366
  o.push(
332
- ...Wt(p, u.component, O(e, $.componentFile), j, D)
367
+ ...cs(f, l.component, D(e, w.componentFile), E, A)
333
368
  );
334
369
  }
335
370
  }
336
- at(ct(u.component, j, { sourceFile: $?.componentFile, sourceText: N }));
371
+ Rt(Pt(l.component, E, { sourceFile: w?.componentFile, sourceText: T }));
337
372
  }
338
373
  }
339
- return $e(e), o;
374
+ return Ee(e), o;
340
375
  }
341
- function Be(e) {
376
+ function ct(e) {
342
377
  return Object.entries(e.modules.systems).filter(([, t]) => t.visibility !== "dev-only").map(([t]) => t);
343
378
  }
344
- async function Ue(e, t, n) {
345
- for (const s of n)
379
+ async function lt(e, t, s) {
380
+ for (const n of s)
346
381
  try {
347
- await (await Ie(await Te(e, t, s, "serve"))).listen(), console.log(`nimpress modules: ${s} harness on port ${ut(t.modules, s)}`);
382
+ await (await st(await Ye(e, t, n, "serve"))).listen(), console.log(`nimpress modules: ${n} harness on port ${Mt(t.modules, n)}`);
348
383
  } catch (o) {
349
- console.warn(`nimpress modules: harness for ${s} failed to start: ${String(o)}`);
384
+ console.warn(`nimpress modules: harness for ${n} failed to start: ${String(o)}`);
350
385
  }
351
386
  }
352
- async function Ge(e, t, n) {
353
- for (const s of n)
354
- await ze(await Te(e, t, s, "build")), console.log(`nimpress modules: built ${s}`);
387
+ async function ut(e, t, s) {
388
+ for (const n of s)
389
+ await nt(await Ye(e, t, n, "build")), console.log(`nimpress modules: built ${n}`);
355
390
  }
356
- async function Nt(e, t) {
357
- const n = await Ie(Pe({ cwd: e, command: "serve", resolved: t }));
358
- await n.listen(), await Ue(e, t, Object.keys(t.modules.systems)), n.printUrls(), n.bindCLIShortcuts({ print: !0 });
391
+ async function ls(e, t) {
392
+ const s = await st(Ke({ cwd: e, command: "serve", resolved: t }));
393
+ await s.listen(), await lt(e, t, Object.keys(t.modules.systems)), s.printUrls(), s.bindCLIShortcuts({ print: !0 });
359
394
  }
360
- async function He(e, t) {
361
- const n = d(e, "index.html"), s = !b(n);
362
- s && A(n, lt(t));
395
+ async function pt(e, t) {
396
+ const s = d(e, "index.html"), n = !$(s);
397
+ n && N(s, It(t));
363
398
  const o = () => {
364
- s && ae(n, { force: !0 });
399
+ n && ee(s, { force: !0 });
365
400
  }, r = () => {
366
401
  o(), process.exit(130);
367
402
  };
368
403
  process.once("SIGINT", r), process.once("SIGTERM", r);
369
404
  try {
370
- await ze(Pe({ cwd: e, command: "build", resolved: t, htmlInput: n }));
405
+ await nt(Ke({ cwd: e, command: "build", resolved: t, htmlInput: s }));
371
406
  } finally {
372
407
  process.off("SIGINT", r), process.off("SIGTERM", r), o();
373
408
  }
374
- await Ge(e, t, Be(t));
409
+ await ut(e, t, ct(t));
375
410
  }
376
- const Pt = [".ts", ".tsx", ".js", ".mjs", ".vue", ".svelte"], Tt = ["", ".ts", ".tsx", ".js", ".mjs", ".vue", ".svelte", "/index.ts", "/index.js"], De = /^[a-z0-9][a-z0-9.-]*$/, At = /^[A-Z][A-Za-z0-9]*$/;
377
- function Mt(e) {
411
+ const us = [".ts", ".tsx", ".js", ".mjs", ".vue", ".svelte"], ps = ["", ".ts", ".tsx", ".js", ".mjs", ".vue", ".svelte", "/index.ts", "/index.js"], Le = /^[a-z0-9][a-z0-9.-]*$/, ms = /^[A-Z][A-Za-z0-9]*$/;
412
+ function fs(e) {
378
413
  const t = e.resolve;
379
414
  if (!t || typeof t != "object") return [];
380
- const n = t.alias;
381
- return !n || typeof n != "object" ? [] : Array.isArray(n) ? n.flatMap((s) => {
382
- if (!s || typeof s != "object") return [];
383
- const { find: o, replacement: r } = s;
415
+ const s = t.alias;
416
+ return !s || typeof s != "object" ? [] : Array.isArray(s) ? s.flatMap((n) => {
417
+ if (!n || typeof n != "object") return [];
418
+ const { find: o, replacement: r } = n;
384
419
  return typeof o != "string" || typeof r != "string" ? [] : [{ find: o, replacement: r }];
385
- }) : Object.entries(n).flatMap(
386
- ([s, o]) => typeof o == "string" ? [{ find: s, replacement: o }] : []
420
+ }) : Object.entries(s).flatMap(
421
+ ([n, o]) => typeof o == "string" ? [{ find: n, replacement: o }] : []
387
422
  );
388
423
  }
389
- function Rt(e) {
390
- const t = [], n = [
424
+ function ds(e) {
425
+ const t = [], s = [
391
426
  /(?:^|\n)[ \t]*import[^'"\n]*?from[ \t]*['"]([^'"\n]+)['"]/g,
392
427
  /(?:^|\n)[ \t]*export[^'"\n]*?from[ \t]*['"]([^'"\n]+)['"]/g,
393
428
  /(?:^|\n)[ \t]*import[ \t]+['"]([^'"\n]+)['"]/g,
394
429
  /\bimport\(\s*['"]([^'"\n]+)['"]\s*\)/g
395
430
  ];
396
- for (const s of n) {
431
+ for (const n of s) {
397
432
  let o;
398
- for (; o = s.exec(e); ) t.push(o[1]);
433
+ for (; o = n.exec(e); ) t.push(o[1]);
399
434
  }
400
435
  return t;
401
436
  }
402
- function _e(e) {
403
- return Tt.some((t) => {
404
- const n = e + t;
405
- if (!b(n)) return !1;
437
+ function Be(e) {
438
+ return ps.some((t) => {
439
+ const s = e + t;
440
+ if (!$(s)) return !1;
406
441
  try {
407
- return Me(n).isFile();
442
+ return et(s).isFile();
408
443
  } catch {
409
444
  return !1;
410
445
  }
411
446
  });
412
447
  }
413
- function It(e, t) {
414
- const n = F(e, t.contentDir), s = Mt(t.vite), o = [];
415
- for (const r of re(n)) {
416
- if (!Pt.some((l) => r.endsWith(l))) continue;
448
+ function hs(e, t) {
449
+ const s = j(e, t.contentDir), n = fs(t.vite), o = [];
450
+ for (const r of se(s)) {
451
+ if (!us.some((u) => r.endsWith(u))) continue;
417
452
  let i;
418
453
  try {
419
- i = W(r, "utf-8");
454
+ i = C(r, "utf-8");
420
455
  } catch {
421
456
  continue;
422
457
  }
423
- const a = O(n, r).split(q).join("/");
424
- for (const l of Rt(i)) {
425
- if (l.includes("_shared/") || l.startsWith("_shared")) {
458
+ const c = D(s, r).split(I).join("/");
459
+ for (const u of ds(i)) {
460
+ if (u.includes("_shared/") || u.startsWith("_shared")) {
426
461
  o.push(
427
- `${a}: imports ${l}, shared fixture folders are forbidden, stories are self contained and shared setup lives in a group harness component`
462
+ `${c}: imports ${u}, shared fixture folders are forbidden, stories are self contained and shared setup lives in a group harness component`
428
463
  );
429
464
  continue;
430
465
  }
431
- const c = l.split("?")[0];
432
- if (c.startsWith("./") || c.startsWith("../")) {
433
- const u = F(L(r), c);
434
- _e(u) || o.push(`${a}: unresolved import ${l}, fix the path or create the file`);
466
+ const a = u.split("?")[0];
467
+ if (a.startsWith("./") || a.startsWith("../")) {
468
+ const l = j(_(r), a);
469
+ Be(l) || o.push(`${c}: unresolved import ${u}, fix the path or create the file`);
435
470
  continue;
436
471
  }
437
- const m = s.find((u) => c === u.find || c.startsWith(u.find + "/"));
438
- if (m) {
439
- const u = F(e, m.replacement + c.slice(m.find.length));
440
- _e(u) || o.push(`${a}: unresolved import ${l} via alias ${m.find}`);
472
+ const p = n.find((l) => a === l.find || a.startsWith(l.find + "/"));
473
+ if (p) {
474
+ const l = j(e, p.replacement + a.slice(p.find.length));
475
+ Be(l) || o.push(`${c}: unresolved import ${u} via alias ${p.find}`);
441
476
  }
442
477
  }
443
478
  }
444
479
  return o;
445
480
  }
446
- function zt(e, t) {
447
- const n = F(e, t.contentDir), s = [];
448
- if (!b(n)) return [`${t.contentDir}: contentDir does not exist`];
449
- const o = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Map();
450
- for (const a of re(n)) {
451
- const l = O(n, a).split(q).join("/"), c = L(a), m = C(a);
481
+ function gs(e, t) {
482
+ const s = j(e, t.contentDir), n = [];
483
+ if (!$(s)) return [`${t.contentDir}: contentDir does not exist`];
484
+ const o = /* @__PURE__ */ new Map();
485
+ let r, i;
486
+ const c = /* @__PURE__ */ new Map();
487
+ for (const a of se(s)) {
488
+ const p = D(s, a).split(I).join("/"), l = _(a), m = O(a);
452
489
  if (m.endsWith(".md")) {
453
- const u = r.get(c) ?? [];
454
- u.push(a), r.set(c, u);
490
+ const f = c.get(l) ?? [];
491
+ f.push(a), c.set(l, f);
455
492
  const h = m.slice(0, -3);
456
- De.test(h) || s.push(`${l}: markdown file names are lowercase kebab case, rename to ${h.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase().replace(/[^a-z0-9.-]+/g, "-")}.md`);
457
- let p;
493
+ Le.test(h) || n.push(`${p}: 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
+ let g;
458
495
  try {
459
- p = yt(W(a, "utf-8")).data;
496
+ g = pe(C(a, "utf-8")).data, typeof g.type == "number" && (g.type = String(g.type));
460
497
  } catch {
461
498
  continue;
462
499
  }
463
- if (p?.type === "component") {
464
- const f = o.get(c);
465
- f ? s.push(`${l}: second type component page in one folder, ${O(n, f).split(q).join("/")} already owns it, one component per folder`) : o.set(c, a);
500
+ if (g?.type === "glossary" && (i ? n.push(`${p}: second type glossary page in the site, ${D(s, i).split(I).join("/")} already owns it, one glossary per site`) : i = a, /^: /m.test(pe(C(a, "utf-8")).content) || n.push(`${p}: type glossary needs a definition list body, term lines followed by lines starting with a colon`)), g?.type === "section" && !a.endsWith(`${I}index.md`) && n.push(`${p}: type section belongs on a folder index.md, move the page or drop the type`), g?.type === "404" && (r ? n.push(`${p}: second type 404 page in the site, ${D(s, r).split(I).join("/")} already owns it, one not found page per site`) : r = a), g?.type === "component") {
501
+ const w = o.get(l);
502
+ w ? n.push(`${p}: second type component page in one folder, ${D(s, w).split(I).join("/")} already owns it, one component per folder`) : o.set(l, a);
503
+ }
504
+ if (g?.type === "dbml") {
505
+ const w = typeof g.spec == "string" ? g.spec : "";
506
+ w ? $(j(l, w)) || n.push(`${p}: spec ${w} does not resolve, create the file or fix the path`) : n.push(`${p}: type dbml needs a spec field pointing at the .dbml file`);
466
507
  }
467
- if (p?.type === "dbml") {
468
- const f = typeof p.spec == "string" ? p.spec : "";
469
- f ? b(F(c, f)) || s.push(`${l}: spec ${f} does not resolve, create the file or fix the path`) : s.push(`${l}: type dbml needs a spec field pointing at the .dbml file`);
508
+ g?.type === "changelog" && typeof g.path == "string" && n.push(`${p}: changelog entries never set path, the collection mounts at the folder route, remove the path field`);
509
+ }
510
+ if (m.endsWith(".css") && !m.startsWith("_") && O(_(a)) === "styles" && _(_(a)) === s) {
511
+ const f = m.replace(/\.css$/, "");
512
+ fe.includes(f) || n.push(`${p}: ${f} is not a component class root, name the file after one of ${fe.join(", ")}`);
513
+ continue;
514
+ }
515
+ if (m.endsWith(".css") && !m.startsWith("_") && m.split(".").length > 2) {
516
+ const f = m.split(".")[0], h = Lt(m, f);
517
+ if (h && $(d(_(a), `${f}.md`))) {
518
+ fe.includes(h) || n.push(`${p}: ${h} is not a component class root, name the file after one of ${fe.join(", ")}`);
519
+ continue;
470
520
  }
471
- p?.type === "changelog" && typeof p.path == "string" && s.push(`${l}: changelog entries never set path, the collection mounts at the folder route, remove the path field`);
472
521
  }
473
522
  if (m.endsWith(".css") && !m.startsWith("_")) {
474
- const u = a.replace(/\.css$/, ".md");
475
- b(u) || s.push(`${l}: page css without a matching ${C(u)}, page styles are named after the page they scope`);
523
+ const f = a.replace(/\.css$/, ".md");
524
+ $(f) || n.push(`${p}: page css without a matching ${O(f)}, page styles are named after the page they scope`);
476
525
  }
477
526
  }
478
- for (const [a, l] of r) {
479
- const c = O(n, a).split(q).join("/") || ".", m = o.has(a);
480
- let u = [];
527
+ for (const [a, p] of c) {
528
+ const l = D(s, a).split(I).join("/") || ".", m = o.has(a);
529
+ let f = [];
481
530
  try {
482
- u = Y(a);
531
+ f = X(a);
483
532
  } catch {
484
533
  continue;
485
534
  }
486
- u.filter((p) => /\.story\.tsx?$/.test(p)).length && !m && s.push(`${c}: story files without a type component page, add the component index.md or move the stories`);
487
- for (const p of ["schema.json", "schema.yml"])
488
- u.includes(p) && !m && s.push(`${c}: ${p} without a type component page, it belongs beside the component index.md`);
489
- if (m && l.length > 1) {
490
- const p = l.filter((f) => f !== o.get(a)).map((f) => C(f));
491
- s.push(`${c}: a component folder holds exactly one md file, move ${p.join(", ")} out`);
535
+ f.filter((g) => /\.story\.tsx?$/.test(g)).length && !m && n.push(`${l}: story files without a type component page, add the component index.md or move the stories`);
536
+ for (const g of ["schema.json", "schema.yml"])
537
+ f.includes(g) && !m && n.push(`${l}: ${g} without a type component page, it belongs beside the component index.md`);
538
+ if (m && p.length > 1) {
539
+ const g = p.filter((w) => w !== o.get(a)).map((w) => O(w));
540
+ n.push(`${l}: a component folder holds exactly one md file, move ${g.join(", ")} out`);
492
541
  }
493
542
  }
494
- const i = (a) => {
495
- let l;
543
+ const u = (a) => {
544
+ let p;
496
545
  try {
497
- l = Y(a, { withFileTypes: !0 });
546
+ p = X(a, { withFileTypes: !0 });
498
547
  } catch {
499
548
  return;
500
549
  }
501
- for (const c of l)
502
- if (c.isDirectory() && !(c.name.startsWith(".") || c.name === "node_modules")) {
503
- if (!De.test(c.name) && !At.test(c.name)) {
504
- const m = O(n, d(a, c.name)).split(q).join("/");
505
- s.push(`${m}/: folder names are lowercase kebab case, or PascalCase for component and group folders, rename it`);
550
+ for (const l of p)
551
+ if (l.isDirectory() && !(l.name.startsWith(".") || l.name === "node_modules")) {
552
+ if (!Le.test(l.name) && !ms.test(l.name)) {
553
+ const m = D(s, d(a, l.name)).split(I).join("/");
554
+ n.push(`${m}/: folder names are lowercase kebab case, or PascalCase for component and group folders, rename it`);
506
555
  }
507
- i(d(a, c.name));
556
+ u(d(a, l.name));
508
557
  }
509
558
  };
510
- return i(n), s;
559
+ return u(s), n;
511
560
  }
512
- async function Lt(e, t) {
513
- const n = pt(e, t, "lint"), s = () => ae(n, { recursive: !0, force: !0 }), o = () => {
514
- s(), process.exit(130);
561
+ async function ws(e, t) {
562
+ const s = Qe(e, t, "lint"), n = () => ee(s, { recursive: !0, force: !0 }), o = () => {
563
+ n(), process.exit(130);
515
564
  };
516
565
  process.once("SIGINT", o), process.once("SIGTERM", o);
517
566
  try {
518
- return await He(e, { ...t, paths: { ...t.paths, out: n } }), [];
567
+ return await pt(e, { ...t, paths: { ...t.paths, out: s } }), [];
519
568
  } catch (r) {
520
569
  return (r instanceof Error ? r.message : String(r)).split(`
521
- `).filter((a) => a.trim()).map((a) => `build: ${a.trim()}`);
570
+ `).filter((c) => c.trim()).map((c) => `build: ${c.trim()}`);
522
571
  } finally {
523
- process.off("SIGINT", o), process.off("SIGTERM", o), s();
572
+ process.off("SIGINT", o), process.off("SIGTERM", o), n();
524
573
  }
525
574
  }
526
- async function Jt(e, t) {
527
- const n = process.argv.slice(2), s = [
528
- ...zt(e, t),
529
- ...await mt(e, t.contentDir),
530
- ...It(e, t),
531
- ...await Je(e, t)
575
+ async function $s(e, t) {
576
+ const s = process.argv.slice(2), n = [
577
+ ...gs(e, t),
578
+ ...(zt(e, t.pageTypes ?? {}), await Jt(e, t.contentDir)),
579
+ ...hs(e, t),
580
+ ...await at(e, t)
532
581
  ];
533
- if (s.length) {
534
- we("nimpress lint", s, "");
582
+ if (n.length) {
583
+ Oe("nimpress lint", n, "");
535
584
  return;
536
585
  }
537
- if (console.log("nimpress lint: structure, frontmatter, imports, and modules ok"), X(n, "no-build")) return;
586
+ if (console.log("nimpress lint: structure, frontmatter, imports, and modules ok"), M(s, "no-build")) return;
538
587
  console.log("nimpress lint: building to verify the output compiles");
539
- const o = await Lt(e, t);
540
- we("nimpress lint", o, "nimpress lint: build ok, everything passes");
588
+ const o = await ws(e, t);
589
+ Oe("nimpress lint", o, "nimpress lint: build ok, everything passes");
541
590
  }
542
- const Bt = {
591
+ const ys = {
543
592
  ".json": "application/json",
544
593
  ".xml": "application/rss+xml",
545
594
  ".html": "text/html",
@@ -552,490 +601,490 @@ const Bt = {
552
601
  ".webp": "image/webp",
553
602
  ".pdf": "application/pdf"
554
603
  };
555
- function Ut(e, t, n) {
556
- const s = n[0], o = d(e, T(n, "dist") ?? t.paths.out), r = `/${t.paths.guarded}/`, i = d(o, "access.json");
557
- if (!b(i))
604
+ function bs(e, t, s) {
605
+ const n = s[0], o = d(e, W(s, "dist") ?? t.paths.out), r = `/${t.paths.guarded}/`, i = d(o, "access.json");
606
+ if (!$(i))
558
607
  throw new Error(`[nimpress] guard: ${i} not found, run a build first`);
559
- const a = JSON.parse(W(i, "utf-8"));
560
- if (s === "map") {
561
- const l = Ee(o, t), c = d(o, "guard.map.json"), m = b(c) ? JSON.parse(W(c, "utf-8")) : { prefix: a.prefix ?? r, routes: a.routes, bundles: {} }, u = b(l) ? re(l) : [], h = m.prefix ?? r, p = u.map(($) => {
562
- const k = O(l, $).split("\\").join("/"), E = k.split("/")[0] ?? "", j = [
608
+ const c = JSON.parse(C(i, "utf-8"));
609
+ if (n === "map") {
610
+ const u = ze(o, t), a = d(o, "guard.map.json"), p = $(a) ? JSON.parse(C(a, "utf-8")) : { prefix: c.prefix ?? r, routes: c.routes, bundles: {} }, l = $(u) ? se(u) : [], m = p.prefix ?? r, f = l.map((w) => {
611
+ const v = D(u, w).split("\\").join("/"), F = v.split("/")[0] ?? "", E = [
563
612
  ...new Set(
564
- Object.values(m.routes ?? {}).filter((N) => N.bundle === E && N.gate).map((N) => N.gate)
613
+ Object.values(p.routes ?? {}).filter((T) => T.bundle === F && T.gate).map((T) => T.gate)
565
614
  )
566
- ], x = W($);
615
+ ], k = C(w);
567
616
  return {
568
- path: `${h}${k}`,
569
- file: k,
570
- bundle: E,
571
- sha256: xt("sha256").update(x).digest("hex"),
572
- size: Me($).size,
573
- mime: Bt[oe($).toLowerCase()] ?? "application/octet-stream",
574
- gates: j
617
+ path: `${m}${v}`,
618
+ file: v,
619
+ bundle: F,
620
+ sha256: ot("sha256").update(k).digest("hex"),
621
+ size: et(w).size,
622
+ mime: ys[ue(w).toLowerCase()] ?? "application/octet-stream",
623
+ gates: E
575
624
  };
576
- }), f = T(n, "out"), w = f ? d(e, f) : c;
577
- A(
578
- w,
579
- JSON.stringify({ ...m, prefix: h, files: p }, null, 2) + `
625
+ }), h = W(s, "out"), g = h ? d(e, h) : a;
626
+ N(
627
+ g,
628
+ JSON.stringify({ ...p, prefix: m, files: f }, null, 2) + `
580
629
  `
581
- ), console.log(`nimpress guard: mapped ${p.length} guarded files to ${w}`);
630
+ ), console.log(`nimpress guard: mapped ${f.length} guarded files to ${g}`);
582
631
  return;
583
632
  }
584
- if (s === "apply") {
585
- const l = T(n, "map");
586
- if (!l) throw new Error("[nimpress] guard apply requires --map=<uploaded mapping json>");
587
- const c = JSON.parse(W(d(e, l), "utf-8"));
588
- if (!c.base) throw new Error("[nimpress] guard apply: mapping json carries no base url");
589
- a.base = c.base.replace(/\/$/, ""), a.files = (c.files ?? []).map((m) => ({
590
- path: m.path,
591
- file: m.file,
592
- bundle: m.bundle,
593
- asset_id: m.asset_id,
594
- url: m.url
595
- })), A(i, JSON.stringify(a, null, 2) + `
596
- `), ae(Ee(o, t), { recursive: !0, force: !0 }), ae(d(o, "guard.map.json"), { force: !0 }), console.log(`nimpress guard: base ${a.base} applied, ${t.paths.guarded} removed from ${o}`);
633
+ if (n === "apply") {
634
+ const u = W(s, "map");
635
+ if (!u) throw new Error("[nimpress] guard apply requires --map=<uploaded mapping json>");
636
+ const a = JSON.parse(C(d(e, u), "utf-8"));
637
+ if (!a.base) throw new Error("[nimpress] guard apply: mapping json carries no base url");
638
+ c.base = a.base.replace(/\/$/, ""), c.files = (a.files ?? []).map((p) => ({
639
+ path: p.path,
640
+ file: p.file,
641
+ bundle: p.bundle,
642
+ asset_id: p.asset_id,
643
+ url: p.url
644
+ })), N(i, JSON.stringify(c, null, 2) + `
645
+ `), ee(ze(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}`);
597
646
  return;
598
647
  }
599
648
  throw new Error("[nimpress] guard expects map or apply");
600
649
  }
601
- function Ze(e) {
602
- const t = oe(e);
650
+ function mt(e) {
651
+ const t = ue(e);
603
652
  return t === ".vue" ? "vue" : t === ".svelte" ? "svelte" : null;
604
653
  }
605
- async function je(e, t, n, s, o) {
606
- const i = (await ke(e, t.contentDir)).find((h) => h.system === n && h.component === s);
654
+ async function Re(e, t, s, n, o) {
655
+ const i = (await Te(e, t.contentDir)).find((m) => m.system === s && m.component === n);
607
656
  if (!i)
608
- return console.warn(`[nimpress] modules story: no type component page found for ${n}/${s}`), null;
609
- const a = Se(e, t.modules, n, s, i.file);
610
- if (!a)
611
- return console.warn(`[nimpress] modules story: no source found for ${n}/${s}`), null;
612
- const l = o ?? Ze(a.componentFile);
613
- if (!l)
657
+ return console.warn(`[nimpress] modules story: no type component page found for ${s}/${n}`), null;
658
+ const c = Ae(e, t.modules, s, n, i.file);
659
+ if (!c)
660
+ return console.warn(`[nimpress] modules story: no source found for ${s}/${n}`), null;
661
+ const u = o ?? mt(c.componentFile);
662
+ if (!u)
614
663
  throw new Error(
615
- `[nimpress] modules story: failed to detect framework for ${a.componentFile}, pass --framework=vue or --framework=svelte`
664
+ `[nimpress] modules story: failed to detect framework for ${c.componentFile}, pass --framework=vue or --framework=svelte`
616
665
  );
617
- const c = l === "vue" ? "vueStory" : "svelteStory", m = `import { ${c} } from '@nimtech/nimpress/story'
666
+ const a = u === "vue" ? "vueStory" : "svelteStory", p = `import { ${a} } from '@nimtech/nimpress/story'
618
667
 
619
668
  // story: Default
620
- export default ${c}({
669
+ export default ${a}({
621
670
  name: "Default"
622
671
  })
623
- `, u = d(L(i.pageFile), "default.story.tsx");
624
- return b(u) ? (console.warn(`[nimpress] modules story: ${u} exists, not overwriting`), null) : (await G(u, m), u);
672
+ `, l = d(_(i.pageFile), "default.story.tsx");
673
+ return $(l) ? (console.warn(`[nimpress] modules story: ${l} exists, not overwriting`), null) : (await q(l, p), l);
625
674
  }
626
- async function Gt(e, t, n) {
627
- const s = await ke(e, t.contentDir);
675
+ async function vs(e, t, s) {
676
+ const n = await Te(e, t.contentDir);
628
677
  let o = 0;
629
- for (const r of s)
630
- if (!(r.system !== n || (await Ne(L(r.pageFile))).length))
678
+ for (const r of n)
679
+ if (!(r.system !== s || (await qe(_(r.pageFile))).length))
631
680
  try {
632
- await je(e, t, n, r.component) && o++;
633
- } catch (a) {
634
- console.warn(String(a));
681
+ await Re(e, t, s, r.component) && o++;
682
+ } catch (c) {
683
+ console.warn(String(c));
635
684
  }
636
685
  return o;
637
686
  }
638
- async function Ht(e, t, n, s, o) {
639
- const r = t.modules.systems[n];
640
- if (!r) throw new Error(`[nimpress] modules create: unknown system ${n}`);
641
- const i = d(e, t.contentDir, "components", "Components", s), a = d(i, "index.md");
642
- if (b(a))
643
- throw new Error(`[nimpress] modules create: ${a} exists`);
644
- const { mkdir: l } = await import("node:fs/promises");
645
- await l(i, { recursive: !0 });
646
- const c = r.package;
647
- await G(
648
- a,
687
+ async function ks(e, t, s, n, o) {
688
+ const r = t.modules.systems[s];
689
+ if (!r) throw new Error(`[nimpress] modules create: unknown system ${s}`);
690
+ const i = d(e, t.contentDir, "components", "Components", n), c = d(i, "index.md");
691
+ if ($(c))
692
+ throw new Error(`[nimpress] modules create: ${c} exists`);
693
+ const { mkdir: u } = await import("node:fs/promises");
694
+ await u(i, { recursive: !0 });
695
+ const a = r.package;
696
+ await q(
697
+ c,
649
698
  `---
650
- title: ${s}
699
+ title: ${n}
651
700
  type: component
652
701
  data:
653
- system: ${n}
654
- component: ${s}${c ? `
655
- package: "${c}"` : ""}
702
+ system: ${s}
703
+ component: ${n}${a ? `
704
+ package: "${a}"` : ""}
656
705
  ---
657
706
 
658
707
  ## Usage
659
708
 
660
709
  \`\`\`ts
661
- import { ${s} } from "${c ?? n}";
710
+ import { ${n} } from "${a ?? s}";
662
711
  \`\`\`
663
712
  `
664
713
  );
665
- const m = Se(e, t.modules, n, s);
666
- if (m) {
667
- const u = o ?? Ze(m.componentFile) ?? r.framework;
668
- await ne(i, s, await se(m.componentFile, u, s)), await je(e, t, n, s, o);
714
+ const p = Ae(e, t.modules, s, n);
715
+ if (p) {
716
+ const l = o ?? mt(p.componentFile) ?? r.framework;
717
+ await le(i, n, await ce(p.componentFile, l, n)), await Re(e, t, s, n, o);
669
718
  } else {
670
- const u = r.framework === "vue" ? "vueStory" : "svelteStory";
671
- await G(
719
+ const l = r.framework === "vue" ? "vueStory" : "svelteStory";
720
+ await q(
672
721
  d(i, "default.story.tsx"),
673
- `import { ${u} } from '@nimtech/nimpress/story'
722
+ `import { ${l} } from '@nimtech/nimpress/story'
674
723
 
675
724
  // story: Default
676
- export default ${u}({
725
+ export default ${l}({
677
726
  name: "Default",
678
727
  props: {}
679
728
  })
680
729
  `
681
730
  ), console.warn(
682
- `nimpress modules: no source found for ${s}, wrote a stub story, schema.json follows once the component exists and import or create runs again`
731
+ `nimpress modules: no source found for ${n}, wrote a stub story, schema.json follows once the component exists and import or create runs again`
683
732
  );
684
733
  }
685
734
  return i;
686
735
  }
687
- function le(e) {
736
+ function ge(e) {
688
737
  try {
689
- return JSON.parse(JSON.stringify(e, (t, n) => typeof n == "function" ? void 0 : n));
738
+ return JSON.parse(JSON.stringify(e, (t, s) => typeof s == "function" ? void 0 : s));
690
739
  } catch {
691
740
  return {};
692
741
  }
693
742
  }
694
- function ue(e, t = []) {
695
- let n;
743
+ function we(e, t = []) {
744
+ let s;
696
745
  try {
697
- n = Y(e, { withFileTypes: !0 });
746
+ s = X(e, { withFileTypes: !0 });
698
747
  } catch {
699
748
  return t;
700
749
  }
701
- for (const s of n) {
702
- const o = d(e, s.name);
703
- if (s.isDirectory()) {
704
- if (s.name === "node_modules" || s.name.startsWith(".")) continue;
705
- ue(o, t);
706
- } else s.isFile() && t.push(o);
750
+ for (const n of s) {
751
+ const o = d(e, n.name);
752
+ if (n.isDirectory()) {
753
+ if (n.name === "node_modules" || n.name.startsWith(".")) continue;
754
+ we(o, t);
755
+ } else n.isFile() && t.push(o);
707
756
  }
708
757
  return t;
709
758
  }
710
- function be(e) {
759
+ function De(e) {
711
760
  return e.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase().replace(/[^a-z0-9-]/g, "");
712
761
  }
713
- function xe(e) {
714
- const t = W(e, "utf-8"), n = t.split(`
715
- `), s = [];
762
+ function We(e) {
763
+ const t = C(e, "utf-8"), s = t.split(`
764
+ `), n = [];
716
765
  let o = 0;
717
- for (; o < n.length; ) {
718
- const p = n[o];
719
- if (/^\s*import\b/.test(p)) {
720
- let f = p;
721
- for (; !/from\s+["'][^"']+["'];?\s*$/.test(f) && !/^\s*import\s+["'][^"']+["'];?\s*$/.test(f) && o + 1 < n.length; )
722
- o++, f += `
723
- ` + n[o];
724
- s.push(f), o++;
766
+ for (; o < s.length; ) {
767
+ const f = s[o];
768
+ if (/^\s*import\b/.test(f)) {
769
+ let h = f;
770
+ for (; !/from\s+["'][^"']+["'];?\s*$/.test(h) && !/^\s*import\s+["'][^"']+["'];?\s*$/.test(h) && o + 1 < s.length; )
771
+ o++, h += `
772
+ ` + s[o];
773
+ n.push(h), o++;
725
774
  continue;
726
775
  }
727
- if (/^\s*$/.test(p)) {
776
+ if (/^\s*$/.test(f)) {
728
777
  o++;
729
778
  continue;
730
779
  }
731
780
  break;
732
781
  }
733
- const r = L(e), i = [], a = (p) => {
734
- const f = F(r, p);
735
- return /\.(vue|svelte)$/.test(p) ? { kind: "source", abs: f } : p.endsWith(".ts") ? b(f) ? { kind: "data", abs: f } : null : b(`${f}.ts`) ? { kind: "data", abs: `${f}.ts` } : b(`${f}.vue`) || b(`${f}.svelte`) || b(d(f, "index.ts")) ? { kind: "source", abs: f } : null;
782
+ const r = _(e), i = [], c = (f) => {
783
+ const h = j(r, f);
784
+ return /\.(vue|svelte)$/.test(f) ? { kind: "source", abs: h } : f.endsWith(".ts") ? $(h) ? { kind: "data", abs: h } : null : $(`${h}.ts`) ? { kind: "data", abs: `${h}.ts` } : $(`${h}.vue`) || $(`${h}.svelte`) || $(d(h, "index.ts")) ? { kind: "source", abs: h } : null;
736
785
  };
737
- for (const p of s) {
738
- const f = p.match(/from\s+["'](\.\.?\/[^"']+)["']/)?.[1];
739
- if (!f) continue;
740
- const w = a(f);
741
- w?.kind === "data" && i.push(w.abs);
742
- }
743
- const l = s.filter((p) => !p.includes("@storybook")).map(
744
- (p) => p.replace(/from\s+["'](\.\.?\/[^"']+)["']/g, (f, w) => {
745
- const $ = a(w);
746
- return $?.kind === "source" ? `from ${JSON.stringify($.abs)}` : `from "./${C(w).replace(/\.ts$/, "")}"`;
786
+ for (const f of n) {
787
+ const h = f.match(/from\s+["'](\.\.?\/[^"']+)["']/)?.[1];
788
+ if (!h) continue;
789
+ const g = c(h);
790
+ g?.kind === "data" && i.push(g.abs);
791
+ }
792
+ const u = n.filter((f) => !f.includes("@storybook")).map(
793
+ (f) => f.replace(/from\s+["'](\.\.?\/[^"']+)["']/g, (h, g) => {
794
+ const w = c(g);
795
+ return w?.kind === "source" ? `from ${JSON.stringify(w.abs)}` : `from "./${O(g).replace(/\.ts$/, "")}"`;
747
796
  })
748
797
  ).join(`
749
798
  `);
750
- let c = t.slice(n.slice(0, o).join(`
799
+ let a = t.slice(s.slice(0, o).join(`
751
800
  `).length);
752
- const m = (p) => {
753
- const f = c.search(p);
754
- if (f < 0) return;
755
- const w = c.indexOf("{", f);
756
- if (w < 0) {
757
- c = c.slice(0, f) + c.slice(c.indexOf(`
758
- `, f) + 1);
801
+ const p = (f) => {
802
+ const h = a.search(f);
803
+ if (h < 0) return;
804
+ const g = a.indexOf("{", h);
805
+ if (g < 0) {
806
+ a = a.slice(0, h) + a.slice(a.indexOf(`
807
+ `, h) + 1);
759
808
  return;
760
809
  }
761
- const $ = ce(c, w + 1), k = w + 1 + $.length + 1, E = c.slice(k).match(/^[^\n]*/)?.[0] ?? "";
762
- c = c.slice(0, f) + c.slice(k + E.length);
810
+ const w = he(a, g + 1), v = g + 1 + w.length + 1, F = a.slice(v).match(/^[^\n]*/)?.[0] ?? "";
811
+ a = a.slice(0, h) + a.slice(v + F.length);
763
812
  };
764
- m(/^const meta\b[^\n]*/m), c = c.replace(/^export default meta;?\s*$/m, ""), c = c.replace(/^(?:export )?type \w+[^\n]*\n(?:[ \t]+[^\n]*\n?)*/gm, "");
765
- let u = 0;
766
- for (; /^(?:export )?interface \w+/m.test(c) && u < 50; )
767
- m(/^(?:export )?interface \w+[^\n]*/m), u++;
768
- let h = 0;
769
- for (; /^export const \w+/m.test(c) && h < 200; )
770
- m(/^export const \w+[^\n]*/m), h++;
813
+ p(/^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, "");
814
+ let l = 0;
815
+ for (; /^(?:export )?interface \w+/m.test(a) && l < 50; )
816
+ p(/^(?:export )?interface \w+[^\n]*/m), l++;
817
+ let m = 0;
818
+ for (; /^export const \w+/m.test(a) && m < 200; )
819
+ p(/^export const \w+[^\n]*/m), m++;
771
820
  return {
772
821
  file: e,
773
822
  text: t,
774
823
  title: t.match(/\btitle:\s*["']([^"']+)["']/)?.[1],
775
824
  metaComponent: t.match(/\bcomponent:\s*([A-Za-z_$][\w$]*)\s*[,\n}]/)?.[1],
776
- imports: l,
777
- declarations: c.trim(),
825
+ imports: u,
826
+ declarations: a.trim(),
778
827
  dataModules: i
779
828
  };
780
829
  }
781
- function Zt(e, t) {
782
- const n = e.indexOf(":", t) + 1;
783
- let s = 0, o = null;
784
- for (let r = n; r < e.length; r++) {
785
- const i = e[r], a = e[r - 1];
830
+ function xs(e, t) {
831
+ const s = e.indexOf(":", t) + 1;
832
+ let n = 0, o = null;
833
+ for (let r = s; r < e.length; r++) {
834
+ const i = e[r], c = e[r - 1];
786
835
  if (o) {
787
- i === o && a !== "\\" && (o = null);
836
+ i === o && c !== "\\" && (o = null);
788
837
  continue;
789
838
  }
790
839
  if (i === "'" || i === '"' || i === "`") {
791
840
  o = i;
792
841
  continue;
793
842
  }
794
- if (i === "{" || i === "(" || i === "[") s++;
795
- else if (i === "}" || i === ")" || i === "]") s--;
796
- else if (i === "," && s === 0) return e.slice(n, r).trim();
843
+ if (i === "{" || i === "(" || i === "[") n++;
844
+ else if (i === "}" || i === ")" || i === "]") n--;
845
+ else if (i === "," && n === 0) return e.slice(s, r).trim();
797
846
  }
798
- return e.slice(n).trim();
847
+ return e.slice(s).trim();
799
848
  }
800
- function Ve(e) {
849
+ function ft(e) {
801
850
  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)");
802
851
  }
803
- function qe(e) {
804
- const t = [], n = /export const (\w+)\s*(?::[^=]*)?=\s*\{/g;
805
- let s;
806
- for (; s = n.exec(e.text); ) {
807
- const o = s[1];
852
+ function dt(e) {
853
+ const t = [], s = /export const (\w+)\s*(?::[^=]*)?=\s*\{/g;
854
+ let n;
855
+ for (; n = s.exec(e.text); ) {
856
+ const o = n[1];
808
857
  if (o === "default" || o === "meta") continue;
809
- const r = ce(e.text, n.lastIndex), i = r.search(/\brender\s*:/);
858
+ const r = he(e.text, s.lastIndex), i = r.search(/\brender\s*:/);
810
859
  if (i >= 0) {
811
- const c = Zt(r, i);
812
- if (c) {
813
- t.push({ name: o, renderFn: c });
860
+ const a = xs(r, i);
861
+ if (a) {
862
+ t.push({ name: o, renderFn: a });
814
863
  continue;
815
864
  }
816
865
  }
817
- const a = r.search(/\bargs\s*:/);
818
- let l = {};
819
- if (a >= 0) {
820
- const c = r.indexOf("{", a);
821
- if (c >= 0) {
822
- const m = ce(r, c + 1);
866
+ const c = r.search(/\bargs\s*:/);
867
+ let u = {};
868
+ if (c >= 0) {
869
+ const a = r.indexOf("{", c);
870
+ if (a >= 0) {
871
+ const p = he(r, a + 1);
823
872
  try {
824
- l = le(new Function(`${Ve(e.declarations)}
825
- return {${m}}`)());
873
+ u = ge(new Function(`${ft(e.declarations)}
874
+ return {${p}}`)());
826
875
  } catch {
827
876
  try {
828
- l = le(new Function(`return {${m}}`)());
877
+ u = ge(new Function(`return {${p}}`)());
829
878
  } catch {
830
- l = {};
879
+ u = {};
831
880
  }
832
881
  }
833
882
  }
834
883
  }
835
- t.push({ name: o, props: l });
884
+ t.push({ name: o, props: u });
836
885
  }
837
886
  return t;
838
887
  }
839
- function Ke(e) {
888
+ function ht(e) {
840
889
  const t = e.text.search(/\bargTypes\s*:\s*\{/);
841
890
  if (t < 0) return;
842
- const n = e.text.indexOf("{", t), s = ce(e.text, n + 1);
891
+ const s = e.text.indexOf("{", t), n = he(e.text, s + 1);
843
892
  let o;
844
893
  try {
845
- o = le(new Function(`return {${s}}`)());
894
+ o = ge(new Function(`return {${n}}`)());
846
895
  } catch {
847
896
  try {
848
- o = le(
849
- new Function(`${Ve(e.declarations)}
850
- return {${s}}`)()
897
+ o = ge(
898
+ new Function(`${ft(e.declarations)}
899
+ return {${n}}`)()
851
900
  );
852
901
  } catch {
853
902
  return;
854
903
  }
855
904
  }
856
905
  const r = {};
857
- for (const [i, a] of Object.entries(o)) {
858
- if (!a || typeof a != "object") continue;
859
- const l = a.control, c = typeof l == "string" ? l : String(l?.type ?? ""), m = a.options ?? (typeof l == "object" ? l?.options : void 0), u = {};
860
- typeof a.description == "string" && (u.description = a.description), Array.isArray(m) ? u.enum = m : c === "boolean" ? u.type = "boolean" : c === "number" || c === "range" ? u.type = "number" : c === "text" || c === "color" || c === "date" ? u.type = "string" : c === "object" && (u.type = "object"), a.defaultValue !== void 0 && (u.default = a.defaultValue), Object.keys(u).length && (r[i] = u);
906
+ for (const [i, c] of Object.entries(o)) {
907
+ if (!c || typeof c != "object") continue;
908
+ const u = c.control, a = typeof u == "string" ? u : String(u?.type ?? ""), p = c.options ?? (typeof u == "object" ? u?.options : void 0), l = {};
909
+ typeof c.description == "string" && (l.description = c.description), Array.isArray(p) ? l.enum = p : a === "boolean" ? l.type = "boolean" : a === "number" || a === "range" ? l.type = "number" : a === "text" || a === "color" || a === "date" ? l.type = "string" : a === "object" && (l.type = "object"), c.defaultValue !== void 0 && (l.default = c.defaultValue), Object.keys(l).length && (r[i] = l);
861
910
  }
862
911
  return Object.keys(r).length ? r : void 0;
863
912
  }
864
- async function Ye(e) {
913
+ async function gt(e) {
865
914
  const t = [...e].sort();
866
915
  for (let i = 0; i < t.length; i++)
867
916
  console.log(`${String(i + 1).padStart(4)} ${t[i]}`);
868
- const n = vt({ input: process.stdin, output: process.stdout }), s = await n.question(
917
+ const s = rt({ input: process.stdin, output: process.stdout }), n = await s.question(
869
918
  "select components to import, comma separated numbers, names, or /regex/, empty imports all: "
870
919
  );
871
- n.close();
872
- const o = s.trim();
920
+ s.close();
921
+ const o = n.trim();
873
922
  if (!o) return new Set(t);
874
923
  const r = /* @__PURE__ */ new Set();
875
- for (const i of o.split(",").map((a) => a.trim()).filter(Boolean)) {
876
- const a = i.match(/^\/(.+)\/$/);
877
- if (a) {
878
- const l = new RegExp(a[1]);
879
- for (const c of t) l.test(c) && r.add(c);
924
+ for (const i of o.split(",").map((c) => c.trim()).filter(Boolean)) {
925
+ const c = i.match(/^\/(.+)\/$/);
926
+ if (c) {
927
+ const u = new RegExp(c[1]);
928
+ for (const a of t) u.test(a) && r.add(a);
880
929
  continue;
881
930
  }
882
931
  if (/^\d+$/.test(i)) {
883
- const l = t[Number(i) - 1];
884
- l && r.add(l);
932
+ const u = t[Number(i) - 1];
933
+ u && r.add(u);
885
934
  continue;
886
935
  }
887
- for (const l of t) l === i && r.add(l);
936
+ for (const u of t) u === i && r.add(u);
888
937
  }
889
938
  return r;
890
939
  }
891
- function Qe(e, t) {
892
- const n = /* @__PURE__ */ new Map(), s = d(e, "node_modules", t, "index.mjs");
893
- if (!b(s)) return n;
894
- const o = W(s, "utf-8");
940
+ function wt(e, t) {
941
+ const s = /* @__PURE__ */ new Map(), n = d(e, "node_modules", t, "index.mjs");
942
+ if (!$(n)) return s;
943
+ const o = C(n, "utf-8");
895
944
  for (const r of o.matchAll(/export \{ default as ([A-Za-z]+) \}/g))
896
- n.set(r[1].toLowerCase(), r[1]);
897
- return n;
898
- }
899
- async function Vt(e, t, n, s) {
900
- const o = t.modules.systems[n];
901
- if (!o) throw new Error(`[nimpress] modules import: unknown system ${n}`);
902
- const r = o.framework, i = r === "vue" ? ".vue" : ".svelte", a = d(e, t.contentDir, "components"), l = o.package, c = s.match ? new RegExp(s.match) : null;
903
- if (s.file) {
904
- const g = F(e, s.file);
905
- if (!b(g)) throw new Error(`[nimpress] modules import: ${g} not found`);
906
- if (oe(g) !== i)
907
- throw new Error(`[nimpress] modules import: ${g} does not match system framework ${r}`);
908
- const y = s.name ?? C(g, i), J = o.source ? F(e, o.source) : e, _ = d(a, "Components", y);
909
- await ye(_, { recursive: !0 });
910
- const P = O(J, g);
911
- await G(d(_, "index.md"), ve(n, y, l, P)), await ne(_, y, await se(g, r, y)), console.log(`nimpress modules: imported ${y} at ${O(e, _)}`);
945
+ s.set(r[1].toLowerCase(), r[1]);
946
+ return s;
947
+ }
948
+ async function Ss(e, t, s, n) {
949
+ const o = t.modules.systems[s];
950
+ if (!o) throw new Error(`[nimpress] modules import: unknown system ${s}`);
951
+ const r = o.framework, i = r === "vue" ? ".vue" : ".svelte", c = d(e, t.contentDir, "components"), u = o.package, a = n.match ? new RegExp(n.match) : null;
952
+ if (n.file) {
953
+ const y = j(e, n.file);
954
+ if (!$(y)) throw new Error(`[nimpress] modules import: ${y} not found`);
955
+ if (ue(y) !== i)
956
+ throw new Error(`[nimpress] modules import: ${y} does not match system framework ${r}`);
957
+ const b = n.name ?? O(y, i), H = o.source ? j(e, o.source) : e, R = d(c, "Components", b);
958
+ await Fe(R, { recursive: !0 });
959
+ const P = D(H, y);
960
+ await q(d(R, "index.md"), _e(s, b, u, P)), await le(R, b, await ce(y, r, b)), console.log(`nimpress modules: imported ${b} at ${D(e, R)}`);
912
961
  return;
913
962
  }
914
- if (s.fromStories) {
915
- await qt(e, t, n, s);
963
+ if (n.fromStories) {
964
+ await js(e, t, s, n);
916
965
  return;
917
966
  }
918
- const m = F(e, s.source ?? o.source ?? "");
919
- if (!b(m))
920
- throw new Error(`[nimpress] modules import: source ${m} not found`);
921
- const u = ue(m), h = /* @__PURE__ */ new Map(), p = /* @__PURE__ */ new Map(), f = u.filter((g) => g.endsWith(".stories.ts")), w = s.stories ? [F(e, s.stories)] : [];
922
- for (const g of w)
923
- for (const y of ue(g))
924
- y.endsWith(".stories.ts") && f.push(y);
925
- const $ = u.filter(
926
- (g) => g.endsWith(i) && /^[A-Z][A-Za-z0-9]*$/.test(C(g, i))
927
- ), k = new Set($.map((g) => C(g, i))), E = l && !o.source ? Qe(e, l) : null;
928
- for (const g of f) {
929
- const y = xe(g);
930
- if (y.title?.includes("/")) {
931
- const [R, M] = y.title.split("/");
932
- h.set(M, R.replace(/\s+/g, ""));
967
+ const p = j(e, n.source ?? o.source ?? "");
968
+ if (!$(p))
969
+ throw new Error(`[nimpress] modules import: source ${p} not found`);
970
+ const l = we(p), m = /* @__PURE__ */ new Map(), f = /* @__PURE__ */ new Map(), h = l.filter((y) => y.endsWith(".stories.ts")), g = n.stories ? [j(e, n.stories)] : [];
971
+ for (const y of g)
972
+ for (const b of we(y))
973
+ b.endsWith(".stories.ts") && h.push(b);
974
+ const w = l.filter(
975
+ (y) => y.endsWith(i) && /^[A-Z][A-Za-z0-9]*$/.test(O(y, i))
976
+ ), v = new Set(w.map((y) => O(y, i))), F = u && !o.source ? wt(e, u) : null;
977
+ for (const y of h) {
978
+ const b = We(y);
979
+ if (b.title?.includes("/")) {
980
+ const [L, z] = b.title.split("/");
981
+ m.set(z, L.replace(/\s+/g, ""));
933
982
  }
934
- const J = C(g, ".stories.ts");
935
- let P = b(d(L(g), `${J}${i}`)) ? J : y.metaComponent ?? J;
936
- if (!k.has(P)) {
937
- let R = "";
938
- for (const M of k)
939
- J.startsWith(M) && M.length > R.length && (R = M);
940
- R ? P = R : console.warn(`nimpress modules: ${C(g)} targets ${P} which has no component page`);
983
+ const H = O(y, ".stories.ts");
984
+ let P = $(d(_(y), `${H}${i}`)) ? H : b.metaComponent ?? H;
985
+ if (!v.has(P)) {
986
+ let L = "";
987
+ for (const z of v)
988
+ H.startsWith(z) && z.length > L.length && (L = z);
989
+ L ? P = L : console.warn(`nimpress modules: ${O(y)} targets ${P} which has no component page`);
941
990
  }
942
- const v = E?.get(P.toLowerCase()) ?? P, B = p.get(v) ?? [];
943
- B.push(y), p.set(v, B);
944
- }
945
- const j = /* @__PURE__ */ new Map();
946
- let x = 0, N = 0;
947
- const S = $.filter((g) => !c || c.test(C(g, i))), D = s.select ? await Ye(S.map((g) => C(g, i))) : null;
948
- for (const g of S) {
949
- const y = C(g, i);
950
- if (D && !D.has(y)) continue;
951
- if (j.has(y)) {
952
- console.warn(`nimpress modules: skip duplicate ${y}, kept ${j.get(y)}`);
991
+ const S = F?.get(P.toLowerCase()) ?? P, U = f.get(S) ?? [];
992
+ U.push(b), f.set(S, U);
993
+ }
994
+ const E = /* @__PURE__ */ new Map();
995
+ let k = 0, T = 0;
996
+ const x = w.filter((y) => !a || a.test(O(y, i))), A = n.select ? await gt(x.map((y) => O(y, i))) : null;
997
+ for (const y of x) {
998
+ const b = O(y, i);
999
+ if (A && !A.has(b)) continue;
1000
+ if (E.has(b)) {
1001
+ console.warn(`nimpress modules: skip duplicate ${b}, kept ${E.get(b)}`);
953
1002
  continue;
954
1003
  }
955
- j.set(y, O(m, g));
956
- const J = h.get(y) ?? "Components", _ = d(a, J, y);
957
- await ye(_, { recursive: !0 });
958
- const P = O(m, g), v = P === `${y}/${y}${i}` || P === `${y}${i}`, B = (p.get(y) ?? []).map((I) => Ke(I)).reduce(
959
- (I, Z) => Z ? { ...I ?? {}, ...Z } : I,
1004
+ E.set(b, D(p, y));
1005
+ const H = m.get(b) ?? "Components", R = d(c, H, b);
1006
+ await Fe(R, { recursive: !0 });
1007
+ const P = D(p, y), S = P === `${b}/${b}${i}` || P === `${b}${i}`, U = (f.get(b) ?? []).map((B) => ht(B)).reduce(
1008
+ (B, Y) => Y ? { ...B ?? {}, ...Y } : B,
960
1009
  void 0
961
1010
  );
962
- await G(d(_, "index.md"), ve(n, y, l, v ? void 0 : P)), await ne(_, y, await se(g, r, y)), B && await Ae(_, { properties: B }), x++;
963
- const R = p.get(y) ?? [], M = /* @__PURE__ */ new Set();
964
- for (const I of R) {
965
- const Z = C(I.file, ".stories.ts"), Ce = qe(I);
966
- Ce.length || console.warn(`nimpress modules: no stories mined from ${C(I.file)}`);
967
- for (const U of I.dataModules)
968
- await Re(U, d(_, C(U)));
969
- for (const U of Ce) {
970
- const Fe = U.name === y ? "Default" : Z === y ? U.name : `${Z} ${U.name}`;
971
- let ie = be(Fe);
972
- M.has(ie) && (ie = be(`${Z}-${U.name}`));
973
- const Oe = d(_, `${ie}.story.tsx`);
974
- M.add(ie), !b(Oe) && (await G(Oe, Xe(r, Fe, Z, U, I)), N++);
1011
+ await q(d(R, "index.md"), _e(s, b, u, S ? void 0 : P)), await le(R, b, await ce(y, r, b)), U && await Xe(R, { properties: U }), k++;
1012
+ const L = f.get(b) ?? [], z = /* @__PURE__ */ new Set();
1013
+ for (const B of L) {
1014
+ const Y = O(B.file, ".stories.ts"), Pe = dt(B);
1015
+ Pe.length || console.warn(`nimpress modules: no stories mined from ${O(B.file)}`);
1016
+ for (const V of B.dataModules)
1017
+ await tt(V, d(R, O(V)));
1018
+ for (const V of Pe) {
1019
+ const Ie = V.name === b ? "Default" : Y === b ? V.name : `${Y} ${V.name}`;
1020
+ let me = De(Ie);
1021
+ z.has(me) && (me = De(`${Y}-${V.name}`));
1022
+ const Me = d(R, `${me}.story.tsx`);
1023
+ z.add(me), !$(Me) && (await q(Me, $t(r, Ie, Y, V, B)), T++);
975
1024
  }
976
1025
  }
977
1026
  }
978
- console.log(`nimpress modules: imported ${x} components with ${N} stories for ${n}`);
1027
+ console.log(`nimpress modules: imported ${k} components with ${T} stories for ${s}`);
979
1028
  }
980
- async function qt(e, t, n, s) {
981
- const o = t.modules.systems[n], r = o.framework, i = d(e, t.contentDir, "components"), a = F(e, s.stories ?? "");
982
- if (!s.stories || !b(a))
1029
+ async function js(e, t, s, n) {
1030
+ const o = t.modules.systems[s], r = o.framework, i = d(e, t.contentDir, "components"), c = j(e, n.stories ?? "");
1031
+ if (!n.stories || !$(c))
983
1032
  throw new Error("[nimpress] modules import --from-stories requires --stories=<csf dir>");
984
- const l = o.source ? F(e, o.source) : e, c = s.match ? new RegExp(s.match) : null, m = /* @__PURE__ */ new Set();
985
- let u = 0, h = 0;
986
- const p = ue(a).filter((w) => w.endsWith(".stories.ts")), f = s.select ? await Ye(
987
- p.map((w) => xe(w).metaComponent ?? C(w, ".stories.ts"))
1033
+ const u = o.source ? j(e, o.source) : e, a = n.match ? new RegExp(n.match) : null, p = /* @__PURE__ */ new Set();
1034
+ let l = 0, m = 0;
1035
+ const f = we(c).filter((g) => g.endsWith(".stories.ts")), h = n.select ? await gt(
1036
+ f.map((g) => We(g).metaComponent ?? O(g, ".stories.ts"))
988
1037
  ) : null;
989
- for (const w of p) {
990
- const $ = xe(w), k = C(w, ".stories.ts"), E = $.metaComponent ?? k;
991
- if (f && !f.has(E)) continue;
992
- const j = $.text.match(
993
- new RegExp(`import\\s+(?:\\{\\s*)?${E}(?:\\s*\\})?\\s+from\\s+["']([^"']+)["']`)
1038
+ for (const g of f) {
1039
+ const w = We(g), v = O(g, ".stories.ts"), F = w.metaComponent ?? v;
1040
+ if (h && !h.has(F)) continue;
1041
+ const E = w.text.match(
1042
+ new RegExp(`import\\s+(?:\\{\\s*)?${F}(?:\\s*\\})?\\s+from\\s+["']([^"']+)["']`)
994
1043
  )?.[1];
995
- let x = E, N = o.package, S;
996
- if (j && !j.startsWith(".") && !j.startsWith("@/")) {
997
- const v = j.split("/")[0].startsWith("@") ? j.split("/").slice(0, 2).join("/") : j.split("/")[0];
998
- N = v, x = Qe(e, v).get(E.toLowerCase()) ?? E;
999
- } else if (j?.startsWith("@/components/")) {
1000
- const v = j.slice(13);
1001
- v === x || v === `${x}/${x}.vue` || (S = v.endsWith(".vue") || v.endsWith(".svelte") ? v : `${v}/${x}.vue`);
1002
- } else if (j?.startsWith(".")) {
1003
- const v = F(L(w), j);
1004
- S = O(l, v);
1044
+ let k = F, T = o.package, x;
1045
+ if (E && !E.startsWith(".") && !E.startsWith("@/")) {
1046
+ const S = E.split("/")[0].startsWith("@") ? E.split("/").slice(0, 2).join("/") : E.split("/")[0];
1047
+ T = S, k = wt(e, S).get(F.toLowerCase()) ?? F;
1048
+ } else if (E?.startsWith("@/components/")) {
1049
+ const S = E.slice(13);
1050
+ S === k || S === `${k}/${k}.vue` || (x = S.endsWith(".vue") || S.endsWith(".svelte") ? S : `${S}/${k}.vue`);
1051
+ } else if (E?.startsWith(".")) {
1052
+ const S = j(_(g), E);
1053
+ x = D(u, S);
1005
1054
  }
1006
- if (c && !c.test(x)) continue;
1007
- if (m.has(x)) {
1008
- console.warn(`nimpress modules: skip duplicate ${x} from ${C(w)}`);
1055
+ if (a && !a.test(k)) continue;
1056
+ if (p.has(k)) {
1057
+ console.warn(`nimpress modules: skip duplicate ${k} from ${O(g)}`);
1009
1058
  continue;
1010
1059
  }
1011
- m.add(x);
1012
- const D = $.title?.includes("/") ? $.title.split("/")[0].replace(/\s+/g, "") : "Components", g = d(i, D, x);
1013
- await ye(g, { recursive: !0 }), await G(d(g, "index.md"), ve(n, x, N, S));
1014
- const y = r === "vue" ? ".vue" : ".svelte", _ = (S ? [F(l, S)] : [
1015
- d(l, x, `${x}${y}`),
1016
- d(l, `${x}${y}`)
1017
- ]).find((v) => b(v));
1018
- if (_)
1019
- await ne(g, x, await se(_, r, x));
1020
- else if (N) {
1021
- const v = ft(e, N, x);
1022
- v ? await ne(g, x, dt(W(v, "utf-8"), x)) : console.warn(`nimpress modules: no source or d.ts found for ${x}, the schema seed is skipped`);
1060
+ p.add(k);
1061
+ const A = w.title?.includes("/") ? w.title.split("/")[0].replace(/\s+/g, "") : "Components", y = d(i, A, k);
1062
+ await Fe(y, { recursive: !0 }), await q(d(y, "index.md"), _e(s, k, T, x));
1063
+ const b = r === "vue" ? ".vue" : ".svelte", R = (x ? [j(u, x)] : [
1064
+ d(u, k, `${k}${b}`),
1065
+ d(u, `${k}${b}`)
1066
+ ]).find((S) => $(S));
1067
+ if (R)
1068
+ await le(y, k, await ce(R, r, k));
1069
+ else if (T) {
1070
+ const S = Bt(e, T, k);
1071
+ S ? await le(y, k, Gt(C(S, "utf-8"), k)) : console.warn(`nimpress modules: no source or d.ts found for ${k}, the schema seed is skipped`);
1023
1072
  }
1024
- const P = Ke($);
1025
- P && await Ae(g, { properties: P }), u++;
1026
- for (const v of $.dataModules)
1027
- await Re(v, d(g, C(v)));
1028
- for (const v of qe($)) {
1029
- const B = v.name === x ? "Default" : v.name, R = be(B), M = d(g, `${R}.story.tsx`);
1030
- b(M) || (await G(M, Xe(r, B, k, v, $)), h++);
1073
+ const P = ht(w);
1074
+ P && await Xe(y, { properties: P }), l++;
1075
+ for (const S of w.dataModules)
1076
+ await tt(S, d(y, O(S)));
1077
+ for (const S of dt(w)) {
1078
+ const U = S.name === k ? "Default" : S.name, L = De(U), z = d(y, `${L}.story.tsx`);
1079
+ $(z) || (await q(z, $t(r, U, v, S, w)), m++);
1031
1080
  }
1032
1081
  }
1033
- console.log(`nimpress modules: imported ${u} components with ${h} stories for ${n} from stories`);
1082
+ console.log(`nimpress modules: imported ${l} components with ${m} stories for ${s} from stories`);
1034
1083
  }
1035
- function ve(e, t, n, s) {
1036
- const o = n ? `
1037
- package: "${n}"` : "", r = s ? `
1038
- file: ${JSON.stringify(s)}` : "";
1084
+ function _e(e, t, s, n) {
1085
+ const o = s ? `
1086
+ package: "${s}"` : "", r = n ? `
1087
+ file: ${JSON.stringify(n)}` : "";
1039
1088
  return `---
1040
1089
  title: ${t}
1041
1090
  type: component
@@ -1047,13 +1096,13 @@ data:
1047
1096
  ## Usage
1048
1097
 
1049
1098
  \`\`\`ts
1050
- import { ${t} } from "${n ?? e}";
1099
+ import { ${t} } from "${s ?? e}";
1051
1100
  \`\`\`
1052
1101
  `;
1053
1102
  }
1054
- function Xe(e, t, n, s, o) {
1103
+ function $t(e, t, s, n, o) {
1055
1104
  const r = e === "vue" ? "vueStory" : "svelteStory";
1056
- return s.renderFn ? `import { ${r} } from '@nimtech/nimpress/story'
1105
+ return n.renderFn ? `import { ${r} } from '@nimtech/nimpress/story'
1057
1106
  ${o.imports}
1058
1107
 
1059
1108
  ${o.declarations}
@@ -1061,212 +1110,212 @@ ${o.declarations}
1061
1110
  // story: ${t}
1062
1111
  export default ${r}({
1063
1112
  name: ${JSON.stringify(t)},
1064
- description: ${JSON.stringify(`Scenario from ${n}`)},
1065
- render: ${s.renderFn}
1113
+ description: ${JSON.stringify(`Scenario from ${s}`)},
1114
+ render: ${n.renderFn}
1066
1115
  })
1067
1116
  ` : `import { ${r} } from '@nimtech/nimpress/story'
1068
1117
 
1069
1118
  // story: ${t}
1070
1119
  export default ${r}({
1071
1120
  name: ${JSON.stringify(t)},
1072
- props: ${JSON.stringify(s.props ?? {}, null, 2)}
1121
+ props: ${JSON.stringify(n.props ?? {}, null, 2)}
1073
1122
  })
1074
1123
  `;
1075
1124
  }
1076
- function te(e, t) {
1077
- const n = T(t, "system");
1078
- if (n === void 0) return;
1079
- const s = Object.keys(e.modules.systems);
1080
- if (!s.includes(n))
1081
- throw new Error(`[nimpress] modules: unknown system ${n}, configured: ${s.join(", ") || "none"}`);
1082
- return n;
1083
- }
1084
- function de(e, t, n) {
1085
- const s = te(e, t);
1086
- if (s) return s;
1125
+ function ae(e, t) {
1126
+ const s = W(t, "system");
1127
+ if (s === void 0) return;
1128
+ const n = Object.keys(e.modules.systems);
1129
+ if (!n.includes(s))
1130
+ throw new Error(`[nimpress] modules: unknown system ${s}, configured: ${n.join(", ") || "none"}`);
1131
+ return s;
1132
+ }
1133
+ function ke(e, t, s) {
1134
+ const n = ae(e, t);
1135
+ if (n) return n;
1087
1136
  const o = Object.keys(e.modules.systems);
1088
1137
  if (o.length === 1) return o[0];
1089
1138
  throw o.length ? new Error(
1090
- `[nimpress] modules ${n}: several systems configured (${o.join(", ")}), pass --system=<name>`
1091
- ) : new Error(`[nimpress] modules ${n}: no systems configured`);
1139
+ `[nimpress] modules ${s}: several systems configured (${o.join(", ")}), pass --system=<name>`
1140
+ ) : new Error(`[nimpress] modules ${s}: no systems configured`);
1092
1141
  }
1093
- async function Kt(e, t, n) {
1094
- const s = n[0], o = n.slice(1), r = Object.keys(t.modules.systems);
1095
- if (s === "init") {
1096
- Yt(e, t);
1142
+ async function Cs(e, t, s) {
1143
+ const n = s[0], o = s.slice(1), r = Object.keys(t.modules.systems);
1144
+ if (n === "init") {
1145
+ Es(e, t);
1097
1146
  return;
1098
1147
  }
1099
- if (s === "dev") {
1100
- const i = te(t, o), a = i ? [i] : r;
1101
- if (!a.length) throw new Error("[nimpress] modules dev: no systems configured");
1102
- await Ue(e, t, a), await new Promise(() => {
1148
+ if (n === "dev") {
1149
+ const i = ae(t, o), c = i ? [i] : r;
1150
+ if (!c.length) throw new Error("[nimpress] modules dev: no systems configured");
1151
+ await lt(e, t, c), await new Promise(() => {
1103
1152
  });
1104
1153
  }
1105
- if (s === "build") {
1106
- const i = te(t, o), a = i ? [i] : Be(t);
1107
- if (!a.length) throw new Error("[nimpress] modules build: no systems configured");
1108
- await Ge(e, t, a);
1154
+ if (n === "build") {
1155
+ const i = ae(t, o), c = i ? [i] : ct(t);
1156
+ if (!c.length) throw new Error("[nimpress] modules build: no systems configured");
1157
+ await ut(e, t, c);
1109
1158
  return;
1110
1159
  }
1111
- if (s === "lint") {
1112
- const i = await Je(e, t, te(t, o));
1113
- we("nimpress modules lint", i, "nimpress modules lint: systems, schemas, and stories ok");
1160
+ if (n === "lint") {
1161
+ const i = await at(e, t, ae(t, o));
1162
+ Oe("nimpress modules lint", i, "nimpress modules lint: systems, schemas, and stories ok");
1114
1163
  return;
1115
1164
  }
1116
- if (s === "story") {
1117
- const i = de(t, o, "story"), a = ee(o, 0), l = T(o, "framework");
1118
- if (a) {
1119
- const m = await je(e, t, i, a, l);
1120
- m && console.log(`nimpress modules: story written to ${m}`);
1165
+ if (n === "story") {
1166
+ const i = ke(t, o, "story"), c = ne(o, 0), u = W(o, "framework");
1167
+ if (c) {
1168
+ const p = await Re(e, t, i, c, u);
1169
+ p && console.log(`nimpress modules: story written to ${p}`);
1121
1170
  return;
1122
1171
  }
1123
- const c = await Gt(e, t, i);
1124
- console.log(`nimpress modules: ${c} auto stories written for ${i}`);
1172
+ const a = await vs(e, t, i);
1173
+ console.log(`nimpress modules: ${a} auto stories written for ${i}`);
1125
1174
  return;
1126
1175
  }
1127
- if (s === "import") {
1128
- const i = de(t, o, "import"), a = ee(o, 0);
1129
- await Vt(e, t, i, {
1130
- file: a,
1131
- name: T(o, "name"),
1132
- source: T(o, "source"),
1133
- stories: T(o, "stories"),
1134
- match: T(o, "match"),
1176
+ if (n === "import") {
1177
+ const i = ke(t, o, "import"), c = ne(o, 0);
1178
+ await Ss(e, t, i, {
1179
+ file: c,
1180
+ name: W(o, "name"),
1181
+ source: W(o, "source"),
1182
+ stories: W(o, "stories"),
1183
+ match: W(o, "match"),
1135
1184
  fromStories: o.includes("--from-stories"),
1136
1185
  select: o.includes("--select")
1137
- }), $e(e);
1186
+ }), Ee(e);
1138
1187
  return;
1139
1188
  }
1140
- if (s === "update") {
1141
- const i = T(o, "component") ?? ee(o, 0), a = await ht(e, t, { ref: i, system: te(t, o) });
1142
- console.log(`nimpress modules: ${a} schema${a === 1 ? "" : "s"} upserted`), $e(e);
1189
+ if (n === "update") {
1190
+ const i = W(o, "component") ?? ne(o, 0), c = await Ht(e, t, { ref: i, system: ae(t, o) });
1191
+ console.log(`nimpress modules: ${c} schema${c === 1 ? "" : "s"} upserted`), Ee(e);
1143
1192
  return;
1144
1193
  }
1145
- if (s === "create") {
1146
- const i = T(o, "component");
1194
+ if (n === "create") {
1195
+ const i = W(o, "component");
1147
1196
  if (i) {
1148
- if (!X(o, "schema"))
1197
+ if (!M(o, "schema"))
1149
1198
  throw new Error("[nimpress] modules create --component expects --schema to upsert the schema");
1150
- const u = await gt(e, t, i);
1151
- console.log(`nimpress modules: schema upserted at ${u}`);
1199
+ const l = await Ut(e, t, i);
1200
+ console.log(`nimpress modules: schema upserted at ${l}`);
1152
1201
  return;
1153
1202
  }
1154
- const a = ee(o, 0);
1155
- if (!a)
1203
+ const c = ne(o, 0);
1204
+ if (!c)
1156
1205
  throw new Error("[nimpress] modules create expects: nimpress modules create <Component> [--system=<name>], or --component=<ref> --schema");
1157
- const l = de(t, o, "create"), c = T(o, "framework"), m = await Ht(e, t, l, a, c);
1158
- console.log(`nimpress modules: created ${a} at ${O(e, m)}`);
1206
+ const u = ke(t, o, "create"), a = W(o, "framework"), p = await ks(e, t, u, c, a);
1207
+ console.log(`nimpress modules: created ${c} at ${D(e, p)}`);
1159
1208
  return;
1160
1209
  }
1161
1210
  throw new Error("[nimpress] modules expects init, dev, build, lint, story, import, create or update");
1162
1211
  }
1163
- function Yt(e, t) {
1164
- const n = d(e, t.modules.dir);
1165
- Q(n, { recursive: !0 });
1166
- const s = d(e, "nimpress.config.json");
1167
- if (b(s)) {
1168
- const o = JSON.parse(W(s, "utf-8"));
1169
- o.modules || (o.modules = { dir: t.modules.dir, route: t.modules.route, systems: {} }, A(s, JSON.stringify(o, null, 2) + `
1170
- `), console.log(`nimpress modules: modules block added to ${s}`));
1212
+ function Es(e, t) {
1213
+ const s = d(e, t.modules.dir);
1214
+ G(s, { recursive: !0 });
1215
+ const n = d(e, "nimpress.config.json");
1216
+ if ($(n)) {
1217
+ const o = JSON.parse(C(n, "utf-8"));
1218
+ o.modules || (o.modules = { dir: t.modules.dir, route: t.modules.route, systems: {} }, N(n, JSON.stringify(o, null, 2) + `
1219
+ `), console.log(`nimpress modules: modules block added to ${n}`));
1171
1220
  } else
1172
1221
  console.log("nimpress modules: add a modules block with systems entries to your nimpress config");
1173
- console.log(`nimpress modules: folder ready at ${n}`);
1222
+ console.log(`nimpress modules: folder ready at ${s}`);
1174
1223
  }
1175
- function et(e) {
1224
+ function yt(e) {
1176
1225
  if (!e.startsWith(`---
1177
1226
  `)) return null;
1178
1227
  const t = e.indexOf(`
1179
1228
  ---`, 4);
1180
1229
  return t < 0 ? null : e.slice(4, t);
1181
1230
  }
1182
- function Qt(e) {
1231
+ function Fs(e) {
1183
1232
  for (const t of e.split(`
1184
1233
  `)) {
1185
1234
  if (!t.startsWith("export:")) continue;
1186
- const n = t.slice(7).trim().replace(/^["']|["']$/g, "");
1187
- return n === "" || n === "false" ? null : n;
1235
+ const s = t.slice(7).trim().replace(/^["']|["']$/g, "");
1236
+ return s === "" || s === "false" ? null : s;
1188
1237
  }
1189
1238
  return null;
1190
1239
  }
1191
- function Xt(e, t) {
1192
- const n = et(e);
1193
- if (n === null) return e;
1194
- const s = n.split(`
1195
- `).filter((r) => !r.startsWith("export:") && !r.startsWith(" file:")), o = s.findIndex((r) => r.startsWith(" package:"));
1196
- return t && o >= 0 && !s.some((r) => r.startsWith(" version:")) && s.splice(o + 1, 0, ` version: ${JSON.stringify(t)}`), `---
1197
- ${s.join(`
1198
- `)}${e.slice(4 + n.length)}`;
1199
- }
1200
- function es(e, t, n) {
1201
- const s = T(n, "target") ?? "", o = d(e, T(n, "out") ?? t.paths.export), r = d(e, t.contentDir);
1240
+ function Os(e, t) {
1241
+ const s = yt(e);
1242
+ if (s === null) return e;
1243
+ const n = s.split(`
1244
+ `).filter((r) => !r.startsWith("export:") && !r.startsWith(" file:")), o = n.findIndex((r) => r.startsWith(" package:"));
1245
+ return t && o >= 0 && !n.some((r) => r.startsWith(" version:")) && n.splice(o + 1, 0, ` version: ${JSON.stringify(t)}`), `---
1246
+ ${n.join(`
1247
+ `)}${e.slice(4 + s.length)}`;
1248
+ }
1249
+ function Ne(e, t, s) {
1250
+ const n = W(s, "target") ?? "", o = d(e, W(s, "out") ?? t.paths.export), r = d(e, t.contentDir);
1202
1251
  let i = "";
1203
1252
  try {
1204
- i = JSON.parse(W(d(e, "package.json"), "utf-8")).version ?? "";
1253
+ i = JSON.parse(C(d(e, "package.json"), "utf-8")).version ?? "";
1205
1254
  } catch {
1206
1255
  i = "";
1207
1256
  }
1208
- let a = 0;
1209
- for (const l of re(r)) {
1210
- if (!l.endsWith(".md")) continue;
1211
- const c = W(l, "utf-8"), m = et(c);
1212
- if (m === null) continue;
1213
- const u = Qt(m);
1214
- if (u === null || s && u !== s && u !== "true") continue;
1215
- const h = L(l), p = d(o, O(r, h));
1216
- Q(p, { recursive: !0 });
1217
- for (const f of Y(h, { withFileTypes: !0 })) {
1218
- if (!f.isFile()) continue;
1219
- const w = W(d(h, f.name), "utf-8");
1220
- A(
1221
- d(p, f.name),
1222
- f.name.endsWith(".md") ? Xt(w, i) : w
1257
+ let c = 0;
1258
+ for (const u of se(r)) {
1259
+ if (!u.endsWith(".md")) continue;
1260
+ const a = C(u, "utf-8"), p = yt(a);
1261
+ if (p === null) continue;
1262
+ const l = Fs(p);
1263
+ if (l === null || n && l !== n && l !== "true") continue;
1264
+ const m = _(u), f = d(o, D(r, m));
1265
+ G(f, { recursive: !0 });
1266
+ for (const h of X(m, { withFileTypes: !0 })) {
1267
+ if (!h.isFile()) continue;
1268
+ const g = C(d(m, h.name), "utf-8");
1269
+ N(
1270
+ d(f, h.name),
1271
+ h.name.endsWith(".md") ? Os(g, i) : g
1223
1272
  );
1224
1273
  }
1225
- a++;
1274
+ c++;
1226
1275
  }
1227
- console.log(`nimpress export: ${a} pages collected into ${o}`);
1228
- }
1229
- const he = d(".claude", "skills", "nimpress", "SKILL.md");
1230
- function tt() {
1231
- const e = L(kt(import.meta.url)), t = [
1232
- F(e, he),
1233
- F(e, "..", he),
1234
- F(e, "..", "..", he)
1276
+ console.log(`nimpress export: ${c} pages collected into ${o}`);
1277
+ }
1278
+ const xe = d(".claude", "skills", "nimpress", "SKILL.md");
1279
+ function bt() {
1280
+ const e = _(Yt(import.meta.url)), t = [
1281
+ j(e, xe),
1282
+ j(e, "..", xe),
1283
+ j(e, "..", "..", xe)
1235
1284
  ];
1236
- for (const n of t)
1285
+ for (const s of t)
1237
1286
  try {
1238
- return W(n, "utf-8");
1287
+ return C(s, "utf-8");
1239
1288
  } catch {
1240
1289
  }
1241
1290
  throw new Error(`[nimpress] skill: SKILL.md not found, looked in ${t.join(", ")}`);
1242
1291
  }
1243
- function st(e, t) {
1244
- const n = t ? d(Le(), ".claude") : d(e, ".claude"), s = d(n, "skills", "nimpress");
1245
- Q(s, { recursive: !0 });
1246
- const o = d(s, "SKILL.md");
1247
- return A(o, tt()), console.log(`wrote ${o}`), o;
1292
+ function vt(e, t) {
1293
+ const s = t ? d(Z(), ".claude") : d(e, ".claude"), n = d(s, "skills", "nimpress");
1294
+ G(n, { recursive: !0 });
1295
+ const o = d(n, "SKILL.md");
1296
+ return N(o, bt()), console.log(`wrote ${o}`), o;
1248
1297
  }
1249
- function ts(e, t) {
1250
- const n = t[0];
1251
- if (n === "get") {
1252
- process.stdout.write(tt());
1298
+ function Ds(e, t) {
1299
+ const s = t[0];
1300
+ if (s === "get") {
1301
+ process.stdout.write(bt());
1253
1302
  return;
1254
1303
  }
1255
- if (n === "put") {
1256
- st(e, !X(t, "project"));
1304
+ if (s === "put") {
1305
+ vt(e, !M(t, "project"));
1257
1306
  return;
1258
1307
  }
1259
1308
  throw new Error("[nimpress] skill expects get or put");
1260
1309
  }
1261
- const V = {
1310
+ const Q = {
1262
1311
  name: "--system",
1263
1312
  value: !0,
1264
1313
  describe: "the configured component system to act on"
1265
- }, We = {
1314
+ }, Ge = {
1266
1315
  name: "--framework",
1267
1316
  value: !0,
1268
1317
  describe: "vue or svelte, overriding the framework of the system"
1269
- }, H = [
1318
+ }, K = [
1270
1319
  {
1271
1320
  name: "init",
1272
1321
  describe: "Write the config, the content folder, and the agent guide",
@@ -1276,7 +1325,7 @@ const V = {
1276
1325
  {
1277
1326
  name: "dev",
1278
1327
  describe: "Serve the site and every component harness",
1279
- flags: [],
1328
+ flags: [{ name: "--view", value: !1, describe: "serve the central docs site with this repo's exported pages in place" }],
1280
1329
  subs: []
1281
1330
  },
1282
1331
  {
@@ -1291,21 +1340,27 @@ const V = {
1291
1340
  flags: [{ name: "--no-build", value: !1, describe: "stop after the checks and skip the verification build" }],
1292
1341
  subs: []
1293
1342
  },
1343
+ {
1344
+ name: "seo",
1345
+ describe: "Report the search and robot metadata of every page, and write the generated fields",
1346
+ flags: [{ name: "--write", value: !1, describe: "put the generated keywords and description into the frontmatter where the page has none" }, { name: "--out", value: !0, describe: "where the map is written instead of seo.map.json" }],
1347
+ subs: []
1348
+ },
1294
1349
  {
1295
1350
  name: "modules",
1296
1351
  describe: "Drive the component workshop",
1297
1352
  flags: [],
1298
1353
  subs: [
1299
1354
  { name: "init", describe: "Create the modules folder and the config block", flags: [], subs: [] },
1300
- { name: "dev", describe: "Serve the harnesses and stay running", flags: [V], subs: [] },
1301
- { name: "build", describe: "Build the harness bundles", flags: [V], subs: [] },
1302
- { name: "lint", describe: "Check the systems, the schemas, and the stories", flags: [V], subs: [] },
1303
- { name: "story", describe: "Write auto stories for one component or for every component", flags: [V, We], subs: [] },
1355
+ { name: "dev", describe: "Serve the harnesses and stay running", flags: [Q], subs: [] },
1356
+ { name: "build", describe: "Build the harness bundles", flags: [Q], subs: [] },
1357
+ { name: "lint", describe: "Check the systems, the schemas, and the stories", flags: [Q], subs: [] },
1358
+ { name: "story", describe: "Write auto stories for one component or for every component", flags: [Q, Ge], subs: [] },
1304
1359
  {
1305
1360
  name: "import",
1306
1361
  describe: "Import components and storybook stories into component pages",
1307
1362
  flags: [
1308
- V,
1363
+ Q,
1309
1364
  { name: "--name", value: !0, describe: "the component name when a single file is imported" },
1310
1365
  { name: "--source", value: !0, describe: "the component source root, overriding the system source" },
1311
1366
  { name: "--stories", value: !0, describe: "an extra folder of storybook csf files" },
@@ -1319,8 +1374,8 @@ const V = {
1319
1374
  name: "create",
1320
1375
  describe: "Create a component page, or upsert one schema",
1321
1376
  flags: [
1322
- V,
1323
- We,
1377
+ Q,
1378
+ Ge,
1324
1379
  { name: "--component", value: !0, describe: "the component reference whose schema is upserted" },
1325
1380
  { name: "--schema", value: !1, describe: "required with --component, upserts the schema" }
1326
1381
  ],
@@ -1329,7 +1384,7 @@ const V = {
1329
1384
  {
1330
1385
  name: "update",
1331
1386
  describe: "Upsert the component schemas from the component types",
1332
- flags: [V, { name: "--component", value: !0, describe: "limit the upsert to one component reference" }],
1387
+ flags: [Q, { name: "--component", value: !0, describe: "limit the upsert to one component reference" }],
1333
1388
  subs: []
1334
1389
  }
1335
1390
  ]
@@ -1343,6 +1398,35 @@ const V = {
1343
1398
  ],
1344
1399
  subs: []
1345
1400
  },
1401
+ {
1402
+ name: "view",
1403
+ describe: "Preview the export folder inside the central docs site it publishes to",
1404
+ flags: [
1405
+ { name: "--no-browser", value: !1, describe: "print the url instead of opening a browser" },
1406
+ { name: "--docs-repo", value: !0, describe: "the docs site as owner/repo or a url when the workflows do not name it" },
1407
+ { name: "--export-dir", value: !0, describe: "the export folder when no workflow names it" },
1408
+ { name: "--target", value: !0, describe: "the export target name when the repo has a nimpress config" },
1409
+ { name: "--offline", value: !1, describe: "serve from the cached clone without fetching" }
1410
+ ],
1411
+ subs: []
1412
+ },
1413
+ {
1414
+ name: "cache",
1415
+ describe: "Clear the links and clones view keeps, and the local cache root",
1416
+ flags: [],
1417
+ subs: [
1418
+ {
1419
+ name: "clear",
1420
+ describe: "Clear the links, the docs site clones, or the local cache root",
1421
+ flags: [
1422
+ { name: "--links", value: !1, describe: "clear only the links and login methods" },
1423
+ { name: "--sites", value: !1, describe: "clear only the docs site clones" },
1424
+ { name: "--local", value: !1, describe: "clear only the cache root of the current repo" }
1425
+ ],
1426
+ subs: []
1427
+ }
1428
+ ]
1429
+ },
1346
1430
  {
1347
1431
  name: "guard",
1348
1432
  describe: "Wire the gated pages to the auth provider artifacts",
@@ -1396,55 +1480,55 @@ const V = {
1396
1480
  { name: "powershell", describe: "the powershell completion script", flags: [], subs: [] }
1397
1481
  ]
1398
1482
  }
1399
- ], nt = ["bash", "zsh", "fish", "powershell"];
1400
- function me(e) {
1483
+ ], kt = ["bash", "zsh", "fish", "powershell"];
1484
+ function ye(e) {
1401
1485
  const t = [];
1402
- for (const n of [...e.flags, ...e.subs.flatMap((s) => s.flags)])
1403
- t.some((s) => s.name === n.name) || t.push(n);
1486
+ for (const s of [...e.flags, ...e.subs.flatMap((n) => n.flags)])
1487
+ t.some((n) => n.name === s.name) || t.push(s);
1404
1488
  return t;
1405
1489
  }
1406
- function pe(e, t) {
1490
+ function be(e, t) {
1407
1491
  return t && e.value ? `${e.name}=` : e.name;
1408
1492
  }
1409
- function ss() {
1493
+ function Ws() {
1410
1494
  const e = ["_nimpress() {", ' local cur="${COMP_WORDS[COMP_CWORD]}"'];
1411
- e.push(` local words="${H.map((t) => t.name).join(" ")}"`), e.push(' if [ "$COMP_CWORD" -gt 1 ]; then'), e.push(' case "${COMP_WORDS[1]}" in');
1412
- for (const t of H) {
1413
- const n = [...t.subs.map((s) => s.name), ...me(t).map((s) => pe(s, !1))];
1414
- e.push(` ${t.name}) words="${n.join(" ")}" ;;`);
1495
+ e.push(` local words="${K.map((t) => t.name).join(" ")}"`), e.push(' if [ "$COMP_CWORD" -gt 1 ]; then'), e.push(' case "${COMP_WORDS[1]}" in');
1496
+ for (const t of K) {
1497
+ const s = [...t.subs.map((n) => n.name), ...ye(t).map((n) => be(n, !1))];
1498
+ e.push(` ${t.name}) words="${s.join(" ")}" ;;`);
1415
1499
  }
1416
1500
  return e.push(' *) words="" ;;'), e.push(" esac"), e.push(" fi"), e.push(' COMPREPLY=( $(compgen -W "$words" -- "$cur") )'), e.push("}"), e.push("complete -o default -F _nimpress nimpress"), e.join(`
1417
1501
  `) + `
1418
1502
  `;
1419
1503
  }
1420
- function ge(e, t, n) {
1421
- const s = [`${e}entries=(`];
1422
- for (const o of n) s.push(`${e} ${o}`);
1423
- return s.push(`${e})`), s.push(`${e}_describe '${t}' entries`), s.push(`${e}return`), s;
1504
+ function Se(e, t, s) {
1505
+ const n = [`${e}entries=(`];
1506
+ for (const o of s) n.push(`${e} ${o}`);
1507
+ return n.push(`${e})`), n.push(`${e}_describe '${t}' entries`), n.push(`${e}return`), n;
1424
1508
  }
1425
- function ns() {
1509
+ function _s() {
1426
1510
  const e = ["#compdef nimpress", "", "_nimpress() {", " local -a entries", " if (( CURRENT == 2 )); then"];
1427
1511
  e.push(
1428
- ...ge(
1512
+ ...Se(
1429
1513
  " ",
1430
1514
  "nimpress command",
1431
- H.map((t) => `'${t.name}:${t.describe}'`)
1515
+ K.map((t) => `'${t.name}:${t.describe}'`)
1432
1516
  )
1433
1517
  ), e.push(" fi"), e.push(' case "$words[2]" in');
1434
- for (const t of H) {
1518
+ for (const t of K) {
1435
1519
  e.push(` ${t.name})`), t.subs.length && (e.push(" if (( CURRENT == 3 )); then"), e.push(
1436
- ...ge(
1520
+ ...Se(
1437
1521
  " ",
1438
1522
  `${t.name} argument`,
1439
- t.subs.map((s) => `'${s.name}:${s.describe}'`)
1523
+ t.subs.map((n) => `'${n.name}:${n.describe}'`)
1440
1524
  )
1441
1525
  ), e.push(" fi"));
1442
- const n = me(t);
1443
- n.length ? e.push(
1444
- ...ge(
1526
+ const s = ye(t);
1527
+ s.length ? e.push(
1528
+ ...Se(
1445
1529
  " ",
1446
1530
  "nimpress flag",
1447
- n.map((s) => `'${pe(s, !0)}:${s.describe}'`)
1531
+ s.map((n) => `'${be(n, !0)}:${n.describe}'`)
1448
1532
  )
1449
1533
  ) : e.push(" return"), e.push(" ;;");
1450
1534
  }
@@ -1452,153 +1536,537 @@ function ns() {
1452
1536
  `) + `
1453
1537
  `;
1454
1538
  }
1455
- function os() {
1539
+ function Ns() {
1456
1540
  const e = ["complete -c nimpress -f"];
1457
- for (const t of H)
1541
+ for (const t of K)
1458
1542
  e.push(
1459
1543
  `complete -c nimpress -n '__fish_use_subcommand' -a '${t.name}' -d '${t.describe}'`
1460
1544
  );
1461
- for (const t of H) {
1462
- const n = `__fish_seen_subcommand_from ${t.name}`;
1463
- for (const s of t.subs)
1464
- e.push(`complete -c nimpress -n '${n}' -a '${s.name}' -d '${s.describe}'`);
1465
- for (const s of me(t))
1545
+ for (const t of K) {
1546
+ const s = `__fish_seen_subcommand_from ${t.name}`;
1547
+ for (const n of t.subs)
1548
+ e.push(`complete -c nimpress -n '${s}' -a '${n.name}' -d '${n.describe}'`);
1549
+ for (const n of ye(t))
1466
1550
  e.push(
1467
- `complete -c nimpress -n '${n}' -a '${pe(s, !0)}' -d '${s.describe}'`
1551
+ `complete -c nimpress -n '${s}' -a '${be(n, !0)}' -d '${n.describe}'`
1468
1552
  );
1469
1553
  }
1470
1554
  return e.join(`
1471
1555
  `) + `
1472
1556
  `;
1473
1557
  }
1474
- function rs() {
1558
+ function Ts() {
1475
1559
  const e = [
1476
1560
  "Register-ArgumentCompleter -Native -CommandName nimpress -ScriptBlock {",
1477
1561
  " param($wordToComplete, $commandAst, $cursorPosition)",
1478
1562
  " $words = @($commandAst.CommandElements | ForEach-Object { $_.ToString() })",
1479
1563
  " $candidates = @()",
1480
1564
  " if ($words.Count -le 2) {",
1481
- ` $candidates = @(${H.map((t) => `'${t.name}'`).join(", ")})`,
1565
+ ` $candidates = @(${K.map((t) => `'${t.name}'`).join(", ")})`,
1482
1566
  " } else {",
1483
1567
  " switch ($words[1]) {"
1484
1568
  ];
1485
- for (const t of H) {
1486
- const n = [...t.subs.map((s) => s.name), ...me(t).map((s) => pe(s, !0))];
1487
- e.push(` '${t.name}' { $candidates = @(${n.map((s) => `'${s}'`).join(", ")}) }`);
1569
+ for (const t of K) {
1570
+ const s = [...t.subs.map((n) => n.name), ...ye(t).map((n) => be(n, !0))];
1571
+ e.push(` '${t.name}' { $candidates = @(${s.map((n) => `'${n}'`).join(", ")}) }`);
1488
1572
  }
1489
1573
  return e.push(" }"), e.push(" }"), e.push(' $candidates | Where-Object { $_ -like "$wordToComplete*" } | ForEach-Object {'), e.push(" [System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_)"), e.push(" }"), e.push("}"), e.join(`
1490
1574
  `) + `
1491
1575
  `;
1492
1576
  }
1493
- function ot(e) {
1494
- if (e === "bash") return ss();
1495
- if (e === "zsh") return ns();
1496
- if (e === "fish") return os();
1497
- if (e === "powershell") return rs();
1498
- throw new Error(`[nimpress] completion: unsupported shell ${e}, use ${nt.join(", ")}`);
1577
+ function xt(e) {
1578
+ if (e === "bash") return Ws();
1579
+ if (e === "zsh") return _s();
1580
+ if (e === "fish") return Ns();
1581
+ if (e === "powershell") return Ts();
1582
+ throw new Error(`[nimpress] completion: unsupported shell ${e}, use ${kt.join(", ")}`);
1499
1583
  }
1500
- function is() {
1501
- const e = C(process.env.SHELL ?? "");
1584
+ function As() {
1585
+ const e = O(process.env.SHELL ?? "");
1502
1586
  for (const t of ["zsh", "bash", "fish"])
1503
1587
  if (e.includes(t)) return t;
1504
1588
  return "";
1505
1589
  }
1506
- function as(e, t) {
1507
- const n = "# >>> nimpress completion >>>", s = "# <<< nimpress completion <<<", o = `${n}
1590
+ function Rs(e, t) {
1591
+ const s = "# >>> nimpress completion >>>", n = "# <<< nimpress completion <<<", o = `${s}
1508
1592
  ${t}
1509
- ${s}`, r = e.indexOf(n), i = e.indexOf(s);
1510
- return r >= 0 && i > r ? e.slice(0, r) + o + e.slice(i + s.length) : r >= 0 ? e.replace(/\n+$/, "") + `
1593
+ ${n}`, r = e.indexOf(s), i = e.indexOf(n);
1594
+ return r >= 0 && i > r ? e.slice(0, r) + o + e.slice(i + n.length) : r >= 0 ? e.replace(/\n+$/, "") + `
1511
1595
  ` + o + `
1512
1596
  ` : (e === "" || e.endsWith(`
1513
1597
  `) ? e : e + `
1514
1598
  `) + o + `
1515
1599
  `;
1516
1600
  }
1517
- function cs(e, t) {
1518
- let n = "";
1601
+ function Ps(e, t) {
1602
+ let s = "";
1519
1603
  try {
1520
- n = W(e, "utf-8");
1604
+ s = C(e, "utf-8");
1521
1605
  } catch {
1522
- n = "";
1606
+ s = "";
1523
1607
  }
1524
- A(e, as(n, t));
1608
+ N(e, Rs(s, t));
1525
1609
  }
1526
- function ls(e) {
1527
- const t = e || is();
1610
+ function Is(e) {
1611
+ const t = e || As();
1528
1612
  if (!t)
1529
1613
  throw new Error("[nimpress] completion: could not detect the shell from $SHELL, name it: nimpress completion <shell> --auto");
1530
- const n = ot(t), s = Le();
1614
+ const s = xt(t), n = Z();
1531
1615
  if (t === "fish") {
1532
- const l = d(s, ".config", "fish", "completions");
1533
- Q(l, { recursive: !0 });
1534
- const c = d(l, "nimpress.fish");
1535
- A(c, n), console.log(`wrote ${c}`), console.log("fish loads it on the next shell");
1616
+ const u = d(n, ".config", "fish", "completions");
1617
+ G(u, { recursive: !0 });
1618
+ const a = d(u, "nimpress.fish");
1619
+ N(a, s), console.log(`wrote ${a}`), console.log("fish loads it on the next shell");
1536
1620
  return;
1537
1621
  }
1538
1622
  if (t !== "bash" && t !== "zsh")
1539
1623
  throw new Error(`[nimpress] completion: auto install covers bash, zsh, and fish, for ${t} run: nimpress completion ${t}`);
1540
- const o = d(s, ".config", "nimpress", "completions");
1541
- Q(o, { recursive: !0 });
1624
+ const o = d(n, ".config", "nimpress", "completions");
1625
+ G(o, { recursive: !0 });
1542
1626
  const r = d(o, t === "zsh" ? "_nimpress" : "nimpress.bash");
1543
- A(r, n), console.log(`wrote ${r}`);
1544
- const i = d(s, t === "zsh" ? ".zshrc" : ".bashrc"), a = t === "zsh" ? `fpath=("${o}" $fpath)
1627
+ N(r, s), console.log(`wrote ${r}`);
1628
+ const i = d(n, t === "zsh" ? ".zshrc" : ".bashrc"), c = t === "zsh" ? `fpath=("${o}" $fpath)
1545
1629
  autoload -Uz compinit && compinit -u` : `[ -f "${r}" ] && source "${r}"`;
1546
- cs(i, a), console.log(`wired ${i}`), console.log(`start a new shell or run: source ${i}`);
1630
+ Ps(i, c), console.log(`wired ${i}`), console.log(`start a new shell or run: source ${i}`);
1547
1631
  }
1548
- function us(e, t) {
1549
- const n = ee(t, 0) ?? "", s = X(t, "auto"), o = X(t, "skill");
1550
- if (!s) {
1632
+ function Ms(e, t) {
1633
+ const s = ne(t, 0) ?? "", n = M(t, "auto"), o = M(t, "skill");
1634
+ if (!n) {
1551
1635
  if (o) throw new Error("[nimpress] completion: --skill installs alongside --auto");
1552
- if (!n) throw new Error(`[nimpress] completion: name a shell (${nt.join(", ")}) or pass --auto`);
1553
- process.stdout.write(ot(n));
1636
+ if (!s) throw new Error(`[nimpress] completion: name a shell (${kt.join(", ")}) or pass --auto`);
1637
+ process.stdout.write(xt(s));
1638
+ return;
1639
+ }
1640
+ Is(s), o && vt(e, !0);
1641
+ }
1642
+ function zs(e, t, s) {
1643
+ if (typeof s.path == "string") return s.path.startsWith("/") ? s.path : `/${s.path}`;
1644
+ const n = D(e, t).split(I).join("/").replace(/\.md$/, "");
1645
+ return n === "index" ? "/" : `/${n.replace(/\/index$/, "")}`;
1646
+ }
1647
+ function He(e) {
1648
+ return e ? (Array.isArray(e) ? e : String(e).split(",")).map((s) => String(s).trim()).filter(Boolean) : [];
1649
+ }
1650
+ function Js(e) {
1651
+ return e.split(`
1652
+ `).filter((t) => /^#{1,6}\s/.test(t)).map((t) => t.replace(/^#{1,6}\s+/, "").trim());
1653
+ }
1654
+ function Ls(e, t) {
1655
+ const s = j(e, t.contentDir), o = se(s).filter((a) => a.endsWith(".md")).map((a) => {
1656
+ const { data: p, content: l } = pe(C(a, "utf-8"));
1657
+ return { file: a, data: p, content: l };
1658
+ }).filter((a) => typeof a.data.title == "string" && a.data.visibility !== "hidden" && !a.data.link), r = o.map((a) => ({
1659
+ slug: a.file,
1660
+ title: String(a.data.title),
1661
+ headings: Js(a.content),
1662
+ tags: He(a.data.tags),
1663
+ body: a.content
1664
+ })), i = Zt(r), c = t.site?.url?.replace(/\/$/, "") ?? "", u = t.base.replace(/\/$/, "");
1665
+ return o.map((a) => {
1666
+ const p = i.get(a.file) ?? { keywords: [], description: "" }, l = a.data.meta ?? {}, m = Array.isArray(l.keywords) ? l.keywords : typeof l.keywords == "string" ? [l.keywords] : void 0, f = typeof l.description == "string" ? l.description : typeof a.data.description == "string" ? a.data.description : void 0, h = l.override === !0, g = t.seo?.auto === !0, w = g ? h && m ? m : p.keywords.length ? p.keywords : m ?? [] : m ?? He(a.data.tags), v = g ? h && f ? f : p.description || f || "" : f ?? "", F = zs(s, a.file, a.data);
1667
+ return {
1668
+ path: F,
1669
+ file: D(e, a.file).split(I).join("/"),
1670
+ title: String(a.data.title),
1671
+ keywords: w,
1672
+ description: v,
1673
+ robots: Vt(typeof l.robots == "string" ? l.robots : "index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1", t.seo?.ai?.index, typeof l.ai == "boolean" ? l.ai : void 0),
1674
+ canonical: typeof l.canonical == "string" ? l.canonical : c ? `${c}${u}${F === "/" ? "/" : F}` : "",
1675
+ generated: p,
1676
+ authored: { keywords: m, description: f, override: h, ai: typeof l.ai == "boolean" ? l.ai : void 0 }
1677
+ };
1678
+ });
1679
+ }
1680
+ function Bs(e, t) {
1681
+ let s = 0;
1682
+ for (const n of t) {
1683
+ const o = j(e, n.file), { data: r, content: i } = pe(C(o, "utf-8")), c = { ...r.meta ?? {} };
1684
+ let u = !1;
1685
+ c.keywords === void 0 && n.generated.keywords.length && (c.keywords = n.generated.keywords, u = !0), c.description === void 0 && n.generated.description && (c.description = n.generated.description, u = !0), u && (N(o, pe.stringify(i, { ...r, meta: c })), s += 1);
1686
+ }
1687
+ return s;
1688
+ }
1689
+ function Gs(e, t, s) {
1690
+ const n = Ls(e, t), o = W(s, "out") ?? "seo.map.json";
1691
+ for (const r of n) {
1692
+ const i = t.seo?.auto ? r.authored.override ? "authored" : "generated" : "authored";
1693
+ 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}`);
1694
+ }
1695
+ if (N(j(e, o), JSON.stringify(n, null, 2) + `
1696
+ `), console.log(`nimpress seo: ${n.length} pages, map written to ${o}`), s.includes("--write")) {
1697
+ const r = Bs(e, n);
1698
+ console.log(`nimpress seo: generated fields written into ${r} pages`);
1699
+ }
1700
+ }
1701
+ function St(e = Z()) {
1702
+ return d(e, ".nimpress", "config.json");
1703
+ }
1704
+ function jt(e = Z()) {
1705
+ return d(e, ".tide", "nimpress", "sites");
1706
+ }
1707
+ function Ct(e = Z()) {
1708
+ const t = St(e);
1709
+ return $(t) ? { links: JSON.parse(C(t, "utf-8")).links ?? {} } : { links: {} };
1710
+ }
1711
+ function Et(e, t = Z()) {
1712
+ const s = St(t);
1713
+ G(_(s), { recursive: !0 }), N(s, `${JSON.stringify(e, null, 2)}
1714
+ `);
1715
+ }
1716
+ function $e(e) {
1717
+ const t = e.trim().replace(/\.git$/, "").replace(/\/+$/, ""), s = t.match(/[:/]([^/:]+)\/([^/]+)$/);
1718
+ if (s && t.includes("github.com")) return `${s[1]}/${s[2]}`;
1719
+ const n = t.match(/^([^/\s]+)\/([^/\s]+)$/);
1720
+ if (n) return `${n[1]}/${n[2]}`;
1721
+ throw new Error(`[nimpress] view: cannot read owner/repo from ${e}`);
1722
+ }
1723
+ function je(e) {
1724
+ const t = e.trim();
1725
+ return /^(https?:\/\/|git@|ssh:\/\/)/.test(t) ? t : `https://github.com/${$e(t)}.git`;
1726
+ }
1727
+ function Ft(e) {
1728
+ const t = d(e, ".github", "workflows");
1729
+ return $(t) ? X(t).filter((s) => s.endsWith(".yml") || s.endsWith(".yaml")).sort().map((s) => d(t, s)) : [];
1730
+ }
1731
+ function Ot(e) {
1732
+ try {
1733
+ const t = Xt(C(e, "utf-8"));
1734
+ return typeof t == "object" && t !== null ? t : null;
1735
+ } catch {
1736
+ return null;
1737
+ }
1738
+ }
1739
+ function re(e, t) {
1740
+ return String(e ?? "").replace(/\$\{\{\s*env\.([A-Za-z_][A-Za-z0-9_]*)\s*\}\}/g, (n, o) => {
1741
+ for (const r of t)
1742
+ if (r && r[o] !== void 0) return String(r[o]);
1743
+ return "";
1744
+ }).trim();
1745
+ }
1746
+ function Dt(e, t) {
1747
+ const s = [];
1748
+ for (const n of Object.values(e.jobs ?? {}))
1749
+ for (const o of n.steps ?? [])
1750
+ typeof o.uses == "string" && o.uses.includes(`/actions/${t}@`) && s.push({ step: o, scopes: [o.env, n.env, e.env] });
1751
+ return s;
1752
+ }
1753
+ function Hs(e) {
1754
+ const t = /* @__PURE__ */ new Map();
1755
+ for (const s of Ft(e)) {
1756
+ const n = Ot(s);
1757
+ if (n)
1758
+ for (const { step: o, scopes: r } of Dt(n, "docs-notify")) {
1759
+ const i = re(o.with?.["docs-repo"], r);
1760
+ if (!i) continue;
1761
+ const c = re(o.with?.["export-dir"], r) || ".nimpress";
1762
+ t.set(i, { repo: i, exportDir: c });
1763
+ }
1764
+ }
1765
+ return [...t.values()];
1766
+ }
1767
+ function Ue(e) {
1768
+ return e.replace(/\$\{\{\s*github\.workspace\s*\}\}\/?/g, "").replace(/^\.\//, "");
1769
+ }
1770
+ function Us(e, t) {
1771
+ const s = {
1772
+ contentRoot: t,
1773
+ mapping: $(d(e, "nimpress.sources.json")) ? "nimpress.sources.json" : "",
1774
+ defaults: {}
1775
+ };
1776
+ for (const n of Ft(e)) {
1777
+ const o = Ot(n);
1778
+ if (o)
1779
+ for (const { step: r, scopes: i } of Dt(o, "docs-sync")) {
1780
+ const c = Ue(re(r.with?.["docs-dir"], i)), u = (m) => {
1781
+ const f = Ue(m);
1782
+ return (c && f.startsWith(`${c}/`) ? f.slice(c.length + 1) : f).replace(/\/+$/, "");
1783
+ }, a = re(r.with?.["content-root"], i);
1784
+ a && (s.contentRoot = u(a));
1785
+ const p = re(r.with?.mapping, i);
1786
+ p && (s.mapping = u(p));
1787
+ const l = re(r.with?.defaults, i);
1788
+ return l && (s.defaults = JSON.parse(l)), s;
1789
+ }
1790
+ }
1791
+ return s;
1792
+ }
1793
+ function Zs(e, t) {
1794
+ const s = { ...e };
1795
+ return t.target && (s.target = t.target), t.targets?.length && (s.targets = t.targets), t.mode && (s.mode = t.mode), s;
1796
+ }
1797
+ function Vs(e) {
1798
+ const t = e.mode || "mirror";
1799
+ 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 }] : [];
1800
+ }
1801
+ function qs(e, t, s) {
1802
+ let n = t.defaults;
1803
+ const o = t.mapping ? d(e, t.mapping) : "";
1804
+ if (o && $(o)) {
1805
+ const i = JSON.parse(C(o, "utf-8")).sources?.[s];
1806
+ i && (n = Zs(n, i));
1807
+ }
1808
+ return n;
1809
+ }
1810
+ function Ze(e) {
1811
+ const t = /* @__PURE__ */ new Map();
1812
+ if (!$(e)) return t;
1813
+ for (const s of se(e))
1814
+ t.set(D(e, s).split(I).join("/"), C(s));
1815
+ return t;
1816
+ }
1817
+ function Ks(e, t, s) {
1818
+ const n = { added: [], modified: [], deleted: [] }, o = Ze(e), r = Ze(t);
1819
+ for (const [i, c] of o) {
1820
+ const u = r.get(i);
1821
+ if (u && u.equals(c)) continue;
1822
+ const a = d(t, ...i.split("/"));
1823
+ G(_(a), { recursive: !0 }), N(a, c), u ? n.modified.push(i) : n.added.push(i);
1824
+ }
1825
+ if (s === "mirror")
1826
+ for (const i of r.keys())
1827
+ o.has(i) || (ee(d(t, ...i.split("/")), { force: !0 }), n.deleted.push(i));
1828
+ return n;
1829
+ }
1830
+ function ie(e, t, s) {
1831
+ const n = te("git", e, { cwd: t, encoding: "utf-8", env: { ...process.env, ...s } });
1832
+ return { ok: n.status === 0, out: `${n.stdout ?? ""}${n.stderr ?? ""}`.trim() };
1833
+ }
1834
+ function Wt(e) {
1835
+ const t = ie(["rev-parse", "--show-toplevel"], e);
1836
+ return t.ok ? t.out : e;
1837
+ }
1838
+ function Ys(e) {
1839
+ const t = ie(["remote", "get-url", "origin"], e);
1840
+ if (!t.ok) throw new Error(`[nimpress] view: ${e} has no origin remote, so its docs site mapping cannot be looked up`);
1841
+ return $e(t.out);
1842
+ }
1843
+ function Qs() {
1844
+ return te("gh", ["--version"], { encoding: "utf-8" }).status === 0;
1845
+ }
1846
+ function _t(e) {
1847
+ return e?.method === "ssh" && e.key ? { GIT_SSH_COMMAND: `ssh -i ${e.key} -o IdentitiesOnly=yes` } : {};
1848
+ }
1849
+ function Ce(e) {
1850
+ return e.login?.method === "gh" ? te("gh", ["repo", "view", e.repo, "--json", "name"], { encoding: "utf-8" }).status === 0 : ie(["ls-remote", "--exit-code", "-h", e.url], void 0, _t(e.login)).ok;
1851
+ }
1852
+ async function Nt(e) {
1853
+ const t = rt({ input: process.stdin, output: process.stdout });
1854
+ try {
1855
+ return (await t.question(e)).trim();
1856
+ } finally {
1857
+ t.close();
1858
+ }
1859
+ }
1860
+ async function Xs(e) {
1861
+ if (Ce(e)) return e;
1862
+ if (console.log(`nimpress view: ${e.url} refused the connection`), Qs()) {
1863
+ 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");
1864
+ const o = { ...e, login: { method: "gh" } };
1865
+ if (Ce(o)) return o;
1866
+ throw new Error(`[nimpress] view: ${e.repo} is still unreachable after the gh login, ask for access to it`);
1867
+ }
1868
+ const t = await Nt("nimpress view: path to the ssh key with access to the repo: ");
1869
+ if (!t) throw new Error("[nimpress] view: no ssh key given and gh is not installed");
1870
+ const s = { ...e, login: { method: "ssh", key: j(t.replace(/^~/, Z())) } };
1871
+ if (Ce(s)) return s;
1872
+ throw new Error(`[nimpress] view: ${e.repo} is still unreachable with ${s.login.key}, ask for access to it`);
1873
+ }
1874
+ async function en(e, t, s = Z()) {
1875
+ const n = Wt(e), o = Ct(s), r = o.links[n] ?? [], i = Hs(n), c = W(t, "docs-repo");
1876
+ let u;
1877
+ if (c) {
1878
+ const p = $e(c), l = i.find((m) => m.repo === p)?.exportDir ?? W(t, "export-dir") ?? ".nimpress";
1879
+ u = [{ repo: p, url: je(c), exportDir: l, login: r.find((m) => m.repo === p)?.login }];
1880
+ } else if (i.length)
1881
+ u = i.map((p) => ({
1882
+ repo: p.repo,
1883
+ url: r.find((l) => l.repo === p.repo)?.url ?? je(p.repo),
1884
+ exportDir: p.exportDir,
1885
+ login: r.find((l) => l.repo === p.repo)?.login
1886
+ }));
1887
+ else if (r.length)
1888
+ u = r;
1889
+ else {
1890
+ console.log(`nimpress view: no workflow under ${n} names a docs site`);
1891
+ const p = await Nt("nimpress view: docs site repo, owner/repo or a url, http or ssh: ");
1892
+ if (!p) throw new Error("[nimpress] view: no docs site given");
1893
+ u = [{ repo: $e(p), url: je(p), exportDir: W(t, "export-dir") ?? ".nimpress" }];
1894
+ }
1895
+ const a = [];
1896
+ for (const p of u) a.push(await Xs(p));
1897
+ return o.links[n] = a, Et(o, s), a;
1898
+ }
1899
+ function tn(e, t = Z()) {
1900
+ return d(jt(t), e.repo.replace("/", "__"));
1901
+ }
1902
+ function sn(e, t, s) {
1903
+ const n = _t(e.login);
1904
+ if (!$(d(t, ".git"))) {
1905
+ G(_(t), { recursive: !0 }), console.log(`nimpress view: cloning ${e.repo}`);
1906
+ 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 } });
1907
+ if (r.status !== 0) throw new Error(`[nimpress] view: clone of ${e.repo} failed
1908
+ ${r.stderr ?? ""}`);
1554
1909
  return;
1555
1910
  }
1556
- ls(n), o && st(e, !0);
1911
+ if (s) return;
1912
+ const o = ie(["fetch", "--depth", "1", "origin", "HEAD"], t, n);
1913
+ if (!o.ok) throw new Error(`[nimpress] view: fetch of ${e.repo} failed
1914
+ ${o.out}`);
1915
+ ie(["reset", "--hard", "FETCH_HEAD"], t), ie(["clean", "-fd"], t);
1916
+ }
1917
+ function nn(e) {
1918
+ const t = ["pnpm-lock.yaml", "package.json"].map((s) => d(e, s)).find((s) => $(s));
1919
+ return t ? ot("sha256").update(C(t)).digest("hex") : "";
1920
+ }
1921
+ function on(e) {
1922
+ const t = d(e, J.paths.cache, "view", "lockfile.sha256"), s = nn(e);
1923
+ if ($(d(e, "node_modules")) && $(t) && C(t, "utf-8").trim() === s) return;
1924
+ 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");
1925
+ G(_(t), { recursive: !0 }), N(t, `${s}
1926
+ `);
1927
+ }
1928
+ function rn(e) {
1929
+ const t = Qt(), s = t === "darwin" ? ["open", e] : t === "win32" ? ["cmd", "/c", "start", "", e] : ["xdg-open", e], n = it(s[0], s.slice(1), { stdio: "ignore", detached: !0 });
1930
+ n.on("error", () => console.log(`nimpress view: open ${e} in a browser`)), n.unref();
1931
+ }
1932
+ function Ve(e, t) {
1933
+ let s;
1934
+ return () => {
1935
+ s && clearTimeout(s), s = setTimeout(e, t);
1936
+ };
1937
+ }
1938
+ function an(e, t) {
1939
+ 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`);
1940
+ }
1941
+ function cn(e) {
1942
+ const t = it("pnpm", ["exec", "nimpress", "dev"], { cwd: e, stdio: ["ignore", "pipe", "inherit"] }), s = new Promise((n, o) => {
1943
+ let r = !1;
1944
+ t.stdout?.on("data", (i) => {
1945
+ const c = i.toString();
1946
+ if (process.stdout.write(c), r) return;
1947
+ const u = c.replace(/\x1b\[[0-9;]*m/g, "").match(/Local\s*:?\s+(https?:\/\/\S+)/);
1948
+ u && (r = !0, n(u[1]));
1949
+ }), t.on("exit", (i) => {
1950
+ r || o(new Error(`[nimpress] view: the docs site dev server exited with ${i ?? "a signal"} before it printed a url`));
1951
+ }), t.on("error", (i) => o(new Error(`[nimpress] view: cannot run the docs site dev server, ${i.message}`)));
1952
+ });
1953
+ return { child: t, origin: s };
1954
+ }
1955
+ async function ln(e, t) {
1956
+ const s = M(t, "offline"), n = await en(e, t), o = Ys(e), r = Wt(e), i = await de(e), c = W(t, "target") ? [`--target=${W(t, "target")}`] : [], u = [];
1957
+ for (const p of n) {
1958
+ const l = j(r, p.exportDir);
1959
+ if (i.configFile && Ne(e, i.resolved, [...c, `--out=${l}`]), !$(l))
1960
+ throw new Error(`[nimpress] view: no export folder at ${l}, write the pages there or mark pages with export: and add a config`);
1961
+ const m = tn(p);
1962
+ sn(p, m, s), on(m);
1963
+ const f = await de(m);
1964
+ if (!f.configFile) throw new Error(`[nimpress] view: ${p.repo} carries no nimpress config, so it is not a docs site`);
1965
+ const h = Us(m, f.resolved.contentDir), g = Vs(qs(m, h, o));
1966
+ if (!g.length)
1967
+ throw new Error(
1968
+ `[nimpress] view: ${p.repo} has no target for ${o}, add it to nimpress.sources.json or the receiver defaults`
1969
+ );
1970
+ const w = j(m, h.contentRoot), v = () => {
1971
+ for (const x of g)
1972
+ an(x.to, Ks(d(l, ...x.from.split("/").filter(Boolean)), d(w, ...x.to.split("/")), x.mode));
1973
+ };
1974
+ v();
1975
+ const F = Je(l, { recursive: !0 }, Ve(v, 150));
1976
+ if (u.push(() => F.close()), i.configFile) {
1977
+ const x = Je(
1978
+ j(e, i.resolved.contentDir),
1979
+ { recursive: !0 },
1980
+ Ve(() => Ne(e, i.resolved, [...c, `--out=${l}`]), 150)
1981
+ );
1982
+ u.push(() => x.close());
1983
+ }
1984
+ const { child: E, origin: k } = cn(m);
1985
+ u.push(() => E.kill());
1986
+ const T = `${(await k).replace(/\/$/, "")}/${g[0].to}`;
1987
+ console.log(`nimpress view: ${o} inside ${p.repo} at ${T}`), M(t, "no-browser") || rn(T);
1988
+ }
1989
+ const a = () => {
1990
+ for (const p of u) p();
1991
+ process.exit(0);
1992
+ };
1993
+ process.on("SIGINT", a), process.on("SIGTERM", a);
1994
+ }
1995
+ async function un(e, t) {
1996
+ const s = ne(t, 0);
1997
+ if (s !== "clear") throw new Error(`[nimpress] cache: unknown subcommand ${s ?? ""}, use clear`);
1998
+ const n = M(t, "links"), o = M(t, "sites"), r = M(t, "local"), i = !n && !o && !r;
1999
+ if (n || i) {
2000
+ const c = Ct(), u = Object.keys(c.links).length;
2001
+ Et({ links: {} }), console.log(`nimpress cache: cleared ${u} links`);
2002
+ }
2003
+ if (o || i) {
2004
+ const c = jt();
2005
+ ee(c, { recursive: !0, force: !0 }), console.log(`nimpress cache: cleared the docs site clones under ${c}`);
2006
+ }
2007
+ if (r) {
2008
+ const { resolved: c, configFile: u } = await de(e);
2009
+ if (!u) throw new Error(`[nimpress] cache: --local needs a nimpress config in ${e}`);
2010
+ const a = Qe(e, c);
2011
+ $(a) && ee(a, { recursive: !0, force: !0 }), console.log(`nimpress cache: cleared ${a}`);
2012
+ }
1557
2013
  }
1558
- async function ks(e) {
1559
- const t = e[0] ?? "dev", n = e.slice(1), s = process.cwd();
2014
+ async function jn(e) {
2015
+ const t = e[0] ?? "dev", s = e.slice(1), n = process.cwd();
1560
2016
  if (t === "init") {
1561
- Ft(s);
2017
+ ns(n);
1562
2018
  return;
1563
2019
  }
1564
2020
  if (t === "skill") {
1565
- ts(s, n);
2021
+ Ds(n, s);
1566
2022
  return;
1567
2023
  }
1568
2024
  if (t === "completion") {
1569
- us(s, n);
2025
+ Ms(n, s);
2026
+ return;
2027
+ }
2028
+ if (t === "view" || t === "dev" && M(s, "view")) {
2029
+ await ln(n, s);
2030
+ return;
2031
+ }
2032
+ if (t === "cache") {
2033
+ await un(n, s);
2034
+ return;
2035
+ }
2036
+ const { resolved: o } = await de(n);
2037
+ if (t === "seo") {
2038
+ Gs(n, o, s);
1570
2039
  return;
1571
2040
  }
1572
- const { resolved: o } = await $t(s);
1573
2041
  if (t === "lint") {
1574
- await Jt(s, o);
2042
+ await $s(n, o);
1575
2043
  return;
1576
2044
  }
1577
2045
  if (t === "dev") {
1578
- await Nt(s, o);
2046
+ await ls(n, o);
1579
2047
  return;
1580
2048
  }
1581
2049
  if (t === "build") {
1582
- await He(s, o);
2050
+ await pt(n, o);
1583
2051
  return;
1584
2052
  }
1585
2053
  if (t === "guard") {
1586
- Ut(s, o, n);
2054
+ bs(n, o, s);
1587
2055
  return;
1588
2056
  }
1589
2057
  if (t === "modules") {
1590
- await Kt(s, o, n);
2058
+ await Cs(n, o, s);
1591
2059
  return;
1592
2060
  }
1593
2061
  if (t === "export") {
1594
- es(s, o, n);
2062
+ Ne(n, o, s);
1595
2063
  return;
1596
2064
  }
1597
2065
  throw new Error(`[nimpress] unknown command: ${t}`);
1598
2066
  }
1599
2067
  export {
1600
- Pe as buildViteConfig,
1601
- lt as indexHtml,
1602
- $t as loadNimpressConfig,
1603
- ks as run
2068
+ Ke as buildViteConfig,
2069
+ It as indexHtml,
2070
+ de as loadNimpressConfig,
2071
+ jn as run
1604
2072
  };