@unterberg/nivel 0.0.4 → 0.0.6

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.
@@ -1,8 +1,10 @@
1
1
  import {
2
- extractDocHeadings,
2
+ extractDocHeadings
3
+ } from "./chunk-SOVTSE5J.js";
4
+ import {
3
5
  getResolvedPageById,
4
6
  resolveDocsConfig
5
- } from "./chunk-D7IAGT53.js";
7
+ } from "./chunk-CL74JUQ4.js";
6
8
 
7
9
  // src/runtime/node/codegen.ts
8
10
  import fs from "fs";
@@ -113,11 +115,33 @@ var toDocPageLinkData = (page) => {
113
115
  };
114
116
  };
115
117
  var getGeneratedPagesRoot = (rootDir) => path.join(rootDir, "pages", GENERATED_DIRNAME);
118
+ var getDocsConfigPath = (rootDir) => path.join(rootDir, "pages", "+docs.ts");
119
+ var getDocsGraphPath = (rootDir) => path.join(rootDir, "docs", "docs.graph.ts");
120
+ var getDocsSourcePaths = (options) => {
121
+ const resolved = resolveDocsConfig(options.docsConfig);
122
+ return {
123
+ contentRootPath: path.join(options.rootDir, resolved.contentDir),
124
+ docsConfigPath: getDocsConfigPath(options.rootDir),
125
+ docsGraphPath: getDocsGraphPath(options.rootDir),
126
+ generatedRootPath: getGeneratedPagesRoot(options.rootDir)
127
+ };
128
+ };
129
+ var isDocsSourcePath = (filePath, docsSourcePaths) => {
130
+ const normalized = toPosix(filePath);
131
+ const generatedRootPath = toPosix(docsSourcePaths.generatedRootPath);
132
+ const docsConfigPath = toPosix(docsSourcePaths.docsConfigPath);
133
+ const docsGraphPath = toPosix(docsSourcePaths.docsGraphPath);
134
+ const contentRootPath = toPosix(docsSourcePaths.contentRootPath);
135
+ if (normalized.startsWith(generatedRootPath)) {
136
+ return false;
137
+ }
138
+ return normalized === docsConfigPath || normalized === docsGraphPath || normalized === contentRootPath || normalized.startsWith(`${contentRootPath}/`);
139
+ };
116
140
  var syncGeneratedDocsPages = (options) => {
117
141
  const { rootDir, docsConfig } = options;
118
142
  const resolved = resolveDocsConfig(docsConfig);
119
143
  const generatedPagesRoot = getGeneratedPagesRoot(rootDir);
120
- const docsRoot = path.join(rootDir, "docs");
144
+ const docsContentRoot = path.join(rootDir, resolved.contentDir);
121
145
  const expectedFiles = /* @__PURE__ */ new Set();
122
146
  const globalContextFilePath = path.join(generatedPagesRoot, "_docsGlobalContext.ts");
123
147
  fs.mkdirSync(generatedPagesRoot, { recursive: true });
@@ -137,7 +161,7 @@ var syncGeneratedDocsPages = (options) => {
137
161
  writeFileIfChanged(globalContextFilePath, getGeneratedGlobalContextSource(globalContextData));
138
162
  expectedFiles.add(globalContextFilePath);
139
163
  for (const [pageIndex, page] of resolved.pages.entries()) {
140
- const contentFilePath = path.join(docsRoot, page.source);
164
+ const contentFilePath = path.join(docsContentRoot, page.source);
141
165
  if (!fs.existsSync(contentFilePath)) {
142
166
  throw new Error(`Docs page "${page.id}" points to missing source file: ${contentFilePath}`);
143
167
  }
@@ -148,9 +172,15 @@ var syncGeneratedDocsPages = (options) => {
148
172
  previousPage: toDocPageLinkData(resolved.pages[pageIndex - 1]),
149
173
  nextPage: toDocPageLinkData(resolved.pages[pageIndex + 1])
150
174
  };
151
- for (const routeHref of [page.href, ...page.aliasHrefs]) {
152
- const routeSlug = routeHref.replace(/^\/docs\//, "").replace(/\/+$/g, "");
153
- const pageDir = path.join(generatedPagesRoot, ...routeSlug.split("/"));
175
+ const routeTargets = [
176
+ { routeHref: page.href, routePath: page.slug },
177
+ ...page.aliases.map((routePath, index) => ({
178
+ routeHref: page.aliasHrefs[index],
179
+ routePath
180
+ }))
181
+ ];
182
+ for (const { routeHref, routePath } of routeTargets) {
183
+ const pageDir = path.join(generatedPagesRoot, ...routePath.split("/"));
154
184
  const contentImportPath = getRelativeImportPath(pageDir, contentFilePath);
155
185
  const pageFilePath = path.join(pageDir, "+Page.tsx");
156
186
  const dataFilePath = path.join(pageDir, "+data.ts");
@@ -179,16 +209,6 @@ var syncGeneratedDocsPages = (options) => {
179
209
  }
180
210
  removeEmptyDirectories(generatedPagesRoot, generatedPagesRoot);
181
211
  };
182
- var isDocsSourcePath = (filePath, rootDir) => {
183
- const normalized = toPosix(filePath);
184
- const docsRoot = toPosix(path.join(rootDir, "docs"));
185
- const docsConfigPath = toPosix(path.join(rootDir, "pages", "+docs.ts"));
186
- const generatedRoot = toPosix(getGeneratedPagesRoot(rootDir));
187
- if (normalized.startsWith(generatedRoot)) {
188
- return false;
189
- }
190
- return normalized === docsConfigPath || normalized.startsWith(`${docsRoot}/`);
191
- };
192
212
 
193
213
  // src/runtime/node/loadDocsConfig.ts
194
214
  import path2 from "path";
@@ -258,12 +278,32 @@ var getDocsGraphTemplate = () => {
258
278
  };
259
279
  var getConfigTemplate = () => {
260
280
  return [
261
- "import { createNivelVikeConfig } from '@unterberg/nivel/vike'",
281
+ "import nivel from '@unterberg/nivel/vike'",
282
+ "import type { Config } from 'vike/types'",
283
+ "import vikeReact from 'vike-react/config'",
262
284
  "import docsConfig from './+docs'",
263
285
  "",
264
286
  "export { config }",
265
287
  "",
266
- "const config = createNivelVikeConfig(docsConfig)",
288
+ "const themePreference = docsConfig.theme?.defaultPreference ?? 'light'",
289
+ "const dataTheme =",
290
+ " themePreference === 'dark'",
291
+ " ? (docsConfig.theme?.dark ?? 'consumer-dark')",
292
+ " : (docsConfig.theme?.light ?? 'consumer-light')",
293
+ "",
294
+ "const config: Config = {",
295
+ " ...nivel,",
296
+ " extends: [vikeReact],",
297
+ " title: docsConfig.siteTitle,",
298
+ " description: docsConfig.siteDescription ?? `${docsConfig.siteTitle} documentation`,",
299
+ " htmlAttributes: { 'data-theme': dataTheme },",
300
+ " passToClient: ['docs'],",
301
+ "",
302
+ " // User-facing Vike levers stay visible in +config.ts.",
303
+ " prerender: true,",
304
+ " // ssr: true,",
305
+ " // prefetchStaticAssets: 'viewport',",
306
+ "}",
267
307
  ""
268
308
  ].join("\n");
269
309
  };
@@ -464,10 +504,11 @@ var initConsumer = (options) => {
464
504
 
465
505
  export {
466
506
  getGeneratedPagesRoot,
467
- syncGeneratedDocsPages,
507
+ getDocsSourcePaths,
468
508
  isDocsSourcePath,
509
+ syncGeneratedDocsPages,
469
510
  loadDocsConfig,
470
511
  getInitSummary,
471
512
  initConsumer
472
513
  };
473
- //# sourceMappingURL=chunk-67GE3PJ6.js.map
514
+ //# sourceMappingURL=chunk-G7DN5RH7.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/runtime/node/codegen.ts","../src/runtime/node/loadDocsConfig.ts","../src/runtime/node/scaffold.ts"],"sourcesContent":["import fs from 'node:fs'\nimport path from 'node:path'\nimport type { DocPageData, DocPageLinkData, DocsConfig, DocsGlobalContextData } from '../../docs/types.js'\nimport { extractDocHeadings } from '../../docs/docHeadings.js'\nimport { getResolvedPageById, resolveDocsConfig } from '../../docs/resolveDocsConfig.js'\n\nconst GENERATED_DIRNAME = '(nivel-generated)'\n\nconst writeFileIfChanged = (filePath: string, source: string) => {\n const current = fs.existsSync(filePath) ? fs.readFileSync(filePath, 'utf8') : null\n if (current === source) {\n return\n }\n\n fs.mkdirSync(path.dirname(filePath), { recursive: true })\n fs.writeFileSync(filePath, source)\n}\n\nconst toPosix = (value: string) => value.split(path.sep).join(path.posix.sep)\n\nconst getRelativeImportPath = (fromDirectory: string, toFile: string) => {\n const relativePath = toPosix(path.relative(fromDirectory, toFile))\n if (relativePath.startsWith('.')) {\n return relativePath\n }\n return `./${relativePath}`\n}\n\nconst serializeData = (data: DocPageData | DocsGlobalContextData) => JSON.stringify(data, null, 2)\n\nconst collectFiles = (directoryPath: string): string[] => {\n if (!fs.existsSync(directoryPath)) {\n return []\n }\n\n const entries = fs.readdirSync(directoryPath, { withFileTypes: true })\n\n return entries.flatMap((entry) => {\n const entryPath = path.join(directoryPath, entry.name)\n return entry.isDirectory() ? collectFiles(entryPath) : [entryPath]\n })\n}\n\nconst removeEmptyDirectories = (directoryPath: string, rootPath: string) => {\n if (!fs.existsSync(directoryPath)) {\n return\n }\n\n for (const entry of fs.readdirSync(directoryPath, { withFileTypes: true })) {\n if (!entry.isDirectory()) {\n continue\n }\n\n removeEmptyDirectories(path.join(directoryPath, entry.name), rootPath)\n }\n\n if (directoryPath === rootPath) {\n return\n }\n\n if (fs.readdirSync(directoryPath).length === 0) {\n fs.rmdirSync(directoryPath)\n }\n}\n\nconst getGeneratedPageSource = (contentImportPath: string) => {\n return [\n \"import { DocsPage } from '@unterberg/nivel/client'\",\n `import Content from ${JSON.stringify(contentImportPath)}`,\n '',\n 'const Page = () => {',\n ' return <DocsPage Content={Content} />',\n '}',\n '',\n 'export default Page',\n '',\n ].join('\\n')\n}\n\nconst getGeneratedDataSource = (data: DocPageData) => {\n return [\n \"import type { DocPageData } from '@unterberg/nivel'\",\n '',\n `const data: DocPageData = ${serializeData(data)}`,\n '',\n 'const pageData = () => {',\n ' return data',\n '}',\n '',\n 'export default pageData',\n '',\n ].join('\\n')\n}\n\nconst getGeneratedGlobalContextSource = (data: DocsGlobalContextData) => {\n return [\n \"import type { DocsGlobalContextData } from '@unterberg/nivel'\",\n '',\n `const docsGlobalContextData: DocsGlobalContextData = ${serializeData(data)}`,\n '',\n 'export { docsGlobalContextData }',\n '',\n ].join('\\n')\n}\n\nconst getRouteString = (href: string) => {\n if (href === '/') {\n return href\n }\n\n return href.replace(/\\/+$/g, '')\n}\n\nconst getGeneratedRouteSource = (href: string) => {\n return [`export default ${JSON.stringify(getRouteString(href))}`, ''].join('\\n')\n}\n\nconst getGeneratedTextExport = (value: string) => {\n return [`export default ${JSON.stringify(value)}`, ''].join('\\n')\n}\n\nconst toDocPageLinkData = (\n page:\n | {\n id: string\n title: string\n href: string\n documentTitle: string\n }\n | undefined,\n): DocPageLinkData | null => {\n if (!page) {\n return null\n }\n\n return {\n id: page.id,\n title: page.title,\n href: page.href,\n documentTitle: page.documentTitle,\n }\n}\n\nexport const getGeneratedPagesRoot = (rootDir: string) => path.join(rootDir, 'pages', GENERATED_DIRNAME)\n\nexport type DocsSourcePaths = {\n contentRootPath: string\n docsConfigPath: string\n docsGraphPath: string\n generatedRootPath: string\n}\n\nconst getDocsConfigPath = (rootDir: string) => path.join(rootDir, 'pages', '+docs.ts')\n\nconst getDocsGraphPath = (rootDir: string) => path.join(rootDir, 'docs', 'docs.graph.ts')\n\nexport const getDocsSourcePaths = (options: { rootDir: string; docsConfig: DocsConfig }): DocsSourcePaths => {\n const resolved = resolveDocsConfig(options.docsConfig)\n\n return {\n contentRootPath: path.join(options.rootDir, resolved.contentDir),\n docsConfigPath: getDocsConfigPath(options.rootDir),\n docsGraphPath: getDocsGraphPath(options.rootDir),\n generatedRootPath: getGeneratedPagesRoot(options.rootDir),\n }\n}\n\nexport const isDocsSourcePath = (filePath: string, docsSourcePaths: DocsSourcePaths) => {\n const normalized = toPosix(filePath)\n const generatedRootPath = toPosix(docsSourcePaths.generatedRootPath)\n const docsConfigPath = toPosix(docsSourcePaths.docsConfigPath)\n const docsGraphPath = toPosix(docsSourcePaths.docsGraphPath)\n const contentRootPath = toPosix(docsSourcePaths.contentRootPath)\n\n if (normalized.startsWith(generatedRootPath)) {\n return false\n }\n\n return (\n normalized === docsConfigPath ||\n normalized === docsGraphPath ||\n normalized === contentRootPath ||\n normalized.startsWith(`${contentRootPath}/`)\n )\n}\n\nexport const syncGeneratedDocsPages = (options: { rootDir: string; docsConfig: DocsConfig }) => {\n const { rootDir, docsConfig } = options\n const resolved = resolveDocsConfig(docsConfig)\n const generatedPagesRoot = getGeneratedPagesRoot(rootDir)\n const docsContentRoot = path.join(rootDir, resolved.contentDir)\n const expectedFiles = new Set<string>()\n const globalContextFilePath = path.join(generatedPagesRoot, '_docsGlobalContext.ts')\n\n fs.mkdirSync(generatedPagesRoot, { recursive: true })\n\n const globalContextData: DocsGlobalContextData = {\n siteTitle: resolved.siteTitle,\n basePath: resolved.basePath,\n theme: resolved.theme,\n footer: resolved.footer,\n brand: resolved.brand,\n head: resolved.head,\n partners: resolved.partners,\n algolia: resolved.algolia,\n pages: resolved.pages,\n navbarItems: resolved.navbarItems,\n sidebarSections: resolved.sections,\n }\n\n writeFileIfChanged(globalContextFilePath, getGeneratedGlobalContextSource(globalContextData))\n expectedFiles.add(globalContextFilePath)\n\n for (const [pageIndex, page] of resolved.pages.entries()) {\n const contentFilePath = path.join(docsContentRoot, page.source)\n\n if (!fs.existsSync(contentFilePath)) {\n throw new Error(`Docs page \"${page.id}\" points to missing source file: ${contentFilePath}`)\n }\n\n const pageSource = fs.readFileSync(contentFilePath, 'utf8')\n const data: DocPageData = {\n page: getResolvedPageById(resolved, page.id),\n headings: extractDocHeadings(pageSource),\n previousPage: toDocPageLinkData(resolved.pages[pageIndex - 1]),\n nextPage: toDocPageLinkData(resolved.pages[pageIndex + 1]),\n }\n\n const routeTargets = [\n { routeHref: page.href, routePath: page.slug },\n ...page.aliases.map((routePath, index) => ({\n routeHref: page.aliasHrefs[index] as string,\n routePath,\n })),\n ]\n\n for (const { routeHref, routePath } of routeTargets) {\n const pageDir = path.join(generatedPagesRoot, ...routePath.split('/'))\n const contentImportPath = getRelativeImportPath(pageDir, contentFilePath)\n\n const pageFilePath = path.join(pageDir, '+Page.tsx')\n const dataFilePath = path.join(pageDir, '+data.ts')\n const routeFilePath = path.join(pageDir, '+route.ts')\n const titleFilePath = path.join(pageDir, '+title.ts')\n\n writeFileIfChanged(pageFilePath, getGeneratedPageSource(contentImportPath))\n writeFileIfChanged(dataFilePath, getGeneratedDataSource(data))\n writeFileIfChanged(routeFilePath, getGeneratedRouteSource(routeHref))\n writeFileIfChanged(titleFilePath, getGeneratedTextExport(page.documentTitle))\n\n expectedFiles.add(pageFilePath)\n expectedFiles.add(dataFilePath)\n expectedFiles.add(routeFilePath)\n expectedFiles.add(titleFilePath)\n\n if (page.description) {\n const descriptionFilePath = path.join(pageDir, '+description.ts')\n writeFileIfChanged(descriptionFilePath, getGeneratedTextExport(page.description))\n expectedFiles.add(descriptionFilePath)\n }\n }\n }\n\n for (const filePath of collectFiles(generatedPagesRoot)) {\n if (expectedFiles.has(filePath)) {\n continue\n }\n\n fs.rmSync(filePath, { force: true })\n }\n\n removeEmptyDirectories(generatedPagesRoot, generatedPagesRoot)\n}\n","import path from 'node:path'\nimport type { DocsConfig } from '../../docs/types.js'\n\nconst getDocsConfigModulePath = (rootDir: string) => {\n return path.join(rootDir, 'pages', '+docs.ts')\n}\n\nconst getDocsConfigFromLoadedModule = (loaded: unknown, modulePath: string) => {\n const docsConfig = (loaded as { default?: DocsConfig }).default\n\n if (!docsConfig) {\n throw new Error(`Expected default export from ${modulePath}`)\n }\n\n return docsConfig\n}\n\nexport const loadDocsConfig = async (options: {\n rootDir: string\n loadModule: (modulePath: string) => Promise<unknown>\n}) => {\n const modulePath = getDocsConfigModulePath(options.rootDir)\n const loaded = await options.loadModule(modulePath)\n return getDocsConfigFromLoadedModule(loaded, modulePath)\n}\n","import fs from 'node:fs'\nimport path from 'node:path'\n\nconst MANAGED_SCRIPT_NAMES = ['generate:docs', 'predev', 'prebuild', 'pretypecheck'] as const\n\nconst REQUIRED_DEPENDENCIES = ['@unterberg/nivel', 'react', 'react-dom', 'vike', 'vike-react'] as const\nconst REQUIRED_DEV_DEPENDENCIES = ['vite', 'typescript', '@types/react', '@types/react-dom'] as const\n\ntype InitConsumerOptions = { force: boolean; rootDir: string }\n\ntype InitConsumerResult = {\n allDependenciesPresent: boolean\n createdFiles: string[]\n missingDependencies: string[]\n overwrittenFiles: string[]\n skippedFiles: string[]\n updatedScripts: string[]\n}\n\ntype PackageJsonShape = {\n dependencies?: Record<string, string>\n devDependencies?: Record<string, string>\n packageManager?: string\n scripts?: Record<string, string>\n}\n\nconst getDocsConfigTemplate = () => {\n return [\n \"import { defineDocsConfig } from '@unterberg/nivel/config'\",\n \"import { docsGraph } from '../docs/docs.graph'\",\n '',\n 'const docsConfig = defineDocsConfig({',\n ' graph: docsGraph,',\n \" siteTitle: 'My Docs',\",\n \" siteDescription: 'Documentation site powered by @unterberg/nivel.',\",\n \" basePath: '/docs',\",\n '})',\n '',\n 'export default docsConfig',\n '',\n ].join('\\n')\n}\n\nconst getDocsGraphTemplate = () => {\n return [\n \"import { defineDocsGraph } from '@unterberg/nivel/config'\",\n '',\n 'export const docsGraph = defineDocsGraph({',\n ' items: [',\n ' {',\n \" kind: 'section',\",\n \" id: 'docs',\",\n \" title: 'Docs',\",\n ' items: [',\n ' {',\n \" kind: 'page',\",\n \" id: 'gettingStarted',\",\n \" title: 'Getting Started',\",\n \" slug: 'getting-started',\",\n \" source: 'content/getting-started/content.mdx',\",\n \" description: 'Getting started with @unterberg/nivel.',\",\n ' },',\n ' ],',\n ' },',\n ' ],',\n '})',\n '',\n ].join('\\n')\n}\n\nconst getConfigTemplate = () => {\n return [\n \"import nivel from '@unterberg/nivel/vike'\",\n \"import type { Config } from 'vike/types'\",\n \"import vikeReact from 'vike-react/config'\",\n \"import docsConfig from './+docs'\",\n '',\n 'export { config }',\n '',\n \"const themePreference = docsConfig.theme?.defaultPreference ?? 'light'\",\n 'const dataTheme =',\n \" themePreference === 'dark'\",\n \" ? (docsConfig.theme?.dark ?? 'consumer-dark')\",\n \" : (docsConfig.theme?.light ?? 'consumer-light')\",\n '',\n 'const config: Config = {',\n ' ...nivel,',\n ' extends: [vikeReact],',\n ' title: docsConfig.siteTitle,',\n ' description: docsConfig.siteDescription ?? `${docsConfig.siteTitle} documentation`,',\n \" htmlAttributes: { 'data-theme': dataTheme },\",\n \" passToClient: ['docs'],\",\n '',\n ' // User-facing Vike levers stay visible in +config.ts.',\n ' prerender: true,',\n ' // ssr: true,',\n \" // prefetchStaticAssets: 'viewport',\",\n '}',\n '',\n ].join('\\n')\n}\n\nconst getHeadTemplate = () => {\n return [\n \"import { MetaHead } from '@unterberg/nivel/client'\",\n '',\n 'export const Head = () => {',\n ' return <MetaHead />',\n '}',\n '',\n ].join('\\n')\n}\n\nconst getLayoutTemplate = () => {\n return [\n \"import { AppLayout } from '@unterberg/nivel/client'\",\n \"import type { ReactNode } from 'react'\",\n '',\n 'const Layout = ({ children }: { children: ReactNode }) => {',\n ' return <AppLayout>{children}</AppLayout>',\n '}',\n '',\n 'export default Layout',\n '',\n ].join('\\n')\n}\n\nconst getGlobalContextTemplate = () => {\n return [\n \"import { docsGlobalContextData } from './(nivel-generated)/_docsGlobalContext'\",\n '',\n 'export const onCreateGlobalContext = (globalContext: { docs?: typeof docsGlobalContextData }) => {',\n ' globalContext.docs = docsGlobalContextData',\n '}',\n '',\n ].join('\\n')\n}\n\nconst getWrapperTemplate = () => {\n return [\n \"import type { ReactNode } from 'react'\",\n '',\n 'const Wrapper = ({ children }: { children: ReactNode }) => {',\n ' return <>{children}</>',\n '}',\n '',\n 'export default Wrapper',\n '',\n ].join('\\n')\n}\n\nconst getGlobalTypesTemplate = () => {\n return [\n \"declare module '*.mdx' {\",\n \" import type { ComponentType } from 'react'\",\n '',\n ' const MdxComponent: ComponentType',\n ' export default MdxComponent',\n '}',\n '',\n \"declare module '*.css'\",\n '',\n 'declare global {',\n ' namespace Vike {',\n ' interface GlobalContext {',\n \" docs: import('@unterberg/nivel').DocsGlobalContextData\",\n ' }',\n ' }',\n '}',\n '',\n ].join('\\n')\n}\n\nconst getManagedFileEntries = () => {\n return [\n ['pages/+docs.ts', getDocsConfigTemplate()],\n ['docs/docs.graph.ts', getDocsGraphTemplate()],\n ['pages/+config.ts', getConfigTemplate()],\n ['pages/+Head.tsx', getHeadTemplate()],\n ['pages/+Layout.tsx', getLayoutTemplate()],\n ['pages/+onCreateGlobalContext.ts', getGlobalContextTemplate()],\n ['pages/+Wrapper.tsx', getWrapperTemplate()],\n ['global.d.ts', getGlobalTypesTemplate()],\n ] as const\n}\n\nconst getGenerateDocsRunner = (packageJson: PackageJsonShape) => {\n const packageManager = packageJson.packageManager?.trim() ?? ''\n\n if (packageManager.startsWith('pnpm@')) {\n return 'pnpm generate:docs'\n }\n\n if (packageManager.startsWith('npm@')) {\n return 'npm run generate:docs'\n }\n\n return 'npm run generate:docs'\n}\n\nconst getManagedScripts = (packageJson: PackageJsonShape) => {\n const generateDocsRunner = getGenerateDocsRunner(packageJson)\n\n return {\n 'generate:docs': 'nivel prepare',\n predev: generateDocsRunner,\n prebuild: generateDocsRunner,\n pretypecheck: generateDocsRunner,\n } satisfies Record<(typeof MANAGED_SCRIPT_NAMES)[number], string>\n}\n\nconst writeFile = (filePath: string, source: string) => {\n fs.mkdirSync(path.dirname(filePath), { recursive: true })\n fs.writeFileSync(filePath, source)\n}\n\nconst writeManagedFile = (\n rootDir: string,\n relativeFilePath: string,\n source: string,\n force: boolean,\n result: InitConsumerResult,\n) => {\n const filePath = path.join(rootDir, relativeFilePath)\n const exists = fs.existsSync(filePath)\n\n if (exists && !force) {\n result.skippedFiles.push(relativeFilePath)\n return\n }\n\n writeFile(filePath, source)\n\n if (exists) {\n result.overwrittenFiles.push(relativeFilePath)\n return\n }\n\n result.createdFiles.push(relativeFilePath)\n}\n\nconst readPackageJson = (rootDir: string) => {\n const packageJsonPath = path.join(rootDir, 'package.json')\n\n if (!fs.existsSync(packageJsonPath)) {\n throw new Error(`Expected package.json in ${rootDir}`)\n }\n\n return {\n packageJson: JSON.parse(fs.readFileSync(packageJsonPath, 'utf8')) as PackageJsonShape,\n packageJsonPath,\n }\n}\n\nconst patchPackageScripts = (packageJson: PackageJsonShape, packageJsonPath: string, result: InitConsumerResult) => {\n const scripts = { ...(packageJson.scripts ?? {}) }\n const managedScripts = getManagedScripts(packageJson)\n\n for (const scriptName of MANAGED_SCRIPT_NAMES) {\n if (scripts[scriptName] === managedScripts[scriptName]) {\n continue\n }\n\n scripts[scriptName] = managedScripts[scriptName]\n result.updatedScripts.push(scriptName)\n }\n\n const nextPackageJson = {\n ...packageJson,\n scripts,\n }\n\n fs.writeFileSync(packageJsonPath, `${JSON.stringify(nextPackageJson, null, 2)}\\n`)\n}\n\nconst getMissingDependencies = (packageJson: PackageJsonShape) => {\n const installed = new Set<string>([\n ...Object.keys(packageJson.dependencies ?? {}),\n ...Object.keys(packageJson.devDependencies ?? {}),\n ])\n\n return [...REQUIRED_DEPENDENCIES, ...REQUIRED_DEV_DEPENDENCIES].filter((packageName) => !installed.has(packageName))\n}\n\nexport const getInitSummary = (result: InitConsumerResult) => {\n const lines = ['Initialized nivel consumer scaffolding.']\n\n if (result.createdFiles.length > 0) {\n lines.push(`Created files: ${result.createdFiles.join(', ')}`)\n }\n\n if (result.overwrittenFiles.length > 0) {\n lines.push(`Overwritten files: ${result.overwrittenFiles.join(', ')}`)\n }\n\n if (result.skippedFiles.length > 0) {\n lines.push(`Skipped existing files: ${result.skippedFiles.join(', ')}`)\n }\n\n if (result.updatedScripts.length > 0) {\n lines.push(`Updated package.json scripts: ${result.updatedScripts.join(', ')}`)\n }\n\n if (result.missingDependencies.length > 0) {\n lines.push(`Missing dependencies: ${result.missingDependencies.join(', ')}`)\n lines.push(\n 'Consumer CSS stays hand-authored. Add your stylesheet import manually, for example in pages/+Wrapper.tsx.',\n )\n } else if (!result.allDependenciesPresent) {\n lines.push('Dependency validation completed with warnings.')\n } else {\n lines.push('All required dependencies are already present.')\n }\n\n return `${lines.join('\\n')}\\n`\n}\n\nexport const initConsumer = (options: InitConsumerOptions): InitConsumerResult => {\n const result: InitConsumerResult = {\n allDependenciesPresent: true,\n createdFiles: [],\n missingDependencies: [],\n overwrittenFiles: [],\n skippedFiles: [],\n updatedScripts: [],\n }\n\n const { packageJson, packageJsonPath } = readPackageJson(options.rootDir)\n\n for (const [relativeFilePath, source] of getManagedFileEntries()) {\n writeManagedFile(options.rootDir, relativeFilePath, source, options.force, result)\n }\n\n patchPackageScripts(packageJson, packageJsonPath, result)\n\n result.missingDependencies = getMissingDependencies(packageJson)\n result.allDependenciesPresent = result.missingDependencies.length === 0\n\n return result\n}\n"],"mappings":";;;;;;;;;AAAA,OAAO,QAAQ;AACf,OAAO,UAAU;AAKjB,IAAM,oBAAoB;AAE1B,IAAM,qBAAqB,CAAC,UAAkB,WAAmB;AAC/D,QAAM,UAAU,GAAG,WAAW,QAAQ,IAAI,GAAG,aAAa,UAAU,MAA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ACJ;AAAA,IACF;AAAA,EACF,WAAW,CAAC,OAAO,wBAAwB;AACzC,UAAM,KAAK,gDAAgD;AAAA,EAC7D,OAAO;AACL,UAAM,KAAK,gDAAgD;AAAA,EAC7D;AAEA,SAAO,GAAG,MAAM,KAAK,IAAI,CAAC;AAAA;AAC5B;AAEO,IAAM,eAAe,CAAC,YAAqD;AAChF,QAAM,SAA6B;AAAA,IACjC,wBAAwB;AAAA,IACxB,cAAc,CAAC;AAAA,IACf,qBAAqB,CAAC;AAAA,IACtB,kBAAkB,CAAC;AAAA,IACnB,cAAc,CAAC;AAAA,IACf,gBAAgB,CAAC;AAAA,EACnB;AAEA,QAAM,EAAE,aAAa,gBAAgB,IAAI,gBAAgB,QAAQ,OAAO;AAExE,aAAW,CAAC,kBAAkB,MAAM,KAAK,sBAAsB,GAAG;AAChE,qBAAiB,QAAQ,SAAS,kBAAkB,QAAQ,QAAQ,OAAO,MAAM;AAAA,EACnF;AAEA,sBAAoB,aAAa,iBAAiB,MAAM;AAExD,SAAO,sBAAsB,uBAAuB,WAAW;AAC/D,SAAO,yBAAyB,OAAO,oBAAoB,WAAW;AAEtE,SAAO;AACT;","names":["path","fs","path"]}
@@ -0,0 +1,65 @@
1
+ // src/docs/docHeadings.ts
2
+ var normalizeWhitespace = (value) => value.replace(/\s+/g, " ").trim();
3
+ var slugifyHeading = (value) => {
4
+ const normalized = normalizeWhitespace(value).normalize("NFKD").toLowerCase().replace(/['"]/g, "").replace(/[^\p{Letter}\p{Number}\s-]/gu, " ").replace(/\s+/g, "-").replace(/-+/g, "-").replace(/^-+|-+$/g, "");
5
+ return normalized || "section";
6
+ };
7
+ var createHeadingSlugger = () => {
8
+ const slugCounts = /* @__PURE__ */ new Map();
9
+ return (value) => {
10
+ const baseSlug = slugifyHeading(value);
11
+ const count = slugCounts.get(baseSlug) ?? 0;
12
+ slugCounts.set(baseSlug, count + 1);
13
+ return count === 0 ? baseSlug : `${baseSlug}-${count}`;
14
+ };
15
+ };
16
+ var stripInlineMarkdown = (value) => {
17
+ return normalizeWhitespace(
18
+ value.replace(/!\[([^\]]*)\]\([^)]+\)/g, "$1").replace(/\[([^\]]+)\]\([^)]+\)/g, "$1").replace(/`([^`]+)`/g, "$1").replace(/<[^>]+>/g, " ").replace(/\\([\\`*_[\]{}()#+\-.!])/g, "$1").replace(/[*_~]/g, "").replace(/\{[^}]+\}/g, " ")
19
+ );
20
+ };
21
+ var getFenceMarker = (line) => {
22
+ const match = line.match(/^\s{0,3}(`{3,}|~{3,})/);
23
+ return match?.[1]?.[0] ?? null;
24
+ };
25
+ var extractDocHeadings = (source, minDepth = 2, maxDepth = 3) => {
26
+ const slugify = createHeadingSlugger();
27
+ const headings = [];
28
+ let activeFenceMarker = null;
29
+ for (const line of source.split("\n")) {
30
+ const fenceMarker = getFenceMarker(line);
31
+ if (activeFenceMarker) {
32
+ if (fenceMarker === activeFenceMarker) {
33
+ activeFenceMarker = null;
34
+ }
35
+ continue;
36
+ }
37
+ if (fenceMarker) {
38
+ activeFenceMarker = fenceMarker;
39
+ continue;
40
+ }
41
+ const match = line.match(/^\s{0,3}(#{1,6})\s+(.*?)(?:\s+#+\s*)?$/);
42
+ if (!match) {
43
+ continue;
44
+ }
45
+ const depth = match[1].length;
46
+ const title = stripInlineMarkdown(match[2] ?? "");
47
+ if (!title || depth < minDepth || depth > maxDepth) {
48
+ continue;
49
+ }
50
+ headings.push({
51
+ depth,
52
+ id: slugify(title),
53
+ title
54
+ });
55
+ }
56
+ return headings;
57
+ };
58
+ var normalizeHeadingTitle = (value) => normalizeWhitespace(value);
59
+
60
+ export {
61
+ createHeadingSlugger,
62
+ extractDocHeadings,
63
+ normalizeHeadingTitle
64
+ };
65
+ //# sourceMappingURL=chunk-SOVTSE5J.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/docs/docHeadings.ts"],"sourcesContent":["import type { DocHeading } from './types.js'\n\nconst normalizeWhitespace = (value: string) => value.replace(/\\s+/g, ' ').trim()\n\nconst slugifyHeading = (value: string) => {\n const normalized = normalizeWhitespace(value)\n .normalize('NFKD')\n .toLowerCase()\n .replace(/['\"]/g, '')\n .replace(/[^\\p{Letter}\\p{Number}\\s-]/gu, ' ')\n .replace(/\\s+/g, '-')\n .replace(/-+/g, '-')\n .replace(/^-+|-+$/g, '')\n\n return normalized || 'section'\n}\n\nexport const createHeadingSlugger = () => {\n const slugCounts = new Map<string, number>()\n\n return (value: string) => {\n const baseSlug = slugifyHeading(value)\n const count = slugCounts.get(baseSlug) ?? 0\n slugCounts.set(baseSlug, count + 1)\n\n return count === 0 ? baseSlug : `${baseSlug}-${count}`\n }\n}\n\nconst stripInlineMarkdown = (value: string) => {\n return normalizeWhitespace(\n value\n .replace(/!\\[([^\\]]*)\\]\\([^)]+\\)/g, '$1')\n .replace(/\\[([^\\]]+)\\]\\([^)]+\\)/g, '$1')\n .replace(/`([^`]+)`/g, '$1')\n .replace(/<[^>]+>/g, ' ')\n .replace(/\\\\([\\\\`*_[\\]{}()#+\\-.!])/g, '$1')\n .replace(/[*_~]/g, '')\n .replace(/\\{[^}]+\\}/g, ' '),\n )\n}\n\nconst getFenceMarker = (line: string) => {\n const match = line.match(/^\\s{0,3}(`{3,}|~{3,})/)\n return match?.[1]?.[0] ?? null\n}\n\nexport const extractDocHeadings = (source: string, minDepth = 2, maxDepth = 3): DocHeading[] => {\n const slugify = createHeadingSlugger()\n const headings: DocHeading[] = []\n let activeFenceMarker: string | null = null\n\n for (const line of source.split('\\n')) {\n const fenceMarker = getFenceMarker(line)\n\n if (activeFenceMarker) {\n if (fenceMarker === activeFenceMarker) {\n activeFenceMarker = null\n }\n continue\n }\n\n if (fenceMarker) {\n activeFenceMarker = fenceMarker\n continue\n }\n\n const match = line.match(/^\\s{0,3}(#{1,6})\\s+(.*?)(?:\\s+#+\\s*)?$/)\n if (!match) {\n continue\n }\n\n const depth = match[1].length\n const title = stripInlineMarkdown(match[2] ?? '')\n if (!title || depth < minDepth || depth > maxDepth) {\n continue\n }\n\n headings.push({\n depth,\n id: slugify(title),\n title,\n })\n }\n\n return headings\n}\n\nexport const normalizeHeadingTitle = (value: string) => normalizeWhitespace(value)\n"],"mappings":";AAEA,IAAM,sBAAsB,CAAC,UAAkB,MAAM,QAAQ,QAAQ,GAAG,EAAE,KAAK;AAE/E,IAAM,iBAAiB,CAAC,UAAkB;AACxC,QAAM,aAAa,oBAAoB,KAAK,EACzC,UAAU,MAAM,EAChB,YAAY,EACZ,QAAQ,SAAS,EAAE,EACnB,QAAQ,gCAAgC,GAAG,EAC3C,QAAQ,QAAQ,GAAG,EACnB,QAAQ,OAAO,GAAG,EAClB,QAAQ,YAAY,EAAE;AAEzB,SAAO,cAAc;AACvB;AAEO,IAAM,uBAAuB,MAAM;AACxC,QAAM,aAAa,oBAAI,IAAoB;AAE3C,SAAO,CAAC,UAAkB;AACxB,UAAM,WAAW,eAAe,KAAK;AACrC,UAAM,QAAQ,WAAW,IAAI,QAAQ,KAAK;AAC1C,eAAW,IAAI,UAAU,QAAQ,CAAC;AAElC,WAAO,UAAU,IAAI,WAAW,GAAG,QAAQ,IAAI,KAAK;AAAA,EACtD;AACF;AAEA,IAAM,sBAAsB,CAAC,UAAkB;AAC7C,SAAO;AAAA,IACL,MACG,QAAQ,2BAA2B,IAAI,EACvC,QAAQ,0BAA0B,IAAI,EACtC,QAAQ,cAAc,IAAI,EAC1B,QAAQ,YAAY,GAAG,EACvB,QAAQ,6BAA6B,IAAI,EACzC,QAAQ,UAAU,EAAE,EACpB,QAAQ,cAAc,GAAG;AAAA,EAC9B;AACF;AAEA,IAAM,iBAAiB,CAAC,SAAiB;AACvC,QAAM,QAAQ,KAAK,MAAM,uBAAuB;AAChD,SAAO,QAAQ,CAAC,IAAI,CAAC,KAAK;AAC5B;AAEO,IAAM,qBAAqB,CAAC,QAAgB,WAAW,GAAG,WAAW,MAAoB;AAC9F,QAAM,UAAU,qBAAqB;AACrC,QAAM,WAAyB,CAAC;AAChC,MAAI,oBAAmC;AAEvC,aAAW,Q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