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