vite-plugin-generoutes 0.2.7 → 0.2.9

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Ronnie Zhang(大脸怪)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/dist/index.d.ts CHANGED
@@ -10,30 +10,35 @@ import { Plugin } from 'vite';
10
10
 
11
11
  interface Options {
12
12
  /**
13
- * pages 文件夹
13
+ * pages folder
14
14
  *
15
15
  * default: `src/pages`
16
16
  */
17
17
  pagesFolder: string;
18
18
  /**
19
- * 忽略文件夹
19
+ * ignore folders
20
+ *
21
+ * ignore these folders when generating routes
20
22
  *
21
23
  * default: `['components']`
22
24
  */
23
25
  ignoreFolders: string[];
24
26
  /**
25
- * 路由文件路径
27
+ * routes file path
28
+ *
29
+ * default: `src/router/routes.js`
30
+ *
31
+ * It can also be a ts file,such as `src/router/routes.ts`
26
32
  *
27
- * default: `${pagesFolder}/generoutes.js`
28
33
  */
29
- routesPath?: string;
34
+ routesPath: string;
30
35
  /**
31
- * 是否嵌套
36
+ * nested routes
32
37
  *
33
38
  * default: false
34
39
  */
35
40
  nested: boolean;
36
41
  }
37
- declare function VitePluginGeneroutes(options?: Partial<Options>): Plugin<any>;
42
+ declare function VitePluginGeneroutes(options?: Partial<Options>): Plugin;
38
43
 
39
44
  export { VitePluginGeneroutes as default };
package/dist/index.js CHANGED
@@ -59,19 +59,14 @@ function findDuplicateRoutes(routes) {
59
59
  }
60
60
 
61
61
  // src/index.ts
62
- var defaultOptions = {
63
- pagesFolder: "src/pages",
64
- ignoreFolders: ["components"],
65
- nested: false
66
- };
67
62
  function VitePluginGeneroutes(options = {}) {
68
63
  if (options.routesPath && ![".ts", ".js"].includes(path.extname(options.routesPath)))
69
64
  throw new Error("routesPath must be a js or ts file path, such as src/router/generoutes.js");
70
65
  let rootDir;
71
- const pagesFolder = options.pagesFolder || defaultOptions.pagesFolder;
72
- const routesPath = options.routesPath || path.join(pagesFolder, "generoutes.js");
73
- const nested = options.nested || defaultOptions.nested;
74
- const ignoreFolders = options.ignoreFolders || defaultOptions.ignoreFolders;
66
+ const pagesFolder = options.pagesFolder || "src/pages";
67
+ const routesPath = options.routesPath || "src/router/routes.js";
68
+ const ignoreFolders = options.ignoreFolders || ["components"];
69
+ const nested = options.nested || false;
75
70
  const defineOptionsCache = /* @__PURE__ */ new Map();
76
71
  function generateMenusAndRoutes() {
77
72
  const pages = globSync(`${pagesFolder}/**/*.vue`, { ignore: ignoreFolders.map((folder) => `${pagesFolder}/**/${folder}/**`) });
@@ -90,7 +85,7 @@ function VitePluginGeneroutes(options = {}) {
90
85
  name,
91
86
  path: routePath,
92
87
  redirect: defineOptions.redirect,
93
- component,
88
+ component: defineOptions.redirect ? void 0 : component,
94
89
  meta,
95
90
  parent: defineOptions.parent
96
91
  };
@@ -107,8 +102,7 @@ function VitePluginGeneroutes(options = {}) {
107
102
  async function writerRoutesFile() {
108
103
  const { routes } = generateMenusAndRoutes();
109
104
  let routesStr = `
110
- // ! \u6B64\u6587\u4EF6\u7531 vite-plugin-generoutes \u81EA\u52A8\u751F\u6210\uFF0C\u5EFA\u8BAE\u6DFB\u52A0\u5230 .gitignore\uFF0C\u8BF7\u52FF\u76F4\u63A5\u5728\u6B64\u6587\u4EF6\u4FEE\u6539!!!
111
- // ! This file is generated by vite-plugin-generoutes, it is recommended to add it to .gitignore, do not modify it directly in this file!!!
105
+ // Generated by vite-plugin-generoutes, don't modify it directly.
112
106
 
113
107
  export const routes = ${JSON.stringify(routes, null, 2)}
114
108
  `;
@@ -139,7 +133,8 @@ function VitePluginGeneroutes(options = {}) {
139
133
  async configResolved(config) {
140
134
  rootDir = config.root;
141
135
  await writerRoutesFile();
142
- config.command !== "build" && createWatcher();
136
+ if (config.command !== "build")
137
+ createWatcher();
143
138
  },
144
139
  async handleHotUpdate({ file, read }) {
145
140
  if (file.includes(pagesFolder) && !ignoreFolders.some((folder) => file.includes(`/${folder}/`)) && file.endsWith(".vue")) {
@@ -151,7 +146,8 @@ function VitePluginGeneroutes(options = {}) {
151
146
  }
152
147
  },
153
148
  closeBundle() {
154
- watcher && watcher.close();
149
+ if (watcher)
150
+ watcher.close();
155
151
  }
156
152
  };
157
153
  }
package/package.json CHANGED
@@ -1,81 +1,83 @@
1
- {
2
- "name": "vite-plugin-generoutes",
3
- "type": "module",
4
- "version": "0.2.7",
5
- "packageManager": "pnpm@9.1.1",
6
- "description": "A Vite plugin that generate routes based on the file structure, supports dynamic routes, and supports custom meta data for each route.",
7
- "author": "Ronnie Zhang <zclzone@outlook.com>",
8
- "license": "MIT",
9
- "homepage": "https://github.com/zclzone/vite-plugin-generoutes",
10
- "repository": {
11
- "type": "git",
12
- "url": "git+https://github.com/zclzone/vite-plugin-generoutes.git"
13
- },
14
- "bugs": "https://github.com/zclzone/vite-plugin-generoutes/issues",
15
- "keywords": [],
16
- "sideEffects": false,
17
- "exports": {
18
- ".": {
19
- "types": "./dist/index.d.ts",
20
- "import": "./dist/index.js"
21
- }
22
- },
23
- "main": "./dist/index.js",
24
- "module": "./dist/index.js",
25
- "types": "./dist/index.d.ts",
26
- "typesVersions": {
27
- "*": {
28
- "*": [
29
- "./dist/*",
30
- "./dist/index.d.ts"
31
- ]
32
- }
33
- },
34
- "files": [
35
- "dist"
36
- ],
37
- "scripts": {
38
- "start": "tsup --watch",
39
- "build": "tsup",
40
- "lint": "eslint .",
41
- "prepublishOnly": "nr build",
42
- "release": "bumpp && npm publish",
43
- "test": "vitest",
44
- "typecheck": "tsc --noEmit",
45
- "prepare": "simple-git-hooks"
46
- },
47
- "peerDependencies": {
48
- "vite": "^5.2.11"
49
- },
50
- "dependencies": {
51
- "@antfu/utils": "^0.7.8",
52
- "@vue/compiler-sfc": "^3.4.27",
53
- "chokidar": "^3.6.0",
54
- "fs-extra": "^11.2.0",
55
- "glob": "^10.4.1",
56
- "prettier": "^3.3.2"
57
- },
58
- "devDependencies": {
59
- "@antfu/eslint-config": "^2.18.1",
60
- "@antfu/ni": "^0.21.12",
61
- "@types/fs-extra": "^11.0.4",
62
- "@types/node": "^20.12.12",
63
- "bumpp": "^9.4.1",
64
- "eslint": "^9.3.0",
65
- "esno": "^4.7.0",
66
- "lint-staged": "^15.2.2",
67
- "pnpm": "^9.1.1",
68
- "rimraf": "^5.0.7",
69
- "simple-git-hooks": "^2.11.1",
70
- "tsup": "^8.1.0",
71
- "typescript": "^5.4.5",
72
- "unbuild": "^2.0.0",
73
- "vitest": "^1.6.0"
74
- },
75
- "simple-git-hooks": {
76
- "pre-commit": "pnpm lint-staged"
77
- },
78
- "lint-staged": {
79
- "*": "eslint --fix"
80
- }
81
- }
1
+ {
2
+ "name": "vite-plugin-generoutes",
3
+ "type": "module",
4
+ "version": "0.2.9",
5
+ "packageManager": "pnpm@9.9.0",
6
+ "description": "A Vite plugin that generate routes based on the file structure, supports dynamic routes, and supports custom meta data for each route.",
7
+ "author": "Ronnie Zhang <zclzone@outlook.com>",
8
+ "license": "MIT",
9
+ "homepage": "https://github.com/zclzone/vite-plugin-generoutes",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git+https://github.com/zclzone/vite-plugin-generoutes.git"
13
+ },
14
+ "bugs": "https://github.com/zclzone/vite-plugin-generoutes/issues",
15
+ "keywords": [],
16
+ "sideEffects": false,
17
+ "exports": {
18
+ ".": {
19
+ "types": "./dist/index.d.ts",
20
+ "import": "./dist/index.js"
21
+ }
22
+ },
23
+ "main": "./dist/index.js",
24
+ "module": "./dist/index.js",
25
+ "types": "./dist/index.d.ts",
26
+ "typesVersions": {
27
+ "*": {
28
+ "*": [
29
+ "./dist/*",
30
+ "./dist/index.d.ts"
31
+ ]
32
+ }
33
+ },
34
+ "files": [
35
+ "dist"
36
+ ],
37
+ "scripts": {
38
+ "start": "tsup --watch",
39
+ "build": "tsup",
40
+ "lint": "eslint .",
41
+ "prepublishOnly": "nr build",
42
+ "release": "bumpp && npm publish",
43
+ "test": "vitest",
44
+ "typecheck": "tsc --noEmit",
45
+ "prepare": "simple-git-hooks",
46
+ "up:deps": "taze major -I"
47
+ },
48
+ "peerDependencies": {
49
+ "vite": "^5.2.11"
50
+ },
51
+ "dependencies": {
52
+ "@antfu/utils": "^0.7.10",
53
+ "@vue/compiler-sfc": "^3.4.38",
54
+ "chokidar": "^3.6.0",
55
+ "fs-extra": "^11.2.0",
56
+ "glob": "^10.4.5",
57
+ "prettier": "^3.3.3"
58
+ },
59
+ "devDependencies": {
60
+ "@antfu/eslint-config": "^3.0.0",
61
+ "@antfu/ni": "^0.23.0",
62
+ "@types/fs-extra": "^11.0.4",
63
+ "@types/node": "^20.16.2",
64
+ "bumpp": "^9.5.2",
65
+ "eslint": "^9.9.1",
66
+ "esno": "^4.7.0",
67
+ "lint-staged": "^15.2.9",
68
+ "pnpm": "^9.9.0",
69
+ "rimraf": "^5.0.10",
70
+ "simple-git-hooks": "^2.11.1",
71
+ "taze": "^0.16.7",
72
+ "tsup": "^8.2.4",
73
+ "typescript": "^5.5.4",
74
+ "unbuild": "^2.0.0",
75
+ "vitest": "^2.0.5"
76
+ },
77
+ "simple-git-hooks": {
78
+ "pre-commit": "pnpm lint-staged"
79
+ },
80
+ "lint-staged": {
81
+ "*": "eslint --fix"
82
+ }
83
+ }