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