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