vite-plugin-generoutes 0.2.10 → 0.3.0-beta.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 +7 -12
- package/dist/index.js +25 -35
- package/package.json +21 -23
package/dist/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { Plugin } from 'vite';
|
|
|
3
3
|
/**********************************
|
|
4
4
|
* @Author: Ronnie Zhang
|
|
5
5
|
* @LastEditor: Ronnie Zhang
|
|
6
|
-
* @LastEditTime:
|
|
6
|
+
* @LastEditTime: 2025/03/13 16:42:47
|
|
7
7
|
* @Email: zclzone@outlook.com
|
|
8
8
|
* Copyright © 2023 Ronnie Zhang(大脸怪) | https://isme.top
|
|
9
9
|
**********************************/
|
|
@@ -12,30 +12,25 @@ interface Options {
|
|
|
12
12
|
/**
|
|
13
13
|
* pages folder
|
|
14
14
|
*
|
|
15
|
-
* default
|
|
15
|
+
* @default src/pages
|
|
16
16
|
*/
|
|
17
17
|
pagesFolder: string;
|
|
18
18
|
/**
|
|
19
|
-
* ignore folders
|
|
19
|
+
* ignore folders, ignore these folders when generating routes
|
|
20
20
|
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
* default: `['components']`
|
|
21
|
+
* @default ['components']
|
|
24
22
|
*/
|
|
25
23
|
ignoreFolders: string[];
|
|
26
24
|
/**
|
|
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`
|
|
25
|
+
* routes file path, It can also be a ts file,such as `src/router/routes.ts`
|
|
32
26
|
*
|
|
27
|
+
* @default src/router/routes.js
|
|
33
28
|
*/
|
|
34
29
|
routesPath: string;
|
|
35
30
|
/**
|
|
36
31
|
* nested routes
|
|
37
32
|
*
|
|
38
|
-
* default
|
|
33
|
+
* @default false
|
|
39
34
|
*/
|
|
40
35
|
nested: boolean;
|
|
41
36
|
}
|
package/dist/index.js
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
2
|
import path from "node:path";
|
|
3
|
+
import { debounce, slash } from "@antfu/utils";
|
|
4
|
+
import { parse } from "@vue/compiler-sfc";
|
|
5
|
+
import chalk from "chalk";
|
|
3
6
|
import fs from "fs-extra";
|
|
4
7
|
import { globSync } from "glob";
|
|
5
|
-
import { parse } from "@vue/compiler-sfc";
|
|
6
|
-
import { debounce, slash } from "@antfu/utils";
|
|
7
|
-
import chokidar from "chokidar";
|
|
8
8
|
import prettier from "prettier";
|
|
9
|
-
import chalk from "chalk";
|
|
10
9
|
|
|
11
10
|
// src/utils.ts
|
|
12
11
|
function toPascalCase(str) {
|
|
@@ -115,42 +114,33 @@ function VitePluginGeneroutes(options = {}) {
|
|
|
115
114
|
console.log(` \u2705 ${isInit ? "routes generated:" : "routes updated:"} ${chalk.cyan(routesPath)}`);
|
|
116
115
|
}
|
|
117
116
|
const debounceWriter = debounce(500, writerRoutesFile);
|
|
118
|
-
let watcher;
|
|
119
|
-
function createWatcher() {
|
|
120
|
-
watcher = chokidar.watch(`${pagesFolder}/**/*.vue`, { ignoreInitial: true });
|
|
121
|
-
return watcher.on("all", async (event, path2) => {
|
|
122
|
-
if (ignoreFolders.some((folder) => slash(path2).includes(`/${folder}/`)))
|
|
123
|
-
return;
|
|
124
|
-
if (path2.endsWith(".vue") && (event === "add" || event === "unlink")) {
|
|
125
|
-
debounceWriter();
|
|
126
|
-
if (watcher) {
|
|
127
|
-
await watcher.close();
|
|
128
|
-
createWatcher();
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
117
|
return {
|
|
134
118
|
name: "vite-plugin-generoutes",
|
|
135
119
|
async configResolved(config) {
|
|
136
120
|
rootDir = config.root;
|
|
137
121
|
await writerRoutesFile(true);
|
|
138
|
-
if (config.command !== "build") {
|
|
139
|
-
createWatcher();
|
|
140
|
-
}
|
|
141
122
|
},
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
if (
|
|
147
|
-
|
|
123
|
+
configureServer(server) {
|
|
124
|
+
const { watcher } = server;
|
|
125
|
+
watcher.on("all", async (event, filePath) => {
|
|
126
|
+
filePath = slash(filePath);
|
|
127
|
+
if (!filePath.endsWith(".vue") || ignoreFolders.some((folder) => filePath.includes(`/${folder}/`)))
|
|
128
|
+
return;
|
|
129
|
+
if (filePath.includes(pagesFolder)) {
|
|
130
|
+
if (event === "change") {
|
|
131
|
+
const relativePath = path.relative(rootDir, filePath);
|
|
132
|
+
const slashedPath = slash(relativePath);
|
|
133
|
+
const prevDefineOptions = defineOptionsCache.get(slashedPath);
|
|
134
|
+
const content = await fs.readFile(filePath, "utf-8");
|
|
135
|
+
const defineOptions = JSON.stringify(parseDefineOptions(filePath, content));
|
|
136
|
+
if (prevDefineOptions !== defineOptions) {
|
|
137
|
+
debounceWriter();
|
|
138
|
+
}
|
|
139
|
+
} else if (event === "add" || event === "unlink") {
|
|
140
|
+
debounceWriter();
|
|
141
|
+
}
|
|
148
142
|
}
|
|
149
|
-
}
|
|
150
|
-
},
|
|
151
|
-
closeBundle() {
|
|
152
|
-
if (watcher)
|
|
153
|
-
watcher.close();
|
|
143
|
+
});
|
|
154
144
|
}
|
|
155
145
|
};
|
|
156
146
|
}
|
|
@@ -170,7 +160,7 @@ function parseDefineOptions(filePath, content) {
|
|
|
170
160
|
}
|
|
171
161
|
return {};
|
|
172
162
|
}
|
|
173
|
-
var
|
|
163
|
+
var index_default = VitePluginGeneroutes;
|
|
174
164
|
export {
|
|
175
|
-
|
|
165
|
+
index_default as default
|
|
176
166
|
};
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite-plugin-generoutes",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
5
|
-
"packageManager": "pnpm@
|
|
4
|
+
"version": "0.3.0-beta.1",
|
|
5
|
+
"packageManager": "pnpm@10.6.2",
|
|
6
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
7
|
"author": "Ronnie Zhang <zclzone@outlook.com>",
|
|
8
8
|
"license": "MIT",
|
|
@@ -46,34 +46,32 @@
|
|
|
46
46
|
"up:deps": "taze major -I"
|
|
47
47
|
},
|
|
48
48
|
"peerDependencies": {
|
|
49
|
-
"vite": "^
|
|
49
|
+
"vite": "^6.1.0"
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"@antfu/utils": "^
|
|
53
|
-
"@vue/compiler-sfc": "^3.
|
|
54
|
-
"chalk": "^5.
|
|
55
|
-
"
|
|
56
|
-
"
|
|
57
|
-
"
|
|
58
|
-
"prettier": "^3.3.3"
|
|
52
|
+
"@antfu/utils": "^9.1.0",
|
|
53
|
+
"@vue/compiler-sfc": "^3.5.13",
|
|
54
|
+
"chalk": "^5.4.1",
|
|
55
|
+
"fs-extra": "^11.3.0",
|
|
56
|
+
"glob": "^11.0.1",
|
|
57
|
+
"prettier": "^3.5.3"
|
|
59
58
|
},
|
|
60
59
|
"devDependencies": {
|
|
61
|
-
"@antfu/eslint-config": "^
|
|
62
|
-
"@antfu/ni": "^0.23.0",
|
|
60
|
+
"@antfu/eslint-config": "^4.10.1",
|
|
63
61
|
"@types/fs-extra": "^11.0.4",
|
|
64
|
-
"@types/node": "^20.
|
|
65
|
-
"bumpp": "^
|
|
66
|
-
"eslint": "^9.
|
|
67
|
-
"esno": "^4.
|
|
68
|
-
"lint-staged": "^15.
|
|
69
|
-
"pnpm": "^
|
|
62
|
+
"@types/node": "^20.17.24",
|
|
63
|
+
"bumpp": "^10.1.0",
|
|
64
|
+
"eslint": "^9.22.0",
|
|
65
|
+
"esno": "^4.8.0",
|
|
66
|
+
"lint-staged": "^15.5.0",
|
|
67
|
+
"pnpm": "^10.6.2",
|
|
70
68
|
"rimraf": "^5.0.10",
|
|
71
69
|
"simple-git-hooks": "^2.11.1",
|
|
72
|
-
"taze": "^0.
|
|
73
|
-
"tsup": "^8.
|
|
74
|
-
"typescript": "^5.
|
|
75
|
-
"unbuild": "^
|
|
76
|
-
"vitest": "^
|
|
70
|
+
"taze": "^19.0.2",
|
|
71
|
+
"tsup": "^8.4.0",
|
|
72
|
+
"typescript": "^5.8.2",
|
|
73
|
+
"unbuild": "^3.5.0",
|
|
74
|
+
"vitest": "^3.0.8"
|
|
77
75
|
},
|
|
78
76
|
"simple-git-hooks": {
|
|
79
77
|
"pre-commit": "pnpm lint-staged"
|