vite-plugin-generoutes 0.1.0 → 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.
Files changed (2) hide show
  1. package/dist/index.js +9 -4
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -6,6 +6,11 @@ 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 toPascalCase(str) {
10
+ return str.toLowerCase().replace(/(?:^|-)([a-z])/g, (_, p1) => {
11
+ return p1.toUpperCase();
12
+ });
13
+ }
9
14
  var defaultOptions = {
10
15
  routesFolder: "src/router/generoutes/"
11
16
  };
@@ -32,11 +37,11 @@ function VitePluginGeneroutes(options = defaultOptions) {
32
37
  const defineOptions = parseDefineOptions(filePath);
33
38
  defineOptionsCache.set(filePath, JSON.stringify(defineOptions));
34
39
  const meta = defineOptions?.meta || {};
40
+ if (meta.enabled === false)
41
+ return null;
35
42
  const fileName = path.basename(filePath);
36
43
  const pageFolders = filePath.replace("src/pages/", "").replace(fileName, "").split("/").filter((item) => !!item && !/^\(.*\)$/.test(item));
37
- meta.id = pageFolders.join("_") || "Index";
38
- const name = defineOptions?.name || meta.id;
39
- meta.parentId = pageFolders.slice(0, -1).join("_") || null;
44
+ const name = defineOptions?.name || pageFolders.map((item) => toPascalCase(item)).join("_") || "Index";
40
45
  const component = `##/${filePath}##`;
41
46
  let routePath = `/${pageFolders.map((item) => item.replace(/\[(.*?)\]/g, (_, p1) => p1.split(",").map((i) => `:${i}`).join("/"))).join("/")}`;
42
47
  if (meta.isNotFound) {
@@ -55,7 +60,7 @@ function VitePluginGeneroutes(options = defaultOptions) {
55
60
  component,
56
61
  meta
57
62
  };
58
- });
63
+ }).filter(Boolean);
59
64
  return {
60
65
  routes
61
66
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "vite-plugin-generoutes",
3
3
  "type": "module",
4
- "version": "0.1.0",
4
+ "version": "0.1.1",
5
5
  "packageManager": "pnpm@9.1.1",
6
6
  "description": "_description_",
7
7
  "author": "Ronnie Zhang <zclzone@outlook.com>",