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