vite-plugin-generoutes 0.0.18 → 0.1.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/index.d.ts CHANGED
@@ -9,7 +9,7 @@ import { Plugin } from 'vite';
9
9
  **********************************/
10
10
 
11
11
  interface Options {
12
- isBuild?: boolean;
12
+ routesFolder?: string;
13
13
  }
14
14
  declare function VitePluginGeneroutes(options?: Options): Plugin<any>;
15
15
 
package/dist/index.js CHANGED
@@ -6,10 +6,18 @@ import { parse } from "@vue/compiler-sfc";
6
6
  import { debounce, slash } from "@antfu/utils";
7
7
  import chokidar from "chokidar";
8
8
  import prettier from "prettier";
9
- function VitePluginGeneroutes(options = {}) {
9
+ function toPascalCase(str) {
10
+ return str.toLowerCase().replace(/(?:^|-)([a-z])/g, (_, p1) => {
11
+ return p1.toUpperCase();
12
+ });
13
+ }
14
+ var defaultOptions = {
15
+ routesFolder: "src/router/generoutes/"
16
+ };
17
+ function VitePluginGeneroutes(options = defaultOptions) {
10
18
  const defineOptionsCache = /* @__PURE__ */ new Map();
11
19
  let rootDir;
12
- let routesFolder = "src/router/generoutes/";
20
+ let routesFolder = options.routesFolder ?? "src/router/generoutes/";
13
21
  async function writerRoutesFile() {
14
22
  const { routes } = generateMenusAndRoutes();
15
23
  let routesStr = `
@@ -29,11 +37,11 @@ function VitePluginGeneroutes(options = {}) {
29
37
  const defineOptions = parseDefineOptions(filePath);
30
38
  defineOptionsCache.set(filePath, JSON.stringify(defineOptions));
31
39
  const meta = defineOptions?.meta || {};
40
+ if (meta.enabled === false)
41
+ return null;
32
42
  const fileName = path.basename(filePath);
33
43
  const pageFolders = filePath.replace("src/pages/", "").replace(fileName, "").split("/").filter((item) => !!item && !/^\(.*\)$/.test(item));
34
- meta.id = pageFolders.join("_") || "Index";
35
- const name = defineOptions?.name || meta.id;
36
- meta.parentId = pageFolders.slice(0, -1).join("_") || null;
44
+ const name = defineOptions?.name || pageFolders.map((item) => toPascalCase(item)).join("_") || "Index";
37
45
  const component = `##/${filePath}##`;
38
46
  let routePath = `/${pageFolders.map((item) => item.replace(/\[(.*?)\]/g, (_, p1) => p1.split(",").map((i) => `:${i}`).join("/"))).join("/")}`;
39
47
  if (meta.isNotFound) {
@@ -52,7 +60,7 @@ function VitePluginGeneroutes(options = {}) {
52
60
  component,
53
61
  meta
54
62
  };
55
- });
63
+ }).filter(Boolean);
56
64
  return {
57
65
  routes
58
66
  };
@@ -74,7 +82,7 @@ function VitePluginGeneroutes(options = {}) {
74
82
  routesFolder = slash(path.resolve(rootDir, routesFolder));
75
83
  await fs.ensureDir(routesFolder);
76
84
  await writerRoutesFile();
77
- !options.isBuild && createWatcher();
85
+ config.command !== "build" && createWatcher();
78
86
  },
79
87
  async handleHotUpdate({ file, read }) {
80
88
  if (file.includes("src/pages") && file.endsWith("index.vue")) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "vite-plugin-generoutes",
3
3
  "type": "module",
4
- "version": "0.0.18",
4
+ "version": "0.1.1",
5
5
  "packageManager": "pnpm@9.1.1",
6
6
  "description": "_description_",
7
7
  "author": "Ronnie Zhang <zclzone@outlook.com>",