@nimtech/nimpress 2.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (223) hide show
  1. package/.claude/rules/changelog-entries.md +229 -0
  2. package/.claude/rules/chunk-cycles.md +23 -0
  3. package/.claude/rules/component-modules.md +152 -0
  4. package/.claude/rules/dbml-pages.md +118 -0
  5. package/.claude/rules/deploy.md +47 -0
  6. package/.claude/rules/doc-pages.md +93 -0
  7. package/.claude/rules/docs-authoring.md +90 -0
  8. package/.claude/rules/docs-sync.md +59 -0
  9. package/.claude/rules/file-layout.md +49 -0
  10. package/.claude/rules/frontmatter.md +91 -0
  11. package/.claude/rules/page-types.md +108 -0
  12. package/.claude/rules/paths.md +27 -0
  13. package/.claude/rules/roadmap-entries.md +154 -0
  14. package/.claude/rules/style.md +61 -0
  15. package/LICENSE +201 -0
  16. package/README.md +137 -0
  17. package/bin/nimpress.mjs +7 -0
  18. package/config.schema.json +555 -0
  19. package/dist/DbmlNote-CTwTd5vM.js +21 -0
  20. package/dist/DbmlTable-BXIyJnLV.js +209 -0
  21. package/dist/cli.es.js +1265 -0
  22. package/dist/nimpress.es.js +8896 -0
  23. package/dist/plugin-DQtunTIv.js +8268 -0
  24. package/dist/plugin.es.js +23 -0
  25. package/dist/src/api/CodeExamples.svelte.d.ts +1 -0
  26. package/dist/src/api/MethodBadge.svelte.d.ts +1 -0
  27. package/dist/src/api/OpenApiRoot.svelte.d.ts +1 -0
  28. package/dist/src/api/Operation.svelte.d.ts +1 -0
  29. package/dist/src/api/ParamRow.svelte.d.ts +1 -0
  30. package/dist/src/api/Schema.svelte.d.ts +1 -0
  31. package/dist/src/api/TryDialog.svelte.d.ts +1 -0
  32. package/dist/src/api/TryPanel.svelte.d.ts +1 -0
  33. package/dist/src/api/refs.d.ts +12 -0
  34. package/dist/src/api/refs.d.ts.map +1 -0
  35. package/dist/src/api/tryState.d.ts +21 -0
  36. package/dist/src/api/tryState.d.ts.map +1 -0
  37. package/dist/src/api/types.d.ts +63 -0
  38. package/dist/src/api/types.d.ts.map +1 -0
  39. package/dist/src/auth/AccountMenu.svelte.d.ts +1 -0
  40. package/dist/src/auth/guard.d.ts +5 -0
  41. package/dist/src/auth/guard.d.ts.map +1 -0
  42. package/dist/src/auth/session.d.ts +8 -0
  43. package/dist/src/auth/session.d.ts.map +1 -0
  44. package/dist/src/banner.d.ts +23 -0
  45. package/dist/src/banner.d.ts.map +1 -0
  46. package/dist/src/cli/export.d.ts +4 -0
  47. package/dist/src/cli/export.d.ts.map +1 -0
  48. package/dist/src/cli/guard.d.ts +3 -0
  49. package/dist/src/cli/guard.d.ts.map +1 -0
  50. package/dist/src/cli/init.d.ts +2 -0
  51. package/dist/src/cli/init.d.ts.map +1 -0
  52. package/dist/src/cli/lint.d.ts +11 -0
  53. package/dist/src/cli/lint.d.ts.map +1 -0
  54. package/dist/src/cli/modules.d.ts +3 -0
  55. package/dist/src/cli/modules.d.ts.map +1 -0
  56. package/dist/src/cli/shared.d.ts +6 -0
  57. package/dist/src/cli/shared.d.ts.map +1 -0
  58. package/dist/src/cli/site.d.ts +7 -0
  59. package/dist/src/cli/site.d.ts.map +1 -0
  60. package/dist/src/cli.d.ts +5 -0
  61. package/dist/src/cli.d.ts.map +1 -0
  62. package/dist/src/config/base.d.ts +4 -0
  63. package/dist/src/config/base.d.ts.map +1 -0
  64. package/dist/src/config/chunkCycles.d.ts +10 -0
  65. package/dist/src/config/chunkCycles.d.ts.map +1 -0
  66. package/dist/src/config/defaults.d.ts +4 -0
  67. package/dist/src/config/defaults.d.ts.map +1 -0
  68. package/dist/src/config/html.d.ts +3 -0
  69. package/dist/src/config/html.d.ts.map +1 -0
  70. package/dist/src/config/load.d.ts +20 -0
  71. package/dist/src/config/load.d.ts.map +1 -0
  72. package/dist/src/config/paths.d.ts +8 -0
  73. package/dist/src/config/paths.d.ts.map +1 -0
  74. package/dist/src/config/schema.d.ts +1238 -0
  75. package/dist/src/config/schema.d.ts.map +1 -0
  76. package/dist/src/config/viteConfig.d.ts +11 -0
  77. package/dist/src/config/viteConfig.d.ts.map +1 -0
  78. package/dist/src/dbml/erd.d.ts +59 -0
  79. package/dist/src/dbml/erd.d.ts.map +1 -0
  80. package/dist/src/framework/configStore.d.ts +7 -0
  81. package/dist/src/framework/configStore.d.ts.map +1 -0
  82. package/dist/src/framework/createNimpressApp.d.ts +10 -0
  83. package/dist/src/framework/createNimpressApp.d.ts.map +1 -0
  84. package/dist/src/framework/gated.d.ts +5 -0
  85. package/dist/src/framework/gated.d.ts.map +1 -0
  86. package/dist/src/framework/hashSpy.d.ts +7 -0
  87. package/dist/src/framework/hashSpy.d.ts.map +1 -0
  88. package/dist/src/framework/pageMeta.d.ts +4 -0
  89. package/dist/src/framework/pageMeta.d.ts.map +1 -0
  90. package/dist/src/framework/pageStyles.d.ts +2 -0
  91. package/dist/src/framework/pageStyles.d.ts.map +1 -0
  92. package/dist/src/framework/router.d.ts +5 -0
  93. package/dist/src/framework/router.d.ts.map +1 -0
  94. package/dist/src/framework/stores/feed.d.ts +8 -0
  95. package/dist/src/framework/stores/feed.d.ts.map +1 -0
  96. package/dist/src/framework/stores/sidebar.d.ts +4 -0
  97. package/dist/src/framework/stores/sidebar.d.ts.map +1 -0
  98. package/dist/src/framework/stores/theme.d.ts +6 -0
  99. package/dist/src/framework/stores/theme.d.ts.map +1 -0
  100. package/dist/src/framework/stores/viewer.d.ts +6 -0
  101. package/dist/src/framework/stores/viewer.d.ts.map +1 -0
  102. package/dist/src/icons/FullscreenIcon.svelte.d.ts +1 -0
  103. package/dist/src/icons/IconAdd.svelte.d.ts +1 -0
  104. package/dist/src/icons/IconChevron.svelte.d.ts +1 -0
  105. package/dist/src/icons/IconClear.svelte.d.ts +1 -0
  106. package/dist/src/icons/IconConsole.svelte.d.ts +1 -0
  107. package/dist/src/icons/IconDock.svelte.d.ts +1 -0
  108. package/dist/src/icons/IconDownload.svelte.d.ts +1 -0
  109. package/dist/src/icons/IconJson.svelte.d.ts +1 -0
  110. package/dist/src/icons/IconMinus.svelte.d.ts +1 -0
  111. package/dist/src/icons/IconMock.svelte.d.ts +1 -0
  112. package/dist/src/icons/IconMoon.svelte.d.ts +1 -0
  113. package/dist/src/icons/IconOpen.svelte.d.ts +1 -0
  114. package/dist/src/icons/IconReload.svelte.d.ts +1 -0
  115. package/dist/src/icons/IconRemove.svelte.d.ts +1 -0
  116. package/dist/src/icons/IconShadow.svelte.d.ts +1 -0
  117. package/dist/src/icons/IconSun.svelte.d.ts +1 -0
  118. package/dist/src/index.d.ts +44 -0
  119. package/dist/src/index.d.ts.map +1 -0
  120. package/dist/src/layout/App.svelte.d.ts +1 -0
  121. package/dist/src/layout/AppRoot.svelte.d.ts +1 -0
  122. package/dist/src/layout/BackToTop.svelte.d.ts +1 -0
  123. package/dist/src/layout/Breadcrumbs.svelte.d.ts +1 -0
  124. package/dist/src/layout/GatedPage.svelte.d.ts +1 -0
  125. package/dist/src/layout/Header.svelte.d.ts +1 -0
  126. package/dist/src/layout/HomePage.svelte.d.ts +1 -0
  127. package/dist/src/layout/RightToc.svelte.d.ts +1 -0
  128. package/dist/src/layout/Sidebar.svelte.d.ts +1 -0
  129. package/dist/src/layout/SidebarNode.svelte.d.ts +1 -0
  130. package/dist/src/markdown/Actions.svelte.d.ts +1 -0
  131. package/dist/src/markdown/CalloutCheck.svelte.d.ts +1 -0
  132. package/dist/src/markdown/CalloutInfo.svelte.d.ts +1 -0
  133. package/dist/src/markdown/CalloutNote.svelte.d.ts +1 -0
  134. package/dist/src/markdown/CalloutTip.svelte.d.ts +1 -0
  135. package/dist/src/markdown/CalloutWarning.svelte.d.ts +1 -0
  136. package/dist/src/markdown/Card.svelte.d.ts +1 -0
  137. package/dist/src/markdown/CardGroup.svelte.d.ts +1 -0
  138. package/dist/src/markdown/ChangelogPage.svelte.d.ts +1 -0
  139. package/dist/src/markdown/CodeBlock.svelte.d.ts +1 -0
  140. package/dist/src/markdown/CodeEditor.svelte.d.ts +1 -0
  141. package/dist/src/markdown/CodeGroup.svelte.d.ts +1 -0
  142. package/dist/src/markdown/ComponentEmbed.svelte.d.ts +1 -0
  143. package/dist/src/markdown/ComponentPage.svelte.d.ts +1 -0
  144. package/dist/src/markdown/ControlNode.svelte.d.ts +1 -0
  145. package/dist/src/markdown/DBMLBlock.svelte.d.ts +1 -0
  146. package/dist/src/markdown/DbmlNote.svelte.d.ts +1 -0
  147. package/dist/src/markdown/DbmlPage.svelte.d.ts +1 -0
  148. package/dist/src/markdown/DbmlTable.svelte.d.ts +1 -0
  149. package/dist/src/markdown/DragDivider.svelte.d.ts +1 -0
  150. package/dist/src/markdown/Feature.svelte.d.ts +1 -0
  151. package/dist/src/markdown/FeatureGrid.svelte.d.ts +1 -0
  152. package/dist/src/markdown/HeroPage.svelte.d.ts +1 -0
  153. package/dist/src/markdown/MermaidBlock.svelte.d.ts +1 -0
  154. package/dist/src/markdown/Page.svelte.d.ts +1 -0
  155. package/dist/src/markdown/PlanetFooter.svelte.d.ts +1 -0
  156. package/dist/src/markdown/RoadmapBlob.svelte.d.ts +1 -0
  157. package/dist/src/markdown/RoadmapNode.svelte.d.ts +1 -0
  158. package/dist/src/markdown/RoadmapPage.svelte.d.ts +1 -0
  159. package/dist/src/markdown/SubscribeDialog.svelte.d.ts +1 -0
  160. package/dist/src/mock/index.d.ts +42 -0
  161. package/dist/src/mock/index.d.ts.map +1 -0
  162. package/dist/src/modules/autoStory.d.ts +5 -0
  163. package/dist/src/modules/autoStory.d.ts.map +1 -0
  164. package/dist/src/modules/componentData.d.ts +14 -0
  165. package/dist/src/modules/componentData.d.ts.map +1 -0
  166. package/dist/src/modules/harness.d.ts +25 -0
  167. package/dist/src/modules/harness.d.ts.map +1 -0
  168. package/dist/src/modules/importStorybook.d.ts +12 -0
  169. package/dist/src/modules/importStorybook.d.ts.map +1 -0
  170. package/dist/src/modules/lint.d.ts +3 -0
  171. package/dist/src/modules/lint.d.ts.map +1 -0
  172. package/dist/src/modules/pages.d.ts +10 -0
  173. package/dist/src/modules/pages.d.ts.map +1 -0
  174. package/dist/src/modules/parse/dts.d.ts +4 -0
  175. package/dist/src/modules/parse/dts.d.ts.map +1 -0
  176. package/dist/src/modules/parse/svelte.d.ts +3 -0
  177. package/dist/src/modules/parse/svelte.d.ts.map +1 -0
  178. package/dist/src/modules/parse/typeMembers.d.ts +64 -0
  179. package/dist/src/modules/parse/typeMembers.d.ts.map +1 -0
  180. package/dist/src/modules/parse/vue.d.ts +3 -0
  181. package/dist/src/modules/parse/vue.d.ts.map +1 -0
  182. package/dist/src/modules/resolve.d.ts +9 -0
  183. package/dist/src/modules/resolve.d.ts.map +1 -0
  184. package/dist/src/modules/schema.d.ts +53 -0
  185. package/dist/src/modules/schema.d.ts.map +1 -0
  186. package/dist/src/modules/stories.d.ts +4 -0
  187. package/dist/src/modules/stories.d.ts.map +1 -0
  188. package/dist/src/search/SearchModal.svelte.d.ts +1 -0
  189. package/dist/src/search/indexer.d.ts +5 -0
  190. package/dist/src/search/indexer.d.ts.map +1 -0
  191. package/dist/src/story/index.d.ts +17 -0
  192. package/dist/src/story/index.d.ts.map +1 -0
  193. package/dist/src/subscribe/subscribe.d.ts +5 -0
  194. package/dist/src/subscribe/subscribe.d.ts.map +1 -0
  195. package/dist/src/types.d.ts +531 -0
  196. package/dist/src/types.d.ts.map +1 -0
  197. package/dist/story.es.js +10 -0
  198. package/dist/style.css +1 -0
  199. package/dist/tailwind.preset.d.ts +4 -0
  200. package/dist/tailwind.preset.d.ts.map +1 -0
  201. package/dist/tailwind.preset.es.js +67 -0
  202. package/dist/typeMembers-CNvE92EX.js +538 -0
  203. package/package.json +125 -0
  204. package/src/harness/svelte/ComponentHarness.svelte +12 -0
  205. package/src/harness/svelte/ComponentHarnessEffects.svelte +24 -0
  206. package/src/harness/svelte/ComponentHarnessOverlay.svelte +9 -0
  207. package/src/harness/svelte/ComponentStory.svelte +9 -0
  208. package/src/harness/svelte/DefaultHarness.svelte +15 -0
  209. package/src/harness/svelte/HarnessRoot.svelte +22 -0
  210. package/src/harness/svelte/context.svelte.ts +33 -0
  211. package/src/harness/svelte/index.ts +12 -0
  212. package/src/harness/vue/ComponentHarness.vue +16 -0
  213. package/src/harness/vue/ComponentHarnessEffects.vue +27 -0
  214. package/src/harness/vue/ComponentHarnessOverlay.vue +12 -0
  215. package/src/harness/vue/ComponentStory.vue +16 -0
  216. package/src/harness/vue/DefaultHarness.vue +14 -0
  217. package/src/harness/vue/context.ts +37 -0
  218. package/src/harness/vue/index.ts +11 -0
  219. package/src/mock/index.ts +88 -0
  220. package/src/styles/app.css +3 -0
  221. package/src/styles/preflight.css +540 -0
  222. package/src/styles/theme.css +81 -0
  223. package/src/styles/tokens.css +150 -0
package/dist/cli.es.js ADDED
@@ -0,0 +1,1265 @@
1
+ import { d as R, c as he, r as ge, s as Ue, p as Ve, a as Fe, b as Q, e as qe, f as Ke, g as le, h as De, i as Qe, j as Ce, k as Xe, l as Ye, m as et, n as Se, w as X, o as Oe, q as tt, t as st, u as nt, v as ot, x as rt } from "./plugin-DQtunTIv.js";
2
+ import { join as h, dirname as z, relative as D, sep as U, extname as Y, resolve as T, basename as F } from "node:path";
3
+ import { readdirSync as q, existsSync as b, writeFileSync as L, mkdirSync as ye, rmSync as ne, readFileSync as J, statSync as Ee } from "node:fs";
4
+ import it from "gray-matter";
5
+ import { readFile as ae, readdir as at, writeFile as Z, mkdir as me, copyFile as Ne } from "node:fs/promises";
6
+ import { s as ct, r as oe } from "./typeMembers-CNvE92EX.js";
7
+ import { createServer as We, build as Ae } from "vite";
8
+ import { createHash as lt } from "node:crypto";
9
+ import { createInterface as mt } from "node:readline/promises";
10
+ function A(t, e) {
11
+ return t.find((s) => s.startsWith(`--${e}=`))?.slice(e.length + 3);
12
+ }
13
+ function $e(t, e) {
14
+ return t.includes(`--${e}`);
15
+ }
16
+ function se(t, e) {
17
+ return t.filter((s) => !s.startsWith("--"))[e];
18
+ }
19
+ function ee(t, e = []) {
20
+ let o;
21
+ try {
22
+ o = q(t, { withFileTypes: !0 });
23
+ } catch {
24
+ return e;
25
+ }
26
+ for (const s of o) {
27
+ const n = h(t, s.name);
28
+ if (s.isDirectory()) {
29
+ if (s.name === "node_modules" || s.name.startsWith(".")) continue;
30
+ ee(n, e);
31
+ } else s.isFile() && e.push(n);
32
+ }
33
+ return e;
34
+ }
35
+ function ue(t, e, o) {
36
+ if (e.length) {
37
+ console.error(`${t} failed with ${e.length} problems`);
38
+ for (const s of e) console.error(` ${s}`);
39
+ process.exit(1);
40
+ }
41
+ console.log(o);
42
+ }
43
+ function ut() {
44
+ return `import { defineConfig } from '@nimtech/nimpress/plugin'
45
+
46
+ /**
47
+ * Every field has a default, so a config can be as small as a title.
48
+ * Hover any field for its full description and an example, the types
49
+ * ship with @nimtech/nimpress. Uncomment what you need.
50
+ */
51
+ export default defineConfig({
52
+ /** Site title shown in the header and the tab. */
53
+ title: ${JSON.stringify(R.title)},
54
+
55
+ /** Folder holding the markdown content. Default ${JSON.stringify(R.contentDir)}. */
56
+ // contentDir: 'docs',
57
+
58
+ /** Root assets folder copied into the build, never inside contentDir. Default ${JSON.stringify(R.assetsDir)}. */
59
+ // assetsDir: 'assets',
60
+
61
+ /** Url base the assets folder serves under. Default ${JSON.stringify(R.assetUrlBase)}. */
62
+ // assetUrlBase: '/assets',
63
+
64
+ /**
65
+ * Build output, cache, export, and served route folders. Every field is optional.
66
+ * out is the build root, cache is the layered cache root under node_modules,
67
+ * export is where the export command collects pages, modules and guarded are the
68
+ * folders under out and the url route segments for the harness bundles and the
69
+ * guarded content.
70
+ */
71
+ // paths: { out: 'dist', cache: 'node_modules/.nimpress', export: '.nimpress', modules: '_components', guarded: '_guarded' },
72
+
73
+ /** Header logo url. @example "/assets/logo.svg" */
74
+ // logo: '/assets/logo.svg',
75
+
76
+ /** Repository url rendered as the header GitHub link. */
77
+ // github: 'https://github.com/nimling/nimpress',
78
+
79
+ /** Brand colors written onto the theme tokens --np-brand and --np-brand-hover. */
80
+ // brand: { primary: '#CC785C', primaryHover: '#B86A52' },
81
+
82
+ /** Site wide footer line, overridable per page with the footer frontmatter field. */
83
+ // footer: 'Made with nimpress',
84
+
85
+ /** Extra header navigation routes. gate hides an entry from viewers that fail the check. */
86
+ // navRoutes: [{ text: 'API', link: '/api' }],
87
+
88
+ /** Canonical site identity used for absolute urls, sitemap, feeds, and social cards. */
89
+ // site: { title: 'Docs', url: 'https://developer.example.io', description: 'One sentence.' },
90
+
91
+ /** SEO, robots, llms.txt, webmanifest, and security.txt emission. */
92
+ // meta: { keywords: ['docs'], llms: { full: true } },
93
+
94
+ /**
95
+ * OAuth 2.0 session login. The guard function runs at build time, once per page
96
+ * carrying a gate frontmatter value; the returned string names the guarded bundle
97
+ * the page lands in under dist/_guarded/<name>/. Without it the gate value is the
98
+ * bundle name.
99
+ */
100
+ // auth: {
101
+ // issuer: 'https://auth.example.io',
102
+ // clientId: 'my-docs',
103
+ // guard: (frontmatter, filePath, relatedFiles) => frontmatter.gate ?? 'default'
104
+ // },
105
+
106
+ /** Path to a client module exporting authFunctions and subscribeFunctions. */
107
+ // client: './docs/client.ts',
108
+
109
+ /** Changelog subscription wiring. */
110
+ // subscribe: { endpoint: 'https://auth.example.io/api/subscribe', appSlug: 'my-docs' },
111
+
112
+ /** Slug prefixes excluded from the site. */
113
+ // exclude: ['drafts'],
114
+
115
+ /** Frontmatter defaults applied to every page that leaves the field unset. */
116
+ // defaultFrontmatter: { lastUpdated: true },
117
+
118
+ /** Path prefixes the frontmatter defaults skip. */
119
+ // defaultFrontmatterExclude: ['/api'],
120
+
121
+ /** Dev server banner, false disables it. */
122
+ // banner: { tagline: 'Component workshop', company: 'Nimling' },
123
+
124
+ /** Extra stylesheets loaded after the framework styles. */
125
+ // css: 'docs/overrides.css',
126
+
127
+ /** Vite overrides merged into the site and harness configs. */
128
+ // vite: { resolve: { alias: { '@': './src' } } },
129
+
130
+ /**
131
+ * Component workshop systems, one entry per component library.
132
+ * @example
133
+ * modules: [{
134
+ * name: 'nimtech',
135
+ * framework: 'vue',
136
+ * source: './src/components',
137
+ * package: '@nimling/components-nimtech',
138
+ * css: ['./src/assets/style.css'],
139
+ * harness: './docs/components/harness.vue'
140
+ * }]
141
+ */
142
+ // modules: []
143
+ })
144
+ `;
145
+ }
146
+ function ft() {
147
+ return JSON.stringify(
148
+ {
149
+ $schema: "./node_modules/@nimtech/nimpress/config.schema.json",
150
+ title: R.title,
151
+ contentDir: R.contentDir,
152
+ assetsDir: R.assetsDir,
153
+ assetUrlBase: R.assetUrlBase
154
+ },
155
+ null,
156
+ 2
157
+ ) + `
158
+ `;
159
+ }
160
+ function pt(t) {
161
+ return `# Nimpress project
162
+
163
+ This site is built with @nimtech/nimpress. Content lives in \`${t}/\` as markdown with typed frontmatter.
164
+
165
+ The full documentation is at https://nimling.github.io/nimpress/.
166
+
167
+ The authoritative AI working rules ship inside the package at \`node_modules/@nimtech/nimpress/.claude/rules/\`. Read the relevant rule before writing:
168
+
169
+ 1. \`frontmatter.md\` and \`page-types.md\` before creating or editing any page.
170
+
171
+ 2. \`docs-authoring.md\` and \`style.md\` for prose, structure, and markdown surface.
172
+
173
+ 3. \`component-modules.md\` before touching component pages, stories, controls, or the modules CLI.
174
+
175
+ 4. \`changelog-entries.md\`, \`roadmap-entries.md\`, and \`dbml-pages.md\` for those page types.
176
+
177
+ 5. \`docs-sync.md\` and \`deploy.md\` for publishing flows and the export header.
178
+
179
+ 6. \`file-layout.md\` and \`doc-pages.md\` for where files go.
180
+
181
+ 7. \`paths.md\` for every folder nimpress writes and the one sanctioned scratch layer for verification pages under the cache root.
182
+
183
+ ## Commands
184
+
185
+ 1. \`nimpress dev\` runs the site and every component harness.
186
+
187
+ 2. \`nimpress lint\` validates structure, frontmatter, and imports, then builds and reports build errors; run it after content changes.
188
+
189
+ 3. \`nimpress modules lint\` checks component pages for framework mixups, missing schema files, and structural drift between the schema and the stories and component source.
190
+
191
+ 4. \`nimpress build\` emits the static site plus harness bundles.
192
+
193
+ 5. \`nimpress modules import | create | story | update\` manage component pages, with \`--system=<name>\` when several systems are configured; never hand roll importer scripts.
194
+
195
+ 6. \`nimpress modules update <name>\` upserts the schema from the component types, adding new members without touching authored defaults, enums, or descriptions; the workshop controls read the schema, not the source.
196
+
197
+ 7. \`nimpress export --target=<name>\` collects pages marked \`export: <name>\` into \`.nimpress\` for the docs pipeline.
198
+
199
+ 8. \`nimpress guard map\` and \`nimpress guard apply\` wire gated pages, marked with the \`gate:\` frontmatter field, to the auth provider artifacts.
200
+ `;
201
+ }
202
+ function dt(t) {
203
+ const e = h(t, "nimpress.config.ts"), o = h(t, "nimpress.config.json"), s = $e(process.argv.slice(2), "json");
204
+ !b(e) && !b(o) && (s ? (L(o, ft()), console.log(`nimpress init: ${o} written, field descriptions come from the referenced config.schema.json`)) : (L(e, ut()), console.log(`nimpress init: ${e} written with every field documented, uncomment what you need`)));
205
+ const n = h(t, R.contentDir);
206
+ (!b(n) || q(n).length === 0) && (ye(n, { recursive: !0 }), L(
207
+ h(n, "index.md"),
208
+ `---
209
+ title: Home
210
+ ---
211
+
212
+ Welcome to your Nimpress site.
213
+ `
214
+ ));
215
+ const r = pt(R.contentDir);
216
+ for (const a of ["CLAUDE.md", "AGENTS.md"]) {
217
+ const l = h(t, a);
218
+ b(l) || (L(l, r), console.log(`nimpress init: ${a} written, pointing at the packaged rules in node_modules/@nimtech/nimpress/.claude/rules/`));
219
+ }
220
+ }
221
+ const ht = { vue: "vueStory", svelte: "svelteStory" }, gt = { vue: ".svelte", svelte: ".vue" };
222
+ function V(t) {
223
+ return `run nimpress modules update ${t}`;
224
+ }
225
+ async function yt(t) {
226
+ let e;
227
+ try {
228
+ e = await at(t, { withFileTypes: !0 });
229
+ } catch {
230
+ return [];
231
+ }
232
+ return e.filter((o) => o.isFile() && /\.story\.tsx?$/.test(o.name)).map((o) => o.name);
233
+ }
234
+ function $t(t, e) {
235
+ const o = e === "integer" ? "number" : e;
236
+ return t.every((s) => typeof s === o);
237
+ }
238
+ function wt(t, e, o, s, n) {
239
+ const i = [], r = s.properties ?? {}, a = n.properties ?? {};
240
+ for (const d of Object.keys(a))
241
+ d in r || i.push(`${t}: prop ${d} is missing from the schema, ${V(e)}`);
242
+ for (const d of Object.keys(r))
243
+ d in a || i.push(`${t}: schema prop ${d} has no counterpart in ${o}, remove it or restore the prop`);
244
+ for (const [d, f] of Object.entries(r)) {
245
+ const p = a[d];
246
+ if (p && (f.type && p.type && f.type !== p.type && !f.enum && i.push(
247
+ `${t}: prop ${d} schema type ${f.type} conflicts with source type ${p.type}, ${V(e)}`
248
+ ), f.enum && p.type && !$t(f.enum, p.type) && i.push(`${t}: prop ${d} enum values mismatch the source type ${p.type}`), f.enum && p.enum)) {
249
+ const w = new Set(p.enum.map((S) => JSON.stringify(S))), y = f.enum.filter((S) => !w.has(JSON.stringify(S)));
250
+ y.length && i.push(
251
+ `${t}: prop ${d} enum carries ${y.map((S) => JSON.stringify(S)).join(", ")} outside the source union`
252
+ );
253
+ }
254
+ }
255
+ const l = s.slots ?? {}, c = n.slots ?? {};
256
+ for (const d of Object.keys(c))
257
+ d in l || i.push(`${t}: slot ${d} is missing from the schema, ${V(e)}`);
258
+ for (const d of Object.keys(l))
259
+ d in c || i.push(`${t}: schema slot ${d} has no counterpart in ${o}`);
260
+ const u = new Set(s.emits ?? []), m = new Set(n.emits ?? []);
261
+ for (const d of m)
262
+ u.has(d) || i.push(`${t}: emit ${d} is missing from the schema, ${V(e)}`);
263
+ for (const d of u)
264
+ m.has(d) || i.push(`${t}: schema emit ${d} has no counterpart in ${o}`);
265
+ return i;
266
+ }
267
+ async function Te(t, e, o) {
268
+ const s = o ? [o] : Object.keys(e.modules.systems), n = [], i = await he(t, e.contentDir);
269
+ for (const r of s) {
270
+ const a = e.modules.systems[r];
271
+ if (!a) {
272
+ n.push(`${r}: not a configured system`);
273
+ continue;
274
+ }
275
+ const l = a.framework, c = ht[l === "vue" ? "svelte" : "vue"], u = gt[l];
276
+ for (const m of i) {
277
+ if (m.system !== r) continue;
278
+ const d = z(m.pageFile), f = D(t, d).split(U).join("/"), p = await yt(d);
279
+ p.length || n.push(`${f}: no story, run nimpress modules story --system=${r} ${m.component}`);
280
+ const w = /* @__PURE__ */ new Set();
281
+ for (const k of p) {
282
+ let O;
283
+ try {
284
+ O = await ae(h(d, k), "utf-8");
285
+ } catch {
286
+ continue;
287
+ }
288
+ (/\bharness\s*:/.test(O) || /\brender\s*:/.test(O)) && w.add(k), O.includes(c) && n.push(`${f}/${k}: uses ${c} inside the ${l} system ${r}`);
289
+ for (const g of O.matchAll(/from\s+['"]([^'"]+)['"]/g))
290
+ Y(g[1]) === u && n.push(`${f}/${k}: imports ${g[1]} inside the ${l} system ${r}`);
291
+ }
292
+ const y = ge(t, e.modules, r, m.component, m.file);
293
+ if (y && Y(y.componentFile) === u && n.push(
294
+ `${f}: component file ${D(t, y.componentFile)} mismatches the ${l} system ${r}`
295
+ ), b(h(d, "schema.json")) && b(h(d, "schema.yml"))) {
296
+ n.push(`${f}: both schema.json and schema.yml exist, keep one`);
297
+ continue;
298
+ }
299
+ const S = Ue(d);
300
+ if (!S) {
301
+ n.push(`${f}: schema file missing, ${V(m.component)}`);
302
+ continue;
303
+ }
304
+ let C;
305
+ try {
306
+ C = await ae(S.path, "utf-8");
307
+ } catch {
308
+ n.push(`${f}: ${S.form} schema unreadable`);
309
+ continue;
310
+ }
311
+ let j;
312
+ try {
313
+ j = Ve(C, S.form);
314
+ } catch {
315
+ n.push(`${f}: schema is not valid ${S.form}, fix it by hand`);
316
+ continue;
317
+ }
318
+ const x = new Set(Object.keys(j.properties ?? {}));
319
+ for (const k of await Fe(d))
320
+ if (!w.has(k.file))
321
+ for (const O of Object.keys(k.props ?? {}))
322
+ x.has(O) || n.push(`${f}/${k.file}: prop ${O} is absent from the schema, ${V(m.component)}`);
323
+ const N = y ? await ae(y.componentFile, "utf-8").catch(() => {
324
+ }) : void 0;
325
+ if (y) {
326
+ const k = await Q(y.componentFile, l, m.component);
327
+ if (k) {
328
+ const O = ct(m.component, k.props, k.slots, k.emits);
329
+ n.push(
330
+ ...wt(f, m.component, D(t, y.componentFile), j, O)
331
+ );
332
+ }
333
+ }
334
+ qe(Ke(m.component, j, { sourceFile: y?.componentFile, sourceText: N }));
335
+ }
336
+ }
337
+ return le(t), n;
338
+ }
339
+ function Je(t) {
340
+ return Object.entries(t.modules.systems).filter(([, e]) => e.visibility !== "dev-only").map(([e]) => e);
341
+ }
342
+ async function Ie(t, e, o) {
343
+ for (const s of o)
344
+ try {
345
+ await (await We(await Ce(t, e, s, "serve"))).listen(), console.log(`nimpress modules: ${s} harness on port ${Xe(e.modules, s)}`);
346
+ } catch (n) {
347
+ console.warn(`nimpress modules: harness for ${s} failed to start: ${String(n)}`);
348
+ }
349
+ }
350
+ async function Pe(t, e, o) {
351
+ for (const s of o)
352
+ await Ae(await Ce(t, e, s, "build")), console.log(`nimpress modules: built ${s}`);
353
+ }
354
+ async function bt(t, e) {
355
+ const o = await We(De({ cwd: t, command: "serve", resolved: e }));
356
+ await o.listen(), await Ie(t, e, Object.keys(e.modules.systems)), o.printUrls(), o.bindCLIShortcuts({ print: !0 });
357
+ }
358
+ async function Me(t, e) {
359
+ const o = h(t, "index.html"), s = !b(o);
360
+ s && L(o, Qe(e));
361
+ const n = () => {
362
+ s && ne(o, { force: !0 });
363
+ }, i = () => {
364
+ n(), process.exit(130);
365
+ };
366
+ process.once("SIGINT", i), process.once("SIGTERM", i);
367
+ try {
368
+ await Ae(De({ cwd: t, command: "build", resolved: e, htmlInput: o }));
369
+ } finally {
370
+ process.off("SIGINT", i), process.off("SIGTERM", i), n();
371
+ }
372
+ await Pe(t, e, Je(e));
373
+ }
374
+ const xt = [".ts", ".tsx", ".js", ".mjs", ".vue", ".svelte"], vt = ["", ".ts", ".tsx", ".js", ".mjs", ".vue", ".svelte", "/index.ts", "/index.js"], ke = /^[a-z0-9][a-z0-9.-]*$/, St = /^[A-Z][A-Za-z0-9]*$/;
375
+ function kt(t) {
376
+ const e = t.resolve;
377
+ if (!e || typeof e != "object") return [];
378
+ const o = e.alias;
379
+ return !o || typeof o != "object" ? [] : Array.isArray(o) ? o.flatMap((s) => {
380
+ if (!s || typeof s != "object") return [];
381
+ const { find: n, replacement: i } = s;
382
+ return typeof n != "string" || typeof i != "string" ? [] : [{ find: n, replacement: i }];
383
+ }) : Object.entries(o).flatMap(
384
+ ([s, n]) => typeof n == "string" ? [{ find: s, replacement: n }] : []
385
+ );
386
+ }
387
+ function jt(t) {
388
+ const e = [], o = [
389
+ /(?:^|\n)[ \t]*import[^'"\n]*?from[ \t]*['"]([^'"\n]+)['"]/g,
390
+ /(?:^|\n)[ \t]*export[^'"\n]*?from[ \t]*['"]([^'"\n]+)['"]/g,
391
+ /(?:^|\n)[ \t]*import[ \t]+['"]([^'"\n]+)['"]/g,
392
+ /\bimport\(\s*['"]([^'"\n]+)['"]\s*\)/g
393
+ ];
394
+ for (const s of o) {
395
+ let n;
396
+ for (; n = s.exec(t); ) e.push(n[1]);
397
+ }
398
+ return e;
399
+ }
400
+ function je(t) {
401
+ return vt.some((e) => {
402
+ const o = t + e;
403
+ if (!b(o)) return !1;
404
+ try {
405
+ return Ee(o).isFile();
406
+ } catch {
407
+ return !1;
408
+ }
409
+ });
410
+ }
411
+ function Ft(t, e) {
412
+ const o = T(t, e.contentDir), s = kt(e.vite), n = [];
413
+ for (const i of ee(o)) {
414
+ if (!xt.some((l) => i.endsWith(l))) continue;
415
+ let r;
416
+ try {
417
+ r = J(i, "utf-8");
418
+ } catch {
419
+ continue;
420
+ }
421
+ const a = D(o, i).split(U).join("/");
422
+ for (const l of jt(r)) {
423
+ if (l.includes("_shared/") || l.startsWith("_shared")) {
424
+ n.push(
425
+ `${a}: imports ${l}, shared fixture folders are forbidden, stories are self contained and shared setup lives in a group harness component`
426
+ );
427
+ continue;
428
+ }
429
+ const c = l.split("?")[0];
430
+ if (c.startsWith("./") || c.startsWith("../")) {
431
+ const m = T(z(i), c);
432
+ je(m) || n.push(`${a}: unresolved import ${l}, fix the path or create the file`);
433
+ continue;
434
+ }
435
+ const u = s.find((m) => c === m.find || c.startsWith(m.find + "/"));
436
+ if (u) {
437
+ const m = T(t, u.replacement + c.slice(u.find.length));
438
+ je(m) || n.push(`${a}: unresolved import ${l} via alias ${u.find}`);
439
+ }
440
+ }
441
+ }
442
+ return n;
443
+ }
444
+ function Dt(t, e) {
445
+ const o = T(t, e.contentDir), s = [];
446
+ if (!b(o)) return [`${e.contentDir}: contentDir does not exist`];
447
+ const n = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Map();
448
+ for (const a of ee(o)) {
449
+ const l = D(o, a).split(U).join("/"), c = z(a), u = F(a);
450
+ if (u.endsWith(".md")) {
451
+ const m = i.get(c) ?? [];
452
+ m.push(a), i.set(c, m);
453
+ const d = u.slice(0, -3);
454
+ ke.test(d) || s.push(`${l}: markdown file names are lowercase kebab case, rename to ${d.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase().replace(/[^a-z0-9.-]+/g, "-")}.md`);
455
+ let f;
456
+ try {
457
+ f = it(J(a, "utf-8")).data;
458
+ } catch {
459
+ continue;
460
+ }
461
+ if (f?.type === "component") {
462
+ const p = n.get(c);
463
+ p ? s.push(`${l}: second type component page in one folder, ${D(o, p).split(U).join("/")} already owns it, one component per folder`) : n.set(c, a);
464
+ }
465
+ if (f?.type === "dbml") {
466
+ const p = typeof f.spec == "string" ? f.spec : "";
467
+ p ? b(T(c, p)) || s.push(`${l}: spec ${p} does not resolve, create the file or fix the path`) : s.push(`${l}: type dbml needs a spec field pointing at the .dbml file`);
468
+ }
469
+ f?.type === "changelog" && typeof f.path == "string" && s.push(`${l}: changelog entries never set path, the collection mounts at the folder route, remove the path field`);
470
+ }
471
+ if (u.endsWith(".css") && !u.startsWith("_")) {
472
+ const m = a.replace(/\.css$/, ".md");
473
+ b(m) || s.push(`${l}: page css without a matching ${F(m)}, page styles are named after the page they scope`);
474
+ }
475
+ }
476
+ for (const [a, l] of i) {
477
+ const c = D(o, a).split(U).join("/") || ".", u = n.has(a);
478
+ let m = [];
479
+ try {
480
+ m = q(a);
481
+ } catch {
482
+ continue;
483
+ }
484
+ m.filter((f) => /\.story\.tsx?$/.test(f)).length && !u && s.push(`${c}: story files without a type component page, add the component index.md or move the stories`);
485
+ for (const f of ["schema.json", "schema.yml"])
486
+ m.includes(f) && !u && s.push(`${c}: ${f} without a type component page, it belongs beside the component index.md`);
487
+ if (u && l.length > 1) {
488
+ const f = l.filter((p) => p !== n.get(a)).map((p) => F(p));
489
+ s.push(`${c}: a component folder holds exactly one md file, move ${f.join(", ")} out`);
490
+ }
491
+ }
492
+ const r = (a) => {
493
+ let l;
494
+ try {
495
+ l = q(a, { withFileTypes: !0 });
496
+ } catch {
497
+ return;
498
+ }
499
+ for (const c of l)
500
+ if (c.isDirectory() && !(c.name.startsWith(".") || c.name === "node_modules")) {
501
+ if (!ke.test(c.name) && !St.test(c.name)) {
502
+ const u = D(o, h(a, c.name)).split(U).join("/");
503
+ s.push(`${u}/: folder names are lowercase kebab case, or PascalCase for component and group folders, rename it`);
504
+ }
505
+ r(h(a, c.name));
506
+ }
507
+ };
508
+ return r(o), s;
509
+ }
510
+ async function Ct(t, e) {
511
+ const o = et(t, e, "lint"), s = () => ne(o, { recursive: !0, force: !0 }), n = () => {
512
+ s(), process.exit(130);
513
+ };
514
+ process.once("SIGINT", n), process.once("SIGTERM", n);
515
+ try {
516
+ return await Me(t, { ...e, paths: { ...e.paths, out: o } }), [];
517
+ } catch (i) {
518
+ return (i instanceof Error ? i.message : String(i)).split(`
519
+ `).filter((a) => a.trim()).map((a) => `build: ${a.trim()}`);
520
+ } finally {
521
+ process.off("SIGINT", n), process.off("SIGTERM", n), s();
522
+ }
523
+ }
524
+ async function Ot(t, e) {
525
+ const o = process.argv.slice(2), s = [
526
+ ...Dt(t, e),
527
+ ...await Ye(t, e.contentDir),
528
+ ...Ft(t, e),
529
+ ...await Te(t, e)
530
+ ];
531
+ if (s.length) {
532
+ ue("nimpress lint", s, "");
533
+ return;
534
+ }
535
+ if (console.log("nimpress lint: structure, frontmatter, imports, and modules ok"), $e(o, "no-build")) return;
536
+ console.log("nimpress lint: building to verify the output compiles");
537
+ const n = await Ct(t, e);
538
+ ue("nimpress lint", n, "nimpress lint: build ok, everything passes");
539
+ }
540
+ const Et = {
541
+ ".json": "application/json",
542
+ ".xml": "application/rss+xml",
543
+ ".html": "text/html",
544
+ ".css": "text/css",
545
+ ".js": "text/javascript",
546
+ ".txt": "text/plain",
547
+ ".svg": "image/svg+xml",
548
+ ".png": "image/png",
549
+ ".jpg": "image/jpeg",
550
+ ".webp": "image/webp",
551
+ ".pdf": "application/pdf"
552
+ };
553
+ function Nt(t, e, o) {
554
+ const s = o[0], n = h(t, A(o, "dist") ?? e.paths.out), i = `/${e.paths.guarded}/`, r = h(n, "access.json");
555
+ if (!b(r))
556
+ throw new Error(`[nimpress] guard: ${r} not found, run a build first`);
557
+ const a = JSON.parse(J(r, "utf-8"));
558
+ if (s === "map") {
559
+ const l = Se(n, e), c = h(n, "guard.map.json"), u = b(c) ? JSON.parse(J(c, "utf-8")) : { prefix: a.prefix ?? i, routes: a.routes, bundles: {} }, m = b(l) ? ee(l) : [], d = u.prefix ?? i, f = m.map((y) => {
560
+ const S = D(l, y).split("\\").join("/"), C = S.split("/")[0] ?? "", j = [
561
+ ...new Set(
562
+ Object.values(u.routes ?? {}).filter((N) => N.bundle === C && N.gate).map((N) => N.gate)
563
+ )
564
+ ], x = J(y);
565
+ return {
566
+ path: `${d}${S}`,
567
+ file: S,
568
+ bundle: C,
569
+ sha256: lt("sha256").update(x).digest("hex"),
570
+ size: Ee(y).size,
571
+ mime: Et[Y(y).toLowerCase()] ?? "application/octet-stream",
572
+ gates: j
573
+ };
574
+ }), p = A(o, "out"), w = p ? h(t, p) : c;
575
+ L(
576
+ w,
577
+ JSON.stringify({ ...u, prefix: d, files: f }, null, 2) + `
578
+ `
579
+ ), console.log(`nimpress guard: mapped ${f.length} guarded files to ${w}`);
580
+ return;
581
+ }
582
+ if (s === "apply") {
583
+ const l = A(o, "map");
584
+ if (!l) throw new Error("[nimpress] guard apply requires --map=<uploaded mapping json>");
585
+ const c = JSON.parse(J(h(t, l), "utf-8"));
586
+ if (!c.base) throw new Error("[nimpress] guard apply: mapping json carries no base url");
587
+ a.base = c.base.replace(/\/$/, ""), a.files = (c.files ?? []).map((u) => ({
588
+ path: u.path,
589
+ file: u.file,
590
+ bundle: u.bundle,
591
+ asset_id: u.asset_id,
592
+ url: u.url
593
+ })), L(r, JSON.stringify(a, null, 2) + `
594
+ `), ne(Se(n, e), { recursive: !0, force: !0 }), ne(h(n, "guard.map.json"), { force: !0 }), console.log(`nimpress guard: base ${a.base} applied, ${e.paths.guarded} removed from ${n}`);
595
+ return;
596
+ }
597
+ throw new Error("[nimpress] guard expects map or apply");
598
+ }
599
+ function Re(t) {
600
+ const e = Y(t);
601
+ return e === ".vue" ? "vue" : e === ".svelte" ? "svelte" : null;
602
+ }
603
+ async function we(t, e, o, s, n) {
604
+ const r = (await he(t, e.contentDir)).find((d) => d.system === o && d.component === s);
605
+ if (!r)
606
+ return console.warn(`[nimpress] modules story: no type component page found for ${o}/${s}`), null;
607
+ const a = ge(t, e.modules, o, s, r.file);
608
+ if (!a)
609
+ return console.warn(`[nimpress] modules story: no source found for ${o}/${s}`), null;
610
+ const l = n ?? Re(a.componentFile);
611
+ if (!l)
612
+ throw new Error(
613
+ `[nimpress] modules story: failed to detect framework for ${a.componentFile}, pass --framework=vue or --framework=svelte`
614
+ );
615
+ const c = l === "vue" ? "vueStory" : "svelteStory", u = `import { ${c} } from '@nimtech/nimpress/story'
616
+
617
+ // story: Default
618
+ export default ${c}({
619
+ name: "Default"
620
+ })
621
+ `, m = h(z(r.pageFile), "default.story.tsx");
622
+ return b(m) ? (console.warn(`[nimpress] modules story: ${m} exists, not overwriting`), null) : (await Z(m, u), m);
623
+ }
624
+ async function Wt(t, e, o) {
625
+ const s = await he(t, e.contentDir);
626
+ let n = 0;
627
+ for (const i of s)
628
+ if (!(i.system !== o || (await Fe(z(i.pageFile))).length))
629
+ try {
630
+ await we(t, e, o, i.component) && n++;
631
+ } catch (a) {
632
+ console.warn(String(a));
633
+ }
634
+ return n;
635
+ }
636
+ async function At(t, e, o, s, n) {
637
+ const i = e.modules.systems[o];
638
+ if (!i) throw new Error(`[nimpress] modules create: unknown system ${o}`);
639
+ const r = h(t, e.contentDir, "components", "Components", s), a = h(r, "index.md");
640
+ if (b(a))
641
+ throw new Error(`[nimpress] modules create: ${a} exists`);
642
+ const { mkdir: l } = await import("node:fs/promises");
643
+ await l(r, { recursive: !0 });
644
+ const c = i.package;
645
+ await Z(
646
+ a,
647
+ `---
648
+ title: ${s}
649
+ type: component
650
+ data:
651
+ system: ${o}
652
+ component: ${s}${c ? `
653
+ package: "${c}"` : ""}
654
+ ---
655
+
656
+ ## Usage
657
+
658
+ \`\`\`ts
659
+ import { ${s} } from "${c ?? o}";
660
+ \`\`\`
661
+ `
662
+ );
663
+ const u = ge(t, e.modules, o, s);
664
+ if (u) {
665
+ const m = n ?? Re(u.componentFile) ?? i.framework;
666
+ await X(r, s, await Q(u.componentFile, m, s)), await we(t, e, o, s, n);
667
+ } else {
668
+ const m = i.framework === "vue" ? "vueStory" : "svelteStory";
669
+ await Z(
670
+ h(r, "default.story.tsx"),
671
+ `import { ${m} } from '@nimtech/nimpress/story'
672
+
673
+ // story: Default
674
+ export default ${m}({
675
+ name: "Default",
676
+ props: {}
677
+ })
678
+ `
679
+ ), console.warn(
680
+ `nimpress modules: no source found for ${s}, wrote a stub story, schema.json follows once the component exists and import or create runs again`
681
+ );
682
+ }
683
+ return r;
684
+ }
685
+ function re(t) {
686
+ try {
687
+ return JSON.parse(JSON.stringify(t, (e, o) => typeof o == "function" ? void 0 : o));
688
+ } catch {
689
+ return {};
690
+ }
691
+ }
692
+ function ie(t, e = []) {
693
+ let o;
694
+ try {
695
+ o = q(t, { withFileTypes: !0 });
696
+ } catch {
697
+ return e;
698
+ }
699
+ for (const s of o) {
700
+ const n = h(t, s.name);
701
+ if (s.isDirectory()) {
702
+ if (s.name === "node_modules" || s.name.startsWith(".")) continue;
703
+ ie(n, e);
704
+ } else s.isFile() && e.push(n);
705
+ }
706
+ return e;
707
+ }
708
+ function fe(t) {
709
+ return t.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase().replace(/[^a-z0-9-]/g, "");
710
+ }
711
+ function pe(t) {
712
+ const e = J(t, "utf-8"), o = e.split(`
713
+ `), s = [];
714
+ let n = 0;
715
+ for (; n < o.length; ) {
716
+ const f = o[n];
717
+ if (/^\s*import\b/.test(f)) {
718
+ let p = f;
719
+ for (; !/from\s+["'][^"']+["'];?\s*$/.test(p) && !/^\s*import\s+["'][^"']+["'];?\s*$/.test(p) && n + 1 < o.length; )
720
+ n++, p += `
721
+ ` + o[n];
722
+ s.push(p), n++;
723
+ continue;
724
+ }
725
+ if (/^\s*$/.test(f)) {
726
+ n++;
727
+ continue;
728
+ }
729
+ break;
730
+ }
731
+ const i = z(t), r = [], a = (f) => {
732
+ const p = T(i, f);
733
+ return /\.(vue|svelte)$/.test(f) ? { kind: "source", abs: p } : f.endsWith(".ts") ? b(p) ? { kind: "data", abs: p } : null : b(`${p}.ts`) ? { kind: "data", abs: `${p}.ts` } : b(`${p}.vue`) || b(`${p}.svelte`) || b(h(p, "index.ts")) ? { kind: "source", abs: p } : null;
734
+ };
735
+ for (const f of s) {
736
+ const p = f.match(/from\s+["'](\.\.?\/[^"']+)["']/)?.[1];
737
+ if (!p) continue;
738
+ const w = a(p);
739
+ w?.kind === "data" && r.push(w.abs);
740
+ }
741
+ const l = s.filter((f) => !f.includes("@storybook")).map(
742
+ (f) => f.replace(/from\s+["'](\.\.?\/[^"']+)["']/g, (p, w) => {
743
+ const y = a(w);
744
+ return y?.kind === "source" ? `from ${JSON.stringify(y.abs)}` : `from "./${F(w).replace(/\.ts$/, "")}"`;
745
+ })
746
+ ).join(`
747
+ `);
748
+ let c = e.slice(o.slice(0, n).join(`
749
+ `).length);
750
+ const u = (f) => {
751
+ const p = c.search(f);
752
+ if (p < 0) return;
753
+ const w = c.indexOf("{", p);
754
+ if (w < 0) {
755
+ c = c.slice(0, p) + c.slice(c.indexOf(`
756
+ `, p) + 1);
757
+ return;
758
+ }
759
+ const y = oe(c, w + 1), S = w + 1 + y.length + 1, C = c.slice(S).match(/^[^\n]*/)?.[0] ?? "";
760
+ c = c.slice(0, p) + c.slice(S + C.length);
761
+ };
762
+ u(/^const meta\b[^\n]*/m), c = c.replace(/^export default meta;?\s*$/m, ""), c = c.replace(/^(?:export )?type \w+[^\n]*\n(?:[ \t]+[^\n]*\n?)*/gm, "");
763
+ let m = 0;
764
+ for (; /^(?:export )?interface \w+/m.test(c) && m < 50; )
765
+ u(/^(?:export )?interface \w+[^\n]*/m), m++;
766
+ let d = 0;
767
+ for (; /^export const \w+/m.test(c) && d < 200; )
768
+ u(/^export const \w+[^\n]*/m), d++;
769
+ return {
770
+ file: t,
771
+ text: e,
772
+ title: e.match(/\btitle:\s*["']([^"']+)["']/)?.[1],
773
+ metaComponent: e.match(/\bcomponent:\s*([A-Za-z_$][\w$]*)\s*[,\n}]/)?.[1],
774
+ imports: l,
775
+ declarations: c.trim(),
776
+ dataModules: r
777
+ };
778
+ }
779
+ function Tt(t, e) {
780
+ const o = t.indexOf(":", e) + 1;
781
+ let s = 0, n = null;
782
+ for (let i = o; i < t.length; i++) {
783
+ const r = t[i], a = t[i - 1];
784
+ if (n) {
785
+ r === n && a !== "\\" && (n = null);
786
+ continue;
787
+ }
788
+ if (r === "'" || r === '"' || r === "`") {
789
+ n = r;
790
+ continue;
791
+ }
792
+ if (r === "{" || r === "(" || r === "[") s++;
793
+ else if (r === "}" || r === ")" || r === "]") s--;
794
+ else if (r === "," && s === 0) return t.slice(o, i).trim();
795
+ }
796
+ return t.slice(o).trim();
797
+ }
798
+ function _e(t) {
799
+ return t.replace(/\bsatisfies\s+[A-Za-z_$][\w$.]*(?:<[^>]*>)?/g, "").replace(/\bas\s+const\b/g, "").replace(/\)\s*:\s*[A-Za-z_$][\w$<>\[\], .|&]*\s*=>/g, ") =>").replace(/\(\s*([A-Za-z_$][\w$]*)\s*:\s*[A-Za-z_$][\w$<>\[\], .|&]*\)/g, "($1)");
800
+ }
801
+ function Be(t) {
802
+ const e = [], o = /export const (\w+)\s*(?::[^=]*)?=\s*\{/g;
803
+ let s;
804
+ for (; s = o.exec(t.text); ) {
805
+ const n = s[1];
806
+ if (n === "default" || n === "meta") continue;
807
+ const i = oe(t.text, o.lastIndex), r = i.search(/\brender\s*:/);
808
+ if (r >= 0) {
809
+ const c = Tt(i, r);
810
+ if (c) {
811
+ e.push({ name: n, renderFn: c });
812
+ continue;
813
+ }
814
+ }
815
+ const a = i.search(/\bargs\s*:/);
816
+ let l = {};
817
+ if (a >= 0) {
818
+ const c = i.indexOf("{", a);
819
+ if (c >= 0) {
820
+ const u = oe(i, c + 1);
821
+ try {
822
+ l = re(new Function(`${_e(t.declarations)}
823
+ return {${u}}`)());
824
+ } catch {
825
+ try {
826
+ l = re(new Function(`return {${u}}`)());
827
+ } catch {
828
+ l = {};
829
+ }
830
+ }
831
+ }
832
+ }
833
+ e.push({ name: n, props: l });
834
+ }
835
+ return e;
836
+ }
837
+ function Le(t) {
838
+ const e = t.text.search(/\bargTypes\s*:\s*\{/);
839
+ if (e < 0) return;
840
+ const o = t.text.indexOf("{", e), s = oe(t.text, o + 1);
841
+ let n;
842
+ try {
843
+ n = re(new Function(`return {${s}}`)());
844
+ } catch {
845
+ try {
846
+ n = re(
847
+ new Function(`${_e(t.declarations)}
848
+ return {${s}}`)()
849
+ );
850
+ } catch {
851
+ return;
852
+ }
853
+ }
854
+ const i = {};
855
+ for (const [r, a] of Object.entries(n)) {
856
+ if (!a || typeof a != "object") continue;
857
+ const l = a.control, c = typeof l == "string" ? l : String(l?.type ?? ""), u = a.options ?? (typeof l == "object" ? l?.options : void 0), m = {};
858
+ typeof a.description == "string" && (m.description = a.description), Array.isArray(u) ? m.enum = u : c === "boolean" ? m.type = "boolean" : c === "number" || c === "range" ? m.type = "number" : c === "text" || c === "color" || c === "date" ? m.type = "string" : c === "object" && (m.type = "object"), a.defaultValue !== void 0 && (m.default = a.defaultValue), Object.keys(m).length && (i[r] = m);
859
+ }
860
+ return Object.keys(i).length ? i : void 0;
861
+ }
862
+ async function ze(t) {
863
+ const e = [...t].sort();
864
+ for (let r = 0; r < e.length; r++)
865
+ console.log(`${String(r + 1).padStart(4)} ${e[r]}`);
866
+ const o = mt({ input: process.stdin, output: process.stdout }), s = await o.question(
867
+ "select components to import, comma separated numbers, names, or /regex/, empty imports all: "
868
+ );
869
+ o.close();
870
+ const n = s.trim();
871
+ if (!n) return new Set(e);
872
+ const i = /* @__PURE__ */ new Set();
873
+ for (const r of n.split(",").map((a) => a.trim()).filter(Boolean)) {
874
+ const a = r.match(/^\/(.+)\/$/);
875
+ if (a) {
876
+ const l = new RegExp(a[1]);
877
+ for (const c of e) l.test(c) && i.add(c);
878
+ continue;
879
+ }
880
+ if (/^\d+$/.test(r)) {
881
+ const l = e[Number(r) - 1];
882
+ l && i.add(l);
883
+ continue;
884
+ }
885
+ for (const l of e) l === r && i.add(l);
886
+ }
887
+ return i;
888
+ }
889
+ function Ge(t, e) {
890
+ const o = /* @__PURE__ */ new Map(), s = h(t, "node_modules", e, "index.mjs");
891
+ if (!b(s)) return o;
892
+ const n = J(s, "utf-8");
893
+ for (const i of n.matchAll(/export \{ default as ([A-Za-z]+) \}/g))
894
+ o.set(i[1].toLowerCase(), i[1]);
895
+ return o;
896
+ }
897
+ async function Jt(t, e, o, s) {
898
+ const n = e.modules.systems[o];
899
+ if (!n) throw new Error(`[nimpress] modules import: unknown system ${o}`);
900
+ const i = n.framework, r = i === "vue" ? ".vue" : ".svelte", a = h(t, e.contentDir, "components"), l = n.package, c = s.match ? new RegExp(s.match) : null;
901
+ if (s.file) {
902
+ const g = T(t, s.file);
903
+ if (!b(g)) throw new Error(`[nimpress] modules import: ${g} not found`);
904
+ if (Y(g) !== r)
905
+ throw new Error(`[nimpress] modules import: ${g} does not match system framework ${i}`);
906
+ const $ = s.name ?? F(g, r), _ = n.source ? T(t, n.source) : t, E = h(a, "Components", $);
907
+ await me(E, { recursive: !0 });
908
+ const W = D(_, g);
909
+ await Z(h(E, "index.md"), de(o, $, l, W)), await X(E, $, await Q(g, i, $)), console.log(`nimpress modules: imported ${$} at ${D(t, E)}`);
910
+ return;
911
+ }
912
+ if (s.fromStories) {
913
+ await It(t, e, o, s);
914
+ return;
915
+ }
916
+ const u = T(t, s.source ?? n.source ?? "");
917
+ if (!b(u))
918
+ throw new Error(`[nimpress] modules import: source ${u} not found`);
919
+ const m = ie(u), d = /* @__PURE__ */ new Map(), f = /* @__PURE__ */ new Map(), p = m.filter((g) => g.endsWith(".stories.ts")), w = s.stories ? [T(t, s.stories)] : [];
920
+ for (const g of w)
921
+ for (const $ of ie(g))
922
+ $.endsWith(".stories.ts") && p.push($);
923
+ const y = m.filter(
924
+ (g) => g.endsWith(r) && /^[A-Z][A-Za-z0-9]*$/.test(F(g, r))
925
+ ), S = new Set(y.map((g) => F(g, r))), C = l && !n.source ? Ge(t, l) : null;
926
+ for (const g of p) {
927
+ const $ = pe(g);
928
+ if ($.title?.includes("/")) {
929
+ const [P, I] = $.title.split("/");
930
+ d.set(I, P.replace(/\s+/g, ""));
931
+ }
932
+ const _ = F(g, ".stories.ts");
933
+ let W = b(h(z(g), `${_}${r}`)) ? _ : $.metaComponent ?? _;
934
+ if (!S.has(W)) {
935
+ let P = "";
936
+ for (const I of S)
937
+ _.startsWith(I) && I.length > P.length && (P = I);
938
+ P ? W = P : console.warn(`nimpress modules: ${F(g)} targets ${W} which has no component page`);
939
+ }
940
+ const v = C?.get(W.toLowerCase()) ?? W, B = f.get(v) ?? [];
941
+ B.push($), f.set(v, B);
942
+ }
943
+ const j = /* @__PURE__ */ new Map();
944
+ let x = 0, N = 0;
945
+ const k = y.filter((g) => !c || c.test(F(g, r))), O = s.select ? await ze(k.map((g) => F(g, r))) : null;
946
+ for (const g of k) {
947
+ const $ = F(g, r);
948
+ if (O && !O.has($)) continue;
949
+ if (j.has($)) {
950
+ console.warn(`nimpress modules: skip duplicate ${$}, kept ${j.get($)}`);
951
+ continue;
952
+ }
953
+ j.set($, D(u, g));
954
+ const _ = d.get($) ?? "Components", E = h(a, _, $);
955
+ await me(E, { recursive: !0 });
956
+ const W = D(u, g), v = W === `${$}/${$}${r}` || W === `${$}${r}`, B = (f.get($) ?? []).map((M) => Le(M)).reduce(
957
+ (M, H) => H ? { ...M ?? {}, ...H } : M,
958
+ void 0
959
+ );
960
+ await Z(h(E, "index.md"), de(o, $, l, v ? void 0 : W)), await X(E, $, await Q(g, i, $)), B && await Oe(E, { properties: B }), x++;
961
+ const P = f.get($) ?? [], I = /* @__PURE__ */ new Set();
962
+ for (const M of P) {
963
+ const H = F(M.file, ".stories.ts"), be = Be(M);
964
+ be.length || console.warn(`nimpress modules: no stories mined from ${F(M.file)}`);
965
+ for (const G of M.dataModules)
966
+ await Ne(G, h(E, F(G)));
967
+ for (const G of be) {
968
+ const xe = G.name === $ ? "Default" : H === $ ? G.name : `${H} ${G.name}`;
969
+ let te = fe(xe);
970
+ I.has(te) && (te = fe(`${H}-${G.name}`));
971
+ const ve = h(E, `${te}.story.tsx`);
972
+ I.add(te), !b(ve) && (await Z(ve, Ze(i, xe, H, G, M)), N++);
973
+ }
974
+ }
975
+ }
976
+ console.log(`nimpress modules: imported ${x} components with ${N} stories for ${o}`);
977
+ }
978
+ async function It(t, e, o, s) {
979
+ const n = e.modules.systems[o], i = n.framework, r = h(t, e.contentDir, "components"), a = T(t, s.stories ?? "");
980
+ if (!s.stories || !b(a))
981
+ throw new Error("[nimpress] modules import --from-stories requires --stories=<csf dir>");
982
+ const l = n.source ? T(t, n.source) : t, c = s.match ? new RegExp(s.match) : null, u = /* @__PURE__ */ new Set();
983
+ let m = 0, d = 0;
984
+ const f = ie(a).filter((w) => w.endsWith(".stories.ts")), p = s.select ? await ze(
985
+ f.map((w) => pe(w).metaComponent ?? F(w, ".stories.ts"))
986
+ ) : null;
987
+ for (const w of f) {
988
+ const y = pe(w), S = F(w, ".stories.ts"), C = y.metaComponent ?? S;
989
+ if (p && !p.has(C)) continue;
990
+ const j = y.text.match(
991
+ new RegExp(`import\\s+(?:\\{\\s*)?${C}(?:\\s*\\})?\\s+from\\s+["']([^"']+)["']`)
992
+ )?.[1];
993
+ let x = C, N = n.package, k;
994
+ if (j && !j.startsWith(".") && !j.startsWith("@/")) {
995
+ const v = j.split("/")[0].startsWith("@") ? j.split("/").slice(0, 2).join("/") : j.split("/")[0];
996
+ N = v, x = Ge(t, v).get(C.toLowerCase()) ?? C;
997
+ } else if (j?.startsWith("@/components/")) {
998
+ const v = j.slice(13);
999
+ v === x || v === `${x}/${x}.vue` || (k = v.endsWith(".vue") || v.endsWith(".svelte") ? v : `${v}/${x}.vue`);
1000
+ } else if (j?.startsWith(".")) {
1001
+ const v = T(z(w), j);
1002
+ k = D(l, v);
1003
+ }
1004
+ if (c && !c.test(x)) continue;
1005
+ if (u.has(x)) {
1006
+ console.warn(`nimpress modules: skip duplicate ${x} from ${F(w)}`);
1007
+ continue;
1008
+ }
1009
+ u.add(x);
1010
+ const O = y.title?.includes("/") ? y.title.split("/")[0].replace(/\s+/g, "") : "Components", g = h(r, O, x);
1011
+ await me(g, { recursive: !0 }), await Z(h(g, "index.md"), de(o, x, N, k));
1012
+ const $ = i === "vue" ? ".vue" : ".svelte", E = (k ? [T(l, k)] : [
1013
+ h(l, x, `${x}${$}`),
1014
+ h(l, `${x}${$}`)
1015
+ ]).find((v) => b(v));
1016
+ if (E)
1017
+ await X(g, x, await Q(E, i, x));
1018
+ else if (N) {
1019
+ const v = tt(t, N, x);
1020
+ v ? await X(g, x, st(J(v, "utf-8"), x)) : console.warn(`nimpress modules: no source or d.ts found for ${x}, the schema seed is skipped`);
1021
+ }
1022
+ const W = Le(y);
1023
+ W && await Oe(g, { properties: W }), m++;
1024
+ for (const v of y.dataModules)
1025
+ await Ne(v, h(g, F(v)));
1026
+ for (const v of Be(y)) {
1027
+ const B = v.name === x ? "Default" : v.name, P = fe(B), I = h(g, `${P}.story.tsx`);
1028
+ b(I) || (await Z(I, Ze(i, B, S, v, y)), d++);
1029
+ }
1030
+ }
1031
+ console.log(`nimpress modules: imported ${m} components with ${d} stories for ${o} from stories`);
1032
+ }
1033
+ function de(t, e, o, s) {
1034
+ const n = o ? `
1035
+ package: "${o}"` : "", i = s ? `
1036
+ file: ${JSON.stringify(s)}` : "";
1037
+ return `---
1038
+ title: ${e}
1039
+ type: component
1040
+ data:
1041
+ system: ${t}
1042
+ component: ${e}${n}${i}
1043
+ ---
1044
+
1045
+ ## Usage
1046
+
1047
+ \`\`\`ts
1048
+ import { ${e} } from "${o ?? t}";
1049
+ \`\`\`
1050
+ `;
1051
+ }
1052
+ function Ze(t, e, o, s, n) {
1053
+ const i = t === "vue" ? "vueStory" : "svelteStory";
1054
+ return s.renderFn ? `import { ${i} } from '@nimtech/nimpress/story'
1055
+ ${n.imports}
1056
+
1057
+ ${n.declarations}
1058
+
1059
+ // story: ${e}
1060
+ export default ${i}({
1061
+ name: ${JSON.stringify(e)},
1062
+ description: ${JSON.stringify(`Scenario from ${o}`)},
1063
+ render: ${s.renderFn}
1064
+ })
1065
+ ` : `import { ${i} } from '@nimtech/nimpress/story'
1066
+
1067
+ // story: ${e}
1068
+ export default ${i}({
1069
+ name: ${JSON.stringify(e)},
1070
+ props: ${JSON.stringify(s.props ?? {}, null, 2)}
1071
+ })
1072
+ `;
1073
+ }
1074
+ function K(t, e) {
1075
+ const o = A(e, "system");
1076
+ if (o === void 0) return;
1077
+ const s = Object.keys(t.modules.systems);
1078
+ if (!s.includes(o))
1079
+ throw new Error(`[nimpress] modules: unknown system ${o}, configured: ${s.join(", ") || "none"}`);
1080
+ return o;
1081
+ }
1082
+ function ce(t, e, o) {
1083
+ const s = K(t, e);
1084
+ if (s) return s;
1085
+ const n = Object.keys(t.modules.systems);
1086
+ if (n.length === 1) return n[0];
1087
+ throw n.length ? new Error(
1088
+ `[nimpress] modules ${o}: several systems configured (${n.join(", ")}), pass --system=<name>`
1089
+ ) : new Error(`[nimpress] modules ${o}: no systems configured`);
1090
+ }
1091
+ async function Pt(t, e, o) {
1092
+ const s = o[0], n = o.slice(1), i = Object.keys(e.modules.systems);
1093
+ if (s === "init") {
1094
+ Mt(t, e);
1095
+ return;
1096
+ }
1097
+ if (s === "dev") {
1098
+ const r = K(e, n), a = r ? [r] : i;
1099
+ if (!a.length) throw new Error("[nimpress] modules dev: no systems configured");
1100
+ await Ie(t, e, a), await new Promise(() => {
1101
+ });
1102
+ }
1103
+ if (s === "build") {
1104
+ const r = K(e, n), a = r ? [r] : Je(e);
1105
+ if (!a.length) throw new Error("[nimpress] modules build: no systems configured");
1106
+ await Pe(t, e, a);
1107
+ return;
1108
+ }
1109
+ if (s === "lint") {
1110
+ const r = await Te(t, e, K(e, n));
1111
+ ue("nimpress modules lint", r, "nimpress modules lint: systems, schemas, and stories ok");
1112
+ return;
1113
+ }
1114
+ if (s === "story") {
1115
+ const r = ce(e, n, "story"), a = se(n, 0), l = A(n, "framework");
1116
+ if (a) {
1117
+ const u = await we(t, e, r, a, l);
1118
+ u && console.log(`nimpress modules: story written to ${u}`);
1119
+ return;
1120
+ }
1121
+ const c = await Wt(t, e, r);
1122
+ console.log(`nimpress modules: ${c} auto stories written for ${r}`);
1123
+ return;
1124
+ }
1125
+ if (s === "import") {
1126
+ const r = ce(e, n, "import"), a = se(n, 0);
1127
+ await Jt(t, e, r, {
1128
+ file: a,
1129
+ name: A(n, "name"),
1130
+ source: A(n, "source"),
1131
+ stories: A(n, "stories"),
1132
+ match: A(n, "match"),
1133
+ fromStories: n.includes("--from-stories"),
1134
+ select: n.includes("--select")
1135
+ }), le(t);
1136
+ return;
1137
+ }
1138
+ if (s === "update") {
1139
+ const r = A(n, "component") ?? se(n, 0), a = await nt(t, e, { ref: r, system: K(e, n) });
1140
+ console.log(`nimpress modules: ${a} schema${a === 1 ? "" : "s"} upserted`), le(t);
1141
+ return;
1142
+ }
1143
+ if (s === "create") {
1144
+ const r = A(n, "component");
1145
+ if (r) {
1146
+ if (!$e(n, "schema"))
1147
+ throw new Error("[nimpress] modules create --component expects --schema to upsert the schema");
1148
+ const m = await ot(t, e, r);
1149
+ console.log(`nimpress modules: schema upserted at ${m}`);
1150
+ return;
1151
+ }
1152
+ const a = se(n, 0);
1153
+ if (!a)
1154
+ throw new Error("[nimpress] modules create expects: nimpress modules create <Component> [--system=<name>], or --component=<ref> --schema");
1155
+ const l = ce(e, n, "create"), c = A(n, "framework"), u = await At(t, e, l, a, c);
1156
+ console.log(`nimpress modules: created ${a} at ${D(t, u)}`);
1157
+ return;
1158
+ }
1159
+ throw new Error("[nimpress] modules expects init, dev, build, lint, story, import, create or update");
1160
+ }
1161
+ function Mt(t, e) {
1162
+ const o = h(t, e.modules.dir);
1163
+ ye(o, { recursive: !0 });
1164
+ const s = h(t, "nimpress.config.json");
1165
+ if (b(s)) {
1166
+ const n = JSON.parse(J(s, "utf-8"));
1167
+ n.modules || (n.modules = { dir: e.modules.dir, route: e.modules.route, systems: {} }, L(s, JSON.stringify(n, null, 2) + `
1168
+ `), console.log(`nimpress modules: modules block added to ${s}`));
1169
+ } else
1170
+ console.log("nimpress modules: add a modules block with systems entries to your nimpress config");
1171
+ console.log(`nimpress modules: folder ready at ${o}`);
1172
+ }
1173
+ function He(t) {
1174
+ if (!t.startsWith(`---
1175
+ `)) return null;
1176
+ const e = t.indexOf(`
1177
+ ---`, 4);
1178
+ return e < 0 ? null : t.slice(4, e);
1179
+ }
1180
+ function Rt(t) {
1181
+ for (const e of t.split(`
1182
+ `)) {
1183
+ if (!e.startsWith("export:")) continue;
1184
+ const o = e.slice(7).trim().replace(/^["']|["']$/g, "");
1185
+ return o === "" || o === "false" ? null : o;
1186
+ }
1187
+ return null;
1188
+ }
1189
+ function _t(t, e) {
1190
+ const o = He(t);
1191
+ if (o === null) return t;
1192
+ const s = o.split(`
1193
+ `).filter((i) => !i.startsWith("export:") && !i.startsWith(" file:")), n = s.findIndex((i) => i.startsWith(" package:"));
1194
+ return e && n >= 0 && !s.some((i) => i.startsWith(" version:")) && s.splice(n + 1, 0, ` version: ${JSON.stringify(e)}`), `---
1195
+ ${s.join(`
1196
+ `)}${t.slice(4 + o.length)}`;
1197
+ }
1198
+ function Bt(t, e, o) {
1199
+ const s = A(o, "target") ?? "", n = h(t, A(o, "out") ?? e.paths.export), i = h(t, e.contentDir);
1200
+ let r = "";
1201
+ try {
1202
+ r = JSON.parse(J(h(t, "package.json"), "utf-8")).version ?? "";
1203
+ } catch {
1204
+ r = "";
1205
+ }
1206
+ let a = 0;
1207
+ for (const l of ee(i)) {
1208
+ if (!l.endsWith(".md")) continue;
1209
+ const c = J(l, "utf-8"), u = He(c);
1210
+ if (u === null) continue;
1211
+ const m = Rt(u);
1212
+ if (m === null || s && m !== s && m !== "true") continue;
1213
+ const d = z(l), f = h(n, D(i, d));
1214
+ ye(f, { recursive: !0 });
1215
+ for (const p of q(d, { withFileTypes: !0 })) {
1216
+ if (!p.isFile()) continue;
1217
+ const w = J(h(d, p.name), "utf-8");
1218
+ L(
1219
+ h(f, p.name),
1220
+ p.name.endsWith(".md") ? _t(w, r) : w
1221
+ );
1222
+ }
1223
+ a++;
1224
+ }
1225
+ console.log(`nimpress export: ${a} pages collected into ${n}`);
1226
+ }
1227
+ async function Xt(t) {
1228
+ const e = t[0] ?? "dev", o = t.slice(1), s = process.cwd();
1229
+ if (e === "init") {
1230
+ dt(s);
1231
+ return;
1232
+ }
1233
+ const { resolved: n } = await rt(s);
1234
+ if (e === "lint") {
1235
+ await Ot(s, n);
1236
+ return;
1237
+ }
1238
+ if (e === "dev") {
1239
+ await bt(s, n);
1240
+ return;
1241
+ }
1242
+ if (e === "build") {
1243
+ await Me(s, n);
1244
+ return;
1245
+ }
1246
+ if (e === "guard") {
1247
+ Nt(s, n, o);
1248
+ return;
1249
+ }
1250
+ if (e === "modules") {
1251
+ await Pt(s, n, o);
1252
+ return;
1253
+ }
1254
+ if (e === "export") {
1255
+ Bt(s, n, o);
1256
+ return;
1257
+ }
1258
+ throw new Error(`[nimpress] unknown command: ${e}`);
1259
+ }
1260
+ export {
1261
+ De as buildViteConfig,
1262
+ Qe as indexHtml,
1263
+ rt as loadNimpressConfig,
1264
+ Xt as run
1265
+ };