vona-module-a-web 5.0.33 → 5.0.34
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.
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { combineApiPathControllerAndActionRaw } from '@cabloy/utils';
|
|
2
|
+
import { toUpperCaseFirstChar } from '@cabloy/word-utils';
|
|
3
|
+
export default async function (options) {
|
|
4
|
+
const { sceneName, moduleName, globFiles } = options;
|
|
5
|
+
const contentImports = [];
|
|
6
|
+
const contentActions = [];
|
|
7
|
+
const contentPaths = {};
|
|
8
|
+
for (const globFile of globFiles) {
|
|
9
|
+
const { className, beanName, fileNameJSRelative, fileContent } = globFile;
|
|
10
|
+
const opionsName = `IControllerOptions${toUpperCaseFirstChar(beanName)}`;
|
|
11
|
+
contentImports.push(`// @ts-ignore ignore\nimport type { ${className} } from '${fileNameJSRelative}';`);
|
|
12
|
+
contentActions.push(`
|
|
13
|
+
export interface ${opionsName} {
|
|
14
|
+
actions?: TypeControllerOptionsActions<${className}>;
|
|
15
|
+
}`);
|
|
16
|
+
// controllerPath
|
|
17
|
+
const controllerPath = __parseControllerPath(fileContent);
|
|
18
|
+
if (controllerPath === false)
|
|
19
|
+
continue;
|
|
20
|
+
// actionPath;
|
|
21
|
+
const actionPaths = __parseActionPaths(fileContent);
|
|
22
|
+
for (const [method, actionPath] of actionPaths) {
|
|
23
|
+
if (!contentPaths[method])
|
|
24
|
+
contentPaths[method] = [];
|
|
25
|
+
const apiPath = __combineApiPath(moduleName, controllerPath, actionPath);
|
|
26
|
+
if (!apiPath.includes(':')) {
|
|
27
|
+
contentPaths[method].push(`'${apiPath}': undefined;`);
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
// const apiPath1 = apiPath.replace(/(:[^/]+)/g, (_, _part) => {
|
|
31
|
+
// return ':_string_';
|
|
32
|
+
// });
|
|
33
|
+
// const apiPath2 = apiPath.replace(/(\/:[^/]+)/g, (_, part) => {
|
|
34
|
+
// return `:{${part.substring(2)}}`;
|
|
35
|
+
// });
|
|
36
|
+
// const apiPath3 = apiPath.replace(/(:[^/]+)/g, (_, _part) => {
|
|
37
|
+
// return '${string}';
|
|
38
|
+
// });
|
|
39
|
+
// contentPaths[method].push(`'${apiPath1}': '${apiPath2}'`);
|
|
40
|
+
contentPaths[method].push(`'${apiPath}': undefined;`);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
let contentRecord = '';
|
|
45
|
+
for (const method in contentPaths) {
|
|
46
|
+
contentRecord += `export interface IApiPath${method}Record{
|
|
47
|
+
${contentPaths[method].join('\n')}
|
|
48
|
+
}\n`;
|
|
49
|
+
}
|
|
50
|
+
const contentRecord2 = contentRecord
|
|
51
|
+
? `declare module 'vona-module-a-web' {
|
|
52
|
+
${contentRecord}
|
|
53
|
+
}`
|
|
54
|
+
: '';
|
|
55
|
+
// combine
|
|
56
|
+
const content = `/** ${sceneName}: begin */
|
|
57
|
+
${contentImports.join('\n')}
|
|
58
|
+
declare module 'vona-module-${moduleName}' {
|
|
59
|
+
${contentActions.join('\n')}
|
|
60
|
+
}
|
|
61
|
+
${contentRecord2}
|
|
62
|
+
/** ${sceneName}: end */
|
|
63
|
+
`;
|
|
64
|
+
return content;
|
|
65
|
+
}
|
|
66
|
+
function __parseControllerPath(fileContent) {
|
|
67
|
+
let matched = fileContent.match(/@Controller<.*?>\(\{[\s\S]*?path: ('[^']*')[\s\S]*?\}[\s\S]*?\)\s*export class/);
|
|
68
|
+
if (!matched) {
|
|
69
|
+
matched = fileContent.match(/@Controller<.*?>\(([^)]*)\)/);
|
|
70
|
+
}
|
|
71
|
+
if (!matched)
|
|
72
|
+
return false;
|
|
73
|
+
const controllerPath = matched[1];
|
|
74
|
+
if (controllerPath === '')
|
|
75
|
+
return '';
|
|
76
|
+
return controllerPath.split(',')[0].replaceAll("'", '');
|
|
77
|
+
}
|
|
78
|
+
function __parseActionPaths(fileContent) {
|
|
79
|
+
const actionPaths = [];
|
|
80
|
+
const matches = fileContent.match(/(@Web\.get|@Web\.post|@Web\.delete|@Web\.put|@Web\.patch)\([\s\S]*?\)/g);
|
|
81
|
+
if (!matches)
|
|
82
|
+
return [];
|
|
83
|
+
for (const match of matches) {
|
|
84
|
+
const matches2 = match.match(/@([^(]*)\(([\s\S]*?)\)/);
|
|
85
|
+
if (!matches2)
|
|
86
|
+
throw new Error('parse action path error');
|
|
87
|
+
let actionPath = matches2[2];
|
|
88
|
+
if (actionPath !== '' && !actionPath.startsWith("'"))
|
|
89
|
+
continue; // exclude regexp
|
|
90
|
+
if (actionPath.startsWith("'")) {
|
|
91
|
+
const pos = actionPath.indexOf("'", 1);
|
|
92
|
+
actionPath = actionPath.substring(1, pos);
|
|
93
|
+
}
|
|
94
|
+
const method = toUpperCaseFirstChar(matches2[1].substring(4));
|
|
95
|
+
actionPaths.push([method, actionPath]);
|
|
96
|
+
}
|
|
97
|
+
return actionPaths;
|
|
98
|
+
}
|
|
99
|
+
function __combineApiPath(moduleName, controllerPath, actionPath) {
|
|
100
|
+
return combineApiPathControllerAndActionRaw(moduleName, controllerPath, actionPath, true);
|
|
101
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { toUpperCaseFirstChar } from '@cabloy/word-utils';
|
|
2
|
+
export default async function (options) {
|
|
3
|
+
const { sceneName, moduleName, globFiles } = options;
|
|
4
|
+
const contentImports = [];
|
|
5
|
+
const contentFields = [];
|
|
6
|
+
for (const globFile of globFiles) {
|
|
7
|
+
const { className, beanName, fileNameJSRelative } = globFile;
|
|
8
|
+
const opionsName = `IDtoOptions${toUpperCaseFirstChar(beanName)}`;
|
|
9
|
+
contentImports.push(`import type { ${className} } from '${fileNameJSRelative}';`);
|
|
10
|
+
contentFields.push(`
|
|
11
|
+
export interface ${opionsName} {
|
|
12
|
+
fields?: TypeEntityOptionsFields<${className}, ${opionsName}[TypeSymbolKeyFieldsMore]>;
|
|
13
|
+
}`);
|
|
14
|
+
}
|
|
15
|
+
if (contentFields.length === 0)
|
|
16
|
+
return '';
|
|
17
|
+
// combine
|
|
18
|
+
const content = `/** ${sceneName}: begin */
|
|
19
|
+
${contentImports.join('\n')}
|
|
20
|
+
declare module 'vona-module-${moduleName}' {
|
|
21
|
+
${contentFields.join('\n')}
|
|
22
|
+
}
|
|
23
|
+
/** ${sceneName}: end */
|
|
24
|
+
`;
|
|
25
|
+
return content;
|
|
26
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vona-module-a-web",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "5.0.
|
|
4
|
+
"version": "5.0.34",
|
|
5
5
|
"title": "a-web",
|
|
6
6
|
"vonaModule": {
|
|
7
7
|
"capabilities": {
|
|
@@ -13,20 +13,20 @@
|
|
|
13
13
|
"sceneIsolate": true,
|
|
14
14
|
"optionsGlobalInterfaceName": "IDecoratorDtoOptions",
|
|
15
15
|
"optionsGlobalInterfaceFrom": "vona-module-a-web",
|
|
16
|
-
"boilerplate": "
|
|
17
|
-
"metadataCustom": "
|
|
16
|
+
"boilerplate": "dto/boilerplate",
|
|
17
|
+
"metadataCustom": "dto/metadata/generate.ts"
|
|
18
18
|
},
|
|
19
19
|
"controller": {
|
|
20
20
|
"sceneIsolate": true,
|
|
21
21
|
"optionsGlobalInterfaceName": "IDecoratorControllerOptions",
|
|
22
22
|
"optionsGlobalInterfaceFrom": "vona-module-a-web",
|
|
23
|
-
"boilerplate": "
|
|
24
|
-
"metadataCustom": "
|
|
23
|
+
"boilerplate": "controller/boilerplate",
|
|
24
|
+
"metadataCustom": "controller/metadata/generate.ts"
|
|
25
25
|
},
|
|
26
26
|
"filterTransform": {
|
|
27
27
|
"optionsGlobalInterfaceName": "IDecoratorFilterTransformOptions",
|
|
28
28
|
"optionsGlobalInterfaceFrom": "vona-module-a-web",
|
|
29
|
-
"boilerplate": "
|
|
29
|
+
"boilerplate": "filterTransform/boilerplate"
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
},
|
|
@@ -48,7 +48,8 @@
|
|
|
48
48
|
"files": [
|
|
49
49
|
"assets",
|
|
50
50
|
"cli",
|
|
51
|
-
"dist"
|
|
51
|
+
"dist",
|
|
52
|
+
"dist-cli"
|
|
52
53
|
],
|
|
53
54
|
"dependencies": {
|
|
54
55
|
"find-my-way": "^9.2.0"
|
|
@@ -58,7 +59,7 @@
|
|
|
58
59
|
"rimraf": "^6.0.1"
|
|
59
60
|
},
|
|
60
61
|
"scripts": {
|
|
61
|
-
"clean": "rimraf dist tsconfig.build.tsbuildinfo",
|
|
62
|
-
"tsc:publish": "npm run clean && vona :bin:buildModule && tsc -p tsconfig.build.json"
|
|
62
|
+
"clean": "rimraf dist dist-cli tsconfig.build.tsbuildinfo tsconfig.cli.tsbuildinfo",
|
|
63
|
+
"tsc:publish": "npm run clean && vona :bin:buildModule && tsc -p tsconfig.build.json && tsc -p tsconfig.cli.json"
|
|
63
64
|
}
|
|
64
65
|
}
|