@ox-content/vite-plugin 2.81.0 → 2.82.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.
- package/dist/incremental-dom.cjs +3 -2
- package/dist/incremental-dom.cjs.map +1 -1
- package/dist/incremental-dom.d.cts.map +1 -1
- package/dist/incremental-dom.d.mts.map +1 -1
- package/dist/incremental-dom.mjs +2 -1
- package/dist/incremental-dom.mjs.map +1 -1
- package/dist/index.cjs +1486 -99
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -13
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +8 -13
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1429 -69
- package/dist/index.mjs.map +1 -1
- package/dist/interop.cjs.map +1 -1
- package/dist/interop.mjs.map +1 -1
- package/dist/tabs.cjs +3 -4
- package/dist/tabs.cjs.map +1 -1
- package/dist/tabs.mjs +99 -2
- package/dist/tabs.mjs.map +1 -0
- package/dist/vitepress-cli.cjs +5 -4
- package/dist/vitepress-cli.cjs.map +1 -1
- package/dist/vitepress-cli.d.cts +1 -1
- package/dist/vitepress-cli.d.mts +1 -1
- package/dist/vitepress-cli.mjs +4 -2
- package/dist/vitepress-cli.mjs.map +1 -1
- package/dist/vitepress.cjs +106 -2
- package/dist/vitepress.cjs.map +1 -1
- package/dist/vitepress.mjs +32 -2
- package/dist/vitepress.mjs.map +1 -1
- package/package.json +19 -19
- package/dist/chunk.cjs +0 -57
- package/dist/github.cjs +0 -690
- package/dist/github.cjs.map +0 -1
- package/dist/github.mjs +0 -625
- package/dist/github.mjs.map +0 -1
- package/dist/github2.mjs +0 -2
- package/dist/media.cjs +0 -310
- package/dist/media.cjs.map +0 -1
- package/dist/media.mjs +0 -302
- package/dist/media.mjs.map +0 -1
- package/dist/media2.mjs +0 -2
- package/dist/mermaid.cjs +0 -114
- package/dist/mermaid.cjs.map +0 -1
- package/dist/mermaid.mjs +0 -2
- package/dist/mermaid2.mjs +0 -92
- package/dist/mermaid2.mjs.map +0 -1
- package/dist/napi.cjs +0 -45
- package/dist/napi.cjs.map +0 -1
- package/dist/napi.mjs +0 -34
- package/dist/napi.mjs.map +0 -1
- package/dist/ogp.cjs +0 -341
- package/dist/ogp.cjs.map +0 -1
- package/dist/ogp.mjs +0 -2
- package/dist/ogp2.mjs +0 -302
- package/dist/ogp2.mjs.map +0 -1
- package/dist/pm.cjs +0 -45
- package/dist/pm.cjs.map +0 -1
- package/dist/pm.mjs +0 -2
- package/dist/pm2.mjs +0 -38
- package/dist/pm2.mjs.map +0 -1
- package/dist/tabs2.mjs +0 -56
- package/dist/tabs2.mjs.map +0 -1
- package/dist/youtube.cjs +0 -57
- package/dist/youtube.cjs.map +0 -1
- package/dist/youtube.mjs +0 -2
- package/dist/youtube2.mjs +0 -35
- package/dist/youtube2.mjs.map +0 -1
package/dist/interop.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interop.cjs","names":[],"sources":["../src/interop.ts"],"sourcesContent":["/**\n * Interop helpers for loading ESM-only dependencies from the CommonJS build.\n */\n\n/**\n * Unwrap the `default` export of an ESM-only dependency.\n *\n * The CommonJS build (`dist/index.cjs`) loads pure-ESM packages such as\n * `rehype-parse` and `rehype-stringify` through `require(esm)`. The bundler's\n * interop helper then double-wraps their default export: what should be the\n * plugin function arrives as the module namespace `{ default: fn }` instead of\n * `fn` itself. Passing that object to `unified().use()` throws\n * \"Expected usable value but received an empty preset\".\n *\n * Calling `interopDefault` on a default import unwraps one extra level of\n * `default` nesting, so the same code works whether the dependency was loaded\n * as native ESM (`.mjs`) or through the CommonJS interop (`.cjs`). See #452.\n */\nexport function interopDefault<T>(value: T): T {\n if (value !== null && typeof value === \"object\" && \"default\" in value) {\n return (value as { default: T }).default;\n }\n return value;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAkBA,SAAgB,eAAkB,OAAa;CAC7C,IAAI,UAAU,QAAQ,OAAO,UAAU,YAAY,aAAa,OAC9D,OAAQ,MAAyB;CAEnC,OAAO"}
|
|
1
|
+
{"version":3,"file":"interop.cjs","names":[],"sources":["../src/interop.ts"],"sourcesContent":["/**\n * Interop helpers for loading ESM-only dependencies from the CommonJS build.\n */\n\n/**\n * Unwrap the `default` export of an ESM-only dependency.\n *\n * The CommonJS build (`dist/index.cjs`) loads pure-ESM packages such as\n * `rehype-parse` and `rehype-stringify` through `require(esm)`. The bundler's\n * interop helper then double-wraps their default export: what should be the\n * plugin function arrives as the module namespace `{ default: fn }` instead of\n * `fn` itself. Passing that object to `unified().use()` throws\n * \"Expected usable value but received an empty preset\".\n *\n * Calling `interopDefault` on a default import unwraps one extra level of\n * `default` nesting, so the same code works whether the dependency was loaded\n * as native ESM (`.mjs`) or through the CommonJS interop (`.cjs`). See #452.\n */\nexport function interopDefault<T>(value: T): T {\n if (value !== null && typeof value === \"object\" && \"default\" in value) {\n return (value as { default: T }).default;\n }\n return value;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAkBA,SAAgB,eAAkB,OAAa;CAC7C,IAAI,UAAU,QAAQ,OAAO,UAAU,YAAY,aAAa,OAC9D,OAAQ,MAAyB;CAEnC,OAAO;AACT"}
|
package/dist/interop.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interop.mjs","names":[],"sources":["../src/interop.ts"],"sourcesContent":["/**\n * Interop helpers for loading ESM-only dependencies from the CommonJS build.\n */\n\n/**\n * Unwrap the `default` export of an ESM-only dependency.\n *\n * The CommonJS build (`dist/index.cjs`) loads pure-ESM packages such as\n * `rehype-parse` and `rehype-stringify` through `require(esm)`. The bundler's\n * interop helper then double-wraps their default export: what should be the\n * plugin function arrives as the module namespace `{ default: fn }` instead of\n * `fn` itself. Passing that object to `unified().use()` throws\n * \"Expected usable value but received an empty preset\".\n *\n * Calling `interopDefault` on a default import unwraps one extra level of\n * `default` nesting, so the same code works whether the dependency was loaded\n * as native ESM (`.mjs`) or through the CommonJS interop (`.cjs`). See #452.\n */\nexport function interopDefault<T>(value: T): T {\n if (value !== null && typeof value === \"object\" && \"default\" in value) {\n return (value as { default: T }).default;\n }\n return value;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAkBA,SAAgB,eAAkB,OAAa;CAC7C,IAAI,UAAU,QAAQ,OAAO,UAAU,YAAY,aAAa,OAC9D,OAAQ,MAAyB;CAEnC,OAAO"}
|
|
1
|
+
{"version":3,"file":"interop.mjs","names":[],"sources":["../src/interop.ts"],"sourcesContent":["/**\n * Interop helpers for loading ESM-only dependencies from the CommonJS build.\n */\n\n/**\n * Unwrap the `default` export of an ESM-only dependency.\n *\n * The CommonJS build (`dist/index.cjs`) loads pure-ESM packages such as\n * `rehype-parse` and `rehype-stringify` through `require(esm)`. The bundler's\n * interop helper then double-wraps their default export: what should be the\n * plugin function arrives as the module namespace `{ default: fn }` instead of\n * `fn` itself. Passing that object to `unified().use()` throws\n * \"Expected usable value but received an empty preset\".\n *\n * Calling `interopDefault` on a default import unwraps one extra level of\n * `default` nesting, so the same code works whether the dependency was loaded\n * as native ESM (`.mjs`) or through the CommonJS interop (`.cjs`). See #452.\n */\nexport function interopDefault<T>(value: T): T {\n if (value !== null && typeof value === \"object\" && \"default\" in value) {\n return (value as { default: T }).default;\n }\n return value;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAkBA,SAAgB,eAAkB,OAAa;CAC7C,IAAI,UAAU,QAAQ,OAAO,UAAU,YAAY,aAAa,OAC9D,OAAQ,MAAyB;CAEnC,OAAO;AACT"}
|
package/dist/tabs.cjs
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
const
|
|
2
|
-
const require_napi = require("./napi.cjs");
|
|
1
|
+
const require_vitepress = require("./vitepress.cjs");
|
|
3
2
|
//#region src/plugins/tabs.ts
|
|
4
3
|
/**
|
|
5
4
|
* Tabs Plugin - Pure CSS implementation
|
|
@@ -13,7 +12,7 @@ const require_napi = require("./napi.cjs");
|
|
|
13
12
|
* advanced by the number of groups the Rust transform reports, so CSS
|
|
14
13
|
* generation still covers exactly the groups that were emitted.
|
|
15
14
|
*/
|
|
16
|
-
var tabs_exports = /* @__PURE__ */
|
|
15
|
+
var tabs_exports = /* @__PURE__ */ require_vitepress.__exportAll({
|
|
17
16
|
generateTabsCSS: () => generateTabsCSS,
|
|
18
17
|
getTabGroupCounter: () => getTabGroupCounter,
|
|
19
18
|
resetTabGroupCounter: () => resetTabGroupCounter,
|
|
@@ -44,7 +43,7 @@ function setTabGroupCounter(value) {
|
|
|
44
43
|
*/
|
|
45
44
|
async function transformTabs(html) {
|
|
46
45
|
if (!/<tabs/i.test(html)) return html;
|
|
47
|
-
const result = (await
|
|
46
|
+
const result = (await require_vitepress.importNapiModule()).transformTabsEmbeds(html, tabGroupCounter);
|
|
48
47
|
tabGroupCounter += result.groupCount;
|
|
49
48
|
return result.html;
|
|
50
49
|
}
|
package/dist/tabs.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tabs.cjs","names":["importNapiModule"],"sources":["../src/plugins/tabs.ts"],"sourcesContent":["/**\n * Tabs Plugin - Pure CSS implementation\n *\n * Transforms <Tabs>/<Tab> components into accessible HTML with CSS :has()\n * based tab switching (no JavaScript required).\n *\n * The HTML rewrite is performed in Rust (`transformTabsEmbeds` in\n * @ox-content/napi), replacing the previous rehype parse/stringify round-trip.\n * The per-build group counter (consumed by `generateTabsCSS`) stays here and is\n * advanced by the number of groups the Rust transform reports, so CSS\n * generation still covers exactly the groups that were emitted.\n */\n\nimport { importNapiModule } from \"../napi\";\n\nlet tabGroupCounter = 0;\n\n/**\n * Reset tab group counter (for testing and per dev-server request).\n */\nexport function resetTabGroupCounter(): void {\n tabGroupCounter = 0;\n}\n\n/**\n * Read the shared tab group counter. Other tab-like transforms (such as the\n * package-manager tabs) share this counter so `data-group` ids and the CSS\n * generated by {@link generateTabsCSS} stay unique across a page.\n */\nexport function getTabGroupCounter(): number {\n return tabGroupCounter;\n}\n\n/** Set the shared tab group counter (advanced by other tab-like transforms). */\nexport function setTabGroupCounter(value: number): void {\n tabGroupCounter = value;\n}\n\n/**\n * Transform Tabs components in HTML.\n */\nexport async function transformTabs(html: string): Promise<string> {\n // Cheap marker check: skip the NAPI call entirely when there's no `<tabs>`\n // element. The Rust side guards the same way, but short-circuiting here\n // avoids marshalling the whole document across the boundary.\n if (!/<tabs/i.test(html)) {\n return html;\n }\n\n const mod = await importNapiModule();\n const result = mod.transformTabsEmbeds(html, tabGroupCounter);\n tabGroupCounter += result.groupCount;\n return result.html;\n}\n\n/**\n * Generate dynamic CSS for :has() based tab switching.\n * This is needed because :has() selectors need unique IDs.\n */\nexport function generateTabsCSS(groupCount: number): string {\n if (groupCount === 0) return \"\";\n\n let css = \"/* Dynamic Tabs CSS */\\n\";\n\n for (let g = 0; g < groupCount; g++) {\n for (let t = 0; t < 8; t++) {\n css += `.ox-tabs[data-group=\"${g}\"]:has(#ox-tab-${g}-${t}:checked) .ox-tab-panel[data-tab=\"${t}\"] { display: block; }\\n`;\n }\n }\n\n return css;\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"tabs.cjs","names":["importNapiModule"],"sources":["../src/plugins/tabs.ts"],"sourcesContent":["/**\n * Tabs Plugin - Pure CSS implementation\n *\n * Transforms <Tabs>/<Tab> components into accessible HTML with CSS :has()\n * based tab switching (no JavaScript required).\n *\n * The HTML rewrite is performed in Rust (`transformTabsEmbeds` in\n * @ox-content/napi), replacing the previous rehype parse/stringify round-trip.\n * The per-build group counter (consumed by `generateTabsCSS`) stays here and is\n * advanced by the number of groups the Rust transform reports, so CSS\n * generation still covers exactly the groups that were emitted.\n */\n\nimport { importNapiModule } from \"../napi\";\n\nlet tabGroupCounter = 0;\n\n/**\n * Reset tab group counter (for testing and per dev-server request).\n */\nexport function resetTabGroupCounter(): void {\n tabGroupCounter = 0;\n}\n\n/**\n * Read the shared tab group counter. Other tab-like transforms (such as the\n * package-manager tabs) share this counter so `data-group` ids and the CSS\n * generated by {@link generateTabsCSS} stay unique across a page.\n */\nexport function getTabGroupCounter(): number {\n return tabGroupCounter;\n}\n\n/** Set the shared tab group counter (advanced by other tab-like transforms). */\nexport function setTabGroupCounter(value: number): void {\n tabGroupCounter = value;\n}\n\n/**\n * Transform Tabs components in HTML.\n */\nexport async function transformTabs(html: string): Promise<string> {\n // Cheap marker check: skip the NAPI call entirely when there's no `<tabs>`\n // element. The Rust side guards the same way, but short-circuiting here\n // avoids marshalling the whole document across the boundary.\n if (!/<tabs/i.test(html)) {\n return html;\n }\n\n const mod = await importNapiModule();\n const result = mod.transformTabsEmbeds(html, tabGroupCounter);\n tabGroupCounter += result.groupCount;\n return result.html;\n}\n\n/**\n * Generate dynamic CSS for :has() based tab switching.\n * This is needed because :has() selectors need unique IDs.\n */\nexport function generateTabsCSS(groupCount: number): string {\n if (groupCount === 0) return \"\";\n\n let css = \"/* Dynamic Tabs CSS */\\n\";\n\n for (let g = 0; g < groupCount; g++) {\n for (let t = 0; t < 8; t++) {\n css += `.ox-tabs[data-group=\"${g}\"]:has(#ox-tab-${g}-${t}:checked) .ox-tab-panel[data-tab=\"${t}\"] { display: block; }\\n`;\n }\n }\n\n return css;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAeA,IAAI,kBAAkB;;;;AAKtB,SAAgB,uBAA6B;CAC3C,kBAAkB;AACpB;;;;;;AAOA,SAAgB,qBAA6B;CAC3C,OAAO;AACT;;AAGA,SAAgB,mBAAmB,OAAqB;CACtD,kBAAkB;AACpB;;;;AAKA,eAAsB,cAAc,MAA+B;CAIjE,IAAI,CAAC,SAAS,KAAK,IAAI,GACrB,OAAO;CAIT,MAAM,UAAS,MADGA,kBAAAA,iBAAiB,EAAA,CAChB,oBAAoB,MAAM,eAAe;CAC5D,mBAAmB,OAAO;CAC1B,OAAO,OAAO;AAChB;;;;;AAMA,SAAgB,gBAAgB,YAA4B;CAC1D,IAAI,eAAe,GAAG,OAAO;CAE7B,IAAI,MAAM;CAEV,KAAK,IAAI,IAAI,GAAG,IAAI,YAAY,KAC9B,KAAK,IAAI,IAAI,GAAG,IAAI,GAAG,KACrB,OAAO,wBAAwB,EAAE,iBAAiB,EAAE,GAAG,EAAE,oCAAoC,EAAE;CAInG,OAAO;AACT"}
|
package/dist/tabs.mjs
CHANGED
|
@@ -1,2 +1,99 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { d as importNapiModule } from "./vitepress.mjs";
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
|
+
//#region \0rolldown/runtime.js
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __esmMin = (fn, res, err) => () => {
|
|
9
|
+
if (err) throw err[0];
|
|
10
|
+
try {
|
|
11
|
+
return fn && (res = fn(fn = 0)), res;
|
|
12
|
+
} catch (e) {
|
|
13
|
+
throw err = [e], e;
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
var __exportAll = (all, no_symbols) => {
|
|
17
|
+
let target = {};
|
|
18
|
+
for (var name in all) __defProp(target, name, {
|
|
19
|
+
get: all[name],
|
|
20
|
+
enumerable: true
|
|
21
|
+
});
|
|
22
|
+
if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
23
|
+
return target;
|
|
24
|
+
};
|
|
25
|
+
var __copyProps = (to, from, except, desc) => {
|
|
26
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
27
|
+
key = keys[i];
|
|
28
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
29
|
+
get: ((k) => from[k]).bind(null, key),
|
|
30
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
return to;
|
|
34
|
+
};
|
|
35
|
+
var __toCommonJS = (mod) => __hasOwnProp.call(mod, "module.exports") ? mod["module.exports"] : __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
36
|
+
var __require = /* #__PURE__ */ (() => createRequire(import.meta.url))();
|
|
37
|
+
//#endregion
|
|
38
|
+
//#region src/plugins/tabs.ts
|
|
39
|
+
/**
|
|
40
|
+
* Tabs Plugin - Pure CSS implementation
|
|
41
|
+
*
|
|
42
|
+
* Transforms <Tabs>/<Tab> components into accessible HTML with CSS :has()
|
|
43
|
+
* based tab switching (no JavaScript required).
|
|
44
|
+
*
|
|
45
|
+
* The HTML rewrite is performed in Rust (`transformTabsEmbeds` in
|
|
46
|
+
* @ox-content/napi), replacing the previous rehype parse/stringify round-trip.
|
|
47
|
+
* The per-build group counter (consumed by `generateTabsCSS`) stays here and is
|
|
48
|
+
* advanced by the number of groups the Rust transform reports, so CSS
|
|
49
|
+
* generation still covers exactly the groups that were emitted.
|
|
50
|
+
*/
|
|
51
|
+
var tabs_exports = /* @__PURE__ */ __exportAll({
|
|
52
|
+
generateTabsCSS: () => generateTabsCSS,
|
|
53
|
+
getTabGroupCounter: () => getTabGroupCounter,
|
|
54
|
+
resetTabGroupCounter: () => resetTabGroupCounter,
|
|
55
|
+
setTabGroupCounter: () => setTabGroupCounter,
|
|
56
|
+
transformTabs: () => transformTabs
|
|
57
|
+
});
|
|
58
|
+
let tabGroupCounter = 0;
|
|
59
|
+
/**
|
|
60
|
+
* Reset tab group counter (for testing and per dev-server request).
|
|
61
|
+
*/
|
|
62
|
+
function resetTabGroupCounter() {
|
|
63
|
+
tabGroupCounter = 0;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Read the shared tab group counter. Other tab-like transforms (such as the
|
|
67
|
+
* package-manager tabs) share this counter so `data-group` ids and the CSS
|
|
68
|
+
* generated by {@link generateTabsCSS} stay unique across a page.
|
|
69
|
+
*/
|
|
70
|
+
function getTabGroupCounter() {
|
|
71
|
+
return tabGroupCounter;
|
|
72
|
+
}
|
|
73
|
+
/** Set the shared tab group counter (advanced by other tab-like transforms). */
|
|
74
|
+
function setTabGroupCounter(value) {
|
|
75
|
+
tabGroupCounter = value;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Transform Tabs components in HTML.
|
|
79
|
+
*/
|
|
80
|
+
async function transformTabs(html) {
|
|
81
|
+
if (!/<tabs/i.test(html)) return html;
|
|
82
|
+
const result = (await importNapiModule()).transformTabsEmbeds(html, tabGroupCounter);
|
|
83
|
+
tabGroupCounter += result.groupCount;
|
|
84
|
+
return result.html;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Generate dynamic CSS for :has() based tab switching.
|
|
88
|
+
* This is needed because :has() selectors need unique IDs.
|
|
89
|
+
*/
|
|
90
|
+
function generateTabsCSS(groupCount) {
|
|
91
|
+
if (groupCount === 0) return "";
|
|
92
|
+
let css = "/* Dynamic Tabs CSS */\n";
|
|
93
|
+
for (let g = 0; g < groupCount; g++) for (let t = 0; t < 8; t++) css += `.ox-tabs[data-group="${g}"]:has(#ox-tab-${g}-${t}:checked) .ox-tab-panel[data-tab="${t}"] { display: block; }\n`;
|
|
94
|
+
return css;
|
|
95
|
+
}
|
|
96
|
+
//#endregion
|
|
97
|
+
export { tabs_exports as a, __exportAll as c, setTabGroupCounter as i, __require as l, getTabGroupCounter as n, transformTabs as o, resetTabGroupCounter as r, __esmMin as s, generateTabsCSS as t, __toCommonJS as u };
|
|
98
|
+
|
|
99
|
+
//# sourceMappingURL=tabs.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tabs.mjs","names":[],"sources":["../src/plugins/tabs.ts"],"sourcesContent":["/**\n * Tabs Plugin - Pure CSS implementation\n *\n * Transforms <Tabs>/<Tab> components into accessible HTML with CSS :has()\n * based tab switching (no JavaScript required).\n *\n * The HTML rewrite is performed in Rust (`transformTabsEmbeds` in\n * @ox-content/napi), replacing the previous rehype parse/stringify round-trip.\n * The per-build group counter (consumed by `generateTabsCSS`) stays here and is\n * advanced by the number of groups the Rust transform reports, so CSS\n * generation still covers exactly the groups that were emitted.\n */\n\nimport { importNapiModule } from \"../napi\";\n\nlet tabGroupCounter = 0;\n\n/**\n * Reset tab group counter (for testing and per dev-server request).\n */\nexport function resetTabGroupCounter(): void {\n tabGroupCounter = 0;\n}\n\n/**\n * Read the shared tab group counter. Other tab-like transforms (such as the\n * package-manager tabs) share this counter so `data-group` ids and the CSS\n * generated by {@link generateTabsCSS} stay unique across a page.\n */\nexport function getTabGroupCounter(): number {\n return tabGroupCounter;\n}\n\n/** Set the shared tab group counter (advanced by other tab-like transforms). */\nexport function setTabGroupCounter(value: number): void {\n tabGroupCounter = value;\n}\n\n/**\n * Transform Tabs components in HTML.\n */\nexport async function transformTabs(html: string): Promise<string> {\n // Cheap marker check: skip the NAPI call entirely when there's no `<tabs>`\n // element. The Rust side guards the same way, but short-circuiting here\n // avoids marshalling the whole document across the boundary.\n if (!/<tabs/i.test(html)) {\n return html;\n }\n\n const mod = await importNapiModule();\n const result = mod.transformTabsEmbeds(html, tabGroupCounter);\n tabGroupCounter += result.groupCount;\n return result.html;\n}\n\n/**\n * Generate dynamic CSS for :has() based tab switching.\n * This is needed because :has() selectors need unique IDs.\n */\nexport function generateTabsCSS(groupCount: number): string {\n if (groupCount === 0) return \"\";\n\n let css = \"/* Dynamic Tabs CSS */\\n\";\n\n for (let g = 0; g < groupCount; g++) {\n for (let t = 0; t < 8; t++) {\n css += `.ox-tabs[data-group=\"${g}\"]:has(#ox-tab-${g}-${t}:checked) .ox-tab-panel[data-tab=\"${t}\"] { display: block; }\\n`;\n }\n }\n\n return css;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAeA,IAAI,kBAAkB;;;;AAKtB,SAAgB,uBAA6B;CAC3C,kBAAkB;AACpB;;;;;;AAOA,SAAgB,qBAA6B;CAC3C,OAAO;AACT;;AAGA,SAAgB,mBAAmB,OAAqB;CACtD,kBAAkB;AACpB;;;;AAKA,eAAsB,cAAc,MAA+B;CAIjE,IAAI,CAAC,SAAS,KAAK,IAAI,GACrB,OAAO;CAIT,MAAM,UAAS,MADG,iBAAiB,EAAA,CAChB,oBAAoB,MAAM,eAAe;CAC5D,mBAAmB,OAAO;CAC1B,OAAO,OAAO;AAChB;;;;;AAMA,SAAgB,gBAAgB,YAA4B;CAC1D,IAAI,eAAe,GAAG,OAAO;CAE7B,IAAI,MAAM;CAEV,KAAK,IAAI,IAAI,GAAG,IAAI,YAAY,KAC9B,KAAK,IAAI,IAAI,GAAG,IAAI,GAAG,KACrB,OAAO,wBAAwB,EAAE,iBAAiB,EAAE,GAAG,EAAE,oCAAoC,EAAE;CAInG,OAAO;AACT"}
|
package/dist/vitepress-cli.cjs
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
const require_chunk = require("./chunk.cjs");
|
|
3
2
|
const require_vitepress = require("./vitepress.cjs");
|
|
4
3
|
let node_path = require("node:path");
|
|
5
|
-
node_path =
|
|
4
|
+
node_path = require_vitepress.__toESM(node_path, 1);
|
|
6
5
|
let node_fs_promises = require("node:fs/promises");
|
|
7
6
|
let node_url = require("node:url");
|
|
8
7
|
//#region src/vitepress-cli-runtime.ts
|
|
@@ -22,10 +21,12 @@ async function runVitePressMigrationCli(runtime = createVitePressMigrationCliRun
|
|
|
22
21
|
return;
|
|
23
22
|
}
|
|
24
23
|
const cwd = runtime.cwd();
|
|
25
|
-
const
|
|
24
|
+
const config = await loadVitePressConfig(await resolveConfigPath(args.configPath, cwd), cwd, runtime.name);
|
|
25
|
+
const overrides = {
|
|
26
26
|
...args.srcDir ? { srcDir: args.srcDir } : {},
|
|
27
27
|
...args.outDir ? { outDir: args.outDir } : {}
|
|
28
|
-
}
|
|
28
|
+
};
|
|
29
|
+
const source = require_vitepress.generateVitePressMigrationConfig(config, overrides);
|
|
29
30
|
if (!args.out) {
|
|
30
31
|
await runtime.writeStdout(source);
|
|
31
32
|
return;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vitepress-cli.cjs","names":["generateVitePressMigrationConfig","path"],"sources":["../src/vitepress-cli-runtime.ts","../src/vitepress-cli.ts"],"sourcesContent":["import { access, mkdir, writeFile } from \"node:fs/promises\";\nimport * as path from \"node:path\";\nimport { pathToFileURL } from \"node:url\";\nimport type { OxContentOptions } from \"./types\";\nimport { generateVitePressMigrationConfig, type VitePressConfig } from \"./vitepress\";\n\ninterface RuntimeGlobals {\n Deno?: {\n args: string[];\n cwd(): string;\n exit(code?: number): never;\n stderr: {\n write(data: Uint8Array): Promise<number>;\n };\n stdout: {\n write(data: Uint8Array): Promise<number>;\n };\n };\n Bun?: unknown;\n process?: NodeJS.Process;\n}\n\nexport type VitePressMigrationCliRuntimeName = \"node\" | \"deno\" | \"bun\";\n\nexport interface VitePressMigrationCliRuntime {\n name: VitePressMigrationCliRuntimeName;\n argv: string[];\n cwd(): string;\n writeStdout(value: string): void | Promise<void>;\n writeStderr(value: string): void | Promise<void>;\n setExitCode(code: number): void;\n}\n\ninterface CliOptions {\n configPath?: string;\n out?: string;\n srcDir?: string;\n outDir?: string;\n force: boolean;\n help: boolean;\n}\n\ninterface ConfigEnv {\n command: \"build\" | \"serve\";\n mode: string;\n isSsrBuild: boolean;\n isPreview: boolean;\n}\n\nconst DEFAULT_CONFIG_FILES = [\n \".vitepress/config.ts\",\n \".vitepress/config.mts\",\n \".vitepress/config.js\",\n \".vitepress/config.mjs\",\n \".vitepress/config.cts\",\n \".vitepress/config.cjs\",\n];\n\nconst textEncoder = new TextEncoder();\n\nexport async function runVitePressMigrationCli(\n runtime = createVitePressMigrationCliRuntime(),\n): Promise<void> {\n const args = parseVitePressMigrationCliArgs(runtime.argv);\n\n if (args.help) {\n await runtime.writeStdout(helpText());\n return;\n }\n\n const cwd = runtime.cwd();\n const configPath = await resolveConfigPath(args.configPath, cwd);\n const config = await loadVitePressConfig(configPath, cwd, runtime.name);\n const overrides: OxContentOptions = {\n ...(args.srcDir ? { srcDir: args.srcDir } : {}),\n ...(args.outDir ? { outDir: args.outDir } : {}),\n };\n const source = generateVitePressMigrationConfig(config, overrides);\n\n if (!args.out) {\n await runtime.writeStdout(source);\n return;\n }\n\n const outPath = resolvePath(cwd, args.out);\n if (!args.force && (await fileExists(outPath))) {\n throw new Error(`Refusing to overwrite existing file: ${outPath}. Pass --force to overwrite.`);\n }\n\n await mkdir(path.dirname(outPath), { recursive: true });\n await writeFile(outPath, source);\n await runtime.writeStdout(`Wrote ${path.relative(cwd, outPath) || outPath}\\n`);\n}\n\nexport function createVitePressMigrationCliRuntime(): VitePressMigrationCliRuntime {\n const globals = globalThis as typeof globalThis & RuntimeGlobals;\n const deno = globals.Deno;\n const process = globals.process;\n\n if (deno) {\n return {\n name: \"deno\",\n argv: deno.args,\n cwd: () => deno.cwd(),\n writeStdout: async (value) => {\n await deno.stdout.write(textEncoder.encode(value));\n },\n writeStderr: async (value) => {\n await deno.stderr.write(textEncoder.encode(value));\n },\n setExitCode: (code) => {\n deno.exit(code);\n },\n };\n }\n\n if (!process) {\n throw new Error(\"Could not detect a supported JavaScript runtime.\");\n }\n\n return {\n name: globals.Bun ? \"bun\" : \"node\",\n argv: process.argv.slice(2),\n cwd: () => process.cwd(),\n writeStdout: (value) => {\n process.stdout.write(value);\n },\n writeStderr: (value) => {\n process.stderr.write(value);\n },\n setExitCode: (code) => {\n process.exitCode = code;\n },\n };\n}\n\nexport function parseVitePressMigrationCliArgs(argv: string[]): CliOptions {\n const options: CliOptions = {\n force: false,\n help: false,\n };\n\n for (let index = 0; index < argv.length; index += 1) {\n const arg = argv[index];\n\n if (arg === \"--help\" || arg === \"-h\") {\n options.help = true;\n continue;\n }\n\n if (arg === \"--force\" || arg === \"-f\") {\n options.force = true;\n continue;\n }\n\n if (arg === \"--out\" || arg === \"-o\") {\n options.out = readOptionValue(argv, ++index, arg);\n continue;\n }\n\n if (arg === \"--src-dir\") {\n options.srcDir = readOptionValue(argv, ++index, arg);\n continue;\n }\n\n if (arg === \"--out-dir\") {\n options.outDir = readOptionValue(argv, ++index, arg);\n continue;\n }\n\n if (arg.startsWith(\"-\")) {\n throw new Error(`Unknown option: ${arg}`);\n }\n\n if (options.configPath) {\n throw new Error(`Unexpected positional argument: ${arg}`);\n }\n\n options.configPath = arg;\n }\n\n return options;\n}\n\nfunction readOptionValue(argv: string[], index: number, option: string): string {\n const value = argv[index];\n if (!value || value.startsWith(\"-\")) {\n throw new Error(`Missing value for ${option}`);\n }\n return value;\n}\n\nasync function resolveConfigPath(configPath: string | undefined, cwd: string): Promise<string> {\n if (configPath) {\n return resolvePath(cwd, configPath);\n }\n\n for (const candidate of DEFAULT_CONFIG_FILES) {\n const resolved = resolvePath(cwd, candidate);\n if (await fileExists(resolved)) {\n return resolved;\n }\n }\n\n throw new Error(\n `Could not find a VitePress config. Pass one explicitly, e.g. ${DEFAULT_CONFIG_FILES[0]}`,\n );\n}\n\nasync function loadVitePressConfig(\n configPath: string,\n cwd: string,\n runtime: VitePressMigrationCliRuntimeName,\n): Promise<VitePressConfig> {\n const loaders =\n runtime === \"deno\" || runtime === \"bun\"\n ? [loadConfigByNativeImport, loadConfigWithVite]\n : [loadConfigWithVite, loadConfigByNativeImport];\n const errors: string[] = [];\n\n for (const load of loaders) {\n try {\n return await load(configPath, cwd);\n } catch (error) {\n errors.push(error instanceof Error ? error.message : String(error));\n }\n }\n\n throw new Error(\n `Could not load VitePress config: ${configPath}\\n${errors.map((error) => `- ${error}`).join(\"\\n\")}`,\n );\n}\n\nasync function loadConfigWithVite(configPath: string, cwd: string): Promise<VitePressConfig> {\n const vite = (await import(\"vite\")) as {\n loadConfigFromFile(\n env: ConfigEnv,\n configFile?: string,\n configRoot?: string,\n logLevel?: \"silent\",\n ): Promise<{ config: unknown } | null>;\n };\n const loaded = await vite.loadConfigFromFile(createConfigEnv(), configPath, cwd, \"silent\");\n\n return normalizeLoadedConfig(loaded?.config, configPath);\n}\n\nasync function loadConfigByNativeImport(configPath: string): Promise<VitePressConfig> {\n const url = pathToFileURL(configPath);\n url.searchParams.set(\"mtime\", String(Date.now()));\n const module = (await import(url.href)) as { default?: unknown };\n\n return normalizeLoadedConfig(module.default ?? module, configPath);\n}\n\nasync function normalizeLoadedConfig(value: unknown, configPath: string): Promise<VitePressConfig> {\n const config = typeof value === \"function\" ? await value(createConfigEnv()) : await value;\n\n if (!config || typeof config !== \"object\" || Array.isArray(config)) {\n throw new Error(`VitePress config did not export an object: ${configPath}`);\n }\n\n return config as VitePressConfig;\n}\n\nasync function fileExists(filePath: string): Promise<boolean> {\n try {\n await access(filePath);\n return true;\n } catch {\n return false;\n }\n}\n\nfunction createConfigEnv(): ConfigEnv {\n return {\n command: \"build\",\n mode: \"production\",\n isSsrBuild: false,\n isPreview: false,\n };\n}\n\nfunction resolvePath(cwd: string, value: string): string {\n return path.isAbsolute(value) ? path.normalize(value) : path.resolve(cwd, value);\n}\n\nfunction helpText(): string {\n return `ox-content-migrate-vitepress [config]\n\nGenerate an editable ox-content options object from a VitePress config.\n\nOptions:\n -o, --out <file> Write the generated TypeScript module to a file.\n --src-dir <dir> Add/override the ox-content srcDir option.\n --out-dir <dir> Add/override the ox-content outDir option.\n -f, --force Overwrite --out when the file already exists.\n -h, --help Show this help.\n\nWhen --out is omitted, the generated module is printed to stdout.\n`;\n}\n","#!/usr/bin/env node\nimport {\n createVitePressMigrationCliRuntime,\n runVitePressMigrationCli,\n} from \"./vitepress-cli-runtime\";\n\nconst runtime = createVitePressMigrationCliRuntime();\n\nrunVitePressMigrationCli(runtime).catch(async (error) => {\n await runtime.writeStderr(`${error instanceof Error ? error.message : String(error)}\\n`);\n runtime.setExitCode(1);\n});\n"],"mappings":";;;;;;;;AAiDA,MAAM,uBAAuB;CAC3B;CACA;CACA;CACA;CACA;CACA;CACD;AAED,MAAM,cAAc,IAAI,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AAI;EACF,OAAA,GAAA,iBAAA,QAAa,SAAS;EACtB,OAAO;SACD;EACN,OAAO;;;AAIX,SAAS,kBAA6B;CACpC,OAAO;EACL,SAAS;EACT,MAAM;EACN,YAAY;EACZ,WAAW;EACZ;;AAGH,SAAS,YAAY,KAAa,OAAuB;CACvD,OAAOA,UAAK,WAAW,MAAM,GAAGA,UAAK,UAAU,MAAM,GAAGA,UAAK,QAAQ,KAAK,MAAM;;AAGlF,SAAS,WAAmB;CAC1B,OAAO;;;;;;;;;;;;;;;;AC1RT,MAAM,UAAU,oCAAoC;AAEpD,yBAAyB,QAAQ,CAAC,MAAM,OAAO,UAAU;CACvD,MAAM,QAAQ,YAAY,GAAG,iBAAiB,QAAQ,MAAM,UAAU,OAAO,MAAM,CAAC,IAAI;CACxF,QAAQ,YAAY,EAAE;EACtB"}
|
|
1
|
+
{"version":3,"file":"vitepress-cli.cjs","names":["generateVitePressMigrationConfig","mkdir","path","writeFile","pathToFileURL","access"],"sources":["../src/vitepress-cli-runtime.ts","../src/vitepress-cli.ts"],"sourcesContent":["import { access, mkdir, writeFile } from \"node:fs/promises\";\nimport * as path from \"node:path\";\nimport { pathToFileURL } from \"node:url\";\nimport type { OxContentOptions } from \"./types\";\nimport { generateVitePressMigrationConfig, type VitePressConfig } from \"./vitepress\";\n\ninterface RuntimeGlobals {\n Deno?: {\n args: string[];\n cwd(): string;\n exit(code?: number): never;\n stderr: {\n write(data: Uint8Array): Promise<number>;\n };\n stdout: {\n write(data: Uint8Array): Promise<number>;\n };\n };\n Bun?: unknown;\n process?: NodeJS.Process;\n}\n\nexport type VitePressMigrationCliRuntimeName = \"node\" | \"deno\" | \"bun\";\n\nexport interface VitePressMigrationCliRuntime {\n name: VitePressMigrationCliRuntimeName;\n argv: string[];\n cwd(): string;\n writeStdout(value: string): void | Promise<void>;\n writeStderr(value: string): void | Promise<void>;\n setExitCode(code: number): void;\n}\n\ninterface CliOptions {\n configPath?: string;\n out?: string;\n srcDir?: string;\n outDir?: string;\n force: boolean;\n help: boolean;\n}\n\ninterface ConfigEnv {\n command: \"build\" | \"serve\";\n mode: string;\n isSsrBuild: boolean;\n isPreview: boolean;\n}\n\nconst DEFAULT_CONFIG_FILES = [\n \".vitepress/config.ts\",\n \".vitepress/config.mts\",\n \".vitepress/config.js\",\n \".vitepress/config.mjs\",\n \".vitepress/config.cts\",\n \".vitepress/config.cjs\",\n];\n\nconst textEncoder = new TextEncoder();\n\nexport async function runVitePressMigrationCli(\n runtime = createVitePressMigrationCliRuntime(),\n): Promise<void> {\n const args = parseVitePressMigrationCliArgs(runtime.argv);\n\n if (args.help) {\n await runtime.writeStdout(helpText());\n return;\n }\n\n const cwd = runtime.cwd();\n const configPath = await resolveConfigPath(args.configPath, cwd);\n const config = await loadVitePressConfig(configPath, cwd, runtime.name);\n const overrides: OxContentOptions = {\n ...(args.srcDir ? { srcDir: args.srcDir } : {}),\n ...(args.outDir ? { outDir: args.outDir } : {}),\n };\n const source = generateVitePressMigrationConfig(config, overrides);\n\n if (!args.out) {\n await runtime.writeStdout(source);\n return;\n }\n\n const outPath = resolvePath(cwd, args.out);\n if (!args.force && (await fileExists(outPath))) {\n throw new Error(`Refusing to overwrite existing file: ${outPath}. Pass --force to overwrite.`);\n }\n\n await mkdir(path.dirname(outPath), { recursive: true });\n await writeFile(outPath, source);\n await runtime.writeStdout(`Wrote ${path.relative(cwd, outPath) || outPath}\\n`);\n}\n\nexport function createVitePressMigrationCliRuntime(): VitePressMigrationCliRuntime {\n const globals = globalThis as typeof globalThis & RuntimeGlobals;\n const deno = globals.Deno;\n const process = globals.process;\n\n if (deno) {\n return {\n name: \"deno\",\n argv: deno.args,\n cwd: () => deno.cwd(),\n writeStdout: async (value) => {\n await deno.stdout.write(textEncoder.encode(value));\n },\n writeStderr: async (value) => {\n await deno.stderr.write(textEncoder.encode(value));\n },\n setExitCode: (code) => {\n deno.exit(code);\n },\n };\n }\n\n if (!process) {\n throw new Error(\"Could not detect a supported JavaScript runtime.\");\n }\n\n return {\n name: globals.Bun ? \"bun\" : \"node\",\n argv: process.argv.slice(2),\n cwd: () => process.cwd(),\n writeStdout: (value) => {\n process.stdout.write(value);\n },\n writeStderr: (value) => {\n process.stderr.write(value);\n },\n setExitCode: (code) => {\n process.exitCode = code;\n },\n };\n}\n\nexport function parseVitePressMigrationCliArgs(argv: string[]): CliOptions {\n const options: CliOptions = {\n force: false,\n help: false,\n };\n\n for (let index = 0; index < argv.length; index += 1) {\n const arg = argv[index];\n\n if (arg === \"--help\" || arg === \"-h\") {\n options.help = true;\n continue;\n }\n\n if (arg === \"--force\" || arg === \"-f\") {\n options.force = true;\n continue;\n }\n\n if (arg === \"--out\" || arg === \"-o\") {\n options.out = readOptionValue(argv, ++index, arg);\n continue;\n }\n\n if (arg === \"--src-dir\") {\n options.srcDir = readOptionValue(argv, ++index, arg);\n continue;\n }\n\n if (arg === \"--out-dir\") {\n options.outDir = readOptionValue(argv, ++index, arg);\n continue;\n }\n\n if (arg.startsWith(\"-\")) {\n throw new Error(`Unknown option: ${arg}`);\n }\n\n if (options.configPath) {\n throw new Error(`Unexpected positional argument: ${arg}`);\n }\n\n options.configPath = arg;\n }\n\n return options;\n}\n\nfunction readOptionValue(argv: string[], index: number, option: string): string {\n const value = argv[index];\n if (!value || value.startsWith(\"-\")) {\n throw new Error(`Missing value for ${option}`);\n }\n return value;\n}\n\nasync function resolveConfigPath(configPath: string | undefined, cwd: string): Promise<string> {\n if (configPath) {\n return resolvePath(cwd, configPath);\n }\n\n for (const candidate of DEFAULT_CONFIG_FILES) {\n const resolved = resolvePath(cwd, candidate);\n if (await fileExists(resolved)) {\n return resolved;\n }\n }\n\n throw new Error(\n `Could not find a VitePress config. Pass one explicitly, e.g. ${DEFAULT_CONFIG_FILES[0]}`,\n );\n}\n\nasync function loadVitePressConfig(\n configPath: string,\n cwd: string,\n runtime: VitePressMigrationCliRuntimeName,\n): Promise<VitePressConfig> {\n const loaders =\n runtime === \"deno\" || runtime === \"bun\"\n ? [loadConfigByNativeImport, loadConfigWithVite]\n : [loadConfigWithVite, loadConfigByNativeImport];\n const errors: string[] = [];\n\n for (const load of loaders) {\n try {\n return await load(configPath, cwd);\n } catch (error) {\n errors.push(error instanceof Error ? error.message : String(error));\n }\n }\n\n throw new Error(\n `Could not load VitePress config: ${configPath}\\n${errors.map((error) => `- ${error}`).join(\"\\n\")}`,\n );\n}\n\nasync function loadConfigWithVite(configPath: string, cwd: string): Promise<VitePressConfig> {\n const vite = (await import(\"vite\")) as {\n loadConfigFromFile(\n env: ConfigEnv,\n configFile?: string,\n configRoot?: string,\n logLevel?: \"silent\",\n ): Promise<{ config: unknown } | null>;\n };\n const loaded = await vite.loadConfigFromFile(createConfigEnv(), configPath, cwd, \"silent\");\n\n return normalizeLoadedConfig(loaded?.config, configPath);\n}\n\nasync function loadConfigByNativeImport(configPath: string): Promise<VitePressConfig> {\n const url = pathToFileURL(configPath);\n url.searchParams.set(\"mtime\", String(Date.now()));\n const module = (await import(url.href)) as { default?: unknown };\n\n return normalizeLoadedConfig(module.default ?? module, configPath);\n}\n\nasync function normalizeLoadedConfig(value: unknown, configPath: string): Promise<VitePressConfig> {\n const config = typeof value === \"function\" ? await value(createConfigEnv()) : await value;\n\n if (!config || typeof config !== \"object\" || Array.isArray(config)) {\n throw new Error(`VitePress config did not export an object: ${configPath}`);\n }\n\n return config as VitePressConfig;\n}\n\nasync function fileExists(filePath: string): Promise<boolean> {\n try {\n await access(filePath);\n return true;\n } catch {\n return false;\n }\n}\n\nfunction createConfigEnv(): ConfigEnv {\n return {\n command: \"build\",\n mode: \"production\",\n isSsrBuild: false,\n isPreview: false,\n };\n}\n\nfunction resolvePath(cwd: string, value: string): string {\n return path.isAbsolute(value) ? path.normalize(value) : path.resolve(cwd, value);\n}\n\nfunction helpText(): string {\n return `ox-content-migrate-vitepress [config]\n\nGenerate an editable ox-content options object from a VitePress config.\n\nOptions:\n -o, --out <file> Write the generated TypeScript module to a file.\n --src-dir <dir> Add/override the ox-content srcDir option.\n --out-dir <dir> Add/override the ox-content outDir option.\n -f, --force Overwrite --out when the file already exists.\n -h, --help Show this help.\n\nWhen --out is omitted, the generated module is printed to stdout.\n`;\n}\n","#!/usr/bin/env node\nimport {\n createVitePressMigrationCliRuntime,\n runVitePressMigrationCli,\n} from \"./vitepress-cli-runtime\";\n\nconst runtime = createVitePressMigrationCliRuntime();\n\nrunVitePressMigrationCli(runtime).catch(async (error) => {\n await runtime.writeStderr(`${error instanceof Error ? error.message : String(error)}\\n`);\n runtime.setExitCode(1);\n});\n"],"mappings":";;;;;;;AAiDA,MAAM,uBAAuB;CAC3B;CACA;CACA;CACA;CACA;CACA;AACF;AAEA,MAAM,cAAc,IAAI,YAAY;AAEpC,eAAsB,yBACpB,UAAU,mCAAmC,GAC9B;CACf,MAAM,OAAO,+BAA+B,QAAQ,IAAI;CAExD,IAAI,KAAK,MAAM;EACb,MAAM,QAAQ,YAAY,SAAS,CAAC;EACpC;CACF;CAEA,MAAM,MAAM,QAAQ,IAAI;CAExB,MAAM,SAAS,MAAM,oBAAoB,MADhB,kBAAkB,KAAK,YAAY,GAAG,GACV,KAAK,QAAQ,IAAI;CACtE,MAAM,YAA8B;EAClC,GAAI,KAAK,SAAS,EAAE,QAAQ,KAAK,OAAO,IAAI,CAAC;EAC7C,GAAI,KAAK,SAAS,EAAE,QAAQ,KAAK,OAAO,IAAI,CAAC;CAC/C;CACA,MAAM,SAASA,kBAAAA,iCAAiC,QAAQ,SAAS;CAEjE,IAAI,CAAC,KAAK,KAAK;EACb,MAAM,QAAQ,YAAY,MAAM;EAChC;CACF;CAEA,MAAM,UAAU,YAAY,KAAK,KAAK,GAAG;CACzC,IAAI,CAAC,KAAK,SAAU,MAAM,WAAW,OAAO,GAC1C,MAAM,IAAI,MAAM,wCAAwC,QAAQ,6BAA6B;CAG/F,OAAA,GAAMC,iBAAAA,MAAAA,CAAMC,UAAK,QAAQ,OAAO,GAAG,EAAE,WAAW,KAAK,CAAC;CACtD,OAAA,GAAMC,iBA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
|
|
1
|
+
export {}
|
package/dist/vitepress-cli.d.mts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export {}
|
package/dist/vitepress-cli.mjs
CHANGED
|
@@ -20,10 +20,12 @@ async function runVitePressMigrationCli(runtime = createVitePressMigrationCliRun
|
|
|
20
20
|
return;
|
|
21
21
|
}
|
|
22
22
|
const cwd = runtime.cwd();
|
|
23
|
-
const
|
|
23
|
+
const config = await loadVitePressConfig(await resolveConfigPath(args.configPath, cwd), cwd, runtime.name);
|
|
24
|
+
const overrides = {
|
|
24
25
|
...args.srcDir ? { srcDir: args.srcDir } : {},
|
|
25
26
|
...args.outDir ? { outDir: args.outDir } : {}
|
|
26
|
-
}
|
|
27
|
+
};
|
|
28
|
+
const source = generateVitePressMigrationConfig(config, overrides);
|
|
27
29
|
if (!args.out) {
|
|
28
30
|
await runtime.writeStdout(source);
|
|
29
31
|
return;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vitepress-cli.mjs","names":["path"],"sources":["../src/vitepress-cli-runtime.ts","../src/vitepress-cli.ts"],"sourcesContent":["import { access, mkdir, writeFile } from \"node:fs/promises\";\nimport * as path from \"node:path\";\nimport { pathToFileURL } from \"node:url\";\nimport type { OxContentOptions } from \"./types\";\nimport { generateVitePressMigrationConfig, type VitePressConfig } from \"./vitepress\";\n\ninterface RuntimeGlobals {\n Deno?: {\n args: string[];\n cwd(): string;\n exit(code?: number): never;\n stderr: {\n write(data: Uint8Array): Promise<number>;\n };\n stdout: {\n write(data: Uint8Array): Promise<number>;\n };\n };\n Bun?: unknown;\n process?: NodeJS.Process;\n}\n\nexport type VitePressMigrationCliRuntimeName = \"node\" | \"deno\" | \"bun\";\n\nexport interface VitePressMigrationCliRuntime {\n name: VitePressMigrationCliRuntimeName;\n argv: string[];\n cwd(): string;\n writeStdout(value: string): void | Promise<void>;\n writeStderr(value: string): void | Promise<void>;\n setExitCode(code: number): void;\n}\n\ninterface CliOptions {\n configPath?: string;\n out?: string;\n srcDir?: string;\n outDir?: string;\n force: boolean;\n help: boolean;\n}\n\ninterface ConfigEnv {\n command: \"build\" | \"serve\";\n mode: string;\n isSsrBuild: boolean;\n isPreview: boolean;\n}\n\nconst DEFAULT_CONFIG_FILES = [\n \".vitepress/config.ts\",\n \".vitepress/config.mts\",\n \".vitepress/config.js\",\n \".vitepress/config.mjs\",\n \".vitepress/config.cts\",\n \".vitepress/config.cjs\",\n];\n\nconst textEncoder = new TextEncoder();\n\nexport async function runVitePressMigrationCli(\n runtime = createVitePressMigrationCliRuntime(),\n): Promise<void> {\n const args = parseVitePressMigrationCliArgs(runtime.argv);\n\n if (args.help) {\n await runtime.writeStdout(helpText());\n return;\n }\n\n const cwd = runtime.cwd();\n const configPath = await resolveConfigPath(args.configPath, cwd);\n const config = await loadVitePressConfig(configPath, cwd, runtime.name);\n const overrides: OxContentOptions = {\n ...(args.srcDir ? { srcDir: args.srcDir } : {}),\n ...(args.outDir ? { outDir: args.outDir } : {}),\n };\n const source = generateVitePressMigrationConfig(config, overrides);\n\n if (!args.out) {\n await runtime.writeStdout(source);\n return;\n }\n\n const outPath = resolvePath(cwd, args.out);\n if (!args.force && (await fileExists(outPath))) {\n throw new Error(`Refusing to overwrite existing file: ${outPath}. Pass --force to overwrite.`);\n }\n\n await mkdir(path.dirname(outPath), { recursive: true });\n await writeFile(outPath, source);\n await runtime.writeStdout(`Wrote ${path.relative(cwd, outPath) || outPath}\\n`);\n}\n\nexport function createVitePressMigrationCliRuntime(): VitePressMigrationCliRuntime {\n const globals = globalThis as typeof globalThis & RuntimeGlobals;\n const deno = globals.Deno;\n const process = globals.process;\n\n if (deno) {\n return {\n name: \"deno\",\n argv: deno.args,\n cwd: () => deno.cwd(),\n writeStdout: async (value) => {\n await deno.stdout.write(textEncoder.encode(value));\n },\n writeStderr: async (value) => {\n await deno.stderr.write(textEncoder.encode(value));\n },\n setExitCode: (code) => {\n deno.exit(code);\n },\n };\n }\n\n if (!process) {\n throw new Error(\"Could not detect a supported JavaScript runtime.\");\n }\n\n return {\n name: globals.Bun ? \"bun\" : \"node\",\n argv: process.argv.slice(2),\n cwd: () => process.cwd(),\n writeStdout: (value) => {\n process.stdout.write(value);\n },\n writeStderr: (value) => {\n process.stderr.write(value);\n },\n setExitCode: (code) => {\n process.exitCode = code;\n },\n };\n}\n\nexport function parseVitePressMigrationCliArgs(argv: string[]): CliOptions {\n const options: CliOptions = {\n force: false,\n help: false,\n };\n\n for (let index = 0; index < argv.length; index += 1) {\n const arg = argv[index];\n\n if (arg === \"--help\" || arg === \"-h\") {\n options.help = true;\n continue;\n }\n\n if (arg === \"--force\" || arg === \"-f\") {\n options.force = true;\n continue;\n }\n\n if (arg === \"--out\" || arg === \"-o\") {\n options.out = readOptionValue(argv, ++index, arg);\n continue;\n }\n\n if (arg === \"--src-dir\") {\n options.srcDir = readOptionValue(argv, ++index, arg);\n continue;\n }\n\n if (arg === \"--out-dir\") {\n options.outDir = readOptionValue(argv, ++index, arg);\n continue;\n }\n\n if (arg.startsWith(\"-\")) {\n throw new Error(`Unknown option: ${arg}`);\n }\n\n if (options.configPath) {\n throw new Error(`Unexpected positional argument: ${arg}`);\n }\n\n options.configPath = arg;\n }\n\n return options;\n}\n\nfunction readOptionValue(argv: string[], index: number, option: string): string {\n const value = argv[index];\n if (!value || value.startsWith(\"-\")) {\n throw new Error(`Missing value for ${option}`);\n }\n return value;\n}\n\nasync function resolveConfigPath(configPath: string | undefined, cwd: string): Promise<string> {\n if (configPath) {\n return resolvePath(cwd, configPath);\n }\n\n for (const candidate of DEFAULT_CONFIG_FILES) {\n const resolved = resolvePath(cwd, candidate);\n if (await fileExists(resolved)) {\n return resolved;\n }\n }\n\n throw new Error(\n `Could not find a VitePress config. Pass one explicitly, e.g. ${DEFAULT_CONFIG_FILES[0]}`,\n );\n}\n\nasync function loadVitePressConfig(\n configPath: string,\n cwd: string,\n runtime: VitePressMigrationCliRuntimeName,\n): Promise<VitePressConfig> {\n const loaders =\n runtime === \"deno\" || runtime === \"bun\"\n ? [loadConfigByNativeImport, loadConfigWithVite]\n : [loadConfigWithVite, loadConfigByNativeImport];\n const errors: string[] = [];\n\n for (const load of loaders) {\n try {\n return await load(configPath, cwd);\n } catch (error) {\n errors.push(error instanceof Error ? error.message : String(error));\n }\n }\n\n throw new Error(\n `Could not load VitePress config: ${configPath}\\n${errors.map((error) => `- ${error}`).join(\"\\n\")}`,\n );\n}\n\nasync function loadConfigWithVite(configPath: string, cwd: string): Promise<VitePressConfig> {\n const vite = (await import(\"vite\")) as {\n loadConfigFromFile(\n env: ConfigEnv,\n configFile?: string,\n configRoot?: string,\n logLevel?: \"silent\",\n ): Promise<{ config: unknown } | null>;\n };\n const loaded = await vite.loadConfigFromFile(createConfigEnv(), configPath, cwd, \"silent\");\n\n return normalizeLoadedConfig(loaded?.config, configPath);\n}\n\nasync function loadConfigByNativeImport(configPath: string): Promise<VitePressConfig> {\n const url = pathToFileURL(configPath);\n url.searchParams.set(\"mtime\", String(Date.now()));\n const module = (await import(url.href)) as { default?: unknown };\n\n return normalizeLoadedConfig(module.default ?? module, configPath);\n}\n\nasync function normalizeLoadedConfig(value: unknown, configPath: string): Promise<VitePressConfig> {\n const config = typeof value === \"function\" ? await value(createConfigEnv()) : await value;\n\n if (!config || typeof config !== \"object\" || Array.isArray(config)) {\n throw new Error(`VitePress config did not export an object: ${configPath}`);\n }\n\n return config as VitePressConfig;\n}\n\nasync function fileExists(filePath: string): Promise<boolean> {\n try {\n await access(filePath);\n return true;\n } catch {\n return false;\n }\n}\n\nfunction createConfigEnv(): ConfigEnv {\n return {\n command: \"build\",\n mode: \"production\",\n isSsrBuild: false,\n isPreview: false,\n };\n}\n\nfunction resolvePath(cwd: string, value: string): string {\n return path.isAbsolute(value) ? path.normalize(value) : path.resolve(cwd, value);\n}\n\nfunction helpText(): string {\n return `ox-content-migrate-vitepress [config]\n\nGenerate an editable ox-content options object from a VitePress config.\n\nOptions:\n -o, --out <file> Write the generated TypeScript module to a file.\n --src-dir <dir> Add/override the ox-content srcDir option.\n --out-dir <dir> Add/override the ox-content outDir option.\n -f, --force Overwrite --out when the file already exists.\n -h, --help Show this help.\n\nWhen --out is omitted, the generated module is printed to stdout.\n`;\n}\n","#!/usr/bin/env node\nimport {\n createVitePressMigrationCliRuntime,\n runVitePressMigrationCli,\n} from \"./vitepress-cli-runtime\";\n\nconst runtime = createVitePressMigrationCliRuntime();\n\nrunVitePressMigrationCli(runtime).catch(async (error) => {\n await runtime.writeStderr(`${error instanceof Error ? error.message : String(error)}\\n`);\n runtime.setExitCode(1);\n});\n"],"mappings":";;;;;;AAiDA,MAAM,uBAAuB;CAC3B;CACA;CACA;CACA;CACA;CACA;CACD;AAED,MAAM,cAAc,IAAI,aAAa;AAErC,eAAsB,yBACpB,UAAU,oCAAoC,EAC/B;CACf,MAAM,OAAO,+BAA+B,QAAQ,KAAK;CAEzD,IAAI,KAAK,MAAM;EACb,MAAM,QAAQ,YAAY,UAAU,CAAC;EACrC;;CAGF,MAAM,MAAM,QAAQ,KAAK;CAOzB,MAAM,SAAS,iCAAiC,MAL3B,oBAAoB,MADhB,kBAAkB,KAAK,YAAY,IAAI,EACX,KAAK,QAAQ,KAAK,EAKf;EAHtD,GAAI,KAAK,SAAS,EAAE,QAAQ,KAAK,QAAQ,GAAG,EAAE;EAC9C,GAAI,KAAK,SAAS,EAAE,QAAQ,KAAK,QAAQ,GAAG,EAAE;EAEiB,CAAC;CAElE,IAAI,CAAC,KAAK,KAAK;EACb,MAAM,QAAQ,YAAY,OAAO;EACjC;;CAGF,MAAM,UAAU,YAAY,KAAK,KAAK,IAAI;CAC1C,IAAI,CAAC,KAAK,SAAU,MAAM,WAAW,QAAQ,EAC3C,MAAM,IAAI,MAAM,wCAAwC,QAAQ,8BAA8B;CAGhG,MAAM,MAAMA,OAAK,QAAQ,QAAQ,EAAE,EAAE,WAAW,MAAM,CAAC;CACvD,MAAM,UAAU,SAAS,OAAO;CAChC,MAAM,QAAQ,YAAY,SA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,WAAW;CACrC,IAAI,aAAa,IAAI,SAAS,OAAO,KAAK,KAAK,CAAC,CAAC;CACjD,MAAM,SAAU,MAAM,OAAO,IAAI;CAEjC,OAAO,sBAAsB,OAAO,WAAW,QAAQ,WAAW;;AAGpE,eAAe,sBAAsB,OAAgB,YAA8C;CACjG,MAAM,SAAS,OAAO,UAAU,aAAa,MAAM,MAAM,iBAAiB,CAAC,GAAG,MAAM;CAEpF,IAAI,CAAC,UAAU,OAAO,WAAW,YAAY,MAAM,QAAQ,OAAO,EAChE,MAAM,IAAI,MAAM,8CAA8C,aAAa;CAG7E,OAAO;;AAGT,eAAe,WAAW,UAAoC;CAC5D,IAAI;EACF,MAAM,OAAO,SAAS;EACtB,OAAO;SACD;EACN,OAAO;;;AAIX,SAAS,kBAA6B;CACpC,OAAO;EACL,SAAS;EACT,MAAM;EACN,YAAY;EACZ,WAAW;EACZ;;AAGH,SAAS,YAAY,KAAa,OAAuB;CACvD,OAAOA,OAAK,WAAW,MAAM,GAAGA,OAAK,UAAU,MAAM,GAAGA,OAAK,QAAQ,KAAK,MAAM;;AAGlF,SAAS,WAAmB;CAC1B,OAAO;;;;;;;;;;;;;;;;AC1RT,MAAM,UAAU,oCAAoC;AAEpD,yBAAyB,QAAQ,CAAC,MAAM,OAAO,UAAU;CACvD,MAAM,QAAQ,YAAY,GAAG,iBAAiB,QAAQ,MAAM,UAAU,OAAO,MAAM,CAAC,IAAI;CACxF,QAAQ,YAAY,EAAE;EACtB"}
|
|
1
|
+
{"version":3,"file":"vitepress-cli.mjs","names":["path"],"sources":["../src/vitepress-cli-runtime.ts","../src/vitepress-cli.ts"],"sourcesContent":["import { access, mkdir, writeFile } from \"node:fs/promises\";\nimport * as path from \"node:path\";\nimport { pathToFileURL } from \"node:url\";\nimport type { OxContentOptions } from \"./types\";\nimport { generateVitePressMigrationConfig, type VitePressConfig } from \"./vitepress\";\n\ninterface RuntimeGlobals {\n Deno?: {\n args: string[];\n cwd(): string;\n exit(code?: number): never;\n stderr: {\n write(data: Uint8Array): Promise<number>;\n };\n stdout: {\n write(data: Uint8Array): Promise<number>;\n };\n };\n Bun?: unknown;\n process?: NodeJS.Process;\n}\n\nexport type VitePressMigrationCliRuntimeName = \"node\" | \"deno\" | \"bun\";\n\nexport interface VitePressMigrationCliRuntime {\n name: VitePressMigrationCliRuntimeName;\n argv: string[];\n cwd(): string;\n writeStdout(value: string): void | Promise<void>;\n writeStderr(value: string): void | Promise<void>;\n setExitCode(code: number): void;\n}\n\ninterface CliOptions {\n configPath?: string;\n out?: string;\n srcDir?: string;\n outDir?: string;\n force: boolean;\n help: boolean;\n}\n\ninterface ConfigEnv {\n command: \"build\" | \"serve\";\n mode: string;\n isSsrBuild: boolean;\n isPreview: boolean;\n}\n\nconst DEFAULT_CONFIG_FILES = [\n \".vitepress/config.ts\",\n \".vitepress/config.mts\",\n \".vitepress/config.js\",\n \".vitepress/config.mjs\",\n \".vitepress/config.cts\",\n \".vitepress/config.cjs\",\n];\n\nconst textEncoder = new TextEncoder();\n\nexport async function runVitePressMigrationCli(\n runtime = createVitePressMigrationCliRuntime(),\n): Promise<void> {\n const args = parseVitePressMigrationCliArgs(runtime.argv);\n\n if (args.help) {\n await runtime.writeStdout(helpText());\n return;\n }\n\n const cwd = runtime.cwd();\n const configPath = await resolveConfigPath(args.configPath, cwd);\n const config = await loadVitePressConfig(configPath, cwd, runtime.name);\n const overrides: OxContentOptions = {\n ...(args.srcDir ? { srcDir: args.srcDir } : {}),\n ...(args.outDir ? { outDir: args.outDir } : {}),\n };\n const source = generateVitePressMigrationConfig(config, overrides);\n\n if (!args.out) {\n await runtime.writeStdout(source);\n return;\n }\n\n const outPath = resolvePath(cwd, args.out);\n if (!args.force && (await fileExists(outPath))) {\n throw new Error(`Refusing to overwrite existing file: ${outPath}. Pass --force to overwrite.`);\n }\n\n await mkdir(path.dirname(outPath), { recursive: true });\n await writeFile(outPath, source);\n await runtime.writeStdout(`Wrote ${path.relative(cwd, outPath) || outPath}\\n`);\n}\n\nexport function createVitePressMigrationCliRuntime(): VitePressMigrationCliRuntime {\n const globals = globalThis as typeof globalThis & RuntimeGlobals;\n const deno = globals.Deno;\n const process = globals.process;\n\n if (deno) {\n return {\n name: \"deno\",\n argv: deno.args,\n cwd: () => deno.cwd(),\n writeStdout: async (value) => {\n await deno.stdout.write(textEncoder.encode(value));\n },\n writeStderr: async (value) => {\n await deno.stderr.write(textEncoder.encode(value));\n },\n setExitCode: (code) => {\n deno.exit(code);\n },\n };\n }\n\n if (!process) {\n throw new Error(\"Could not detect a supported JavaScript runtime.\");\n }\n\n return {\n name: globals.Bun ? \"bun\" : \"node\",\n argv: process.argv.slice(2),\n cwd: () => process.cwd(),\n writeStdout: (value) => {\n process.stdout.write(value);\n },\n writeStderr: (value) => {\n process.stderr.write(value);\n },\n setExitCode: (code) => {\n process.exitCode = code;\n },\n };\n}\n\nexport function parseVitePressMigrationCliArgs(argv: string[]): CliOptions {\n const options: CliOptions = {\n force: false,\n help: false,\n };\n\n for (let index = 0; index < argv.length; index += 1) {\n const arg = argv[index];\n\n if (arg === \"--help\" || arg === \"-h\") {\n options.help = true;\n continue;\n }\n\n if (arg === \"--force\" || arg === \"-f\") {\n options.force = true;\n continue;\n }\n\n if (arg === \"--out\" || arg === \"-o\") {\n options.out = readOptionValue(argv, ++index, arg);\n continue;\n }\n\n if (arg === \"--src-dir\") {\n options.srcDir = readOptionValue(argv, ++index, arg);\n continue;\n }\n\n if (arg === \"--out-dir\") {\n options.outDir = readOptionValue(argv, ++index, arg);\n continue;\n }\n\n if (arg.startsWith(\"-\")) {\n throw new Error(`Unknown option: ${arg}`);\n }\n\n if (options.configPath) {\n throw new Error(`Unexpected positional argument: ${arg}`);\n }\n\n options.configPath = arg;\n }\n\n return options;\n}\n\nfunction readOptionValue(argv: string[], index: number, option: string): string {\n const value = argv[index];\n if (!value || value.startsWith(\"-\")) {\n throw new Error(`Missing value for ${option}`);\n }\n return value;\n}\n\nasync function resolveConfigPath(configPath: string | undefined, cwd: string): Promise<string> {\n if (configPath) {\n return resolvePath(cwd, configPath);\n }\n\n for (const candidate of DEFAULT_CONFIG_FILES) {\n const resolved = resolvePath(cwd, candidate);\n if (await fileExists(resolved)) {\n return resolved;\n }\n }\n\n throw new Error(\n `Could not find a VitePress config. Pass one explicitly, e.g. ${DEFAULT_CONFIG_FILES[0]}`,\n );\n}\n\nasync function loadVitePressConfig(\n configPath: string,\n cwd: string,\n runtime: VitePressMigrationCliRuntimeName,\n): Promise<VitePressConfig> {\n const loaders =\n runtime === \"deno\" || runtime === \"bun\"\n ? [loadConfigByNativeImport, loadConfigWithVite]\n : [loadConfigWithVite, loadConfigByNativeImport];\n const errors: string[] = [];\n\n for (const load of loaders) {\n try {\n return await load(configPath, cwd);\n } catch (error) {\n errors.push(error instanceof Error ? error.message : String(error));\n }\n }\n\n throw new Error(\n `Could not load VitePress config: ${configPath}\\n${errors.map((error) => `- ${error}`).join(\"\\n\")}`,\n );\n}\n\nasync function loadConfigWithVite(configPath: string, cwd: string): Promise<VitePressConfig> {\n const vite = (await import(\"vite\")) as {\n loadConfigFromFile(\n env: ConfigEnv,\n configFile?: string,\n configRoot?: string,\n logLevel?: \"silent\",\n ): Promise<{ config: unknown } | null>;\n };\n const loaded = await vite.loadConfigFromFile(createConfigEnv(), configPath, cwd, \"silent\");\n\n return normalizeLoadedConfig(loaded?.config, configPath);\n}\n\nasync function loadConfigByNativeImport(configPath: string): Promise<VitePressConfig> {\n const url = pathToFileURL(configPath);\n url.searchParams.set(\"mtime\", String(Date.now()));\n const module = (await import(url.href)) as { default?: unknown };\n\n return normalizeLoadedConfig(module.default ?? module, configPath);\n}\n\nasync function normalizeLoadedConfig(value: unknown, configPath: string): Promise<VitePressConfig> {\n const config = typeof value === \"function\" ? await value(createConfigEnv()) : await value;\n\n if (!config || typeof config !== \"object\" || Array.isArray(config)) {\n throw new Error(`VitePress config did not export an object: ${configPath}`);\n }\n\n return config as VitePressConfig;\n}\n\nasync function fileExists(filePath: string): Promise<boolean> {\n try {\n await access(filePath);\n return true;\n } catch {\n return false;\n }\n}\n\nfunction createConfigEnv(): ConfigEnv {\n return {\n command: \"build\",\n mode: \"production\",\n isSsrBuild: false,\n isPreview: false,\n };\n}\n\nfunction resolvePath(cwd: string, value: string): string {\n return path.isAbsolute(value) ? path.normalize(value) : path.resolve(cwd, value);\n}\n\nfunction helpText(): string {\n return `ox-content-migrate-vitepress [config]\n\nGenerate an editable ox-content options object from a VitePress config.\n\nOptions:\n -o, --out <file> Write the generated TypeScript module to a file.\n --src-dir <dir> Add/override the ox-content srcDir option.\n --out-dir <dir> Add/override the ox-content outDir option.\n -f, --force Overwrite --out when the file already exists.\n -h, --help Show this help.\n\nWhen --out is omitted, the generated module is printed to stdout.\n`;\n}\n","#!/usr/bin/env node\nimport {\n createVitePressMigrationCliRuntime,\n runVitePressMigrationCli,\n} from \"./vitepress-cli-runtime\";\n\nconst runtime = createVitePressMigrationCliRuntime();\n\nrunVitePressMigrationCli(runtime).catch(async (error) => {\n await runtime.writeStderr(`${error instanceof Error ? error.message : String(error)}\\n`);\n runtime.setExitCode(1);\n});\n"],"mappings":";;;;;;AAiDA,MAAM,uBAAuB;CAC3B;CACA;CACA;CACA;CACA;CACA;AACF;AAEA,MAAM,cAAc,IAAI,YAAY;AAEpC,eAAsB,yBACpB,UAAU,mCAAmC,GAC9B;CACf,MAAM,OAAO,+BAA+B,QAAQ,IAAI;CAExD,IAAI,KAAK,MAAM;EACb,MAAM,QAAQ,YAAY,SAAS,CAAC;EACpC;CACF;CAEA,MAAM,MAAM,QAAQ,IAAI;CAExB,MAAM,SAAS,MAAM,oBAAoB,MADhB,kBAAkB,KAAK,YAAY,GAAG,GACV,KAAK,QAAQ,IAAI;CACtE,MAAM,YAA8B;EAClC,GAAI,KAAK,SAAS,EAAE,QAAQ,KAAK,OAAO,IAAI,CAAC;EAC7C,GAAI,KAAK,SAAS,EAAE,QAAQ,KAAK,OAAO,IAAI,CAAC;CAC/C;CACA,MAAM,SAAS,i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AAM,UAAU,mCAAmC;AAEnD,yBAAyB,OAAO,CAAC,CAAC,MAAM,OAAO,UAAU;CACvD,MAAM,QAAQ,YAAY,GAAG,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,EAAE,GAAG;CACvF,QAAQ,YAAY,CAAC;AACvB,CAAC"}
|
package/dist/vitepress.cjs
CHANGED
|
@@ -1,4 +1,72 @@
|
|
|
1
|
-
|
|
1
|
+
//#region \0rolldown/runtime.js
|
|
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 __esmMin = (fn, res, err) => () => {
|
|
9
|
+
if (err) throw err[0];
|
|
10
|
+
try {
|
|
11
|
+
return fn && (res = fn(fn = 0)), res;
|
|
12
|
+
} catch (e) {
|
|
13
|
+
throw err = [e], e;
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
var __exportAll = (all, no_symbols) => {
|
|
17
|
+
let target = {};
|
|
18
|
+
for (var name in all) __defProp(target, name, {
|
|
19
|
+
get: all[name],
|
|
20
|
+
enumerable: true
|
|
21
|
+
});
|
|
22
|
+
if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
23
|
+
return target;
|
|
24
|
+
};
|
|
25
|
+
var __copyProps = (to, from, except, desc) => {
|
|
26
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
27
|
+
key = keys[i];
|
|
28
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
29
|
+
get: ((k) => from[k]).bind(null, key),
|
|
30
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
return to;
|
|
34
|
+
};
|
|
35
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
|
|
36
|
+
value: mod,
|
|
37
|
+
enumerable: true
|
|
38
|
+
}) : target, mod));
|
|
39
|
+
var __toCommonJS = (mod) => __hasOwnProp.call(mod, "module.exports") ? mod["module.exports"] : __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
40
|
+
//#region src/napi.ts
|
|
41
|
+
const requireNapi = (0, require("node:module").createRequire)(require("url").pathToFileURL(__filename).href);
|
|
42
|
+
function getDefaultExport(value) {
|
|
43
|
+
if (!value || typeof value !== "object" || !("default" in value)) return;
|
|
44
|
+
const defaultExport = value.default;
|
|
45
|
+
return defaultExport && typeof defaultExport === "object" ? defaultExport : void 0;
|
|
46
|
+
}
|
|
47
|
+
function normalizeNapiModule(mod) {
|
|
48
|
+
const defaultExport = getDefaultExport(mod);
|
|
49
|
+
return defaultExport ? {
|
|
50
|
+
...defaultExport,
|
|
51
|
+
...mod
|
|
52
|
+
} : mod;
|
|
53
|
+
}
|
|
54
|
+
async function importNapiModule() {
|
|
55
|
+
return normalizeNapiModule(await import("@ox-content/napi"));
|
|
56
|
+
}
|
|
57
|
+
let syncNapiModule;
|
|
58
|
+
function importNapiModuleSync() {
|
|
59
|
+
if (syncNapiModule) return syncNapiModule;
|
|
60
|
+
if (syncNapiModule === null) throw new Error("[ox-content] @ox-content/napi is required. Please ensure the NAPI module is built.");
|
|
61
|
+
try {
|
|
62
|
+
syncNapiModule = normalizeNapiModule(requireNapi("@ox-content/napi"));
|
|
63
|
+
return syncNapiModule;
|
|
64
|
+
} catch {
|
|
65
|
+
syncNapiModule = null;
|
|
66
|
+
throw new Error("[ox-content] @ox-content/napi is required. Please ensure the NAPI module is built.");
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
//#endregion
|
|
2
70
|
//#region src/theme.ts
|
|
3
71
|
/**
|
|
4
72
|
* Default theme configuration.
|
|
@@ -475,9 +543,33 @@ function formatObjectKey(key) {
|
|
|
475
543
|
* Normalizes VitePress-specific frontmatter into ox-content's entry-page shape.
|
|
476
544
|
*/
|
|
477
545
|
function normalizeVitePressFrontmatter(frontmatter) {
|
|
478
|
-
return
|
|
546
|
+
return importNapiModuleSync().normalizeVitePressFrontmatter(frontmatter);
|
|
479
547
|
}
|
|
480
548
|
//#endregion
|
|
549
|
+
Object.defineProperty(exports, "__esmMin", {
|
|
550
|
+
enumerable: true,
|
|
551
|
+
get: function() {
|
|
552
|
+
return __esmMin;
|
|
553
|
+
}
|
|
554
|
+
});
|
|
555
|
+
Object.defineProperty(exports, "__exportAll", {
|
|
556
|
+
enumerable: true,
|
|
557
|
+
get: function() {
|
|
558
|
+
return __exportAll;
|
|
559
|
+
}
|
|
560
|
+
});
|
|
561
|
+
Object.defineProperty(exports, "__toCommonJS", {
|
|
562
|
+
enumerable: true,
|
|
563
|
+
get: function() {
|
|
564
|
+
return __toCommonJS;
|
|
565
|
+
}
|
|
566
|
+
});
|
|
567
|
+
Object.defineProperty(exports, "__toESM", {
|
|
568
|
+
enumerable: true,
|
|
569
|
+
get: function() {
|
|
570
|
+
return __toESM;
|
|
571
|
+
}
|
|
572
|
+
});
|
|
481
573
|
Object.defineProperty(exports, "convertVitePressNav", {
|
|
482
574
|
enumerable: true,
|
|
483
575
|
get: function() {
|
|
@@ -514,6 +606,18 @@ Object.defineProperty(exports, "generateVitePressMigrationConfig", {
|
|
|
514
606
|
return generateVitePressMigrationConfig;
|
|
515
607
|
}
|
|
516
608
|
});
|
|
609
|
+
Object.defineProperty(exports, "importNapiModule", {
|
|
610
|
+
enumerable: true,
|
|
611
|
+
get: function() {
|
|
612
|
+
return importNapiModule;
|
|
613
|
+
}
|
|
614
|
+
});
|
|
615
|
+
Object.defineProperty(exports, "importNapiModuleSync", {
|
|
616
|
+
enumerable: true,
|
|
617
|
+
get: function() {
|
|
618
|
+
return importNapiModuleSync;
|
|
619
|
+
}
|
|
620
|
+
});
|
|
517
621
|
Object.defineProperty(exports, "mergeThemes", {
|
|
518
622
|
enumerable: true,
|
|
519
623
|
get: function() {
|