vigor-moon 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.
Files changed (53) hide show
  1. package/dist/{chunk-CG4W75R5.mjs → chunk-2PYRPSJR.mjs} +1 -1
  2. package/dist/{chunk-X5IY67V6.js → chunk-WBWQEJDT.js} +1 -1
  3. package/dist/cli.js +13 -11
  4. package/dist/cli.mjs +6 -4
  5. package/dist/dev.js +2 -2
  6. package/dist/dev.mjs +1 -1
  7. package/package.json +4 -2
  8. package/dist/chunk-2M2XJKGT.js +0 -607
  9. package/dist/chunk-3EAR5BNQ.js +0 -610
  10. package/dist/chunk-3ZCIQMBL.js +0 -608
  11. package/dist/chunk-6SPQ2G5U.js +0 -611
  12. package/dist/chunk-7V4TYSIZ.mjs +0 -619
  13. package/dist/chunk-AT54N5D7.js +0 -611
  14. package/dist/chunk-BBRRUMIN.js +0 -616
  15. package/dist/chunk-BE2AQAQS.mjs +0 -608
  16. package/dist/chunk-BS6X4ZCI.js +0 -608
  17. package/dist/chunk-D2WJMNSR.js +0 -618
  18. package/dist/chunk-DTA4ZJEQ.mjs +0 -606
  19. package/dist/chunk-ECPJL6H6.js +0 -618
  20. package/dist/chunk-EU5K7BUZ.mjs +0 -612
  21. package/dist/chunk-FAELXJ3Z.mjs +0 -605
  22. package/dist/chunk-GBGTGHKN.js +0 -621
  23. package/dist/chunk-HW7CAZGA.js +0 -611
  24. package/dist/chunk-IDQ7PFDG.mjs +0 -619
  25. package/dist/chunk-IPVDS3I7.mjs +0 -609
  26. package/dist/chunk-JHZIOXVJ.js +0 -605
  27. package/dist/chunk-KRBN43PO.js +0 -606
  28. package/dist/chunk-KTIICQHT.mjs +0 -622
  29. package/dist/chunk-KZQIA6WA.js +0 -604
  30. package/dist/chunk-L4MZ52TR.mjs +0 -609
  31. package/dist/chunk-LEOZIK2T.mjs +0 -607
  32. package/dist/chunk-MHZT64KI.mjs +0 -605
  33. package/dist/chunk-NTJI6VKJ.mjs +0 -619
  34. package/dist/chunk-NWZZITYZ.mjs +0 -606
  35. package/dist/chunk-OS3F7QDD.js +0 -606
  36. package/dist/chunk-PJPXX4UA.mjs +0 -605
  37. package/dist/chunk-PW73M55D.mjs +0 -611
  38. package/dist/chunk-R6L6GYA4.mjs +0 -607
  39. package/dist/chunk-RNUPZ4CR.mjs +0 -612
  40. package/dist/chunk-SEIXDGYJ.mjs +0 -615
  41. package/dist/chunk-SYCZ35ZW.js +0 -604
  42. package/dist/chunk-THZGRR4I.js +0 -611
  43. package/dist/chunk-TJ5NMLCW.js +0 -614
  44. package/dist/chunk-TYBNSCBA.mjs +0 -611
  45. package/dist/chunk-UGBCHWPA.js +0 -621
  46. package/dist/chunk-VD42YO6T.mjs +0 -622
  47. package/dist/chunk-VMNTKZYD.js +0 -604
  48. package/dist/chunk-W6MHPTGR.js +0 -605
  49. package/dist/chunk-WBSL45KV.mjs +0 -617
  50. package/dist/chunk-XFGBQ3QD.mjs +0 -612
  51. package/dist/chunk-ZBAZASII.js +0 -618
  52. package/dist/chunk-ZGLENLKC.js +0 -610
  53. package/dist/chunk-ZN4CSBNG.mjs +0 -612
@@ -1,607 +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 TOCPlugin = () => {
390
- return (tree) => {
391
- const tocTree = [];
392
- visit(tree, "heading", (node) => {
393
- if (!node.depth || !node.children) {
394
- return;
395
- }
396
- if (node.depth === 1) {
397
- }
398
- if (node.depth > 1 && node.depth < 5) {
399
- const originText = node.children.map((child) => {
400
- switch (child.type) {
401
- case "link":
402
- return child.children?.map((c) => c.value).join("") || "";
403
- default:
404
- return child.value;
405
- }
406
- }).join("");
407
- const id = slugger.slug(originText);
408
- tocTree.push({
409
- id,
410
- text: originText,
411
- depth: node.depth
412
- });
413
- }
414
- });
415
- const insertCode = `export const toc = ${JSON.stringify(tocTree, null, 2)};`;
416
- tree.children.push({
417
- type: "mdxjsEsm",
418
- value: insertCode,
419
- data: {
420
- estree: parse(insertCode, {
421
- ecmaVersion: 2020,
422
- sourceType: "module"
423
- })
424
- }
425
- });
426
- };
427
- };
428
-
429
- // src/node/plugin/plugin-mdx/pluginMdxRollup.ts
430
- async function pluginMdxRollup() {
431
- return pluginMdx({
432
- // 添加github的markdown标准-GFM语法
433
- remarkPlugins: [
434
- remarkGFM,
435
- remarkPluginFrontmatter,
436
- [remarkPluginMDXFrontmatter, { name: "frontmatter" }],
437
- TOCPlugin
438
- ],
439
- // md文件解析插件
440
- rehypePlugins: [
441
- rehypePluginSlug,
442
- [
443
- rehypePluginAutoLinkHeadings,
444
- {
445
- properties: {
446
- class: "header-anchor"
447
- },
448
- content: {
449
- type: "text",
450
- value: "#"
451
- }
452
- }
453
- ],
454
- preWrapperPlugin,
455
- [shikiPlugin, { highlighter: await shiki.getHighlighter({ theme: "nord" }) }]
456
- ]
457
- });
458
- }
459
-
460
- // src/node/plugin/plugin-mdx/index.ts
461
- async function pluginMdx2() {
462
- return [await pluginMdxRollup()];
463
- }
464
-
465
- // src/node/plugin/plugin-routes/RouteService.ts
466
- import fastGlob from "fast-glob";
467
- import path2 from "path";
468
- import { normalizePath } from "vite";
469
- var RouteService = class {
470
- // #scanDir是定义一个私有变量
471
- #scanDir;
472
- // 路由信息数组
473
- #routeData = [];
474
- constructor(scanDir) {
475
- this.#scanDir = scanDir;
476
- }
477
- async init() {
478
- const files = fastGlob.sync(["**/*.{js,jsx,ts,tsx,md,mdx}"], {
479
- cwd: this.#scanDir,
480
- absolute: true,
481
- ignore: ["**/build/**", "**/.vigor/**", "config.ts", "tsconfig.json"]
482
- }).sort();
483
- files.forEach((file) => {
484
- const fileRelativePath = normalizePath(path2.relative(this.#scanDir, file));
485
- const routePath = this.getRoutePath(fileRelativePath);
486
- this.#routeData.push({
487
- routePath,
488
- absolutePath: file
489
- });
490
- });
491
- }
492
- // 得到路由路径
493
- getRoutePath(fileRelativePath) {
494
- const routePath = fileRelativePath.replace(/\.(.*)?$/, "").replace(/index$/, "");
495
- return routePath.startsWith("/") ? routePath : `/${routePath}`;
496
- }
497
- // 生成路由页面代码
498
- generateRoutesPath(ssr) {
499
- return `
500
- import React from 'react';
501
- ${ssr ? "" : 'import loadable from "@loadable/component";'}
502
- ${this.#routeData.map((route, index) => {
503
- return ssr ? `import Route${index} from "${normalizePath(route.absolutePath)}";` : `const Route${index} = loadable(() => import('${normalizePath(
504
- route.absolutePath
505
- )}')); `;
506
- }).join("\n")}
507
-
508
- export const routes = [
509
- ${this.#routeData.map((route, index) => {
510
- return `{ path: '${normalizePath(
511
- route.routePath
512
- )}', element: React.createElement(Route${index}), preload: () => import('${normalizePath(
513
- route.absolutePath
514
- )}') },`;
515
- }).join("\n")}
516
- ]
517
- `;
518
- }
519
- // 设定一个访问私有变量的api,用来单元测试
520
- getRouteData() {
521
- return this.#routeData;
522
- }
523
- };
524
-
525
- // src/node/plugin/plugin-routes/index.ts
526
- var CONVENTIONAL_ROUTE_ID = "vigor:routes";
527
- function pluginRoutes(options2) {
528
- const rootService = new RouteService(options2.root);
529
- return {
530
- name: "vigor:routes",
531
- async configResolved() {
532
- await rootService.init();
533
- },
534
- resolveId(id) {
535
- if (id === CONVENTIONAL_ROUTE_ID) {
536
- return "\0" + id;
537
- }
538
- },
539
- load(id) {
540
- if (id === "\0" + CONVENTIONAL_ROUTE_ID) {
541
- return rootService.generateRoutesPath(options2.isSSR || false);
542
- }
543
- }
544
- };
545
- }
546
-
547
- // src/node/dev.ts
548
- import pluginUnocss from "unocss/vite";
549
-
550
- // src/node/unocssOptions.ts
551
- import { presetAttributify, presetIcons, presetWind } from "unocss";
552
- var options = {
553
- presets: [presetAttributify(), presetIcons(), presetWind({})],
554
- rules: [
555
- // 下面这种写法和此种写法是一样的,只不过用正则会更加灵活
556
- // [
557
- // "divider-bottom",
558
- // {
559
- // "border-bottom": "1px solid var(--island-c-divider-light)"
560
- // }
561
- // ]
562
- [
563
- /^divider-(\w+)$/,
564
- ([, w]) => ({
565
- [`border-${w}`]: "1px solid var(--vigor-c-divider-light)"
566
- })
567
- ]
568
- ],
569
- shortcuts: {
570
- "flex-center": "flex justify-center items-center"
571
- }
572
- };
573
- var unocssOptions_default = options;
574
-
575
- // src/node/dev.ts
576
- async function createDevServer(root, isSSR = false) {
577
- const config = await resolveConfig(root, "serve", "development");
578
- return createViteDevServer({
579
- root: PACKAGE_ROOT,
580
- // 插件注册
581
- plugins: [
582
- pluginUnocss(unocssOptions_default),
583
- pluginIndexHtml(),
584
- pluginReact(),
585
- pluginConfig(config),
586
- pluginRoutes({ root: config.root, isSSR }),
587
- await pluginMdx2()
588
- ],
589
- // 配置e2e的服务器检索目录外的项目的合法性
590
- server: {
591
- fs: {
592
- allow: [PACKAGE_ROOT]
593
- }
594
- }
595
- });
596
- }
597
-
598
- export {
599
- CLIENT_ENTRY_PATH,
600
- SERVER_ENTRY_PATH,
601
- pluginIndexHtml,
602
- pluginConfig,
603
- pluginMdx2 as pluginMdx,
604
- pluginRoutes,
605
- unocssOptions_default,
606
- createDevServer
607
- };