@peng_kai/kit 0.1.2 → 0.1.4
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/admin/defines/route/getRoutes.ts +1 -1
- package/admin/defines/route-guard/getRouteGuards.ts +1 -1
- package/admin/defines/startup/getStartups.ts +1 -1
- package/admin/scripts/routeNameWatcher.ts +99 -0
- package/eslint.config.js +2 -2
- package/package.json +9 -2
- package/pnpm-lock.yaml +639 -233
- package/request/request.ts +4 -0
- package/request/type.d.ts +4 -1
- package/tsconfig.json +3 -0
- package/uno.config.ts +1 -0
- package/utils/index.ts +8 -0
- package/vue/components/infinite-query/src/InfiniteQuery.vue +86 -28
- package/vue/components/infinite-query/src/useCreateTrigger.ts +8 -4
|
@@ -16,7 +16,7 @@ async function getRoutes() {
|
|
|
16
16
|
for (const name in routeFiles) {
|
|
17
17
|
const module: any = await routeFiles[name]();
|
|
18
18
|
|
|
19
|
-
if (
|
|
19
|
+
if (module?.default?.[RouteSymbol])
|
|
20
20
|
Array.prototype.push.apply(routes, module.default());
|
|
21
21
|
}
|
|
22
22
|
|
|
@@ -16,7 +16,7 @@ export async function getRouteGuards() {
|
|
|
16
16
|
for (const name in routeGuardFiles) {
|
|
17
17
|
const module: any = await routeGuardFiles[name]();
|
|
18
18
|
|
|
19
|
-
if (
|
|
19
|
+
if (module?.default?.[RouteGuardSymbol]) {
|
|
20
20
|
const guard = module.default;
|
|
21
21
|
|
|
22
22
|
routeGuards.push(guard);
|
|
@@ -11,7 +11,7 @@ export async function getStartups() {
|
|
|
11
11
|
const module: any = await moduleLoader();
|
|
12
12
|
const plugin: StartupFn = module?.default ?? {};
|
|
13
13
|
|
|
14
|
-
if (!
|
|
14
|
+
if (!plugin?.[StartupSymbol])
|
|
15
15
|
continue;
|
|
16
16
|
|
|
17
17
|
startupPaths.push(path);
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import fs from 'node:fs/promises';
|
|
2
|
+
import fg from 'fast-glob';
|
|
3
|
+
import parser from '@babel/parser';
|
|
4
|
+
import traverse from '@babel/traverse';
|
|
5
|
+
import generator from '@babel/generator';
|
|
6
|
+
import types from '@babel/types';
|
|
7
|
+
import chokidar from 'chokidar';
|
|
8
|
+
import debounce from 'lodash-es/debounce';
|
|
9
|
+
|
|
10
|
+
const routeMap = new Map<string, string[]>();
|
|
11
|
+
const routeWatcher = chokidar.watch('src/pages/**/route.ts');
|
|
12
|
+
const routeTypePath = fg.sync('**/**/router.startup.ts')?.[0];
|
|
13
|
+
|
|
14
|
+
if (routeTypePath)
|
|
15
|
+
console.log('🧐 监听路由文件变化中...');
|
|
16
|
+
else
|
|
17
|
+
throw new Error('未发现 router.startup.ts 文件');
|
|
18
|
+
|
|
19
|
+
routeWatcher.on('add', routeFileChangeHandler);
|
|
20
|
+
routeWatcher.on('change', routeFileChangeHandler);
|
|
21
|
+
routeWatcher.on('unlink', routeFileChangeHandler);
|
|
22
|
+
|
|
23
|
+
async function routeFileChangeHandler(path: string) {
|
|
24
|
+
const access = await fs.access(path).then(() => true).catch(() => false);
|
|
25
|
+
|
|
26
|
+
if (access) {
|
|
27
|
+
const names = await getRouteNames(path);
|
|
28
|
+
routeMap.set(path, names);
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
routeMap.delete(path);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
let allNames = [...routeMap.values()].flat();
|
|
35
|
+
allNames = [...new Set(allNames).values()].sort();
|
|
36
|
+
await writeRouteName(allNames);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
async function getRouteNames(filePath: string) {
|
|
40
|
+
const code = await fs.readFile(filePath, 'utf8');
|
|
41
|
+
const ast = parser.parse(code, {
|
|
42
|
+
sourceType: 'module',
|
|
43
|
+
plugins: ['typescript'],
|
|
44
|
+
});
|
|
45
|
+
const names: string[] = [];
|
|
46
|
+
|
|
47
|
+
traverse.default(ast, {
|
|
48
|
+
enter(path) {
|
|
49
|
+
if (
|
|
50
|
+
path.node.type === 'ObjectProperty'
|
|
51
|
+
&& path.node.key.name === 'name'
|
|
52
|
+
&& typeof path.node.value.value === 'string'
|
|
53
|
+
)
|
|
54
|
+
names.push(path.node.value.value);
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
return names;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const writeRouteName = debounce(async (names: string[]) => {
|
|
62
|
+
const typeCode = await fs.readFile(routeTypePath, 'utf8');
|
|
63
|
+
const typeAst = parser.parse(typeCode, {
|
|
64
|
+
sourceType: 'module',
|
|
65
|
+
plugins: ['typescript'],
|
|
66
|
+
});
|
|
67
|
+
let appRouteNamesNode: any = null;
|
|
68
|
+
|
|
69
|
+
traverse.default(typeAst, {
|
|
70
|
+
enter(path) {
|
|
71
|
+
if (
|
|
72
|
+
path.node.type === 'TSInterfaceDeclaration'
|
|
73
|
+
&& path.node.id.name === 'AppRouteNames'
|
|
74
|
+
)
|
|
75
|
+
appRouteNamesNode = path.node;
|
|
76
|
+
},
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
if (appRouteNamesNode) {
|
|
80
|
+
// 删除现有属性
|
|
81
|
+
appRouteNamesNode.body.body = appRouteNamesNode.body.body.filter(
|
|
82
|
+
node => !types.isTSPropertySignature(node),
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
// 添加新属性
|
|
86
|
+
const newProperties = names.map(name =>
|
|
87
|
+
types.tsPropertySignature(
|
|
88
|
+
types.identifier(name),
|
|
89
|
+
types.tsTypeAnnotation(types.tsBooleanKeyword()),
|
|
90
|
+
),
|
|
91
|
+
);
|
|
92
|
+
appRouteNamesNode.body.body.push(...newProperties);
|
|
93
|
+
|
|
94
|
+
// 生成修改后的代码
|
|
95
|
+
const modifiedCode = generator.default(typeAst, {}, typeCode).code;
|
|
96
|
+
|
|
97
|
+
fs.writeFile(routeTypePath, modifiedCode);
|
|
98
|
+
}
|
|
99
|
+
}, 2000);
|
package/eslint.config.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getAntFuConfig } from '@peng_kai/lint/antfu.mjs';
|
|
2
2
|
|
|
3
|
-
export default
|
|
3
|
+
export default await getAntFuConfig();
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@peng_kai/kit",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.4",
|
|
5
5
|
"description": "",
|
|
6
6
|
"author": "",
|
|
7
7
|
"license": "ISC",
|
|
@@ -23,12 +23,18 @@
|
|
|
23
23
|
"vue-router": "4.2.5"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
+
"@babel/generator": "^7.23.5",
|
|
27
|
+
"@babel/parser": "^7.23.5",
|
|
28
|
+
"@babel/traverse": "^7.23.5",
|
|
29
|
+
"@babel/types": "^7.23.5",
|
|
26
30
|
"@tanstack/vue-query": "^4.37.1",
|
|
27
31
|
"@vueuse/core": "^10.6.1",
|
|
28
32
|
"ant-design-vue": "^4.0.7",
|
|
29
33
|
"axios": "^1.6.2",
|
|
30
34
|
"bignumber.js": "^9.1.2",
|
|
35
|
+
"chokidar": "^3.5.3",
|
|
31
36
|
"dayjs": "^1.11.10",
|
|
37
|
+
"fast-glob": "^3.3.2",
|
|
32
38
|
"lodash-es": "^4.17.21",
|
|
33
39
|
"nprogress": "^0.2.0",
|
|
34
40
|
"vue": "^3.3.8",
|
|
@@ -36,10 +42,11 @@
|
|
|
36
42
|
},
|
|
37
43
|
"devDependencies": {
|
|
38
44
|
"@antfu/eslint-config": "^1.2.1",
|
|
39
|
-
"@peng_kai/lint": "^0.0
|
|
45
|
+
"@peng_kai/lint": "^0.1.0",
|
|
40
46
|
"@types/lodash-es": "^4.17.11",
|
|
41
47
|
"@types/node": "18",
|
|
42
48
|
"@types/nprogress": "^0.2.3",
|
|
49
|
+
"@unocss/eslint-plugin": "^0.57.7",
|
|
43
50
|
"type-fest": "^4.8.1",
|
|
44
51
|
"typescript": "^5.2.2",
|
|
45
52
|
"vue-component-type-helpers": "^1.8.22"
|