@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.
- package/.claude/rules/doc-pages.md +2 -2
- package/.claude/rules/docs-authoring.md +40 -4
- package/.claude/rules/frontmatter.md +30 -2
- package/.claude/rules/page-types.md +52 -0
- package/.claude/rules/style.md +4 -0
- package/.claude/skills/nimpress/SKILL.md +261 -0
- package/dist/cli.es.js +1586 -779
- package/dist/katex-BHBbz4bq.js +11283 -0
- package/dist/nimpress.es.js +7121 -5674
- package/dist/plugin-DOmbMyy0.js +6743 -0
- package/dist/plugin.es.js +11 -3
- package/dist/src/cli/cache.d.ts +2 -0
- package/dist/src/cli/cache.d.ts.map +1 -0
- package/dist/src/cli/completion.d.ts +5 -0
- package/dist/src/cli/completion.d.ts.map +1 -0
- package/dist/src/cli/init.d.ts.map +1 -1
- package/dist/src/cli/lint.d.ts.map +1 -1
- package/dist/src/cli/seo.d.ts +25 -0
- package/dist/src/cli/seo.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/view.d.ts +53 -0
- package/dist/src/cli/view.d.ts.map +1 -0
- package/dist/src/cli.d.ts.map +1 -1
- package/dist/src/config/defaults.d.ts.map +1 -1
- package/dist/src/config/load.d.ts +8 -1
- package/dist/src/config/load.d.ts.map +1 -1
- package/dist/src/config/schema.d.ts +486 -3
- package/dist/src/config/schema.d.ts.map +1 -1
- package/dist/src/feedback/feedback.d.ts +5 -0
- package/dist/src/feedback/feedback.d.ts.map +1 -0
- package/dist/src/framework/configStore.d.ts +3 -1
- package/dist/src/framework/configStore.d.ts.map +1 -1
- package/dist/src/framework/createNimpressApp.d.ts +2 -1
- package/dist/src/framework/createNimpressApp.d.ts.map +1 -1
- package/dist/src/framework/gated.d.ts.map +1 -1
- package/dist/src/framework/hashSpy.d.ts.map +1 -1
- package/dist/src/framework/pageMeta.d.ts.map +1 -1
- package/dist/src/framework/stores/tabs.d.ts +3 -0
- package/dist/src/framework/stores/tabs.d.ts.map +1 -0
- package/dist/src/index.d.ts +15 -7
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/markdown/GlossaryPage.svelte.d.ts +1 -0
- package/dist/src/markdown/Lightbox.svelte.d.ts +1 -0
- package/dist/src/markdown/MathBlock.svelte.d.ts +1 -0
- package/dist/src/markdown/NotFoundPage.svelte.d.ts +1 -0
- package/dist/src/markdown/PricingPage.svelte.d.ts +1 -0
- package/dist/src/markdown/SectionPage.svelte.d.ts +1 -0
- package/dist/src/markdown/Tabs.svelte.d.ts +1 -0
- package/dist/src/markdown/TagsPage.svelte.d.ts +1 -0
- package/dist/src/markdown/TeamPage.svelte.d.ts +1 -0
- package/dist/src/types.d.ts +149 -7
- package/dist/src/types.d.ts.map +1 -1
- package/dist/style.css +1 -1
- package/package.json +12 -2
- package/src/styles/preflight.css +247 -46
- package/src/styles/theme.css +7 -6
- package/src/styles/tokens.css +25 -0
- package/dist/plugin-C3C36uvj.js +0 -3851
- /package/dist/src/{markdown/CalloutCheck.svelte.d.ts → layout/Announce.svelte.d.ts} +0 -0
- /package/dist/src/{markdown/CalloutInfo.svelte.d.ts → layout/Footer.svelte.d.ts} +0 -0
- /package/dist/src/markdown/{CalloutNote.svelte.d.ts → Callout.svelte.d.ts} +0 -0
- /package/dist/src/markdown/{CalloutTip.svelte.d.ts → Feedback.svelte.d.ts} +0 -0
- /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
|
|
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 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
|
-
|
|
26
|
+
s = X(e, { withFileTypes: !0 });
|
|
23
27
|
} catch {
|
|
24
|
-
return
|
|
28
|
+
return t;
|
|
25
29
|
}
|
|
26
|
-
for (const
|
|
27
|
-
const
|
|
28
|
-
if (
|
|
29
|
-
if (
|
|
30
|
-
|
|
31
|
-
} else
|
|
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
|
|
37
|
+
return t;
|
|
34
38
|
}
|
|
35
|
-
function
|
|
36
|
-
if (
|
|
37
|
-
console.error(`${
|
|
38
|
-
for (const
|
|
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(
|
|
45
|
+
console.log(s);
|
|
42
46
|
}
|
|
43
|
-
function
|
|
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(
|
|
57
|
+
title: ${JSON.stringify(J.title)},
|
|
54
58
|
|
|
55
|
-
/** Folder holding the markdown content. Default ${JSON.stringify(
|
|
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(
|
|
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(
|
|
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
|
-
/**
|
|
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
|
|
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
|
|
183
|
+
function ts() {
|
|
147
184
|
return JSON.stringify(
|
|
148
185
|
{
|
|
149
186
|
$schema: "./node_modules/@nimtech/nimpress/config.schema.json",
|
|
150
|
-
title:
|
|
151
|
-
contentDir:
|
|
152
|
-
assetsDir:
|
|
153
|
-
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
|
|
197
|
+
function ss(e) {
|
|
161
198
|
return `# Nimpress project
|
|
162
199
|
|
|
163
|
-
This site is built with @nimtech/nimpress. Content lives in \`${
|
|
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
|
|
203
|
-
const
|
|
204
|
-
|
|
205
|
-
const
|
|
206
|
-
(
|
|
207
|
-
|
|
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
|
|
216
|
-
for (const
|
|
217
|
-
const
|
|
218
|
-
|
|
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
|
|
222
|
-
function
|
|
223
|
-
return `run nimpress modules update ${
|
|
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
|
|
226
|
-
let
|
|
262
|
+
async function is(e) {
|
|
263
|
+
let t;
|
|
227
264
|
try {
|
|
228
|
-
|
|
265
|
+
t = await qt(e, { withFileTypes: !0 });
|
|
229
266
|
} catch {
|
|
230
267
|
return [];
|
|
231
268
|
}
|
|
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
|
-
), f.enum &&
|
|
249
|
-
const
|
|
250
|
-
|
|
251
|
-
`${
|
|
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
|
|
256
|
-
for (const
|
|
257
|
-
|
|
258
|
-
for (const
|
|
259
|
-
|
|
260
|
-
const
|
|
261
|
-
for (const
|
|
262
|
-
|
|
263
|
-
for (const
|
|
264
|
-
|
|
265
|
-
return
|
|
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
|
|
268
|
-
const
|
|
269
|
-
for (const
|
|
270
|
-
const
|
|
271
|
-
if (!
|
|
272
|
-
|
|
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
|
|
276
|
-
for (const
|
|
277
|
-
if (
|
|
278
|
-
const
|
|
279
|
-
|
|
280
|
-
const
|
|
281
|
-
for (const
|
|
282
|
-
let
|
|
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
|
-
|
|
321
|
+
A = await ve(d(m, x), "utf-8");
|
|
285
322
|
} catch {
|
|
286
323
|
continue;
|
|
287
324
|
}
|
|
288
|
-
(/\bharness\s*:/.test(
|
|
289
|
-
for (const
|
|
290
|
-
|
|
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
|
|
293
|
-
if (
|
|
294
|
-
`${f}: component file ${D(
|
|
295
|
-
),
|
|
296
|
-
|
|
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
|
|
300
|
-
if (!
|
|
301
|
-
|
|
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
|
|
341
|
+
let F;
|
|
305
342
|
try {
|
|
306
|
-
|
|
343
|
+
F = await ve(v.path, "utf-8");
|
|
307
344
|
} catch {
|
|
308
|
-
|
|
345
|
+
o.push(`${f}: ${v.form} schema unreadable`);
|
|
309
346
|
continue;
|
|
310
347
|
}
|
|
311
|
-
let
|
|
348
|
+
let E;
|
|
312
349
|
try {
|
|
313
|
-
|
|
350
|
+
E = At(F, v.form);
|
|
314
351
|
} catch {
|
|
315
|
-
|
|
352
|
+
o.push(`${f}: schema is not valid ${v.form}, fix it by hand`);
|
|
316
353
|
continue;
|
|
317
354
|
}
|
|
318
|
-
const
|
|
319
|
-
for (const
|
|
320
|
-
if (!
|
|
321
|
-
for (const
|
|
322
|
-
|
|
323
|
-
const
|
|
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 (
|
|
326
|
-
const
|
|
327
|
-
if (
|
|
328
|
-
const
|
|
329
|
-
|
|
330
|
-
...
|
|
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
|
-
|
|
371
|
+
Rt(Pt(l.component, E, { sourceFile: w?.componentFile, sourceText: T }));
|
|
335
372
|
}
|
|
336
373
|
}
|
|
337
|
-
return
|
|
374
|
+
return Ee(e), o;
|
|
338
375
|
}
|
|
339
|
-
function
|
|
340
|
-
return Object.entries(
|
|
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
|
|
343
|
-
for (const
|
|
379
|
+
async function lt(e, t, s) {
|
|
380
|
+
for (const n of s)
|
|
344
381
|
try {
|
|
345
|
-
await (await
|
|
346
|
-
} catch (
|
|
347
|
-
console.warn(`nimpress modules: harness for ${
|
|
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
|
|
351
|
-
for (const
|
|
352
|
-
await
|
|
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
|
|
355
|
-
const
|
|
356
|
-
await
|
|
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
|
|
359
|
-
const
|
|
360
|
-
|
|
361
|
-
const
|
|
362
|
-
|
|
363
|
-
},
|
|
364
|
-
|
|
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",
|
|
403
|
+
process.once("SIGINT", r), process.once("SIGTERM", r);
|
|
367
404
|
try {
|
|
368
|
-
await
|
|
405
|
+
await nt(Ke({ cwd: e, command: "build", resolved: t, htmlInput: s }));
|
|
369
406
|
} finally {
|
|
370
|
-
process.off("SIGINT",
|
|
371
|
-
}
|
|
372
|
-
await
|
|
373
|
-
}
|
|
374
|
-
const
|
|
375
|
-
function
|
|
376
|
-
const
|
|
377
|
-
if (!
|
|
378
|
-
const
|
|
379
|
-
return !
|
|
380
|
-
if (!
|
|
381
|
-
const { find:
|
|
382
|
-
return typeof
|
|
383
|
-
}) : Object.entries(
|
|
384
|
-
([
|
|
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
|
|
388
|
-
const
|
|
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
|
|
395
|
-
let
|
|
396
|
-
for (;
|
|
431
|
+
for (const n of s) {
|
|
432
|
+
let o;
|
|
433
|
+
for (; o = n.exec(e); ) t.push(o[1]);
|
|
397
434
|
}
|
|
398
|
-
return
|
|
435
|
+
return t;
|
|
399
436
|
}
|
|
400
|
-
function
|
|
401
|
-
return
|
|
402
|
-
const
|
|
403
|
-
if (
|
|
437
|
+
function Be(e) {
|
|
438
|
+
return ps.some((t) => {
|
|
439
|
+
const s = e + t;
|
|
440
|
+
if (!$(s)) return !1;
|
|
404
441
|
try {
|
|
405
|
-
return
|
|
442
|
+
return et(s).isFile();
|
|
406
443
|
} catch {
|
|
407
444
|
return !1;
|
|
408
445
|
}
|
|
409
446
|
});
|
|
410
447
|
}
|
|
411
|
-
function
|
|
412
|
-
const
|
|
413
|
-
for (const
|
|
414
|
-
if (!
|
|
415
|
-
let
|
|
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
|
-
|
|
454
|
+
i = C(r, "utf-8");
|
|
418
455
|
} catch {
|
|
419
456
|
continue;
|
|
420
457
|
}
|
|
421
|
-
const
|
|
422
|
-
for (const
|
|
423
|
-
if (
|
|
424
|
-
|
|
425
|
-
`${
|
|
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
|
|
430
|
-
if (
|
|
431
|
-
const
|
|
432
|
-
|
|
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
|
|
436
|
-
if (
|
|
437
|
-
const
|
|
438
|
-
|
|
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
|
|
479
|
+
return o;
|
|
443
480
|
}
|
|
444
|
-
function
|
|
445
|
-
const
|
|
446
|
-
if (
|
|
447
|
-
const
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
const
|
|
454
|
-
|
|
455
|
-
|
|
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
|
-
|
|
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 (
|
|
462
|
-
const
|
|
463
|
-
|
|
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 (
|
|
466
|
-
const
|
|
467
|
-
|
|
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
|
-
|
|
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 (
|
|
472
|
-
const
|
|
473
|
-
|
|
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,
|
|
477
|
-
const
|
|
478
|
-
let
|
|
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
|
-
|
|
531
|
+
f = X(a);
|
|
481
532
|
} catch {
|
|
482
533
|
continue;
|
|
483
534
|
}
|
|
484
|
-
|
|
485
|
-
for (const
|
|
486
|
-
|
|
487
|
-
if (
|
|
488
|
-
const
|
|
489
|
-
|
|
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
|
|
493
|
-
let
|
|
543
|
+
const u = (a) => {
|
|
544
|
+
let p;
|
|
494
545
|
try {
|
|
495
|
-
|
|
546
|
+
p = X(a, { withFileTypes: !0 });
|
|
496
547
|
} catch {
|
|
497
548
|
return;
|
|
498
549
|
}
|
|
499
|
-
for (const
|
|
500
|
-
if (
|
|
501
|
-
if (!
|
|
502
|
-
const
|
|
503
|
-
|
|
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
|
-
|
|
556
|
+
u(d(a, l.name));
|
|
506
557
|
}
|
|
507
558
|
};
|
|
508
|
-
return
|
|
559
|
+
return u(s), n;
|
|
509
560
|
}
|
|
510
|
-
async function
|
|
511
|
-
const
|
|
512
|
-
|
|
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",
|
|
565
|
+
process.once("SIGINT", o), process.once("SIGTERM", o);
|
|
515
566
|
try {
|
|
516
|
-
return await
|
|
517
|
-
} catch (
|
|
518
|
-
return (
|
|
519
|
-
`).filter((
|
|
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",
|
|
572
|
+
process.off("SIGINT", o), process.off("SIGTERM", o), n();
|
|
522
573
|
}
|
|
523
574
|
}
|
|
524
|
-
async function
|
|
525
|
-
const
|
|
526
|
-
...
|
|
527
|
-
...await
|
|
528
|
-
...
|
|
529
|
-
...await
|
|
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 (
|
|
532
|
-
|
|
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"),
|
|
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
|
|
538
|
-
|
|
588
|
+
const o = await ws(e, t);
|
|
589
|
+
Oe("nimpress lint", o, "nimpress lint: build ok, everything passes");
|
|
539
590
|
}
|
|
540
|
-
const
|
|
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
|
|
554
|
-
const
|
|
555
|
-
if (
|
|
556
|
-
throw new Error(`[nimpress] guard: ${
|
|
557
|
-
const
|
|
558
|
-
if (
|
|
559
|
-
const
|
|
560
|
-
const
|
|
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(
|
|
613
|
+
Object.values(p.routes ?? {}).filter((T) => T.bundle === F && T.gate).map((T) => T.gate)
|
|
563
614
|
)
|
|
564
|
-
],
|
|
615
|
+
], k = C(w);
|
|
565
616
|
return {
|
|
566
|
-
path: `${
|
|
567
|
-
file:
|
|
568
|
-
bundle:
|
|
569
|
-
sha256:
|
|
570
|
-
size:
|
|
571
|
-
mime:
|
|
572
|
-
gates:
|
|
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
|
-
}),
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
JSON.stringify({ ...
|
|
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 ${
|
|
630
|
+
), console.log(`nimpress guard: mapped ${f.length} guarded files to ${g}`);
|
|
580
631
|
return;
|
|
581
632
|
}
|
|
582
|
-
if (
|
|
583
|
-
const
|
|
584
|
-
if (!
|
|
585
|
-
const
|
|
586
|
-
if (!
|
|
587
|
-
|
|
588
|
-
path:
|
|
589
|
-
file:
|
|
590
|
-
bundle:
|
|
591
|
-
asset_id:
|
|
592
|
-
url:
|
|
593
|
-
})),
|
|
594
|
-
`),
|
|
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
|
|
600
|
-
const
|
|
601
|
-
return
|
|
602
|
-
}
|
|
603
|
-
async function
|
|
604
|
-
const
|
|
605
|
-
if (!
|
|
606
|
-
return console.warn(`[nimpress] modules story: no type component page found for ${
|
|
607
|
-
const
|
|
608
|
-
if (!
|
|
609
|
-
return console.warn(`[nimpress] modules story: no source found for ${
|
|
610
|
-
const
|
|
611
|
-
if (!
|
|
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 ${
|
|
664
|
+
`[nimpress] modules story: failed to detect framework for ${c.componentFile}, pass --framework=vue or --framework=svelte`
|
|
614
665
|
);
|
|
615
|
-
const
|
|
666
|
+
const a = u === "vue" ? "vueStory" : "svelteStory", p = `import { ${a} } from '@nimtech/nimpress/story'
|
|
616
667
|
|
|
617
668
|
// story: Default
|
|
618
|
-
export default ${
|
|
669
|
+
export default ${a}({
|
|
619
670
|
name: "Default"
|
|
620
671
|
})
|
|
621
|
-
`,
|
|
622
|
-
return
|
|
623
|
-
}
|
|
624
|
-
async function
|
|
625
|
-
const
|
|
626
|
-
let
|
|
627
|
-
for (const
|
|
628
|
-
if (!(
|
|
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
|
|
631
|
-
} catch (
|
|
632
|
-
console.warn(String(
|
|
681
|
+
await Re(e, t, s, r.component) && o++;
|
|
682
|
+
} catch (c) {
|
|
683
|
+
console.warn(String(c));
|
|
633
684
|
}
|
|
634
|
-
return
|
|
685
|
+
return o;
|
|
635
686
|
}
|
|
636
|
-
async function
|
|
637
|
-
const
|
|
638
|
-
if (!
|
|
639
|
-
const
|
|
640
|
-
if (
|
|
641
|
-
throw new Error(`[nimpress] modules create: ${
|
|
642
|
-
const { mkdir:
|
|
643
|
-
await
|
|
644
|
-
const
|
|
645
|
-
await
|
|
646
|
-
|
|
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: ${
|
|
699
|
+
title: ${n}
|
|
649
700
|
type: component
|
|
650
701
|
data:
|
|
651
|
-
system: ${
|
|
652
|
-
component: ${
|
|
653
|
-
package: "${
|
|
702
|
+
system: ${s}
|
|
703
|
+
component: ${n}${a ? `
|
|
704
|
+
package: "${a}"` : ""}
|
|
654
705
|
---
|
|
655
706
|
|
|
656
707
|
## Usage
|
|
657
708
|
|
|
658
709
|
\`\`\`ts
|
|
659
|
-
import { ${
|
|
710
|
+
import { ${n} } from "${a ?? s}";
|
|
660
711
|
\`\`\`
|
|
661
712
|
`
|
|
662
713
|
);
|
|
663
|
-
const
|
|
664
|
-
if (
|
|
665
|
-
const
|
|
666
|
-
await
|
|
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
|
|
669
|
-
await
|
|
670
|
-
|
|
671
|
-
`import { ${
|
|
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 ${
|
|
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 ${
|
|
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
|
|
734
|
+
return i;
|
|
684
735
|
}
|
|
685
|
-
function
|
|
736
|
+
function ge(e) {
|
|
686
737
|
try {
|
|
687
|
-
return JSON.parse(JSON.stringify(
|
|
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
|
|
693
|
-
let
|
|
743
|
+
function we(e, t = []) {
|
|
744
|
+
let s;
|
|
694
745
|
try {
|
|
695
|
-
|
|
746
|
+
s = X(e, { withFileTypes: !0 });
|
|
696
747
|
} catch {
|
|
697
|
-
return
|
|
698
|
-
}
|
|
699
|
-
for (const
|
|
700
|
-
const
|
|
701
|
-
if (
|
|
702
|
-
if (
|
|
703
|
-
|
|
704
|
-
} else
|
|
705
|
-
}
|
|
706
|
-
return
|
|
707
|
-
}
|
|
708
|
-
function
|
|
709
|
-
return
|
|
710
|
-
}
|
|
711
|
-
function
|
|
712
|
-
const
|
|
713
|
-
`),
|
|
714
|
-
let
|
|
715
|
-
for (;
|
|
716
|
-
const f = o
|
|
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
|
|
719
|
-
for (; !/from\s+["'][^"']+["'];?\s*$/.test(
|
|
720
|
-
|
|
721
|
-
` + o
|
|
722
|
-
|
|
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
|
-
|
|
777
|
+
o++;
|
|
727
778
|
continue;
|
|
728
779
|
}
|
|
729
780
|
break;
|
|
730
781
|
}
|
|
731
|
-
const
|
|
732
|
-
const
|
|
733
|
-
return /\.(vue|svelte)$/.test(f) ? { kind: "source", abs:
|
|
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
|
|
736
|
-
const
|
|
737
|
-
if (!
|
|
738
|
-
const
|
|
739
|
-
|
|
740
|
-
}
|
|
741
|
-
const
|
|
742
|
-
(f) => f.replace(/from\s+["'](\.\.?\/[^"']+)["']/g, (
|
|
743
|
-
const
|
|
744
|
-
return
|
|
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
|
|
799
|
+
let a = t.slice(s.slice(0, o).join(`
|
|
749
800
|
`).length);
|
|
750
|
-
const
|
|
751
|
-
const
|
|
752
|
-
if (
|
|
753
|
-
const
|
|
754
|
-
if (
|
|
755
|
-
|
|
756
|
-
`,
|
|
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
|
|
760
|
-
|
|
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
|
-
|
|
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 (; /^
|
|
765
|
-
|
|
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:
|
|
771
|
-
text:
|
|
772
|
-
title:
|
|
773
|
-
metaComponent:
|
|
774
|
-
imports:
|
|
775
|
-
declarations:
|
|
776
|
-
dataModules:
|
|
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
|
|
780
|
-
const
|
|
781
|
-
let
|
|
782
|
-
for (let
|
|
783
|
-
const
|
|
784
|
-
if (
|
|
785
|
-
|
|
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 (
|
|
789
|
-
|
|
839
|
+
if (i === "'" || i === '"' || i === "`") {
|
|
840
|
+
o = i;
|
|
790
841
|
continue;
|
|
791
842
|
}
|
|
792
|
-
if (
|
|
793
|
-
else if (
|
|
794
|
-
else if (
|
|
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
|
|
847
|
+
return e.slice(s).trim();
|
|
797
848
|
}
|
|
798
|
-
function
|
|
799
|
-
return
|
|
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
|
|
802
|
-
const
|
|
803
|
-
let
|
|
804
|
-
for (;
|
|
805
|
-
const
|
|
806
|
-
if (
|
|
807
|
-
const
|
|
808
|
-
if (
|
|
809
|
-
const
|
|
810
|
-
if (
|
|
811
|
-
|
|
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
|
|
816
|
-
let
|
|
817
|
-
if (
|
|
818
|
-
const
|
|
819
|
-
if (
|
|
820
|
-
const
|
|
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
|
-
|
|
823
|
-
return {${
|
|
873
|
+
u = ge(new Function(`${ft(e.declarations)}
|
|
874
|
+
return {${p}}`)());
|
|
824
875
|
} catch {
|
|
825
876
|
try {
|
|
826
|
-
|
|
877
|
+
u = ge(new Function(`return {${p}}`)());
|
|
827
878
|
} catch {
|
|
828
|
-
|
|
879
|
+
u = {};
|
|
829
880
|
}
|
|
830
881
|
}
|
|
831
882
|
}
|
|
832
883
|
}
|
|
833
|
-
|
|
884
|
+
t.push({ name: o, props: u });
|
|
834
885
|
}
|
|
835
|
-
return
|
|
886
|
+
return t;
|
|
836
887
|
}
|
|
837
|
-
function
|
|
838
|
-
const
|
|
839
|
-
if (
|
|
840
|
-
const
|
|
841
|
-
let
|
|
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
|
-
|
|
894
|
+
o = ge(new Function(`return {${n}}`)());
|
|
844
895
|
} catch {
|
|
845
896
|
try {
|
|
846
|
-
|
|
847
|
-
new Function(`${
|
|
848
|
-
return {${
|
|
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
|
|
855
|
-
for (const [
|
|
856
|
-
if (!
|
|
857
|
-
const
|
|
858
|
-
typeof
|
|
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(
|
|
911
|
+
return Object.keys(r).length ? r : void 0;
|
|
861
912
|
}
|
|
862
|
-
async function
|
|
863
|
-
const
|
|
864
|
-
for (let
|
|
865
|
-
console.log(`${String(
|
|
866
|
-
const
|
|
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
|
-
|
|
870
|
-
const
|
|
871
|
-
if (!
|
|
872
|
-
const
|
|
873
|
-
for (const
|
|
874
|
-
const
|
|
875
|
-
if (
|
|
876
|
-
const
|
|
877
|
-
for (const
|
|
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(
|
|
881
|
-
const
|
|
882
|
-
|
|
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
|
|
936
|
+
for (const u of t) u === i && r.add(u);
|
|
886
937
|
}
|
|
887
|
-
return
|
|
938
|
+
return r;
|
|
888
939
|
}
|
|
889
|
-
function
|
|
890
|
-
const
|
|
891
|
-
if (
|
|
892
|
-
const
|
|
893
|
-
for (const
|
|
894
|
-
|
|
895
|
-
return
|
|
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
|
|
898
|
-
const
|
|
899
|
-
if (!
|
|
900
|
-
const
|
|
901
|
-
if (
|
|
902
|
-
const
|
|
903
|
-
if (
|
|
904
|
-
if (
|
|
905
|
-
throw new Error(`[nimpress] modules import: ${
|
|
906
|
-
const
|
|
907
|
-
await
|
|
908
|
-
const
|
|
909
|
-
await
|
|
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 (
|
|
913
|
-
await
|
|
963
|
+
if (n.fromStories) {
|
|
964
|
+
await js(e, t, s, n);
|
|
914
965
|
return;
|
|
915
966
|
}
|
|
916
|
-
const
|
|
917
|
-
if (
|
|
918
|
-
throw new Error(`[nimpress] modules import: source ${
|
|
919
|
-
const
|
|
920
|
-
for (const
|
|
921
|
-
for (const
|
|
922
|
-
|
|
923
|
-
const
|
|
924
|
-
(
|
|
925
|
-
),
|
|
926
|
-
for (const
|
|
927
|
-
const
|
|
928
|
-
if (
|
|
929
|
-
const [
|
|
930
|
-
|
|
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
|
|
933
|
-
let
|
|
934
|
-
if (!
|
|
935
|
-
let
|
|
936
|
-
for (const
|
|
937
|
-
|
|
938
|
-
|
|
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
|
|
941
|
-
|
|
942
|
-
}
|
|
943
|
-
const
|
|
944
|
-
let
|
|
945
|
-
const
|
|
946
|
-
for (const
|
|
947
|
-
const
|
|
948
|
-
if (
|
|
949
|
-
if (
|
|
950
|
-
console.warn(`nimpress modules: skip duplicate ${
|
|
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
|
-
|
|
954
|
-
const
|
|
955
|
-
await
|
|
956
|
-
const
|
|
957
|
-
(
|
|
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
|
|
961
|
-
const
|
|
962
|
-
for (const
|
|
963
|
-
const
|
|
964
|
-
|
|
965
|
-
for (const
|
|
966
|
-
await
|
|
967
|
-
for (const
|
|
968
|
-
const
|
|
969
|
-
let
|
|
970
|
-
|
|
971
|
-
const
|
|
972
|
-
|
|
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 ${
|
|
1027
|
+
console.log(`nimpress modules: imported ${k} components with ${T} stories for ${s}`);
|
|
977
1028
|
}
|
|
978
|
-
async function
|
|
979
|
-
const
|
|
980
|
-
if (!
|
|
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
|
|
983
|
-
let
|
|
984
|
-
const f =
|
|
985
|
-
f.map((
|
|
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
|
|
988
|
-
const
|
|
989
|
-
if (
|
|
990
|
-
const
|
|
991
|
-
new RegExp(`import\\s+(?:\\{\\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
|
|
994
|
-
if (
|
|
995
|
-
const
|
|
996
|
-
|
|
997
|
-
} else if (
|
|
998
|
-
const
|
|
999
|
-
|
|
1000
|
-
} else if (
|
|
1001
|
-
const
|
|
1002
|
-
|
|
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 (
|
|
1005
|
-
if (
|
|
1006
|
-
console.warn(`nimpress modules: skip duplicate ${
|
|
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
|
-
|
|
1010
|
-
const
|
|
1011
|
-
await
|
|
1012
|
-
const
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
]).find((
|
|
1016
|
-
if (
|
|
1017
|
-
await
|
|
1018
|
-
else if (
|
|
1019
|
-
const
|
|
1020
|
-
|
|
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
|
|
1023
|
-
|
|
1024
|
-
for (const
|
|
1025
|
-
await
|
|
1026
|
-
for (const
|
|
1027
|
-
const
|
|
1028
|
-
|
|
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 ${
|
|
1082
|
+
console.log(`nimpress modules: imported ${l} components with ${m} stories for ${s} from stories`);
|
|
1032
1083
|
}
|
|
1033
|
-
function
|
|
1034
|
-
const
|
|
1035
|
-
package: "${
|
|
1036
|
-
file: ${JSON.stringify(
|
|
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: ${
|
|
1089
|
+
title: ${t}
|
|
1039
1090
|
type: component
|
|
1040
1091
|
data:
|
|
1041
|
-
system: ${
|
|
1042
|
-
component: ${
|
|
1092
|
+
system: ${e}
|
|
1093
|
+
component: ${t}${o}${r}
|
|
1043
1094
|
---
|
|
1044
1095
|
|
|
1045
1096
|
## Usage
|
|
1046
1097
|
|
|
1047
1098
|
\`\`\`ts
|
|
1048
|
-
import { ${
|
|
1099
|
+
import { ${t} } from "${s ?? e}";
|
|
1049
1100
|
\`\`\`
|
|
1050
1101
|
`;
|
|
1051
1102
|
}
|
|
1052
|
-
function
|
|
1053
|
-
const
|
|
1054
|
-
return
|
|
1055
|
-
${
|
|
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
|
-
${
|
|
1108
|
+
${o.declarations}
|
|
1058
1109
|
|
|
1059
|
-
// story: ${
|
|
1060
|
-
export default ${
|
|
1061
|
-
name: ${JSON.stringify(
|
|
1062
|
-
description: ${JSON.stringify(`Scenario from ${
|
|
1063
|
-
render: ${
|
|
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 { ${
|
|
1116
|
+
` : `import { ${r} } from '@nimtech/nimpress/story'
|
|
1066
1117
|
|
|
1067
|
-
// story: ${
|
|
1068
|
-
export default ${
|
|
1069
|
-
name: ${JSON.stringify(
|
|
1070
|
-
props: ${JSON.stringify(
|
|
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
|
|
1075
|
-
const
|
|
1076
|
-
if (
|
|
1077
|
-
const
|
|
1078
|
-
if (!
|
|
1079
|
-
throw new Error(`[nimpress] modules: unknown system ${
|
|
1080
|
-
return
|
|
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
|
|
1083
|
-
const s =
|
|
1084
|
-
if (
|
|
1085
|
-
|
|
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 (
|
|
1098
|
-
const
|
|
1099
|
-
if (!
|
|
1100
|
-
await
|
|
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 (
|
|
1104
|
-
const
|
|
1105
|
-
if (!
|
|
1106
|
-
await
|
|
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 (
|
|
1110
|
-
const
|
|
1111
|
-
|
|
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 (
|
|
1115
|
-
const
|
|
1116
|
-
if (
|
|
1117
|
-
const
|
|
1118
|
-
|
|
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
|
|
1122
|
-
console.log(`nimpress modules: ${
|
|
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 (
|
|
1126
|
-
const
|
|
1127
|
-
await
|
|
1128
|
-
file:
|
|
1129
|
-
name:
|
|
1130
|
-
source:
|
|
1131
|
-
stories:
|
|
1132
|
-
match:
|
|
1133
|
-
fromStories:
|
|
1134
|
-
select:
|
|
1135
|
-
}),
|
|
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 (
|
|
1139
|
-
const
|
|
1140
|
-
console.log(`nimpress modules: ${
|
|
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 (
|
|
1144
|
-
const
|
|
1145
|
-
if (
|
|
1146
|
-
if (
|
|
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
|
|
1149
|
-
console.log(`nimpress modules: schema upserted at ${
|
|
1199
|
+
const l = await Ut(e, t, i);
|
|
1200
|
+
console.log(`nimpress modules: schema upserted at ${l}`);
|
|
1150
1201
|
return;
|
|
1151
1202
|
}
|
|
1152
|
-
const
|
|
1153
|
-
if (!
|
|
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
|
|
1156
|
-
console.log(`nimpress modules: created ${
|
|
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
|
|
1162
|
-
const
|
|
1163
|
-
|
|
1164
|
-
const
|
|
1165
|
-
if (
|
|
1166
|
-
const
|
|
1167
|
-
|
|
1168
|
-
`), console.log(`nimpress modules: modules block added to ${
|
|
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 ${
|
|
1222
|
+
console.log(`nimpress modules: folder ready at ${s}`);
|
|
1172
1223
|
}
|
|
1173
|
-
function
|
|
1174
|
-
if (!
|
|
1224
|
+
function yt(e) {
|
|
1225
|
+
if (!e.startsWith(`---
|
|
1175
1226
|
`)) return null;
|
|
1176
|
-
const
|
|
1227
|
+
const t = e.indexOf(`
|
|
1177
1228
|
---`, 4);
|
|
1178
|
-
return
|
|
1229
|
+
return t < 0 ? null : e.slice(4, t);
|
|
1179
1230
|
}
|
|
1180
|
-
function
|
|
1181
|
-
for (const
|
|
1231
|
+
function Fs(e) {
|
|
1232
|
+
for (const t of e.split(`
|
|
1182
1233
|
`)) {
|
|
1183
|
-
if (!
|
|
1184
|
-
const
|
|
1185
|
-
return
|
|
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
|
|
1190
|
-
const
|
|
1191
|
-
if (
|
|
1192
|
-
const
|
|
1193
|
-
`).filter((
|
|
1194
|
-
return
|
|
1195
|
-
${
|
|
1196
|
-
`)}${
|
|
1197
|
-
}
|
|
1198
|
-
function
|
|
1199
|
-
const
|
|
1200
|
-
let
|
|
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
|
-
|
|
1253
|
+
i = JSON.parse(C(d(e, "package.json"), "utf-8")).version ?? "";
|
|
1203
1254
|
} catch {
|
|
1204
|
-
|
|
1205
|
-
}
|
|
1206
|
-
let
|
|
1207
|
-
for (const
|
|
1208
|
-
if (!
|
|
1209
|
-
const
|
|
1210
|
-
if (
|
|
1211
|
-
const
|
|
1212
|
-
if (
|
|
1213
|
-
const
|
|
1214
|
-
|
|
1215
|
-
for (const
|
|
1216
|
-
if (!
|
|
1217
|
-
const
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
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
|
-
|
|
1234
|
-
|
|
1235
|
-
await Ot(s, n);
|
|
2041
|
+
if (t === "lint") {
|
|
2042
|
+
await $s(n, o);
|
|
1236
2043
|
return;
|
|
1237
2044
|
}
|
|
1238
|
-
if (
|
|
1239
|
-
await
|
|
2045
|
+
if (t === "dev") {
|
|
2046
|
+
await ls(n, o);
|
|
1240
2047
|
return;
|
|
1241
2048
|
}
|
|
1242
|
-
if (
|
|
1243
|
-
await
|
|
2049
|
+
if (t === "build") {
|
|
2050
|
+
await pt(n, o);
|
|
1244
2051
|
return;
|
|
1245
2052
|
}
|
|
1246
|
-
if (
|
|
1247
|
-
|
|
2053
|
+
if (t === "guard") {
|
|
2054
|
+
bs(n, o, s);
|
|
1248
2055
|
return;
|
|
1249
2056
|
}
|
|
1250
|
-
if (
|
|
1251
|
-
await
|
|
2057
|
+
if (t === "modules") {
|
|
2058
|
+
await Cs(n, o, s);
|
|
1252
2059
|
return;
|
|
1253
2060
|
}
|
|
1254
|
-
if (
|
|
1255
|
-
|
|
2061
|
+
if (t === "export") {
|
|
2062
|
+
Ne(n, o, s);
|
|
1256
2063
|
return;
|
|
1257
2064
|
}
|
|
1258
|
-
throw new Error(`[nimpress] unknown command: ${
|
|
2065
|
+
throw new Error(`[nimpress] unknown command: ${t}`);
|
|
1259
2066
|
}
|
|
1260
2067
|
export {
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
2068
|
+
Ke as buildViteConfig,
|
|
2069
|
+
It as indexHtml,
|
|
2070
|
+
de as loadNimpressConfig,
|
|
2071
|
+
jn as run
|
|
1265
2072
|
};
|