unplugin-docubook 1.0.0 → 1.0.2
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/README.md +142 -2
- package/dist/astro.cjs +152 -0
- package/dist/astro.cjs.map +1 -0
- package/dist/astro.js +125 -12
- package/dist/astro.js.map +1 -1
- package/dist/bun.cjs +140 -0
- package/dist/bun.cjs.map +1 -0
- package/dist/bun.js +115 -5
- package/dist/bun.js.map +1 -1
- package/dist/components/index.cjs +829 -0
- package/dist/components/index.cjs.map +1 -0
- package/dist/components/index.js +720 -512
- package/dist/components/index.js.map +1 -1
- package/dist/esbuild.cjs +140 -0
- package/dist/esbuild.cjs.map +1 -0
- package/dist/esbuild.js +115 -5
- package/dist/esbuild.js.map +1 -1
- package/dist/farm.cjs +140 -0
- package/dist/farm.cjs.map +1 -0
- package/dist/farm.js +115 -5
- package/dist/farm.js.map +1 -1
- package/dist/index.cjs +143 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.js +116 -2
- package/dist/index.js.map +1 -0
- package/dist/next.cjs +140 -0
- package/dist/next.cjs.map +1 -0
- package/dist/next.js +119 -0
- package/dist/next.js.map +1 -0
- package/dist/nuxt.cjs +160 -0
- package/dist/nuxt.cjs.map +1 -0
- package/dist/nuxt.js +134 -16
- package/dist/nuxt.js.map +1 -1
- package/dist/rolldown.cjs +140 -0
- package/dist/rolldown.cjs.map +1 -0
- package/dist/rolldown.js +115 -5
- package/dist/rolldown.js.map +1 -1
- package/dist/rollup.cjs +140 -0
- package/dist/rollup.cjs.map +1 -0
- package/dist/rollup.js +115 -5
- package/dist/rollup.js.map +1 -1
- package/dist/rspack.cjs +140 -0
- package/dist/rspack.cjs.map +1 -0
- package/dist/rspack.js +115 -5
- package/dist/rspack.js.map +1 -1
- package/dist/types.cjs +19 -0
- package/dist/types.cjs.map +1 -0
- package/dist/types.js +1 -1
- package/dist/types.js.map +1 -0
- package/dist/vite.cjs +140 -0
- package/dist/vite.cjs.map +1 -0
- package/dist/vite.js +115 -5
- package/dist/vite.js.map +1 -1
- package/dist/webpack.cjs +140 -0
- package/dist/webpack.cjs.map +1 -0
- package/dist/webpack.js +115 -5
- package/dist/webpack.js.map +1 -1
- package/package.json +92 -33
- package/dist/adapters/next-DNQX7_ln.d.ts +0 -24
- package/dist/adapters/next-DNQX7_ln.d.ts.map +0 -1
- package/dist/adapters/next.js +0 -38
- package/dist/adapters/next.js.map +0 -1
- package/dist/adapters/react-C9Vk6aTD.d.ts +0 -24
- package/dist/adapters/react-C9Vk6aTD.d.ts.map +0 -1
- package/dist/adapters/react.js +0 -39
- package/dist/adapters/react.js.map +0 -1
- package/dist/adapters/svelte-C-dhzdmU.d.ts +0 -19
- package/dist/adapters/svelte-C-dhzdmU.d.ts.map +0 -1
- package/dist/adapters/svelte.js +0 -43
- package/dist/adapters/svelte.js.map +0 -1
- package/dist/adapters/vue-BWv1EZit.d.ts +0 -22
- package/dist/adapters/vue-BWv1EZit.d.ts.map +0 -1
- package/dist/adapters/vue.js +0 -41
- package/dist/adapters/vue.js.map +0 -1
- package/dist/astro-BcckVQ-2.d.ts +0 -19
- package/dist/astro-BcckVQ-2.d.ts.map +0 -1
- package/dist/bun-DYPhytPs.d.ts +0 -7
- package/dist/bun-DYPhytPs.d.ts.map +0 -1
- package/dist/components/index-LWFtIGRd.d.ts +0 -265
- package/dist/components/index-LWFtIGRd.d.ts.map +0 -1
- package/dist/context-BKx0jIwX.js +0 -49
- package/dist/context-BKx0jIwX.js.map +0 -1
- package/dist/esbuild-BD42nX0_.d.ts +0 -8
- package/dist/esbuild-BD42nX0_.d.ts.map +0 -1
- package/dist/farm-C3XYk4nf.d.ts +0 -7
- package/dist/farm-C3XYk4nf.d.ts.map +0 -1
- package/dist/framework/index-98dEoo0g.d.ts +0 -11
- package/dist/framework/index-98dEoo0g.d.ts.map +0 -1
- package/dist/framework/index.js +0 -29
- package/dist/framework/index.js.map +0 -1
- package/dist/index-2f48-Fxc.d.ts +0 -10
- package/dist/index-2f48-Fxc.d.ts.map +0 -1
- package/dist/nuxt-BidHgMAG.d.ts +0 -5
- package/dist/nuxt-BidHgMAG.d.ts.map +0 -1
- package/dist/rolldown-CrcgSKP1.d.ts +0 -8
- package/dist/rolldown-CrcgSKP1.d.ts.map +0 -1
- package/dist/rollup-DDEc1C_K.d.ts +0 -8
- package/dist/rollup-DDEc1C_K.d.ts.map +0 -1
- package/dist/rspack-QbbymFlY.d.ts +0 -7
- package/dist/rspack-QbbymFlY.d.ts.map +0 -1
- package/dist/src-KZV_M01u.js +0 -165
- package/dist/src-KZV_M01u.js.map +0 -1
- package/dist/types-BQhWL5Qs.d.ts +0 -34
- package/dist/types-BQhWL5Qs.d.ts.map +0 -1
- package/dist/types-uxY1cMXO.d.ts +0 -28
- package/dist/types-uxY1cMXO.d.ts.map +0 -1
- package/dist/vite-9CqZQPO-.d.ts +0 -8
- package/dist/vite-9CqZQPO-.d.ts.map +0 -1
- package/dist/webpack-CBuuXltg.d.ts +0 -7
- package/dist/webpack-CBuuXltg.d.ts.map +0 -1
package/dist/farm.cjs
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/farm.ts
|
|
21
|
+
var farm_exports = {};
|
|
22
|
+
__export(farm_exports, {
|
|
23
|
+
default: () => farm_default
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(farm_exports);
|
|
26
|
+
var import_unplugin2 = require("unplugin");
|
|
27
|
+
|
|
28
|
+
// src/index.ts
|
|
29
|
+
var import_unplugin = require("unplugin");
|
|
30
|
+
|
|
31
|
+
// src/core/registry.ts
|
|
32
|
+
var FRAMEWORK_PATHS = {
|
|
33
|
+
react: "/react",
|
|
34
|
+
vue: "/vue",
|
|
35
|
+
svelte: "/svelte"
|
|
36
|
+
};
|
|
37
|
+
function createRegistry(framework) {
|
|
38
|
+
const basePath = FRAMEWORK_PATHS[framework];
|
|
39
|
+
return {
|
|
40
|
+
Note: { exports: ["Note"], path: basePath },
|
|
41
|
+
Card: { exports: ["Card"], path: basePath },
|
|
42
|
+
CardGroup: { exports: ["CardGroup"], path: basePath },
|
|
43
|
+
Accordion: { exports: ["Accordion"], path: basePath },
|
|
44
|
+
AccordionGroup: { exports: ["AccordionGroup"], path: basePath },
|
|
45
|
+
Stepper: { exports: ["Stepper", "StepperItem"], path: basePath },
|
|
46
|
+
Kbd: { exports: ["Kbd"], path: basePath },
|
|
47
|
+
Tooltip: { exports: ["Tooltip"], path: basePath },
|
|
48
|
+
Youtube: { exports: ["Youtube"], path: basePath },
|
|
49
|
+
Button: { exports: ["Button"], path: basePath },
|
|
50
|
+
DocuLink: { exports: ["DocuLink"], path: basePath },
|
|
51
|
+
DocuImage: { exports: ["DocuImage"], path: basePath },
|
|
52
|
+
Files: { exports: ["Files"], path: basePath },
|
|
53
|
+
Folder: { exports: ["Folder"], path: basePath },
|
|
54
|
+
File: { exports: ["File"], path: basePath },
|
|
55
|
+
Release: { exports: ["Release"], path: basePath },
|
|
56
|
+
Changes: { exports: ["Changes"], path: basePath },
|
|
57
|
+
Pre: { exports: ["Pre"], path: basePath },
|
|
58
|
+
Copy: { exports: ["Copy"], path: basePath },
|
|
59
|
+
DocuBookProvider: { exports: ["DocuBookProvider"], path: basePath }
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
function getComponentRegistry(framework = "react") {
|
|
63
|
+
return createRegistry(framework);
|
|
64
|
+
}
|
|
65
|
+
function buildComponentDetectionRegex(framework = "react") {
|
|
66
|
+
const registry = getComponentRegistry(framework);
|
|
67
|
+
const names = Object.keys(registry);
|
|
68
|
+
return new RegExp(`<(${names.join("|")})(?=[\\s/>])`, "g");
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// src/core/transform.ts
|
|
72
|
+
var DEFAULT_IMPORT_SOURCE = "unplugin-docubook/components";
|
|
73
|
+
var DEFAULT_FRAMEWORK = "react";
|
|
74
|
+
function detectComponents(code, framework = DEFAULT_FRAMEWORK) {
|
|
75
|
+
const regex = buildComponentDetectionRegex(framework);
|
|
76
|
+
const registry = getComponentRegistry(framework);
|
|
77
|
+
const found = /* @__PURE__ */ new Set();
|
|
78
|
+
let match;
|
|
79
|
+
while ((match = regex.exec(code)) !== null) {
|
|
80
|
+
const name = match[1];
|
|
81
|
+
if (name && registry[name]) {
|
|
82
|
+
found.add(name);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return Array.from(found);
|
|
86
|
+
}
|
|
87
|
+
function generateImports(componentNames, importSource, framework = DEFAULT_FRAMEWORK) {
|
|
88
|
+
const registry = getComponentRegistry(framework);
|
|
89
|
+
const pathToExports = /* @__PURE__ */ new Map();
|
|
90
|
+
for (const name of componentNames) {
|
|
91
|
+
const meta = registry[name];
|
|
92
|
+
if (!meta) continue;
|
|
93
|
+
const fullPath = `${importSource}${meta.path}`;
|
|
94
|
+
if (!pathToExports.has(fullPath)) {
|
|
95
|
+
pathToExports.set(fullPath, /* @__PURE__ */ new Set());
|
|
96
|
+
}
|
|
97
|
+
for (const exp of meta.exports) {
|
|
98
|
+
pathToExports.get(fullPath).add(exp);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
const lines = [];
|
|
102
|
+
for (const [path, exports2] of pathToExports) {
|
|
103
|
+
const names = Array.from(exports2).sort().join(", ");
|
|
104
|
+
lines.push(`import { ${names} } from '${path}'`);
|
|
105
|
+
}
|
|
106
|
+
return lines.join("\n");
|
|
107
|
+
}
|
|
108
|
+
function transformMdx(code, options = {}) {
|
|
109
|
+
var _a, _b;
|
|
110
|
+
const framework = (_a = options.framework) != null ? _a : DEFAULT_FRAMEWORK;
|
|
111
|
+
const usedComponents = detectComponents(code, framework);
|
|
112
|
+
if (usedComponents.length === 0) {
|
|
113
|
+
return { code, hasTransformed: false };
|
|
114
|
+
}
|
|
115
|
+
const importSource = (_b = options.importSource) != null ? _b : DEFAULT_IMPORT_SOURCE;
|
|
116
|
+
const importStatements = generateImports(usedComponents, importSource, framework);
|
|
117
|
+
return {
|
|
118
|
+
code: `${importStatements}
|
|
119
|
+
|
|
120
|
+
${code}`,
|
|
121
|
+
hasTransformed: true
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// src/index.ts
|
|
126
|
+
var unpluginFactory = (options) => ({
|
|
127
|
+
name: "unplugin-docubook",
|
|
128
|
+
transformInclude(id) {
|
|
129
|
+
return /\.mdx?$/.test(id);
|
|
130
|
+
},
|
|
131
|
+
transform(code, _id) {
|
|
132
|
+
const result = transformMdx(code, options);
|
|
133
|
+
if (!result.hasTransformed) return;
|
|
134
|
+
return result.code;
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
// src/farm.ts
|
|
139
|
+
var farm_default = (0, import_unplugin2.createFarmPlugin)(unpluginFactory);
|
|
140
|
+
//# sourceMappingURL=farm.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/farm.ts","../src/index.ts","../src/core/registry.ts","../src/core/transform.ts"],"sourcesContent":["import { createFarmPlugin } from 'unplugin'\nimport { unpluginFactory } from '.'\n\nexport default createFarmPlugin(unpluginFactory)\n","import type { UnpluginFactory } from 'unplugin'\nimport type { Options } from './types'\nimport { createUnplugin } from 'unplugin'\nimport { transformMdx } from './core/transform'\n\nexport const unpluginFactory: UnpluginFactory<Options | undefined> = (\n options,\n) => ({\n name: 'unplugin-docubook',\n\n transformInclude(id) {\n // Only process .mdx and .md files\n return /\\.mdx?$/.test(id)\n },\n\n transform(code, _id) {\n const result = transformMdx(code, options)\n if (!result.hasTransformed) return\n return result.code\n },\n})\n\nexport const unplugin = /* #__PURE__ */ createUnplugin(unpluginFactory)\n\nexport default unplugin\n","import type { Framework } from '../types'\n\nexport interface ComponentMeta {\n exports: string[]\n path: string\n}\n\nconst FRAMEWORK_PATHS: Record<Framework, string> = {\n react: '/react',\n vue: '/vue',\n svelte: '/svelte',\n}\n\nfunction createRegistry(framework: Framework): Record<string, ComponentMeta> {\n const basePath = FRAMEWORK_PATHS[framework]\n\n return {\n Note: { exports: ['Note'], path: basePath },\n Card: { exports: ['Card'], path: basePath },\n CardGroup: { exports: ['CardGroup'], path: basePath },\n Accordion: { exports: ['Accordion'], path: basePath },\n AccordionGroup: { exports: ['AccordionGroup'], path: basePath },\n Stepper: { exports: ['Stepper', 'StepperItem'], path: basePath },\n Kbd: { exports: ['Kbd'], path: basePath },\n Tooltip: { exports: ['Tooltip'], path: basePath },\n Youtube: { exports: ['Youtube'], path: basePath },\n Button: { exports: ['Button'], path: basePath },\n DocuLink: { exports: ['DocuLink'], path: basePath },\n DocuImage: { exports: ['DocuImage'], path: basePath },\n Files: { exports: ['Files'], path: basePath },\n Folder: { exports: ['Folder'], path: basePath },\n File: { exports: ['File'], path: basePath },\n Release: { exports: ['Release'], path: basePath },\n Changes: { exports: ['Changes'], path: basePath },\n Pre: { exports: ['Pre'], path: basePath },\n Copy: { exports: ['Copy'], path: basePath },\n DocuBookProvider: { exports: ['DocuBookProvider'], path: basePath },\n }\n}\n\nexport function getComponentRegistry(framework: Framework = 'react'): Record<string, ComponentMeta> {\n return createRegistry(framework)\n}\n\nexport function buildComponentDetectionRegex(framework: Framework = 'react'): RegExp {\n const registry = getComponentRegistry(framework)\n const names = Object.keys(registry)\n return new RegExp(`<(${names.join('|')})(?=[\\\\s/>])`, 'g')\n}\n","import type { Options, Framework } from '../types'\nimport { getComponentRegistry, buildComponentDetectionRegex } from './registry'\n\nconst DEFAULT_IMPORT_SOURCE = 'unplugin-docubook/components'\nconst DEFAULT_FRAMEWORK: Framework = 'react'\n\nexport function detectComponents(code: string, framework: Framework = DEFAULT_FRAMEWORK): string[] {\n const regex = buildComponentDetectionRegex(framework)\n const registry = getComponentRegistry(framework)\n const found = new Set<string>()\n let match: RegExpExecArray | null\n\n while ((match = regex.exec(code)) !== null) {\n const name = match[1]\n if (name && registry[name]) {\n found.add(name)\n }\n }\n\n return Array.from(found)\n}\n\nexport function generateImports(\n componentNames: string[],\n importSource: string,\n framework: Framework = DEFAULT_FRAMEWORK,\n): string {\n const registry = getComponentRegistry(framework)\n const pathToExports = new Map<string, Set<string>>()\n\n for (const name of componentNames) {\n const meta = registry[name]\n if (!meta) continue\n\n const fullPath = `${importSource}${meta.path}`\n if (!pathToExports.has(fullPath)) {\n pathToExports.set(fullPath, new Set())\n }\n for (const exp of meta.exports) {\n pathToExports.get(fullPath)!.add(exp)\n }\n }\n\n const lines: string[] = []\n for (const [path, exports] of pathToExports) {\n const names = Array.from(exports).sort().join(', ')\n lines.push(`import { ${names} } from '${path}'`)\n }\n\n return lines.join('\\n')\n}\n\nexport function transformMdx(\n code: string,\n options: Options = {},\n): { code: string; hasTransformed: boolean } {\n const framework = options.framework ?? DEFAULT_FRAMEWORK\n const usedComponents = detectComponents(code, framework)\n\n if (usedComponents.length === 0) {\n return { code, hasTransformed: false }\n }\n\n const importSource = options.importSource ?? DEFAULT_IMPORT_SOURCE\n const importStatements = generateImports(usedComponents, importSource, framework)\n\n return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src/farm.ts
|
|
2
2
|
import { createFarmPlugin } from "unplugin";
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
// src/index.ts
|
|
5
|
+
import { createUnplugin } from "unplugin";
|
|
6
|
+
|
|
7
|
+
// src/core/registry.ts
|
|
8
|
+
var FRAMEWORK_PATHS = {
|
|
9
|
+
react: "/react",
|
|
10
|
+
vue: "/vue",
|
|
11
|
+
svelte: "/svelte"
|
|
12
|
+
};
|
|
13
|
+
function createRegistry(framework) {
|
|
14
|
+
const basePath = FRAMEWORK_PATHS[framework];
|
|
15
|
+
return {
|
|
16
|
+
Note: { exports: ["Note"], path: basePath },
|
|
17
|
+
Card: { exports: ["Card"], path: basePath },
|
|
18
|
+
CardGroup: { exports: ["CardGroup"], path: basePath },
|
|
19
|
+
Accordion: { exports: ["Accordion"], path: basePath },
|
|
20
|
+
AccordionGroup: { exports: ["AccordionGroup"], path: basePath },
|
|
21
|
+
Stepper: { exports: ["Stepper", "StepperItem"], path: basePath },
|
|
22
|
+
Kbd: { exports: ["Kbd"], path: basePath },
|
|
23
|
+
Tooltip: { exports: ["Tooltip"], path: basePath },
|
|
24
|
+
Youtube: { exports: ["Youtube"], path: basePath },
|
|
25
|
+
Button: { exports: ["Button"], path: basePath },
|
|
26
|
+
DocuLink: { exports: ["DocuLink"], path: basePath },
|
|
27
|
+
DocuImage: { exports: ["DocuImage"], path: basePath },
|
|
28
|
+
Files: { exports: ["Files"], path: basePath },
|
|
29
|
+
Folder: { exports: ["Folder"], path: basePath },
|
|
30
|
+
File: { exports: ["File"], path: basePath },
|
|
31
|
+
Release: { exports: ["Release"], path: basePath },
|
|
32
|
+
Changes: { exports: ["Changes"], path: basePath },
|
|
33
|
+
Pre: { exports: ["Pre"], path: basePath },
|
|
34
|
+
Copy: { exports: ["Copy"], path: basePath },
|
|
35
|
+
DocuBookProvider: { exports: ["DocuBookProvider"], path: basePath }
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
function getComponentRegistry(framework = "react") {
|
|
39
|
+
return createRegistry(framework);
|
|
40
|
+
}
|
|
41
|
+
function buildComponentDetectionRegex(framework = "react") {
|
|
42
|
+
const registry = getComponentRegistry(framework);
|
|
43
|
+
const names = Object.keys(registry);
|
|
44
|
+
return new RegExp(`<(${names.join("|")})(?=[\\s/>])`, "g");
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// src/core/transform.ts
|
|
48
|
+
var DEFAULT_IMPORT_SOURCE = "unplugin-docubook/components";
|
|
49
|
+
var DEFAULT_FRAMEWORK = "react";
|
|
50
|
+
function detectComponents(code, framework = DEFAULT_FRAMEWORK) {
|
|
51
|
+
const regex = buildComponentDetectionRegex(framework);
|
|
52
|
+
const registry = getComponentRegistry(framework);
|
|
53
|
+
const found = /* @__PURE__ */ new Set();
|
|
54
|
+
let match;
|
|
55
|
+
while ((match = regex.exec(code)) !== null) {
|
|
56
|
+
const name = match[1];
|
|
57
|
+
if (name && registry[name]) {
|
|
58
|
+
found.add(name);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return Array.from(found);
|
|
62
|
+
}
|
|
63
|
+
function generateImports(componentNames, importSource, framework = DEFAULT_FRAMEWORK) {
|
|
64
|
+
const registry = getComponentRegistry(framework);
|
|
65
|
+
const pathToExports = /* @__PURE__ */ new Map();
|
|
66
|
+
for (const name of componentNames) {
|
|
67
|
+
const meta = registry[name];
|
|
68
|
+
if (!meta) continue;
|
|
69
|
+
const fullPath = `${importSource}${meta.path}`;
|
|
70
|
+
if (!pathToExports.has(fullPath)) {
|
|
71
|
+
pathToExports.set(fullPath, /* @__PURE__ */ new Set());
|
|
72
|
+
}
|
|
73
|
+
for (const exp of meta.exports) {
|
|
74
|
+
pathToExports.get(fullPath).add(exp);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
const lines = [];
|
|
78
|
+
for (const [path, exports] of pathToExports) {
|
|
79
|
+
const names = Array.from(exports).sort().join(", ");
|
|
80
|
+
lines.push(`import { ${names} } from '${path}'`);
|
|
81
|
+
}
|
|
82
|
+
return lines.join("\n");
|
|
83
|
+
}
|
|
84
|
+
function transformMdx(code, options = {}) {
|
|
85
|
+
var _a, _b;
|
|
86
|
+
const framework = (_a = options.framework) != null ? _a : DEFAULT_FRAMEWORK;
|
|
87
|
+
const usedComponents = detectComponents(code, framework);
|
|
88
|
+
if (usedComponents.length === 0) {
|
|
89
|
+
return { code, hasTransformed: false };
|
|
90
|
+
}
|
|
91
|
+
const importSource = (_b = options.importSource) != null ? _b : DEFAULT_IMPORT_SOURCE;
|
|
92
|
+
const importStatements = generateImports(usedComponents, importSource, framework);
|
|
93
|
+
return {
|
|
94
|
+
code: `${importStatements}
|
|
6
95
|
|
|
7
|
-
|
|
8
|
-
|
|
96
|
+
${code}`,
|
|
97
|
+
hasTransformed: true
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// src/index.ts
|
|
102
|
+
var unpluginFactory = (options) => ({
|
|
103
|
+
name: "unplugin-docubook",
|
|
104
|
+
transformInclude(id) {
|
|
105
|
+
return /\.mdx?$/.test(id);
|
|
106
|
+
},
|
|
107
|
+
transform(code, _id) {
|
|
108
|
+
const result = transformMdx(code, options);
|
|
109
|
+
if (!result.hasTransformed) return;
|
|
110
|
+
return result.code;
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
// src/farm.ts
|
|
115
|
+
var farm_default = createFarmPlugin(unpluginFactory);
|
|
116
|
+
export {
|
|
117
|
+
farm_default as default
|
|
118
|
+
};
|
|
9
119
|
//# sourceMappingURL=farm.js.map
|
package/dist/farm.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":["../src/farm.ts","../src/index.ts","../src/core/registry.ts","../src/core/transform.ts"],"sourcesContent":["import { createFarmPlugin } from 'unplugin'\nimport { unpluginFactory } from '.'\n\nexport default createFarmPlugin(unpluginFactory)\n","import type { UnpluginFactory } from 'unplugin'\nimport type { Options } from './types'\nimport { createUnplugin } from 'unplugin'\nimport { transformMdx } from './core/transform'\n\nexport const unpluginFactory: UnpluginFactory<Options | undefined> = (\n options,\n) => ({\n name: 'unplugin-docubook',\n\n transformInclude(id) {\n // Only process .mdx and .md files\n return /\\.mdx?$/.test(id)\n },\n\n transform(code, _id) {\n const result = transformMdx(code, options)\n if (!result.hasTransformed) return\n return result.code\n },\n})\n\nexport const unplugin = /* #__PURE__ */ createUnplugin(unpluginFactory)\n\nexport default unplugin\n","import type { Framework } from '../types'\n\nexport interface ComponentMeta {\n exports: string[]\n path: string\n}\n\nconst FRAMEWORK_PATHS: Record<Framework, string> = {\n react: '/react',\n vue: '/vue',\n svelte: '/svelte',\n}\n\nfunction createRegistry(framework: Framework): Record<string, ComponentMeta> {\n const basePath = FRAMEWORK_PATHS[framework]\n\n return {\n Note: { exports: ['Note'], path: basePath },\n Card: { exports: ['Card'], path: basePath },\n CardGroup: { exports: ['CardGroup'], path: basePath },\n Accordion: { exports: ['Accordion'], path: basePath },\n AccordionGroup: { exports: ['AccordionGroup'], path: basePath },\n Stepper: { exports: ['Stepper', 'StepperItem'], path: basePath },\n Kbd: { exports: ['Kbd'], path: basePath },\n Tooltip: { exports: ['Tooltip'], path: basePath },\n Youtube: { exports: ['Youtube'], path: basePath },\n Button: { exports: ['Button'], path: basePath },\n DocuLink: { exports: ['DocuLink'], path: basePath },\n DocuImage: { exports: ['DocuImage'], path: basePath },\n Files: { exports: ['Files'], path: basePath },\n Folder: { exports: ['Folder'], path: basePath },\n File: { exports: ['File'], path: basePath },\n Release: { exports: ['Release'], path: basePath },\n Changes: { exports: ['Changes'], path: basePath },\n Pre: { exports: ['Pre'], path: basePath },\n Copy: { exports: ['Copy'], path: basePath },\n DocuBookProvider: { exports: ['DocuBookProvider'], path: basePath },\n }\n}\n\nexport function getComponentRegistry(framework: Framework = 'react'): Record<string, ComponentMeta> {\n return createRegistry(framework)\n}\n\nexport function buildComponentDetectionRegex(framework: Framework = 'react'): RegExp {\n const registry = getComponentRegistry(framework)\n const names = Object.keys(registry)\n return new RegExp(`<(${names.join('|')})(?=[\\\\s/>])`, 'g')\n}\n","import type { Options, Framework } from '../types'\nimport { getComponentRegistry, buildComponentDetectionRegex } from './registry'\n\nconst DEFAULT_IMPORT_SOURCE = 'unplugin-docubook/components'\nconst DEFAULT_FRAMEWORK: Framework = 'react'\n\nexport function detectComponents(code: string, framework: Framework = DEFAULT_FRAMEWORK): string[] {\n const regex = buildComponentDetectionRegex(framework)\n const registry = getComponentRegistry(framework)\n const found = new Set<string>()\n let match: RegExpExecArray | null\n\n while ((match = regex.exec(code)) !== null) {\n const name = match[1]\n if (name && registry[name]) {\n found.add(name)\n }\n }\n\n return Array.from(found)\n}\n\nexport function generateImports(\n componentNames: string[],\n importSource: string,\n framework: Framework = DEFAULT_FRAMEWORK,\n): string {\n const registry = getComponentRegistry(framework)\n const pathToExports = new Map<string, Set<string>>()\n\n for (const name of componentNames) {\n const meta = registry[name]\n if (!meta) continue\n\n const fullPath = `${importSource}${meta.path}`\n if (!pathToExports.has(fullPath)) {\n pathToExports.set(fullPath, new Set())\n }\n for (const exp of meta.exports) {\n pathToExports.get(fullPath)!.add(exp)\n }\n }\n\n const lines: string[] = []\n for (const [path, exports] of pathToExports) {\n const names = Array.from(exports).sort().join(', ')\n lines.push(`import { ${names} } from '${path}'`)\n }\n\n return lines.join('\\n')\n}\n\nexport function transformMdx(\n code: string,\n options: Options = {},\n): { code: string; hasTransformed: boolean } {\n const framework = options.framework ?? DEFAULT_FRAMEWORK\n const usedComponents = detectComponents(code, framework)\n\n if (usedComponents.length === 0) {\n return { code, hasTransformed: false }\n }\n\n const importSource = options.importSource ?? DEFAULT_IMPORT_SOURCE\n const importStatements = generateImports(usedComponents, importSource, framework)\n\n return {\n code: `${importStatements}\\n\\n${code}`,\n hasTransformed: true,\n }\n}\n"],"mappings":";AAAA,SAAS,wBAAwB;;;ACEjC,SAAS,sBAAsB;;;ACK/B,IAAM,kB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G;AAAA,IACxC;AAAA,EACJ;AAEA,QAAM,QAAkB,CAAC;AACzB,aAAW,CAAC,MAAM,OAAO,KAAK,eAAe;AACzC,UAAM,QAAQ,MAAM,KAAK,OAAO,EAAE,KAAK,EAAE,KAAK,IAAI;AAClD,UAAM,KAAK,YAAY,KAAK,YAAY,IAAI,GAAG;AAAA,EACnD;AAEA,SAAO,MAAM,KAAK,IAAI;AAC1B;AAEO,SAAS,aACZ,MACA,UAAmB,CAAC,GACqB;AAvD7C;AAwDI,QAAM,aAAY,aAAQ,cAAR,YAAqB;AACvC,QAAM,iBAAiB,iBAAiB,MAAM,SAAS;AAEvD,MAAI,eAAe,WAAW,GAAG;AAC7B,WAAO,EAAE,MAAM,gBAAgB,MAAM;AAAA,EACzC;AAEA,QAAM,gBAAe,aAAQ,iBAAR,YAAwB;AAC7C,QAAM,mBAAmB,gBAAgB,gBAAgB,cAAc,SAAS;AAEhF,SAAO;AAAA,IACH,MAAM,GAAG,gBAAgB;AAAA;AAAA,EAAO,IAAI;AAAA,IACpC,gBAAgB;AAAA,EACpB;AACJ;;;AFjEO,IAAM,kBAAwD,CACjE,aACE;AAAA,EACF,MAAM;AAAA,EAEN,iBAAiB,IAAI;AAEjB,WAAO,UAAU,KAAK,EAAE;AAAA,EAC5B;AAAA,EAEA,UAAU,MAAM,KAAK;AACjB,UAAM,SAAS,aAAa,MAAM,OAAO;AACzC,QAAI,CAAC,OAAO,eAAgB;AAC5B,WAAO,OAAO;AAAA,EAClB;AACJ;;;ADjBA,IAAO,eAAQ,iBAAiB,eAAe;","names":[]}
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
default: () => index_default,
|
|
24
|
+
unplugin: () => unplugin,
|
|
25
|
+
unpluginFactory: () => unpluginFactory
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(index_exports);
|
|
28
|
+
var import_unplugin = require("unplugin");
|
|
29
|
+
|
|
30
|
+
// src/core/registry.ts
|
|
31
|
+
var FRAMEWORK_PATHS = {
|
|
32
|
+
react: "/react",
|
|
33
|
+
vue: "/vue",
|
|
34
|
+
svelte: "/svelte"
|
|
35
|
+
};
|
|
36
|
+
function createRegistry(framework) {
|
|
37
|
+
const basePath = FRAMEWORK_PATHS[framework];
|
|
38
|
+
return {
|
|
39
|
+
Note: { exports: ["Note"], path: basePath },
|
|
40
|
+
Card: { exports: ["Card"], path: basePath },
|
|
41
|
+
CardGroup: { exports: ["CardGroup"], path: basePath },
|
|
42
|
+
Accordion: { exports: ["Accordion"], path: basePath },
|
|
43
|
+
AccordionGroup: { exports: ["AccordionGroup"], path: basePath },
|
|
44
|
+
Stepper: { exports: ["Stepper", "StepperItem"], path: basePath },
|
|
45
|
+
Kbd: { exports: ["Kbd"], path: basePath },
|
|
46
|
+
Tooltip: { exports: ["Tooltip"], path: basePath },
|
|
47
|
+
Youtube: { exports: ["Youtube"], path: basePath },
|
|
48
|
+
Button: { exports: ["Button"], path: basePath },
|
|
49
|
+
DocuLink: { exports: ["DocuLink"], path: basePath },
|
|
50
|
+
DocuImage: { exports: ["DocuImage"], path: basePath },
|
|
51
|
+
Files: { exports: ["Files"], path: basePath },
|
|
52
|
+
Folder: { exports: ["Folder"], path: basePath },
|
|
53
|
+
File: { exports: ["File"], path: basePath },
|
|
54
|
+
Release: { exports: ["Release"], path: basePath },
|
|
55
|
+
Changes: { exports: ["Changes"], path: basePath },
|
|
56
|
+
Pre: { exports: ["Pre"], path: basePath },
|
|
57
|
+
Copy: { exports: ["Copy"], path: basePath },
|
|
58
|
+
DocuBookProvider: { exports: ["DocuBookProvider"], path: basePath }
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
function getComponentRegistry(framework = "react") {
|
|
62
|
+
return createRegistry(framework);
|
|
63
|
+
}
|
|
64
|
+
function buildComponentDetectionRegex(framework = "react") {
|
|
65
|
+
const registry = getComponentRegistry(framework);
|
|
66
|
+
const names = Object.keys(registry);
|
|
67
|
+
return new RegExp(`<(${names.join("|")})(?=[\\s/>])`, "g");
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// src/core/transform.ts
|
|
71
|
+
var DEFAULT_IMPORT_SOURCE = "unplugin-docubook/components";
|
|
72
|
+
var DEFAULT_FRAMEWORK = "react";
|
|
73
|
+
function detectComponents(code, framework = DEFAULT_FRAMEWORK) {
|
|
74
|
+
const regex = buildComponentDetectionRegex(framework);
|
|
75
|
+
const registry = getComponentRegistry(framework);
|
|
76
|
+
const found = /* @__PURE__ */ new Set();
|
|
77
|
+
let match;
|
|
78
|
+
while ((match = regex.exec(code)) !== null) {
|
|
79
|
+
const name = match[1];
|
|
80
|
+
if (name && registry[name]) {
|
|
81
|
+
found.add(name);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return Array.from(found);
|
|
85
|
+
}
|
|
86
|
+
function generateImports(componentNames, importSource, framework = DEFAULT_FRAMEWORK) {
|
|
87
|
+
const registry = getComponentRegistry(framework);
|
|
88
|
+
const pathToExports = /* @__PURE__ */ new Map();
|
|
89
|
+
for (const name of componentNames) {
|
|
90
|
+
const meta = registry[name];
|
|
91
|
+
if (!meta) continue;
|
|
92
|
+
const fullPath = `${importSource}${meta.path}`;
|
|
93
|
+
if (!pathToExports.has(fullPath)) {
|
|
94
|
+
pathToExports.set(fullPath, /* @__PURE__ */ new Set());
|
|
95
|
+
}
|
|
96
|
+
for (const exp of meta.exports) {
|
|
97
|
+
pathToExports.get(fullPath).add(exp);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
const lines = [];
|
|
101
|
+
for (const [path, exports2] of pathToExports) {
|
|
102
|
+
const names = Array.from(exports2).sort().join(", ");
|
|
103
|
+
lines.push(`import { ${names} } from '${path}'`);
|
|
104
|
+
}
|
|
105
|
+
return lines.join("\n");
|
|
106
|
+
}
|
|
107
|
+
function transformMdx(code, options = {}) {
|
|
108
|
+
var _a, _b;
|
|
109
|
+
const framework = (_a = options.framework) != null ? _a : DEFAULT_FRAMEWORK;
|
|
110
|
+
const usedComponents = detectComponents(code, framework);
|
|
111
|
+
if (usedComponents.length === 0) {
|
|
112
|
+
return { code, hasTransformed: false };
|
|
113
|
+
}
|
|
114
|
+
const importSource = (_b = options.importSource) != null ? _b : DEFAULT_IMPORT_SOURCE;
|
|
115
|
+
const importStatements = generateImports(usedComponents, importSource, framework);
|
|
116
|
+
return {
|
|
117
|
+
code: `${importStatements}
|
|
118
|
+
|
|
119
|
+
${code}`,
|
|
120
|
+
hasTransformed: true
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// src/index.ts
|
|
125
|
+
var unpluginFactory = (options) => ({
|
|
126
|
+
name: "unplugin-docubook",
|
|
127
|
+
transformInclude(id) {
|
|
128
|
+
return /\.mdx?$/.test(id);
|
|
129
|
+
},
|
|
130
|
+
transform(code, _id) {
|
|
131
|
+
const result = transformMdx(code, options);
|
|
132
|
+
if (!result.hasTransformed) return;
|
|
133
|
+
return result.code;
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
var unplugin = /* @__PURE__ */ (0, import_unplugin.createUnplugin)(unpluginFactory);
|
|
137
|
+
var index_default = unplugin;
|
|
138
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
139
|
+
0 && (module.exports = {
|
|
140
|
+
unplugin,
|
|
141
|
+
unpluginFactory
|
|
142
|
+
});
|
|
143
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/core/registry.ts","../src/core/transform.ts"],"sourcesContent":["import type { UnpluginFactory } from 'unplugin'\nimport type { Options } from './types'\nimport { createUnplugin } from 'unplugin'\nimport { transformMdx } from './core/transform'\n\nexport const unpluginFactory: UnpluginFactory<Options | undefined> = (\n options,\n) => ({\n name: 'unplugin-docubook',\n\n transformInclude(id) {\n // Only process .mdx and .md files\n return /\\.mdx?$/.test(id)\n },\n\n transform(code, _id) {\n const result = transformMdx(code, options)\n if (!result.hasTransformed) return\n return result.code\n },\n})\n\nexport const unplugin = /* #__PURE__ */ createUnplugin(unpluginFactory)\n\nexport default unplugin\n","import type { Framework } from '../types'\n\nexport interface ComponentMeta {\n exports: string[]\n path: string\n}\n\nconst FRAMEWORK_PATHS: Record<Framework, string> = {\n react: '/react',\n vue: '/vue',\n svelte: '/svelte',\n}\n\nfunction createRegistry(framework: Framework): Record<string, ComponentMeta> {\n const basePath = FRAMEWORK_PATHS[framework]\n\n return {\n Note: { exports: ['Note'], path: basePath },\n Card: { exports: ['Card'], path: basePath },\n CardGroup: { exports: ['CardGroup'], path: basePath },\n Accordion: { exports: ['Accordion'], path: basePath },\n AccordionGroup: { exports: ['AccordionGroup'], path: basePath },\n Stepper: { exports: ['Stepper', 'StepperItem'], path: basePath },\n Kbd: { exports: ['Kbd'], path: basePath },\n Tooltip: { exports: ['Tooltip'], path: basePath },\n Youtube: { exports: ['Youtube'], path: basePath },\n Button: { exports: ['Button'], path: basePath },\n DocuLink: { exports: ['DocuLink'], path: basePath },\n DocuImage: { exports: ['DocuImage'], path: basePath },\n Files: { exports: ['Files'], path: basePath },\n Folder: { exports: ['Folder'], path: basePath },\n File: { exports: ['File'], path: basePath },\n Release: { exports: ['Release'], path: basePath },\n Changes: { exports: ['Changes'], path: basePath },\n Pre: { exports: ['Pre'], path: basePath },\n Copy: { exports: ['Copy'], path: basePath },\n DocuBookProvider: { exports: ['DocuBookProvider'], path: basePath },\n }\n}\n\nexport function getComponentRegistry(framework: Framework = 'react'): Record<string, ComponentMeta> {\n return createRegistry(framework)\n}\n\nexport function buildComponentDetectionRegex(framework: Framework = 'react'): RegExp {\n const registry = getComponentRegistry(framework)\n const names = Object.keys(registry)\n return new RegExp(`<(${names.join('|')})(?=[\\\\s/>])`, 'g')\n}\n","import type { Options, Framework } from '../types'\nimport { getComponentRegistry, buildComponentDetectionRegex } from './registry'\n\nconst DEFAULT_IMPORT_SOURCE = 'unplugin-docubook/components'\nconst DEFAULT_FRAMEWORK: Framework = 'react'\n\nexport function detectComponents(code: string, framework: Framework = DEFAULT_FRAMEWORK): string[] {\n const regex = buildComponentDetectionRegex(framework)\n const registry = getComponentRegistry(framework)\n const found = new Set<string>()\n let match: RegExpExecArray | null\n\n while ((match = regex.exec(code)) !== null) {\n const name = match[1]\n if (name && registry[name]) {\n found.add(name)\n }\n }\n\n return Array.from(found)\n}\n\nexport function generateImports(\n componentNames: string[],\n importSource: string,\n framework: Framework = DEFAULT_FRAMEWORK,\n): string {\n const registry = getComponentRegistry(framework)\n const pathToExports = new Map<string, Set<string>>()\n\n for (const name of componentNames) {\n const meta = registry[name]\n if (!meta) continue\n\n const fullPath = `${importSource}${meta.path}`\n if (!pathToExports.has(fullPath)) {\n pathToExports.set(fullPath, new Set())\n }\n for (const exp of meta.exports) {\n pathToExports.get(fullPath)!.add(exp)\n }\n }\n\n const lines: string[] = []\n for (const [path, exports] of pathToExports) {\n const names = Array.from(exports).sort().join(', ')\n lines.push(`import { ${names} } from '${path}'`)\n }\n\n return lines.join('\\n')\n}\n\nexport function transformMdx(\n code: string,\n options: Options = {},\n): { code: string; hasTransformed: boolean } {\n const framework = options.framework ?? DEFAULT_FRAMEWORK\n const usedComponents = detectComponents(code, framework)\n\n if (usedComponents.length === 0) {\n return { code, hasTransformed: false }\n }\n\n const importSource = options.importSource ?? DEFAULT_IMPORT_SOURCE\n const importStatements = generateImports(usedComponents, importSource, framework)\n\n return {\n code: `${importStatements}\\n\\n${code}`,\n hasTransformed: true,\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,sBAA+B;;;ACK/B,IAAM,kBAA6C;AAAA,EAC/C,OAAO;AAAA,EACP,KAAK;AAAA,EACL,QAAQ;AACZ;AAEA,SAAS,eAAe,WAAqD;AACzE,QAAM,WAAW,gBAAgB,SAAS;AAE1C,SAAO;AAAA,IACH,MAAM,EAAE,SAAS,CAAC,MAAM,GAAG,MAAM,SAAS;AAAA,IAC1C,MAAM,EAAE,SAAS,CAAC,MAAM,GAAG,MAAM,SAAS;AAAA,IAC1C,WAAW,EAAE,SAAS,CAAC,WAAW,GAAG,MAAM,SAAS;AAAA,IACpD,WAAW,EAAE,SAAS,CAAC,WAAW,GAAG,MAAM,SAAS;AAAA,IACpD,gBAAgB,EAAE,SAAS,CAAC,gBAAgB,GAAG,MAAM,SAAS;AAAA,IAC9D,SAAS,EAAE,SAAS,CAAC,WAAW,aAAa,GAAG,MAAM,SAAS;AAAA,IAC/D,KAAK,EAAE,SAAS,CAAC,KAAK,GAAG,MAAM,SAAS;AAAA,IACxC,SAAS,EAAE,SAAS,CAAC,SAAS,GAAG,MAAM,SAAS;AAAA,IAChD,SAAS,EAAE,SAAS,CAAC,SAAS,GAAG,MAAM,SAAS;AAAA,IAChD,QAAQ,EAAE,SAAS,CAAC,QAAQ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N,iBAAiB,IAAI;AAEjB,WAAO,UAAU,KAAK,EAAE;AAAA,EAC5B;AAAA,EAEA,UAAU,MAAM,KAAK;AACjB,UAAM,SAAS,aAAa,MAAM,OAAO;AACzC,QAAI,CAAC,OAAO,eAAgB;AAC5B,WAAO,OAAO;AAAA,EAClB;AACJ;AAEO,IAAM,WAA2B,oDAAe,eAAe;AAEtE,IAAO,gBAAQ;","names":["exports"]}
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,117 @@
|
|
|
1
|
-
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import { createUnplugin } from "unplugin";
|
|
2
3
|
|
|
3
|
-
|
|
4
|
+
// src/core/registry.ts
|
|
5
|
+
var FRAMEWORK_PATHS = {
|
|
6
|
+
react: "/react",
|
|
7
|
+
vue: "/vue",
|
|
8
|
+
svelte: "/svelte"
|
|
9
|
+
};
|
|
10
|
+
function createRegistry(framework) {
|
|
11
|
+
const basePath = FRAMEWORK_PATHS[framework];
|
|
12
|
+
return {
|
|
13
|
+
Note: { exports: ["Note"], path: basePath },
|
|
14
|
+
Card: { exports: ["Card"], path: basePath },
|
|
15
|
+
CardGroup: { exports: ["CardGroup"], path: basePath },
|
|
16
|
+
Accordion: { exports: ["Accordion"], path: basePath },
|
|
17
|
+
AccordionGroup: { exports: ["AccordionGroup"], path: basePath },
|
|
18
|
+
Stepper: { exports: ["Stepper", "StepperItem"], path: basePath },
|
|
19
|
+
Kbd: { exports: ["Kbd"], path: basePath },
|
|
20
|
+
Tooltip: { exports: ["Tooltip"], path: basePath },
|
|
21
|
+
Youtube: { exports: ["Youtube"], path: basePath },
|
|
22
|
+
Button: { exports: ["Button"], path: basePath },
|
|
23
|
+
DocuLink: { exports: ["DocuLink"], path: basePath },
|
|
24
|
+
DocuImage: { exports: ["DocuImage"], path: basePath },
|
|
25
|
+
Files: { exports: ["Files"], path: basePath },
|
|
26
|
+
Folder: { exports: ["Folder"], path: basePath },
|
|
27
|
+
File: { exports: ["File"], path: basePath },
|
|
28
|
+
Release: { exports: ["Release"], path: basePath },
|
|
29
|
+
Changes: { exports: ["Changes"], path: basePath },
|
|
30
|
+
Pre: { exports: ["Pre"], path: basePath },
|
|
31
|
+
Copy: { exports: ["Copy"], path: basePath },
|
|
32
|
+
DocuBookProvider: { exports: ["DocuBookProvider"], path: basePath }
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
function getComponentRegistry(framework = "react") {
|
|
36
|
+
return createRegistry(framework);
|
|
37
|
+
}
|
|
38
|
+
function buildComponentDetectionRegex(framework = "react") {
|
|
39
|
+
const registry = getComponentRegistry(framework);
|
|
40
|
+
const names = Object.keys(registry);
|
|
41
|
+
return new RegExp(`<(${names.join("|")})(?=[\\s/>])`, "g");
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// src/core/transform.ts
|
|
45
|
+
var DEFAULT_IMPORT_SOURCE = "unplugin-docubook/components";
|
|
46
|
+
var DEFAULT_FRAMEWORK = "react";
|
|
47
|
+
function detectComponents(code, framework = DEFAULT_FRAMEWORK) {
|
|
48
|
+
const regex = buildComponentDetectionRegex(framework);
|
|
49
|
+
const registry = getComponentRegistry(framework);
|
|
50
|
+
const found = /* @__PURE__ */ new Set();
|
|
51
|
+
let match;
|
|
52
|
+
while ((match = regex.exec(code)) !== null) {
|
|
53
|
+
const name = match[1];
|
|
54
|
+
if (name && registry[name]) {
|
|
55
|
+
found.add(name);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return Array.from(found);
|
|
59
|
+
}
|
|
60
|
+
function generateImports(componentNames, importSource, framework = DEFAULT_FRAMEWORK) {
|
|
61
|
+
const registry = getComponentRegistry(framework);
|
|
62
|
+
const pathToExports = /* @__PURE__ */ new Map();
|
|
63
|
+
for (const name of componentNames) {
|
|
64
|
+
const meta = registry[name];
|
|
65
|
+
if (!meta) continue;
|
|
66
|
+
const fullPath = `${importSource}${meta.path}`;
|
|
67
|
+
if (!pathToExports.has(fullPath)) {
|
|
68
|
+
pathToExports.set(fullPath, /* @__PURE__ */ new Set());
|
|
69
|
+
}
|
|
70
|
+
for (const exp of meta.exports) {
|
|
71
|
+
pathToExports.get(fullPath).add(exp);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
const lines = [];
|
|
75
|
+
for (const [path, exports] of pathToExports) {
|
|
76
|
+
const names = Array.from(exports).sort().join(", ");
|
|
77
|
+
lines.push(`import { ${names} } from '${path}'`);
|
|
78
|
+
}
|
|
79
|
+
return lines.join("\n");
|
|
80
|
+
}
|
|
81
|
+
function transformMdx(code, options = {}) {
|
|
82
|
+
var _a, _b;
|
|
83
|
+
const framework = (_a = options.framework) != null ? _a : DEFAULT_FRAMEWORK;
|
|
84
|
+
const usedComponents = detectComponents(code, framework);
|
|
85
|
+
if (usedComponents.length === 0) {
|
|
86
|
+
return { code, hasTransformed: false };
|
|
87
|
+
}
|
|
88
|
+
const importSource = (_b = options.importSource) != null ? _b : DEFAULT_IMPORT_SOURCE;
|
|
89
|
+
const importStatements = generateImports(usedComponents, importSource, framework);
|
|
90
|
+
return {
|
|
91
|
+
code: `${importStatements}
|
|
92
|
+
|
|
93
|
+
${code}`,
|
|
94
|
+
hasTransformed: true
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// src/index.ts
|
|
99
|
+
var unpluginFactory = (options) => ({
|
|
100
|
+
name: "unplugin-docubook",
|
|
101
|
+
transformInclude(id) {
|
|
102
|
+
return /\.mdx?$/.test(id);
|
|
103
|
+
},
|
|
104
|
+
transform(code, _id) {
|
|
105
|
+
const result = transformMdx(code, options);
|
|
106
|
+
if (!result.hasTransformed) return;
|
|
107
|
+
return result.code;
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
var unplugin = /* @__PURE__ */ createUnplugin(unpluginFactory);
|
|
111
|
+
var index_default = unplugin;
|
|
112
|
+
export {
|
|
113
|
+
index_default as default,
|
|
114
|
+
unplugin,
|
|
115
|
+
unpluginFactory
|
|
116
|
+
};
|
|
117
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/core/registry.ts","../src/core/transform.ts"],"sourcesContent":["import type { UnpluginFactory } from 'unplugin'\nimport type { Options } from './types'\nimport { createUnplugin } from 'unplugin'\nimport { transformMdx } from './core/transform'\n\nexport const unpluginFactory: UnpluginFactory<Options | undefined> = (\n options,\n) => ({\n name: 'unplugin-docubook',\n\n transformInclude(id) {\n // Only process .mdx and .md files\n return /\\.mdx?$/.test(id)\n },\n\n transform(code, _id) {\n const result = transformMdx(code, options)\n if (!result.hasTransformed) return\n return result.code\n },\n})\n\nexport const unplugin = /* #__PURE__ */ createUnplugin(unpluginFactory)\n\nexport default unplugin\n","import type { Framework } from '../types'\n\nexport interface ComponentMeta {\n exports: string[]\n path: string\n}\n\nconst FRAMEWORK_PATHS: Record<Framework, string> = {\n react: '/react',\n vue: '/vue',\n svelte: '/svelte',\n}\n\nfunction createRegistry(framework: Framework): Record<string, ComponentMeta> {\n const basePath = FRAMEWORK_PATHS[framework]\n\n return {\n Note: { exports: ['Note'], path: basePath },\n Card: { exports: ['Card'], path: basePath },\n CardGroup: { exports: ['CardGroup'], path: basePath },\n Accordion: { exports: ['Accordion'], path: basePath },\n AccordionGroup: { exports: ['AccordionGroup'], path: basePath },\n Stepper: { exports: ['Stepper', 'StepperItem'], path: basePath },\n Kbd: { exports: ['Kbd'], path: basePath },\n Tooltip: { exports: ['Tooltip'], path: basePath },\n Youtube: { exports: ['Youtube'], path: basePath },\n Button: { exports: ['Button'], path: basePath },\n DocuLink: { exports: ['DocuLink'], path: basePath },\n DocuImage: { exports: ['DocuImage'], path: basePath },\n Files: { exports: ['Files'], path: basePath },\n Folder: { exports: ['Folder'], path: basePath },\n File: { exports: ['File'], path: basePath },\n Release: { exports: ['Release'], path: basePath },\n Changes: { exports: ['Changes'], path: basePath },\n Pre: { exports: ['Pre'], path: basePath },\n Copy: { exports: ['Copy'], path: basePath },\n DocuBookProvider: { exports: ['DocuBookProvider'], path: basePath },\n }\n}\n\nexport function getComponentRegistry(framework: Framework = 'react'): Record<string, ComponentMeta> {\n return createRegistry(framework)\n}\n\nexport function buildComponentDetectionRegex(framework: Framework = 'react'): RegExp {\n const registry = getComponentRegistry(framework)\n const names = Object.keys(registry)\n return new RegExp(`<(${names.join('|')})(?=[\\\\s/>])`, 'g')\n}\n","import type { Options, Framework } from '../types'\nimport { getComponentRegistry, buildComponentDetectionRegex } from './registry'\n\nconst DEFAULT_IMPORT_SOURCE = 'unplugin-docubook/components'\nconst DEFAULT_FRAMEWORK: Framework = 'react'\n\nexport function detectComponents(code: string, framework: Framework = DEFAULT_FRAMEWORK): string[] {\n const regex = buildComponentDetectionRegex(framework)\n const registry = getComponentRegistry(framework)\n const found = new Set<string>()\n let match: RegExpExecArray | null\n\n while ((match = regex.exec(code)) !== null) {\n const name = match[1]\n if (name && registry[name]) {\n found.add(name)\n }\n }\n\n return Array.from(found)\n}\n\nexport function generateImports(\n componentNames: string[],\n importSource: string,\n framework: Framework = DEFAULT_FRAMEWORK,\n): string {\n const registry = getComponentRegistry(framework)\n const pathToExports = new Map<string, Set<string>>()\n\n for (const name of componentNames) {\n const meta = registry[name]\n if (!meta) continue\n\n const fullPath = `${importSource}${meta.path}`\n if (!pathToExports.has(fullPath)) {\n pathToExports.set(fullPath, new Set())\n }\n for (const exp of meta.exports) {\n pathToExports.get(fullPath)!.add(exp)\n }\n }\n\n const lines: string[] = []\n for (const [path, exports] of pathToExports) {\n const names = Array.from(exports).sort().join(', ')\n lines.push(`import { ${names} } from '${path}'`)\n }\n\n return lines.join('\\n')\n}\n\nexport function transformMdx(\n code: string,\n options: Options = {},\n): { code: string; hasTransformed: boolean } {\n const framework = options.framework ?? DEFAULT_FRAMEWORK\n const usedComponents = detectComponents(code, framework)\n\n if (usedComponents.length === 0) {\n return { code, hasTransformed: false }\n }\n\n const importSource = options.importSource ?? DEFAULT_IMPORT_SOURCE\n const importStatements = generateImports(usedCompon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