vite-plugin-generoutes 0.0.15 → 0.0.17

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 (2) hide show
  1. package/dist/index.js +4 -8
  2. package/package.json +3 -2
package/dist/index.js CHANGED
@@ -1,28 +1,25 @@
1
1
  // src/index.ts
2
2
  import path from "node:path";
3
- import { exec } from "node:child_process";
4
3
  import fs from "fs-extra";
5
4
  import { globSync } from "glob";
6
5
  import { parse } from "@vue/compiler-sfc";
7
6
  import { debounce, slash } from "@antfu/utils";
8
7
  import chokidar from "chokidar";
8
+ import prettier from "prettier";
9
9
  function VitePluginGeneroutes(options = {}) {
10
10
  const defineOptionsCache = /* @__PURE__ */ new Map();
11
11
  let rootDir;
12
12
  let routesFolder = "src/router/generoutes/";
13
13
  const writerRoutesFile = debounce(500, async () => {
14
14
  const { routes } = generateMenusAndRoutes();
15
- const routesStr = `
15
+ let routesStr = `
16
16
  // ! \u6B64\u6587\u4EF6\u7531 vite-plugin-generoutes \u81EA\u52A8\u751F\u6210\uFF0C\u8BF7\u52FF\u4FEE\u6539\uFF0C\u8BF7\u52FF\u4FEE\u6539\uFF0C\u8BF7\u52FF\u4FEE\u6539!!!
17
17
 
18
18
  export const routes = ${JSON.stringify(routes, null, 2)}
19
19
  `.replace(/"##(.*)##"/g, (_, p1) => `() => import('${p1}')`);
20
+ routesStr = await prettier.format(routesStr, { parser: "babel", semi: false, singleQuote: true });
20
21
  const filePath = `${routesFolder}/index.js`;
21
22
  fs.writeFileSync(filePath, routesStr);
22
- try {
23
- exec(`npx eslint --fix ${filePath}`);
24
- } catch (error) {
25
- }
26
23
  });
27
24
  function generateMenusAndRoutes() {
28
25
  const pages = globSync("src/pages/**/index.vue");
@@ -37,8 +34,7 @@ function VitePluginGeneroutes(options = {}) {
37
34
  const name = defineOptions?.name || meta.id;
38
35
  meta.parentId = pageFolders.slice(0, -1).join("_") || null;
39
36
  const component = `##/${filePath}##`;
40
- const folderPath = `/${pageFolders.map((item) => item.replace(/\[(.*?)\]/g, (_, p1) => p1.split(",").map((i) => `:${i}`).join("/"))).join("/")}`;
41
- let routePath = folderPath;
37
+ let routePath = `/${pageFolders.map((item) => item.replace(/\[(.*?)\]/g, (_, p1) => p1.split(",").map((i) => `:${i}`).join("/"))).join("/")}`;
42
38
  if (meta.isNotFound) {
43
39
  routePath = "/:pathMatch(.*)*";
44
40
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "vite-plugin-generoutes",
3
3
  "type": "module",
4
- "version": "0.0.15",
4
+ "version": "0.0.17",
5
5
  "packageManager": "pnpm@9.1.1",
6
6
  "description": "_description_",
7
7
  "author": "Ronnie Zhang <zclzone@outlook.com>",
@@ -52,7 +52,8 @@
52
52
  "@vue/compiler-sfc": "^3.4.27",
53
53
  "chokidar": "^3.6.0",
54
54
  "fs-extra": "^11.2.0",
55
- "glob": "^10.4.1"
55
+ "glob": "^10.4.1",
56
+ "prettier": "^3.3.2"
56
57
  },
57
58
  "devDependencies": {
58
59
  "@antfu/eslint-config": "^2.18.1",