@acmekit/docs-bundler 2.13.41

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js ADDED
@@ -0,0 +1,751 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/index.ts
31
+ var index_exports = {};
32
+ __export(index_exports, {
33
+ build: () => build,
34
+ develop: () => develop,
35
+ serve: () => serve
36
+ });
37
+ module.exports = __toCommonJS(index_exports);
38
+
39
+ // src/commands/develop.ts
40
+ var import_express = __toESM(require("express"));
41
+ var import_fs2 = __toESM(require("fs"));
42
+ var import_path4 = __toESM(require("path"));
43
+
44
+ // src/utils/config.ts
45
+ var import_docs_shared = require("@acmekit/docs-shared");
46
+ var import_path3 = __toESM(require("path"));
47
+
48
+ // src/plugins/inject-tailwindcss.ts
49
+ var import_path = __toESM(require("path"));
50
+ function injectTailwindCSS(options) {
51
+ return {
52
+ name: "acmekit:docs-tailwind",
53
+ config: async () => {
54
+ const docsUiPath = import_path.default.dirname(
55
+ require.resolve("@acmekit/docs-ui/package.json")
56
+ );
57
+ const docsAppPath = import_path.default.dirname(
58
+ require.resolve("@acmekit/docs-app/package.json")
59
+ );
60
+ const sourceExtensions = (options.sources || []).map(
61
+ (source) => `${source}/src/docs/**/*.{js,jsx,ts,tsx,mdx,md}`
62
+ );
63
+ const pluginExtensions = (options.plugins || []).map(
64
+ (plugin) => `${plugin}/**/*.{js,jsx,ts,tsx,mdx,md}`
65
+ );
66
+ return {
67
+ css: {
68
+ postcss: {
69
+ plugins: [
70
+ require("tailwindcss")({
71
+ presets: [require("@acmekit/docs-tailwind").default],
72
+ content: [
73
+ `${options.entry}/**/*.{js,jsx,ts,tsx}`,
74
+ `${docsAppPath}/src/**/*.{js,jsx,ts,tsx}`,
75
+ `${docsUiPath}/src/**/*.{js,jsx,ts,tsx}`,
76
+ ...sourceExtensions,
77
+ ...pluginExtensions
78
+ ],
79
+ darkMode: ["class", `[data-theme="dark"]`]
80
+ })
81
+ ]
82
+ }
83
+ }
84
+ };
85
+ }
86
+ };
87
+ }
88
+
89
+ // ../../../node_modules/unist-util-is/lib/index.js
90
+ var convert = (
91
+ // Note: overloads in JSDoc can’t yet use different `@template`s.
92
+ /**
93
+ * @type {(
94
+ * (<Condition extends string>(test: Condition) => (node: unknown, index?: number | null | undefined, parent?: Parent | null | undefined, context?: unknown) => node is Node & {type: Condition}) &
95
+ * (<Condition extends Props>(test: Condition) => (node: unknown, index?: number | null | undefined, parent?: Parent | null | undefined, context?: unknown) => node is Node & Condition) &
96
+ * (<Condition extends TestFunction>(test: Condition) => (node: unknown, index?: number | null | undefined, parent?: Parent | null | undefined, context?: unknown) => node is Node & Predicate<Condition, Node>) &
97
+ * ((test?: null | undefined) => (node?: unknown, index?: number | null | undefined, parent?: Parent | null | undefined, context?: unknown) => node is Node) &
98
+ * ((test?: Test) => Check)
99
+ * )}
100
+ */
101
+ /**
102
+ * @param {Test} [test]
103
+ * @returns {Check}
104
+ */
105
+ (function(test) {
106
+ if (test === null || test === void 0) {
107
+ return ok;
108
+ }
109
+ if (typeof test === "function") {
110
+ return castFactory(test);
111
+ }
112
+ if (typeof test === "object") {
113
+ return Array.isArray(test) ? anyFactory(test) : (
114
+ // Cast because `ReadonlyArray` goes into the above but `isArray`
115
+ // narrows to `Array`.
116
+ propertiesFactory(
117
+ /** @type {Props} */
118
+ test
119
+ )
120
+ );
121
+ }
122
+ if (typeof test === "string") {
123
+ return typeFactory(test);
124
+ }
125
+ throw new Error("Expected function, string, or object as test");
126
+ })
127
+ );
128
+ function anyFactory(tests) {
129
+ const checks = [];
130
+ let index = -1;
131
+ while (++index < tests.length) {
132
+ checks[index] = convert(tests[index]);
133
+ }
134
+ return castFactory(any);
135
+ function any(...parameters) {
136
+ let index2 = -1;
137
+ while (++index2 < checks.length) {
138
+ if (checks[index2].apply(this, parameters)) return true;
139
+ }
140
+ return false;
141
+ }
142
+ }
143
+ function propertiesFactory(check) {
144
+ const checkAsRecord = (
145
+ /** @type {Record<string, unknown>} */
146
+ check
147
+ );
148
+ return castFactory(all);
149
+ function all(node) {
150
+ const nodeAsRecord = (
151
+ /** @type {Record<string, unknown>} */
152
+ /** @type {unknown} */
153
+ node
154
+ );
155
+ let key;
156
+ for (key in check) {
157
+ if (nodeAsRecord[key] !== checkAsRecord[key]) return false;
158
+ }
159
+ return true;
160
+ }
161
+ }
162
+ function typeFactory(check) {
163
+ return castFactory(type);
164
+ function type(node) {
165
+ return node && node.type === check;
166
+ }
167
+ }
168
+ function castFactory(testFunction) {
169
+ return check;
170
+ function check(value, index, parent) {
171
+ return Boolean(
172
+ looksLikeANode(value) && testFunction.call(
173
+ this,
174
+ value,
175
+ typeof index === "number" ? index : void 0,
176
+ parent || void 0
177
+ )
178
+ );
179
+ }
180
+ }
181
+ function ok() {
182
+ return true;
183
+ }
184
+ function looksLikeANode(value) {
185
+ return value !== null && typeof value === "object" && "type" in value;
186
+ }
187
+
188
+ // ../../../node_modules/unist-util-visit-parents/lib/color.node.js
189
+ function color(d) {
190
+ return "\x1B[33m" + d + "\x1B[39m";
191
+ }
192
+
193
+ // ../../../node_modules/unist-util-visit-parents/lib/index.js
194
+ var empty = [];
195
+ var CONTINUE = true;
196
+ var EXIT = false;
197
+ var SKIP = "skip";
198
+ function visitParents(tree, test, visitor, reverse) {
199
+ let check;
200
+ if (typeof test === "function" && typeof visitor !== "function") {
201
+ reverse = visitor;
202
+ visitor = test;
203
+ } else {
204
+ check = test;
205
+ }
206
+ const is2 = convert(check);
207
+ const step = reverse ? -1 : 1;
208
+ factory(tree, void 0, [])();
209
+ function factory(node, index, parents) {
210
+ const value = (
211
+ /** @type {Record<string, unknown>} */
212
+ node && typeof node === "object" ? node : {}
213
+ );
214
+ if (typeof value.type === "string") {
215
+ const name = (
216
+ // `hast`
217
+ typeof value.tagName === "string" ? value.tagName : (
218
+ // `xast`
219
+ typeof value.name === "string" ? value.name : void 0
220
+ )
221
+ );
222
+ Object.defineProperty(visit2, "name", {
223
+ value: "node (" + color(node.type + (name ? "<" + name + ">" : "")) + ")"
224
+ });
225
+ }
226
+ return visit2;
227
+ function visit2() {
228
+ let result = empty;
229
+ let subresult;
230
+ let offset;
231
+ let grandparents;
232
+ if (!test || is2(node, index, parents[parents.length - 1] || void 0)) {
233
+ result = toResult(visitor(node, parents));
234
+ if (result[0] === EXIT) {
235
+ return result;
236
+ }
237
+ }
238
+ if ("children" in node && node.children) {
239
+ const nodeAsParent = (
240
+ /** @type {UnistParent} */
241
+ node
242
+ );
243
+ if (nodeAsParent.children && result[0] !== SKIP) {
244
+ offset = (reverse ? nodeAsParent.children.length : -1) + step;
245
+ grandparents = parents.concat(nodeAsParent);
246
+ while (offset > -1 && offset < nodeAsParent.children.length) {
247
+ const child = nodeAsParent.children[offset];
248
+ subresult = factory(child, offset, grandparents)();
249
+ if (subresult[0] === EXIT) {
250
+ return subresult;
251
+ }
252
+ offset = typeof subresult[1] === "number" ? subresult[1] : offset + step;
253
+ }
254
+ }
255
+ }
256
+ return result;
257
+ }
258
+ }
259
+ }
260
+ function toResult(value) {
261
+ if (Array.isArray(value)) {
262
+ return value;
263
+ }
264
+ if (typeof value === "number") {
265
+ return [CONTINUE, value];
266
+ }
267
+ return value === null || value === void 0 ? empty : [value];
268
+ }
269
+
270
+ // ../../../node_modules/unist-util-visit/lib/index.js
271
+ function visit(tree, testOrVisitor, visitorOrReverse, maybeReverse) {
272
+ let reverse;
273
+ let test;
274
+ let visitor;
275
+ if (typeof testOrVisitor === "function" && typeof visitorOrReverse !== "function") {
276
+ test = void 0;
277
+ visitor = testOrVisitor;
278
+ reverse = visitorOrReverse;
279
+ } else {
280
+ test = testOrVisitor;
281
+ visitor = visitorOrReverse;
282
+ reverse = maybeReverse;
283
+ }
284
+ visitParents(tree, test, overload, reverse);
285
+ function overload(node, parents) {
286
+ const parent = parents[parents.length - 1];
287
+ const index = parent ? parent.children.indexOf(node) : void 0;
288
+ return visitor(node, index, parent);
289
+ }
290
+ }
291
+
292
+ // src/plugins/remark-lazy-images.ts
293
+ function remarkLazyImages() {
294
+ return (tree) => {
295
+ visit(tree, "image", (node) => {
296
+ const data = node.data || (node.data = {});
297
+ const hProperties = data.hProperties || (data.hProperties = {});
298
+ hProperties.loading = "lazy";
299
+ hProperties.decoding = "async";
300
+ });
301
+ };
302
+ }
303
+
304
+ // src/plugins/inject-mdx.ts
305
+ function injectMdx() {
306
+ let transformFn;
307
+ let resolveIdFn;
308
+ let loadFn;
309
+ return {
310
+ name: "acmekit:docs-mdx",
311
+ enforce: "pre",
312
+ async configResolved() {
313
+ const mdx = (await import("@mdx-js/rollup")).default;
314
+ const remarkGfm = (await import("remark-gfm")).default;
315
+ const remarkFrontmatter = (await import("remark-frontmatter")).default;
316
+ const remarkMdxFrontmatter = (await import("remark-mdx-frontmatter")).default;
317
+ const rehypeSlug = (await import("rehype-slug")).default;
318
+ const rehypeAutolinkHeadings = (await import("rehype-autolink-headings")).default;
319
+ const mdxPlugin = mdx({
320
+ remarkPlugins: [
321
+ remarkGfm,
322
+ remarkFrontmatter,
323
+ [remarkMdxFrontmatter, { name: "frontmatter" }],
324
+ remarkLazyImages
325
+ ],
326
+ rehypePlugins: [
327
+ rehypeSlug,
328
+ [rehypeAutolinkHeadings, { behavior: "wrap" }]
329
+ ],
330
+ providerImportSource: "@mdx-js/react"
331
+ });
332
+ transformFn = mdxPlugin.transform;
333
+ resolveIdFn = mdxPlugin.resolveId;
334
+ loadFn = mdxPlugin.load;
335
+ },
336
+ transform(code, id) {
337
+ if (transformFn) {
338
+ return transformFn.call(this, code, id);
339
+ }
340
+ },
341
+ resolveId(source, importer, options) {
342
+ if (resolveIdFn) {
343
+ return resolveIdFn.call(this, source, importer, options);
344
+ }
345
+ },
346
+ load(id) {
347
+ if (loadFn) {
348
+ return loadFn.call(this, id);
349
+ }
350
+ }
351
+ };
352
+ }
353
+
354
+ // src/utils/write-static-files.ts
355
+ var import_fs = __toESM(require("fs"));
356
+ var import_path2 = __toESM(require("path"));
357
+ var import_outdent = require("outdent");
358
+ function writeFileIfChanged(filePath, content) {
359
+ if (import_fs.default.existsSync(filePath)) {
360
+ const existing = import_fs.default.readFileSync(filePath, "utf-8");
361
+ if (existing === content) return;
362
+ }
363
+ import_fs.default.writeFileSync(filePath, content);
364
+ }
365
+ async function writeStaticFiles(options) {
366
+ const outDir = import_path2.default.resolve(process.cwd(), ".acmekit/docs");
367
+ if (!import_fs.default.existsSync(outDir)) {
368
+ import_fs.default.mkdirSync(outDir, { recursive: true });
369
+ }
370
+ await writeHtmlFile(outDir);
371
+ await writeEntryFile(outDir, options.plugins);
372
+ await writeSSREntryFile(outDir);
373
+ await writeCSSFile(outDir);
374
+ }
375
+ async function writeHtmlFile(outDir) {
376
+ const html = import_outdent.outdent`
377
+ <!DOCTYPE html>
378
+ <html lang="en">
379
+ <head>
380
+ <meta charset="UTF-8" />
381
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
382
+ <title>Documentation</title>
383
+ </head>
384
+ <body>
385
+ <div id="acmekit-docs"></div>
386
+ <script type="module" src="./entry.jsx"></script>
387
+ </body>
388
+ </html>
389
+ `;
390
+ writeFileIfChanged(import_path2.default.join(outDir, "index.html"), html);
391
+ }
392
+ async function writeEntryFile(outDir, plugins) {
393
+ const pluginImports = (plugins || []).map((p, i) => `import plugin${i} from "${p}"`).join("\n");
394
+ const pluginArray = (plugins || []).map((_, i) => `plugin${i}`).join(", ");
395
+ const entry = import_outdent.outdent`
396
+ import { DocsApp } from "@acmekit/docs-app"
397
+ import React from "react"
398
+ import ReactDOM from "react-dom/client"
399
+ import "./index.css"
400
+ ${pluginImports}
401
+
402
+ const plugins = [${pluginArray}]
403
+
404
+ const root = ReactDOM.createRoot(document.getElementById("acmekit-docs"))
405
+ root.render(
406
+ React.createElement(
407
+ React.StrictMode,
408
+ null,
409
+ React.createElement(DocsApp, { plugins })
410
+ )
411
+ )
412
+
413
+ if (import.meta.hot) {
414
+ import.meta.hot.accept()
415
+ }
416
+ `;
417
+ writeFileIfChanged(import_path2.default.join(outDir, "entry.jsx"), entry);
418
+ }
419
+ async function writeSSREntryFile(outDir) {
420
+ const entry = import_outdent.outdent`
421
+ export { render, routes } from "@acmekit/docs-app/entry-server"
422
+ `;
423
+ writeFileIfChanged(import_path2.default.join(outDir, "entry-server.jsx"), entry);
424
+ }
425
+ async function writeCSSFile(outDir) {
426
+ const themeCSS = require.resolve("@acmekit/docs-tailwind/theme.css");
427
+ const themeContent = import_fs.default.readFileSync(themeCSS, "utf-8");
428
+ const css = import_outdent.outdent`
429
+ ${themeContent}
430
+ @tailwind base;
431
+ @tailwind components;
432
+ @tailwind utilities;
433
+ `;
434
+ writeFileIfChanged(import_path2.default.join(outDir, "index.css"), css);
435
+ }
436
+
437
+ // src/plugins/write-static-files.ts
438
+ function writeStaticFiles2(options) {
439
+ return {
440
+ name: "acmekit:docs-write-static-files",
441
+ buildStart: async () => {
442
+ await writeStaticFiles({ plugins: options.plugins });
443
+ }
444
+ };
445
+ }
446
+
447
+ // src/utils/config.ts
448
+ async function getViteConfig(options) {
449
+ const { searchForWorkspaceRoot, mergeConfig } = await import("vite");
450
+ const { default: react } = await import("@vitejs/plugin-react");
451
+ const { default: docsPlugin } = await import("@acmekit/docs-vite-plugin");
452
+ const getPort = await import("get-port");
453
+ const hmrPort = process.env.HMR_PORT ? parseInt(process.env.HMR_PORT) : await getPort.default();
454
+ const hmrOptions = getHmrConfig(hmrPort);
455
+ const root = import_path3.default.resolve(process.cwd(), ".acmekit/docs");
456
+ const resolvePackageDist = (pkg) => {
457
+ try {
458
+ const pkgJson = require.resolve(`${pkg}/package.json`, {
459
+ paths: [process.cwd()]
460
+ });
461
+ return import_path3.default.resolve(import_path3.default.dirname(pkgJson), "dist");
462
+ } catch {
463
+ return null;
464
+ }
465
+ };
466
+ const watchPackages = ["@acmekit/docs-ui", "@acmekit/docs-app"];
467
+ const watchDirs = watchPackages.map((pkg) => resolvePackageDist(pkg)).filter(Boolean);
468
+ const baseConfig = {
469
+ root,
470
+ base: options.path,
471
+ cacheDir: import_path3.default.resolve(process.cwd(), "node_modules/.vite/acmekit-docs"),
472
+ build: {
473
+ emptyOutDir: true,
474
+ outDir: import_path3.default.resolve(process.cwd(), options.outDir)
475
+ },
476
+ optimizeDeps: {
477
+ include: [
478
+ "react",
479
+ "react/jsx-runtime",
480
+ "react-dom/client",
481
+ "react-router-dom",
482
+ "@mdx-js/react",
483
+ "@acmekit/ui",
484
+ "@acmekit/icons",
485
+ "@uidotdev/usehooks",
486
+ "clsx",
487
+ "prism-react-renderer",
488
+ "react-markdown",
489
+ "react-medium-image-zoom",
490
+ "react-tooltip",
491
+ "react-transition-group",
492
+ "react-uuid"
493
+ ],
494
+ exclude: [
495
+ ...import_docs_shared.DOCS_VIRTUAL_MODULES,
496
+ "@acmekit/docs-ui",
497
+ "@acmekit/docs-app"
498
+ ]
499
+ },
500
+ define: {
501
+ __DOCS_BASE__: JSON.stringify(options.path),
502
+ __BACKEND_URL__: JSON.stringify(options.backendUrl ?? "")
503
+ },
504
+ server: {
505
+ fs: {
506
+ allow: [searchForWorkspaceRoot(process.cwd())]
507
+ },
508
+ hmr: hmrOptions
509
+ },
510
+ plugins: [
511
+ watchWorkspacePackages(watchDirs),
512
+ writeStaticFiles2({
513
+ plugins: options.plugins
514
+ }),
515
+ injectTailwindCSS({
516
+ entry: root,
517
+ sources: options.sources,
518
+ plugins: options.plugins
519
+ }),
520
+ injectMdx(),
521
+ react(),
522
+ docsPlugin({
523
+ sources: options.sources,
524
+ basePath: options.path,
525
+ pluginSources: options.pluginSources
526
+ })
527
+ ]
528
+ };
529
+ let finalConfig = baseConfig;
530
+ if (options.vite) {
531
+ const customConfig = options.vite(baseConfig);
532
+ finalConfig = mergeConfig(baseConfig, customConfig);
533
+ }
534
+ return finalConfig;
535
+ }
536
+ function watchWorkspacePackages(dirs) {
537
+ return {
538
+ name: "watch-workspace-packages",
539
+ configureServer(server) {
540
+ if (!dirs.length) {
541
+ return;
542
+ }
543
+ for (const dir of dirs) {
544
+ server.watcher.add(dir);
545
+ }
546
+ server.watcher.on("change", (file) => {
547
+ if (dirs.some((dir) => file.startsWith(dir))) {
548
+ server.moduleGraph.invalidateAll();
549
+ server.ws.send({ type: "full-reload" });
550
+ }
551
+ });
552
+ }
553
+ };
554
+ }
555
+ function getHmrConfig(hmrPort) {
556
+ const options = {
557
+ port: hmrPort
558
+ };
559
+ if (process.env.HMR_PROTOCOL) {
560
+ options.protocol = process.env.HMR_PROTOCOL;
561
+ }
562
+ if (process.env.HMR_HOST) {
563
+ options.host = process.env.HMR_HOST;
564
+ }
565
+ if (process.env.HMR_CLIENT_PORT) {
566
+ options.clientPort = parseInt(process.env.HMR_CLIENT_PORT);
567
+ }
568
+ return options;
569
+ }
570
+
571
+ // src/commands/develop.ts
572
+ var router = import_express.default.Router();
573
+ function findTemplateFilePath(reqPath, root) {
574
+ if (reqPath.endsWith(".html")) {
575
+ const pathToTest = import_path4.default.join(root, reqPath);
576
+ if (import_fs2.default.existsSync(pathToTest)) {
577
+ return pathToTest;
578
+ }
579
+ }
580
+ const basePath = reqPath.slice(0, reqPath.lastIndexOf("/"));
581
+ const dirs = basePath.split("/");
582
+ while (dirs.length > 0) {
583
+ const pathToTest = import_path4.default.join(root, ...dirs, "index.html");
584
+ if (import_fs2.default.existsSync(pathToTest)) {
585
+ return pathToTest;
586
+ }
587
+ dirs.pop();
588
+ }
589
+ return void 0;
590
+ }
591
+ async function injectViteMiddleware(router3, middleware) {
592
+ router3.use((req, res, next) => {
593
+ req.path.endsWith(".html") ? next() : middleware(req, res, next);
594
+ });
595
+ }
596
+ async function injectHtmlMiddleware(router3, server) {
597
+ router3.use(async (req, res, next) => {
598
+ if (req.method !== "GET") {
599
+ return next();
600
+ }
601
+ const templateFilePath = findTemplateFilePath(req.path, server.config.root);
602
+ if (!templateFilePath) {
603
+ return next();
604
+ }
605
+ const template = import_fs2.default.readFileSync(templateFilePath, "utf8");
606
+ const html = await server.transformIndexHtml(
607
+ templateFilePath,
608
+ template,
609
+ req.originalUrl
610
+ );
611
+ res.send(html);
612
+ });
613
+ }
614
+ async function develop(options) {
615
+ const vite = await import("vite");
616
+ try {
617
+ const viteConfig = await getViteConfig(options);
618
+ const developConfig = {
619
+ mode: "development",
620
+ logLevel: "error",
621
+ appType: "spa",
622
+ server: {
623
+ middlewareMode: true
624
+ }
625
+ };
626
+ const mergedConfig = vite.mergeConfig(viteConfig, developConfig);
627
+ const server = await vite.createServer(mergedConfig);
628
+ await injectViteMiddleware(router, server.middlewares);
629
+ await injectHtmlMiddleware(router, server);
630
+ } catch (error) {
631
+ console.error(error);
632
+ throw new Error(
633
+ "Failed to start docs development server. See error above."
634
+ );
635
+ }
636
+ return router;
637
+ }
638
+
639
+ // src/commands/serve.ts
640
+ var import_compression = __toESM(require("compression"));
641
+ var import_express2 = require("express");
642
+ var import_fs3 = __toESM(require("fs"));
643
+ var import_path5 = __toESM(require("path"));
644
+ var router2 = (0, import_express2.Router)();
645
+ async function serve(options) {
646
+ const htmlPath = import_path5.default.resolve(options.outDir, "index.html");
647
+ const indexExists = import_fs3.default.existsSync(htmlPath);
648
+ if (!indexExists) {
649
+ throw new Error(
650
+ `Could not find index.html in the docs build directory. Make sure to run 'acmekit build' before starting the server.`
651
+ );
652
+ }
653
+ const html = import_fs3.default.readFileSync(htmlPath, "utf-8");
654
+ const sendHtml = (_req, res) => {
655
+ res.setHeader("Cache-Control", "no-cache");
656
+ res.setHeader("Vary", "Origin, Cache-Control");
657
+ res.send(html);
658
+ };
659
+ const setStaticHeaders = (res) => {
660
+ res.setHeader("Cache-Control", "max-age=31536000, immutable");
661
+ res.setHeader("Vary", "Origin, Cache-Control");
662
+ };
663
+ router2.use((0, import_compression.default)());
664
+ router2.get("/", sendHtml);
665
+ router2.use(
666
+ (0, import_express2.static)(options.outDir, {
667
+ setHeaders: setStaticHeaders
668
+ })
669
+ );
670
+ router2.get(`/*`, sendHtml);
671
+ return router2;
672
+ }
673
+
674
+ // src/commands/build.ts
675
+ var import_node_fs2 = __toESM(require("fs"));
676
+ var import_node_path2 = __toESM(require("path"));
677
+
678
+ // src/utils/prerender.ts
679
+ var import_node_fs = __toESM(require("fs"));
680
+ var import_node_path = __toESM(require("path"));
681
+ async function prerender(options) {
682
+ const { ssrEntry, htmlTemplate, outDir, basePath } = options;
683
+ const html = import_node_fs.default.readFileSync(htmlTemplate, "utf-8");
684
+ const { render, routes } = await import(ssrEntry);
685
+ for (const route of routes) {
686
+ try {
687
+ const rendered = render(route.path, basePath);
688
+ const pageHtml = html.replace(
689
+ '<div id="acmekit-docs"></div>',
690
+ `<div id="acmekit-docs">${rendered}</div>`
691
+ );
692
+ const routePath = route.path === "/" ? "" : route.path;
693
+ const dir = import_node_path.default.join(outDir, routePath);
694
+ if (!import_node_fs.default.existsSync(dir)) {
695
+ import_node_fs.default.mkdirSync(dir, { recursive: true });
696
+ }
697
+ import_node_fs.default.writeFileSync(import_node_path.default.join(dir, "index.html"), pageHtml);
698
+ } catch {
699
+ }
700
+ }
701
+ }
702
+
703
+ // src/commands/build.ts
704
+ async function build(options) {
705
+ const vite = await import("vite");
706
+ const viteConfig = await getViteConfig(options);
707
+ const buildConfig = {
708
+ mode: "production",
709
+ logLevel: "error"
710
+ };
711
+ await vite.build(vite.mergeConfig(viteConfig, buildConfig));
712
+ const root = import_node_path2.default.resolve(process.cwd(), ".acmekit/docs");
713
+ const ssrOutDir = import_node_path2.default.resolve(process.cwd(), options.outDir, ".ssr");
714
+ try {
715
+ const ssrConfig = {
716
+ ...buildConfig,
717
+ root,
718
+ base: options.path,
719
+ build: {
720
+ ssr: import_node_path2.default.join(root, "entry-server.jsx"),
721
+ outDir: ssrOutDir,
722
+ emptyOutDir: true
723
+ },
724
+ plugins: viteConfig.plugins,
725
+ define: viteConfig.define,
726
+ resolve: viteConfig.resolve
727
+ };
728
+ await vite.build(vite.mergeConfig(viteConfig, ssrConfig));
729
+ const resolvedOutDir = import_node_path2.default.resolve(process.cwd(), options.outDir);
730
+ const ssrEntry = import_node_path2.default.join(ssrOutDir, "entry-server.js");
731
+ if (import_node_fs2.default.existsSync(ssrEntry)) {
732
+ await prerender({
733
+ ssrEntry,
734
+ htmlTemplate: import_node_path2.default.join(resolvedOutDir, "index.html"),
735
+ outDir: resolvedOutDir,
736
+ basePath: options.path
737
+ });
738
+ }
739
+ import_node_fs2.default.rmSync(ssrOutDir, { recursive: true, force: true });
740
+ } catch {
741
+ if (import_node_fs2.default.existsSync(ssrOutDir)) {
742
+ import_node_fs2.default.rmSync(ssrOutDir, { recursive: true, force: true });
743
+ }
744
+ }
745
+ }
746
+ // Annotate the CommonJS export names for ESM import in node:
747
+ 0 && (module.exports = {
748
+ build,
749
+ develop,
750
+ serve
751
+ });