vite-plugin-generoutes 0.2.11 → 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 +1 -1
- package/dist/index.js +23 -33
- package/package.json +15 -17
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
|
**********************************/
|
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
|
}
|
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@10.2
|
|
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",
|
|
@@ -49,31 +49,29 @@
|
|
|
49
49
|
"vite": "^6.1.0"
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"@antfu/utils": "^
|
|
52
|
+
"@antfu/utils": "^9.1.0",
|
|
53
53
|
"@vue/compiler-sfc": "^3.5.13",
|
|
54
54
|
"chalk": "^5.4.1",
|
|
55
|
-
"chokidar": "^4.0.3",
|
|
56
55
|
"fs-extra": "^11.3.0",
|
|
57
56
|
"glob": "^11.0.1",
|
|
58
|
-
"prettier": "^3.
|
|
57
|
+
"prettier": "^3.5.3"
|
|
59
58
|
},
|
|
60
59
|
"devDependencies": {
|
|
61
|
-
"@antfu/eslint-config": "^4.
|
|
62
|
-
"@antfu/ni": "^23.3.1",
|
|
60
|
+
"@antfu/eslint-config": "^4.10.1",
|
|
63
61
|
"@types/fs-extra": "^11.0.4",
|
|
64
|
-
"@types/node": "^20.17.
|
|
65
|
-
"bumpp": "^10.0
|
|
66
|
-
"eslint": "^9.
|
|
62
|
+
"@types/node": "^20.17.24",
|
|
63
|
+
"bumpp": "^10.1.0",
|
|
64
|
+
"eslint": "^9.22.0",
|
|
67
65
|
"esno": "^4.8.0",
|
|
68
|
-
"lint-staged": "^15.
|
|
69
|
-
"pnpm": "^10.2
|
|
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": "^
|
|
73
|
-
"tsup": "^8.
|
|
74
|
-
"typescript": "^5.
|
|
75
|
-
"unbuild": "^3.
|
|
76
|
-
"vitest": "^3.0.
|
|
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"
|