vigor-moon 1.0.0 → 1.0.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/cli.js +5 -3
- package/dist/cli.mjs +5 -3
- package/package.json +4 -2
- package/dist/chunk-2M2XJKGT.js +0 -607
- package/dist/chunk-3EAR5BNQ.js +0 -610
- package/dist/chunk-3ZCIQMBL.js +0 -608
- package/dist/chunk-6SPQ2G5U.js +0 -611
- package/dist/chunk-7V4TYSIZ.mjs +0 -619
- package/dist/chunk-AT54N5D7.js +0 -611
- package/dist/chunk-BBRRUMIN.js +0 -616
- package/dist/chunk-BE2AQAQS.mjs +0 -608
- package/dist/chunk-BS6X4ZCI.js +0 -608
- package/dist/chunk-D2WJMNSR.js +0 -618
- package/dist/chunk-DTA4ZJEQ.mjs +0 -606
- package/dist/chunk-ECPJL6H6.js +0 -618
- package/dist/chunk-EU5K7BUZ.mjs +0 -612
- package/dist/chunk-FAELXJ3Z.mjs +0 -605
- package/dist/chunk-GBGTGHKN.js +0 -621
- package/dist/chunk-HW7CAZGA.js +0 -611
- package/dist/chunk-IDQ7PFDG.mjs +0 -619
- package/dist/chunk-IPVDS3I7.mjs +0 -609
- package/dist/chunk-JHZIOXVJ.js +0 -605
- package/dist/chunk-KRBN43PO.js +0 -606
- package/dist/chunk-KTIICQHT.mjs +0 -622
- package/dist/chunk-KZQIA6WA.js +0 -604
- package/dist/chunk-L4MZ52TR.mjs +0 -609
- package/dist/chunk-LEOZIK2T.mjs +0 -607
- package/dist/chunk-MHZT64KI.mjs +0 -605
- package/dist/chunk-NTJI6VKJ.mjs +0 -619
- package/dist/chunk-NWZZITYZ.mjs +0 -606
- package/dist/chunk-OS3F7QDD.js +0 -606
- package/dist/chunk-PJPXX4UA.mjs +0 -605
- package/dist/chunk-PW73M55D.mjs +0 -611
- package/dist/chunk-R6L6GYA4.mjs +0 -607
- package/dist/chunk-RNUPZ4CR.mjs +0 -612
- package/dist/chunk-SEIXDGYJ.mjs +0 -615
- package/dist/chunk-SYCZ35ZW.js +0 -604
- package/dist/chunk-THZGRR4I.js +0 -611
- package/dist/chunk-TJ5NMLCW.js +0 -614
- package/dist/chunk-TYBNSCBA.mjs +0 -611
- package/dist/chunk-UGBCHWPA.js +0 -621
- package/dist/chunk-VD42YO6T.mjs +0 -622
- package/dist/chunk-VMNTKZYD.js +0 -604
- package/dist/chunk-W6MHPTGR.js +0 -605
- package/dist/chunk-WBSL45KV.mjs +0 -617
- package/dist/chunk-XFGBQ3QD.mjs +0 -612
- package/dist/chunk-ZBAZASII.js +0 -618
- package/dist/chunk-ZGLENLKC.js +0 -610
- package/dist/chunk-ZN4CSBNG.mjs +0 -612
package/dist/chunk-SEIXDGYJ.mjs
DELETED
|
@@ -1,615 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
__dirname,
|
|
3
|
-
resolveConfig
|
|
4
|
-
} from "./chunk-SO47EKIV.mjs";
|
|
5
|
-
|
|
6
|
-
// src/node/dev.ts
|
|
7
|
-
import { createServer as createViteDevServer } from "vite";
|
|
8
|
-
|
|
9
|
-
// src/node/plugin/indexHtml.ts
|
|
10
|
-
import { readFile } from "fs/promises";
|
|
11
|
-
|
|
12
|
-
// src/node/constants/index.ts
|
|
13
|
-
import { join } from "path";
|
|
14
|
-
var PACKAGE_ROOT = join(__dirname, "..");
|
|
15
|
-
var DEFAULT_HTML_PATH = join(PACKAGE_ROOT, "template.html");
|
|
16
|
-
var CLIENT_ENTRY_PATH = join(PACKAGE_ROOT, "src", "runtime", "client-entry.tsx");
|
|
17
|
-
var SERVER_ENTRY_PATH = join(PACKAGE_ROOT, "src", "runtime", "ssr-entry.tsx");
|
|
18
|
-
|
|
19
|
-
// src/node/plugin/indexHtml.ts
|
|
20
|
-
function pluginIndexHtml() {
|
|
21
|
-
return {
|
|
22
|
-
name: "vigor: index-html",
|
|
23
|
-
apply: "serve",
|
|
24
|
-
transformIndexHtml(html) {
|
|
25
|
-
return {
|
|
26
|
-
html,
|
|
27
|
-
tags: [
|
|
28
|
-
{
|
|
29
|
-
tag: "script",
|
|
30
|
-
attrs: {
|
|
31
|
-
type: "module",
|
|
32
|
-
src: `/@fs/${CLIENT_ENTRY_PATH}`
|
|
33
|
-
},
|
|
34
|
-
injectTo: "body"
|
|
35
|
-
}
|
|
36
|
-
]
|
|
37
|
-
};
|
|
38
|
-
},
|
|
39
|
-
configureServer(server) {
|
|
40
|
-
return () => {
|
|
41
|
-
server.middlewares.use(async (req, res, next) => {
|
|
42
|
-
let html = await readFile(DEFAULT_HTML_PATH, "utf-8");
|
|
43
|
-
try {
|
|
44
|
-
html = await server.transformIndexHtml(req.url, html, req.originalUrl);
|
|
45
|
-
res.statusCode = 200;
|
|
46
|
-
res.setHeader("Content-Type", "text/html");
|
|
47
|
-
res.end(html);
|
|
48
|
-
} catch (error) {
|
|
49
|
-
return next(error);
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
// src/node/dev.ts
|
|
58
|
-
import pluginReact from "@vitejs/plugin-react";
|
|
59
|
-
|
|
60
|
-
// src/node/plugin/config.ts
|
|
61
|
-
import { join as join2 } from "path";
|
|
62
|
-
import sirv from "sirv";
|
|
63
|
-
import path from "path";
|
|
64
|
-
import fs from "fs-extra";
|
|
65
|
-
var SITE_DATA_ID = "vigor:site-data";
|
|
66
|
-
function pluginConfig(config) {
|
|
67
|
-
return {
|
|
68
|
-
name: "vigor:site-data",
|
|
69
|
-
resolveId(id) {
|
|
70
|
-
if (id === SITE_DATA_ID) {
|
|
71
|
-
return "\0" + SITE_DATA_ID;
|
|
72
|
-
}
|
|
73
|
-
},
|
|
74
|
-
load(id) {
|
|
75
|
-
if (id === "\0" + SITE_DATA_ID) {
|
|
76
|
-
return `export default ${JSON.stringify(config.siteData)}`;
|
|
77
|
-
}
|
|
78
|
-
},
|
|
79
|
-
// 通过config钩子设置别名,此处设置的别名会自动与vite配置中的别名呼应
|
|
80
|
-
config() {
|
|
81
|
-
return {
|
|
82
|
-
root: PACKAGE_ROOT,
|
|
83
|
-
resolve: {
|
|
84
|
-
alias: {
|
|
85
|
-
"@runtime": join2(PACKAGE_ROOT, "src", "runtime", "index.ts"),
|
|
86
|
-
"@constants": join2(PACKAGE_ROOT, "src", "node", "constants", "index.ts"),
|
|
87
|
-
"@types": join2(PACKAGE_ROOT, "src", "types", "index.ts")
|
|
88
|
-
}
|
|
89
|
-
},
|
|
90
|
-
css: {
|
|
91
|
-
// 在scss中定义类名的时候使用 '-' 格式可以转换为小驼峰形式进行使用
|
|
92
|
-
// 比如:
|
|
93
|
-
// scss: .main-bg
|
|
94
|
-
// tsx: mainBg
|
|
95
|
-
modules: {
|
|
96
|
-
localsConvention: "camelCaseOnly"
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
};
|
|
100
|
-
},
|
|
101
|
-
// 构建一个配置服务器来加载docs文件夹下public中的静态资源
|
|
102
|
-
// sirv 是一个优化过的轻量级中间件,用来处理静态资源请求
|
|
103
|
-
configureServer(server) {
|
|
104
|
-
const publicDir = path.join(config.root, "public");
|
|
105
|
-
if (fs.pathExistsSync(publicDir)) {
|
|
106
|
-
server.middlewares.use(sirv(publicDir));
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
// 一个学习的内容,本身未实现,比较复杂的一个逻辑。
|
|
110
|
-
// 钩子函数:当配置文件发生改变时,达到热更新的效果
|
|
111
|
-
// async handleHotUpdate(ctx) {
|
|
112
|
-
// const customWatchedFiles = [config.configPath];
|
|
113
|
-
// const include = (id: string) => customWatchedFiles.some((file) => id.includes(file));
|
|
114
|
-
// if (include(ctx.file)) {
|
|
115
|
-
// `\n${relative(config.root, ctx.file)} has changed, restarting server...`;
|
|
116
|
-
// // 重启Dev Server的方案
|
|
117
|
-
// // 手动调用dev.ts中的createServer方法
|
|
118
|
-
// }
|
|
119
|
-
// },
|
|
120
|
-
};
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
// src/node/plugin/plugin-mdx/pluginMdxRollup.ts
|
|
124
|
-
import pluginMdx from "@mdx-js/rollup";
|
|
125
|
-
import remarkGFM from "remark-gfm";
|
|
126
|
-
import rehypePluginAutoLinkHeadings from "rehype-autolink-headings";
|
|
127
|
-
import rehypePluginSlug from "rehype-slug";
|
|
128
|
-
import remarkPluginFrontmatter from "remark-frontmatter";
|
|
129
|
-
import remarkPluginMDXFrontmatter from "remark-mdx-frontmatter";
|
|
130
|
-
|
|
131
|
-
// node_modules/.pnpm/unist-util-is@5.2.1/node_modules/unist-util-is/lib/index.js
|
|
132
|
-
var convert = (
|
|
133
|
-
/**
|
|
134
|
-
* @type {(
|
|
135
|
-
* (<Kind extends Node>(test: PredicateTest<Kind>) => AssertPredicate<Kind>) &
|
|
136
|
-
* ((test?: Test) => AssertAnything)
|
|
137
|
-
* )}
|
|
138
|
-
*/
|
|
139
|
-
/**
|
|
140
|
-
* @param {Test} [test]
|
|
141
|
-
* @returns {AssertAnything}
|
|
142
|
-
*/
|
|
143
|
-
function(test) {
|
|
144
|
-
if (test === void 0 || test === null) {
|
|
145
|
-
return ok;
|
|
146
|
-
}
|
|
147
|
-
if (typeof test === "string") {
|
|
148
|
-
return typeFactory(test);
|
|
149
|
-
}
|
|
150
|
-
if (typeof test === "object") {
|
|
151
|
-
return Array.isArray(test) ? anyFactory(test) : propsFactory(test);
|
|
152
|
-
}
|
|
153
|
-
if (typeof test === "function") {
|
|
154
|
-
return castFactory(test);
|
|
155
|
-
}
|
|
156
|
-
throw new Error("Expected function, string, or object as test");
|
|
157
|
-
}
|
|
158
|
-
);
|
|
159
|
-
function anyFactory(tests) {
|
|
160
|
-
const checks = [];
|
|
161
|
-
let index = -1;
|
|
162
|
-
while (++index < tests.length) {
|
|
163
|
-
checks[index] = convert(tests[index]);
|
|
164
|
-
}
|
|
165
|
-
return castFactory(any);
|
|
166
|
-
function any(...parameters) {
|
|
167
|
-
let index2 = -1;
|
|
168
|
-
while (++index2 < checks.length) {
|
|
169
|
-
if (checks[index2].call(this, ...parameters))
|
|
170
|
-
return true;
|
|
171
|
-
}
|
|
172
|
-
return false;
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
function propsFactory(check) {
|
|
176
|
-
return castFactory(all);
|
|
177
|
-
function all(node) {
|
|
178
|
-
let key;
|
|
179
|
-
for (key in check) {
|
|
180
|
-
if (node[key] !== check[key])
|
|
181
|
-
return false;
|
|
182
|
-
}
|
|
183
|
-
return true;
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
function typeFactory(check) {
|
|
187
|
-
return castFactory(type);
|
|
188
|
-
function type(node) {
|
|
189
|
-
return node && node.type === check;
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
function castFactory(check) {
|
|
193
|
-
return assertion;
|
|
194
|
-
function assertion(node, ...parameters) {
|
|
195
|
-
return Boolean(
|
|
196
|
-
node && typeof node === "object" && "type" in node && // @ts-expect-error: fine.
|
|
197
|
-
Boolean(check.call(this, node, ...parameters))
|
|
198
|
-
);
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
function ok() {
|
|
202
|
-
return true;
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
// node_modules/.pnpm/unist-util-visit-parents@5.1.3/node_modules/unist-util-visit-parents/lib/color.js
|
|
206
|
-
function color(d) {
|
|
207
|
-
return "\x1B[33m" + d + "\x1B[39m";
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
// node_modules/.pnpm/unist-util-visit-parents@5.1.3/node_modules/unist-util-visit-parents/lib/index.js
|
|
211
|
-
var CONTINUE = true;
|
|
212
|
-
var EXIT = false;
|
|
213
|
-
var SKIP = "skip";
|
|
214
|
-
var visitParents = (
|
|
215
|
-
/**
|
|
216
|
-
* @type {(
|
|
217
|
-
* (<Tree extends Node, Check extends Test>(tree: Tree, test: Check, visitor: BuildVisitor<Tree, Check>, reverse?: boolean | null | undefined) => void) &
|
|
218
|
-
* (<Tree extends Node>(tree: Tree, visitor: BuildVisitor<Tree>, reverse?: boolean | null | undefined) => void)
|
|
219
|
-
* )}
|
|
220
|
-
*/
|
|
221
|
-
/**
|
|
222
|
-
* @param {Node} tree
|
|
223
|
-
* @param {Test} test
|
|
224
|
-
* @param {Visitor<Node>} visitor
|
|
225
|
-
* @param {boolean | null | undefined} [reverse]
|
|
226
|
-
* @returns {void}
|
|
227
|
-
*/
|
|
228
|
-
function(tree, test, visitor, reverse) {
|
|
229
|
-
if (typeof test === "function" && typeof visitor !== "function") {
|
|
230
|
-
reverse = visitor;
|
|
231
|
-
visitor = test;
|
|
232
|
-
test = null;
|
|
233
|
-
}
|
|
234
|
-
const is2 = convert(test);
|
|
235
|
-
const step = reverse ? -1 : 1;
|
|
236
|
-
factory(tree, void 0, [])();
|
|
237
|
-
function factory(node, index, parents) {
|
|
238
|
-
const value = node && typeof node === "object" ? node : {};
|
|
239
|
-
if (typeof value.type === "string") {
|
|
240
|
-
const name = (
|
|
241
|
-
// `hast`
|
|
242
|
-
typeof value.tagName === "string" ? value.tagName : (
|
|
243
|
-
// `xast`
|
|
244
|
-
typeof value.name === "string" ? value.name : void 0
|
|
245
|
-
)
|
|
246
|
-
);
|
|
247
|
-
Object.defineProperty(visit2, "name", {
|
|
248
|
-
value: "node (" + color(node.type + (name ? "<" + name + ">" : "")) + ")"
|
|
249
|
-
});
|
|
250
|
-
}
|
|
251
|
-
return visit2;
|
|
252
|
-
function visit2() {
|
|
253
|
-
let result = [];
|
|
254
|
-
let subresult;
|
|
255
|
-
let offset;
|
|
256
|
-
let grandparents;
|
|
257
|
-
if (!test || is2(node, index, parents[parents.length - 1] || null)) {
|
|
258
|
-
result = toResult(visitor(node, parents));
|
|
259
|
-
if (result[0] === EXIT) {
|
|
260
|
-
return result;
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
if (node.children && result[0] !== SKIP) {
|
|
264
|
-
offset = (reverse ? node.children.length : -1) + step;
|
|
265
|
-
grandparents = parents.concat(node);
|
|
266
|
-
while (offset > -1 && offset < node.children.length) {
|
|
267
|
-
subresult = factory(node.children[offset], offset, grandparents)();
|
|
268
|
-
if (subresult[0] === EXIT) {
|
|
269
|
-
return subresult;
|
|
270
|
-
}
|
|
271
|
-
offset = typeof subresult[1] === "number" ? subresult[1] : offset + step;
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
return result;
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
);
|
|
279
|
-
function toResult(value) {
|
|
280
|
-
if (Array.isArray(value)) {
|
|
281
|
-
return value;
|
|
282
|
-
}
|
|
283
|
-
if (typeof value === "number") {
|
|
284
|
-
return [CONTINUE, value];
|
|
285
|
-
}
|
|
286
|
-
return [value];
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
// node_modules/.pnpm/unist-util-visit@4.1.2/node_modules/unist-util-visit/lib/index.js
|
|
290
|
-
var visit = (
|
|
291
|
-
/**
|
|
292
|
-
* @type {(
|
|
293
|
-
* (<Tree extends Node, Check extends Test>(tree: Tree, test: Check, visitor: BuildVisitor<Tree, Check>, reverse?: boolean | null | undefined) => void) &
|
|
294
|
-
* (<Tree extends Node>(tree: Tree, visitor: BuildVisitor<Tree>, reverse?: boolean | null | undefined) => void)
|
|
295
|
-
* )}
|
|
296
|
-
*/
|
|
297
|
-
/**
|
|
298
|
-
* @param {Node} tree
|
|
299
|
-
* @param {Test} test
|
|
300
|
-
* @param {Visitor} visitor
|
|
301
|
-
* @param {boolean | null | undefined} [reverse]
|
|
302
|
-
* @returns {void}
|
|
303
|
-
*/
|
|
304
|
-
function(tree, test, visitor, reverse) {
|
|
305
|
-
if (typeof test === "function" && typeof visitor !== "function") {
|
|
306
|
-
reverse = visitor;
|
|
307
|
-
visitor = test;
|
|
308
|
-
test = null;
|
|
309
|
-
}
|
|
310
|
-
visitParents(tree, test, overload, reverse);
|
|
311
|
-
function overload(node, parents) {
|
|
312
|
-
const parent = parents[parents.length - 1];
|
|
313
|
-
return visitor(
|
|
314
|
-
node,
|
|
315
|
-
parent ? parent.children.indexOf(node) : null,
|
|
316
|
-
parent
|
|
317
|
-
);
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
);
|
|
321
|
-
|
|
322
|
-
// src/node/plugin/plugin-mdx/rehypePlugins/preWrapper.ts
|
|
323
|
-
var preWrapperPlugin = () => {
|
|
324
|
-
return (tree) => {
|
|
325
|
-
visit(tree, "element", (node) => {
|
|
326
|
-
if (node.tagName === "pre" && node.children[0]?.type === "element" && node.children[0].tagName === "code" && !node.data?.isVisited) {
|
|
327
|
-
const codeNode = node.children[0];
|
|
328
|
-
const codeClassName = codeNode.properties?.className?.toString() || "";
|
|
329
|
-
const lang = codeClassName.split("-")[1];
|
|
330
|
-
const nodeClone = {
|
|
331
|
-
type: "element",
|
|
332
|
-
tagName: "pre",
|
|
333
|
-
children: node.children,
|
|
334
|
-
data: {
|
|
335
|
-
isVisited: true
|
|
336
|
-
}
|
|
337
|
-
};
|
|
338
|
-
node.tagName = "div";
|
|
339
|
-
node.properties = node.properties || {};
|
|
340
|
-
node.properties.className = codeClassName;
|
|
341
|
-
node.children = [
|
|
342
|
-
{
|
|
343
|
-
type: "element",
|
|
344
|
-
tagName: "span",
|
|
345
|
-
properties: {
|
|
346
|
-
className: "lang"
|
|
347
|
-
},
|
|
348
|
-
children: [
|
|
349
|
-
{
|
|
350
|
-
type: "text",
|
|
351
|
-
value: lang
|
|
352
|
-
}
|
|
353
|
-
]
|
|
354
|
-
},
|
|
355
|
-
nodeClone
|
|
356
|
-
];
|
|
357
|
-
}
|
|
358
|
-
});
|
|
359
|
-
};
|
|
360
|
-
};
|
|
361
|
-
|
|
362
|
-
// src/node/plugin/plugin-mdx/rehypePlugins/shiki.ts
|
|
363
|
-
import { fromHtml } from "hast-util-from-html";
|
|
364
|
-
var shikiPlugin = ({ highlighter }) => {
|
|
365
|
-
return (tree) => {
|
|
366
|
-
visit(tree, "element", (node, index, parent) => {
|
|
367
|
-
if (node.tagName === "pre" && node.children[0]?.type === "element" && node.children[0]?.tagName === "code") {
|
|
368
|
-
const codeNode = node.children[0];
|
|
369
|
-
const codeContent = codeNode.children[0].value;
|
|
370
|
-
const codeClassName = codeNode.properties?.className?.toString() || "";
|
|
371
|
-
const lang = codeClassName.split("-")[1];
|
|
372
|
-
if (!lang)
|
|
373
|
-
return;
|
|
374
|
-
const highlightCode = highlighter.codeToHtml(codeContent, { lang });
|
|
375
|
-
const fragmentAST = fromHtml(highlightCode, { fragment: true });
|
|
376
|
-
parent.children.splice(index, 1, ...fragmentAST.children);
|
|
377
|
-
}
|
|
378
|
-
});
|
|
379
|
-
};
|
|
380
|
-
};
|
|
381
|
-
|
|
382
|
-
// src/node/plugin/plugin-mdx/pluginMdxRollup.ts
|
|
383
|
-
import shiki from "shiki";
|
|
384
|
-
|
|
385
|
-
// src/node/plugin/plugin-mdx/remarkPlugins/toc.ts
|
|
386
|
-
import Slugger from "github-slugger";
|
|
387
|
-
import { parse } from "acorn";
|
|
388
|
-
var slugger = new Slugger();
|
|
389
|
-
var title = "";
|
|
390
|
-
var TOCPlugin = () => {
|
|
391
|
-
return (tree) => {
|
|
392
|
-
const tocTree = [];
|
|
393
|
-
visit(tree, "heading", (node) => {
|
|
394
|
-
if (!node.depth || !node.children) {
|
|
395
|
-
return;
|
|
396
|
-
}
|
|
397
|
-
if (node.depth === 1) {
|
|
398
|
-
title = node.children[0].value;
|
|
399
|
-
}
|
|
400
|
-
if (node.depth > 1 && node.depth < 5) {
|
|
401
|
-
const originText = node.children.map((child) => {
|
|
402
|
-
switch (child.type) {
|
|
403
|
-
case "link":
|
|
404
|
-
return child.children?.map((c) => c.value).join("") || "";
|
|
405
|
-
default:
|
|
406
|
-
return child.value;
|
|
407
|
-
}
|
|
408
|
-
}).join("");
|
|
409
|
-
const id = slugger.slug(originText);
|
|
410
|
-
tocTree.push({
|
|
411
|
-
id,
|
|
412
|
-
text: originText,
|
|
413
|
-
depth: node.depth
|
|
414
|
-
});
|
|
415
|
-
}
|
|
416
|
-
});
|
|
417
|
-
const insertCode = `export const toc = ${JSON.stringify(tocTree, null, 2)};`;
|
|
418
|
-
tree.children.push({
|
|
419
|
-
type: "mdxjsEsm",
|
|
420
|
-
value: insertCode,
|
|
421
|
-
data: {
|
|
422
|
-
estree: parse(insertCode, {
|
|
423
|
-
ecmaVersion: 2020,
|
|
424
|
-
sourceType: "module"
|
|
425
|
-
})
|
|
426
|
-
}
|
|
427
|
-
});
|
|
428
|
-
if (title) {
|
|
429
|
-
const insertTitle = `export const title = "${title}";`;
|
|
430
|
-
tree.children.push({
|
|
431
|
-
type: ""
|
|
432
|
-
});
|
|
433
|
-
}
|
|
434
|
-
};
|
|
435
|
-
};
|
|
436
|
-
|
|
437
|
-
// src/node/plugin/plugin-mdx/pluginMdxRollup.ts
|
|
438
|
-
async function pluginMdxRollup() {
|
|
439
|
-
return pluginMdx({
|
|
440
|
-
// 添加github的markdown标准-GFM语法
|
|
441
|
-
remarkPlugins: [
|
|
442
|
-
remarkGFM,
|
|
443
|
-
remarkPluginFrontmatter,
|
|
444
|
-
[remarkPluginMDXFrontmatter, { name: "frontmatter" }],
|
|
445
|
-
TOCPlugin
|
|
446
|
-
],
|
|
447
|
-
// md文件解析插件
|
|
448
|
-
rehypePlugins: [
|
|
449
|
-
rehypePluginSlug,
|
|
450
|
-
[
|
|
451
|
-
rehypePluginAutoLinkHeadings,
|
|
452
|
-
{
|
|
453
|
-
properties: {
|
|
454
|
-
class: "header-anchor"
|
|
455
|
-
},
|
|
456
|
-
content: {
|
|
457
|
-
type: "text",
|
|
458
|
-
value: "#"
|
|
459
|
-
}
|
|
460
|
-
}
|
|
461
|
-
],
|
|
462
|
-
preWrapperPlugin,
|
|
463
|
-
[shikiPlugin, { highlighter: await shiki.getHighlighter({ theme: "nord" }) }]
|
|
464
|
-
]
|
|
465
|
-
});
|
|
466
|
-
}
|
|
467
|
-
|
|
468
|
-
// src/node/plugin/plugin-mdx/index.ts
|
|
469
|
-
async function pluginMdx2() {
|
|
470
|
-
return [await pluginMdxRollup()];
|
|
471
|
-
}
|
|
472
|
-
|
|
473
|
-
// src/node/plugin/plugin-routes/RouteService.ts
|
|
474
|
-
import fastGlob from "fast-glob";
|
|
475
|
-
import path2 from "path";
|
|
476
|
-
import { normalizePath } from "vite";
|
|
477
|
-
var RouteService = class {
|
|
478
|
-
// #scanDir是定义一个私有变量
|
|
479
|
-
#scanDir;
|
|
480
|
-
// 路由信息数组
|
|
481
|
-
#routeData = [];
|
|
482
|
-
constructor(scanDir) {
|
|
483
|
-
this.#scanDir = scanDir;
|
|
484
|
-
}
|
|
485
|
-
async init() {
|
|
486
|
-
const files = fastGlob.sync(["**/*.{js,jsx,ts,tsx,md,mdx}"], {
|
|
487
|
-
cwd: this.#scanDir,
|
|
488
|
-
absolute: true,
|
|
489
|
-
ignore: ["**/build/**", "**/.vigor/**", "config.ts", "tsconfig.json"]
|
|
490
|
-
}).sort();
|
|
491
|
-
files.forEach((file) => {
|
|
492
|
-
const fileRelativePath = normalizePath(path2.relative(this.#scanDir, file));
|
|
493
|
-
const routePath = this.getRoutePath(fileRelativePath);
|
|
494
|
-
this.#routeData.push({
|
|
495
|
-
routePath,
|
|
496
|
-
absolutePath: file
|
|
497
|
-
});
|
|
498
|
-
});
|
|
499
|
-
}
|
|
500
|
-
// 得到路由路径
|
|
501
|
-
getRoutePath(fileRelativePath) {
|
|
502
|
-
const routePath = fileRelativePath.replace(/\.(.*)?$/, "").replace(/index$/, "");
|
|
503
|
-
return routePath.startsWith("/") ? routePath : `/${routePath}`;
|
|
504
|
-
}
|
|
505
|
-
// 生成路由页面代码
|
|
506
|
-
generateRoutesPath(ssr) {
|
|
507
|
-
return `
|
|
508
|
-
import React from 'react';
|
|
509
|
-
${ssr ? "" : 'import loadable from "@loadable/component";'}
|
|
510
|
-
${this.#routeData.map((route, index) => {
|
|
511
|
-
return ssr ? `import Route${index} from "${normalizePath(route.absolutePath)}";` : `const Route${index} = loadable(() => import('${normalizePath(
|
|
512
|
-
route.absolutePath
|
|
513
|
-
)}')); `;
|
|
514
|
-
}).join("\n")}
|
|
515
|
-
|
|
516
|
-
export const routes = [
|
|
517
|
-
${this.#routeData.map((route, index) => {
|
|
518
|
-
return `{ path: '${normalizePath(
|
|
519
|
-
route.routePath
|
|
520
|
-
)}', element: React.createElement(Route${index}), preload: () => import('${normalizePath(
|
|
521
|
-
route.absolutePath
|
|
522
|
-
)}') },`;
|
|
523
|
-
}).join("\n")}
|
|
524
|
-
]
|
|
525
|
-
`;
|
|
526
|
-
}
|
|
527
|
-
// 设定一个访问私有变量的api,用来单元测试
|
|
528
|
-
getRouteData() {
|
|
529
|
-
return this.#routeData;
|
|
530
|
-
}
|
|
531
|
-
};
|
|
532
|
-
|
|
533
|
-
// src/node/plugin/plugin-routes/index.ts
|
|
534
|
-
var CONVENTIONAL_ROUTE_ID = "vigor:routes";
|
|
535
|
-
function pluginRoutes(options2) {
|
|
536
|
-
const rootService = new RouteService(options2.root);
|
|
537
|
-
return {
|
|
538
|
-
name: "vigor:routes",
|
|
539
|
-
async configResolved() {
|
|
540
|
-
await rootService.init();
|
|
541
|
-
},
|
|
542
|
-
resolveId(id) {
|
|
543
|
-
if (id === CONVENTIONAL_ROUTE_ID) {
|
|
544
|
-
return "\0" + id;
|
|
545
|
-
}
|
|
546
|
-
},
|
|
547
|
-
load(id) {
|
|
548
|
-
if (id === "\0" + CONVENTIONAL_ROUTE_ID) {
|
|
549
|
-
return rootService.generateRoutesPath(options2.isSSR || false);
|
|
550
|
-
}
|
|
551
|
-
}
|
|
552
|
-
};
|
|
553
|
-
}
|
|
554
|
-
|
|
555
|
-
// src/node/dev.ts
|
|
556
|
-
import pluginUnocss from "unocss/vite";
|
|
557
|
-
|
|
558
|
-
// src/node/unocssOptions.ts
|
|
559
|
-
import { presetAttributify, presetIcons, presetWind } from "unocss";
|
|
560
|
-
var options = {
|
|
561
|
-
presets: [presetAttributify(), presetIcons(), presetWind({})],
|
|
562
|
-
rules: [
|
|
563
|
-
// 下面这种写法和此种写法是一样的,只不过用正则会更加灵活
|
|
564
|
-
// [
|
|
565
|
-
// "divider-bottom",
|
|
566
|
-
// {
|
|
567
|
-
// "border-bottom": "1px solid var(--island-c-divider-light)"
|
|
568
|
-
// }
|
|
569
|
-
// ]
|
|
570
|
-
[
|
|
571
|
-
/^divider-(\w+)$/,
|
|
572
|
-
([, w]) => ({
|
|
573
|
-
[`border-${w}`]: "1px solid var(--vigor-c-divider-light)"
|
|
574
|
-
})
|
|
575
|
-
]
|
|
576
|
-
],
|
|
577
|
-
shortcuts: {
|
|
578
|
-
"flex-center": "flex justify-center items-center"
|
|
579
|
-
}
|
|
580
|
-
};
|
|
581
|
-
var unocssOptions_default = options;
|
|
582
|
-
|
|
583
|
-
// src/node/dev.ts
|
|
584
|
-
async function createDevServer(root, isSSR = false) {
|
|
585
|
-
const config = await resolveConfig(root, "serve", "development");
|
|
586
|
-
return createViteDevServer({
|
|
587
|
-
root: PACKAGE_ROOT,
|
|
588
|
-
// 插件注册
|
|
589
|
-
plugins: [
|
|
590
|
-
pluginUnocss(unocssOptions_default),
|
|
591
|
-
pluginIndexHtml(),
|
|
592
|
-
pluginReact(),
|
|
593
|
-
pluginConfig(config),
|
|
594
|
-
pluginRoutes({ root: config.root, isSSR }),
|
|
595
|
-
await pluginMdx2()
|
|
596
|
-
],
|
|
597
|
-
// 配置e2e的服务器检索目录外的项目的合法性
|
|
598
|
-
server: {
|
|
599
|
-
fs: {
|
|
600
|
-
allow: [PACKAGE_ROOT]
|
|
601
|
-
}
|
|
602
|
-
}
|
|
603
|
-
});
|
|
604
|
-
}
|
|
605
|
-
|
|
606
|
-
export {
|
|
607
|
-
CLIENT_ENTRY_PATH,
|
|
608
|
-
SERVER_ENTRY_PATH,
|
|
609
|
-
pluginIndexHtml,
|
|
610
|
-
pluginConfig,
|
|
611
|
-
pluginMdx2 as pluginMdx,
|
|
612
|
-
pluginRoutes,
|
|
613
|
-
unocssOptions_default,
|
|
614
|
-
createDevServer
|
|
615
|
-
};
|