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