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