zova-module-a-bean 5.1.11 → 5.1.13
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/cli/controller/metadata/_extractGenericParams.ts +64 -0
- package/cli/controller/metadata/generate.ts +13 -6
- package/cli/controller/metadata/generateFile.ts +9 -2
- package/cli/controller/metadata/generateFileComponent.ts +36 -80
- package/cli/controller/metadata/generateFilePage.ts +11 -3
- package/cli/controller/metadata/generateMetaPage.ts +38 -10
- package/cli/controller/metadata/types.ts +1 -0
- package/cli/controller/metadata/utils.ts +28 -7
- package/dist/bean/sys.onion.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/lib/useAopMethod.d.ts.map +1 -1
- package/dist/service/aop.d.ts.map +1 -1
- package/dist/service/onion_.d.ts.map +1 -1
- package/dist/types/aop.d.ts.map +1 -1
- package/dist/types/aopMethod.d.ts.map +1 -1
- package/dist/types/component.d.ts +13 -0
- package/dist/types/component.d.ts.map +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/onion.d.ts.map +1 -1
- package/dist-cli/controller/metadata/_extractGenericParams.js +57 -0
- package/dist-cli/controller/metadata/generate.js +12 -6
- package/dist-cli/controller/metadata/generateFileComponent.js +37 -77
- package/dist-cli/controller/metadata/generateMetaPage.js +5 -2
- package/dist-cli/controller/metadata/utils.js +1 -1
- package/package.json +2 -2
- package/src/bean/sys.onion.ts +16 -4
- package/src/lib/useAopMethod.ts +5 -1
- package/src/service/aop.ts +28 -8
- package/src/service/onion_.ts +29 -8
- package/src/types/aop.ts +7 -1
- package/src/types/aopMethod.ts +14 -2
- package/src/types/component.ts +14 -0
- package/src/types/index.ts +1 -0
- package/src/types/onion.ts +14 -4
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import ts from 'typescript';
|
|
3
|
+
|
|
4
|
+
export function extractGenericParamsAndImports(filePath: string, interfaceName: string) {
|
|
5
|
+
const sourceText = fs.readFileSync(filePath, 'utf-8');
|
|
6
|
+
const sourceFile = ts.createSourceFile(filePath, sourceText, ts.ScriptTarget.Latest, true, ts.ScriptKind.TSX);
|
|
7
|
+
|
|
8
|
+
// 1. Find the target interface
|
|
9
|
+
let targetInterface: ts.InterfaceDeclaration | undefined;
|
|
10
|
+
ts.forEachChild(sourceFile, node => {
|
|
11
|
+
if (ts.isInterfaceDeclaration(node) && node.name.text === interfaceName) {
|
|
12
|
+
targetInterface = node;
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
if (!targetInterface?.typeParameters) {
|
|
16
|
+
return { genericParams: '', imports: [] as string[] };
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// 2. Extract generic parameters text
|
|
20
|
+
const genericParams = targetInterface.typeParameters.map(tp => tp.getText(sourceFile)).join(', ');
|
|
21
|
+
|
|
22
|
+
// 3. Collect type reference identifiers within generic parameters
|
|
23
|
+
const typeRefNames = new Set<string>();
|
|
24
|
+
const visit = (node: ts.Node) => {
|
|
25
|
+
if (ts.isTypeReferenceNode(node)) {
|
|
26
|
+
// For qualified names like A.B, only take the leftmost identifier
|
|
27
|
+
const id = ts.isQualifiedName(node.typeName) ? node.typeName.left : node.typeName;
|
|
28
|
+
typeRefNames.add(id.getText(sourceFile));
|
|
29
|
+
}
|
|
30
|
+
ts.forEachChild(node, visit);
|
|
31
|
+
};
|
|
32
|
+
targetInterface.typeParameters.forEach(tp => visit(tp));
|
|
33
|
+
|
|
34
|
+
// Exclude the generic parameter names themselves (TParentData, TComponentName, etc.)
|
|
35
|
+
for (const tp of targetInterface.typeParameters) {
|
|
36
|
+
typeRefNames.delete(tp.name.text);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// 4. Match type references to import statements
|
|
40
|
+
const imports: string[] = [];
|
|
41
|
+
ts.forEachChild(sourceFile, node => {
|
|
42
|
+
if (!ts.isImportDeclaration(node)) return;
|
|
43
|
+
const clause = node.importClause;
|
|
44
|
+
if (!clause?.namedBindings || !ts.isNamedImports(clause.namedBindings)) return;
|
|
45
|
+
|
|
46
|
+
const matched = clause.namedBindings.elements.map(el => el.name.text).filter(name => typeRefNames.has(name));
|
|
47
|
+
if (matched.length === 0) return;
|
|
48
|
+
|
|
49
|
+
const specifier = (node.moduleSpecifier as ts.StringLiteral).text;
|
|
50
|
+
const prefix = clause.isTypeOnly ? 'type ' : '';
|
|
51
|
+
imports.push(`import ${prefix}{ ${matched.join(', ')} } from '${specifier}';`);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
return { genericParams, imports };
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// // --- Demo ---
|
|
58
|
+
// const result = extractGenericParamsAndImports(
|
|
59
|
+
// import.meta.url.replace('file://', '').replace(/_extractGenericParams\.ts$/, 'controller.tsx'),
|
|
60
|
+
// 'ControllerFormFieldPresetProps',
|
|
61
|
+
// );
|
|
62
|
+
// console.log('Generic params:', result.genericParams);
|
|
63
|
+
// console.log('Imports:');
|
|
64
|
+
// result.imports.forEach(imp => console.log(' ', imp));
|
|
@@ -8,10 +8,13 @@ import path from 'node:path';
|
|
|
8
8
|
|
|
9
9
|
import type { IControllerInfo } from './types.ts';
|
|
10
10
|
|
|
11
|
+
import { extractGenericParamsAndImports } from './_extractGenericParams.ts';
|
|
11
12
|
import { generateFile } from './generateFile.ts';
|
|
12
13
|
import { generateMetaComponent } from './generateMetaComponent.ts';
|
|
13
14
|
import { generateMetaPage } from './generateMetaPage.ts';
|
|
14
15
|
|
|
16
|
+
// const __regProps = /interface Controller[^<]*Props<(.*?)>/;
|
|
17
|
+
|
|
15
18
|
export default async function (options: IMetadataCustomGenerateOptions): Promise<string> {
|
|
16
19
|
const { globFiles } = options;
|
|
17
20
|
const globFilesPage: [IGlobBeanFile, IControllerInfo][] = [];
|
|
@@ -34,7 +37,7 @@ export default async function (options: IMetadataCustomGenerateOptions): Promise
|
|
|
34
37
|
}
|
|
35
38
|
|
|
36
39
|
function _parseControllerInfo(options: IMetadataCustomGenerateOptions, globFile: IGlobBeanFile): IControllerInfo | undefined {
|
|
37
|
-
const { className, fileContent, fileNameJSRelative } = globFile;
|
|
40
|
+
const { className, fileContent, fileNameJSRelative, file } = globFile;
|
|
38
41
|
const matches = fileNameJSRelative.match(/..\/(.+?)\/(.+?)\/controller(.jsx?)$/);
|
|
39
42
|
if (!matches) return;
|
|
40
43
|
const type = matches[1];
|
|
@@ -55,10 +58,11 @@ function _parseControllerInfo(options: IMetadataCustomGenerateOptions, globFile:
|
|
|
55
58
|
const hasModels = fileContent.includes(nameModels);
|
|
56
59
|
const hasModelValue = fileContent.includes("'vModel'");
|
|
57
60
|
// generic
|
|
58
|
-
const matchGeneric =
|
|
59
|
-
const hasGeneric = !!matchGeneric;
|
|
60
|
-
const generic = matchGeneric
|
|
61
|
-
const genericKeys =
|
|
61
|
+
const matchGeneric = hasProps && extractGenericParamsAndImports(file, nameProps); // fileContent.match(__regProps);
|
|
62
|
+
const hasGeneric = !!(matchGeneric && matchGeneric.genericParams);
|
|
63
|
+
const generic = hasGeneric ? matchGeneric.genericParams : undefined;
|
|
64
|
+
const genericKeys = hasGeneric ? matchGeneric.genericParams.split(',').map(item => item.trim().split(' ')[0]) : undefined;
|
|
65
|
+
const generateImports = hasGeneric ? matchGeneric.imports : undefined;
|
|
62
66
|
// schemaParams
|
|
63
67
|
const nameSchemaParams = `${className}SchemaParams`;
|
|
64
68
|
const hasSchemaParams = fileContent.includes(nameSchemaParams);
|
|
@@ -70,7 +74,9 @@ function _parseControllerInfo(options: IMetadataCustomGenerateOptions, globFile:
|
|
|
70
74
|
const hasRenderFirst = fse.existsSync(fileRenderFirst);
|
|
71
75
|
const classNameRenderFirst = `Render${type === 'page' ? 'Page' : ''}${nameCapitalize}`;
|
|
72
76
|
const importRenderFirst = `import { ${classNameRenderFirst} } from '../../${type}/${name}/render.jsx';`;
|
|
73
|
-
const fileRenderOthers = globbySync(`src/${type}/${name}/render.*.tsx`, {
|
|
77
|
+
const fileRenderOthers = globbySync(`src/${type}/${name}/render.*.tsx`, {
|
|
78
|
+
cwd: options.modulePath,
|
|
79
|
+
});
|
|
74
80
|
const nameRenderOthers: string[] = fileRenderOthers.map(item => /render\.(.*)\.tsx/.exec(item)![1]);
|
|
75
81
|
const classNameRenderOthers: string[] = nameRenderOthers.map(item => `Render${type === 'page' ? 'Page' : ''}${toUpperCaseFirstChar(item)}`);
|
|
76
82
|
const importRenderOthers: string[] = nameRenderOthers.map(
|
|
@@ -104,6 +110,7 @@ function _parseControllerInfo(options: IMetadataCustomGenerateOptions, globFile:
|
|
|
104
110
|
hasGeneric,
|
|
105
111
|
generic,
|
|
106
112
|
genericKeys,
|
|
113
|
+
generateImports,
|
|
107
114
|
nameSchemaParams,
|
|
108
115
|
hasSchemaParams,
|
|
109
116
|
nameSchemaQuery,
|
|
@@ -9,9 +9,16 @@ import type { IControllerInfo } from './types.ts';
|
|
|
9
9
|
import { generateFileComponent } from './generateFileComponent.ts';
|
|
10
10
|
import { generateFilePage } from './generateFilePage.ts';
|
|
11
11
|
|
|
12
|
-
export async function generateFile(
|
|
12
|
+
export async function generateFile(
|
|
13
|
+
options: IMetadataCustomGenerateOptions,
|
|
14
|
+
globFile: IGlobBeanFile,
|
|
15
|
+
controllerInfo: IControllerInfo,
|
|
16
|
+
) {
|
|
13
17
|
const cli = options.cli;
|
|
14
|
-
const fileDest = path.join(
|
|
18
|
+
const fileDest = path.join(
|
|
19
|
+
options.modulePath,
|
|
20
|
+
`src/.metadata/${controllerInfo.type}/${controllerInfo.name}.ts`,
|
|
21
|
+
);
|
|
15
22
|
const content =
|
|
16
23
|
controllerInfo.type === 'page'
|
|
17
24
|
? await generateFilePage(options, globFile, controllerInfo)
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import type { IMetadataCustomGenerateOptions } from '@cabloy/cli';
|
|
2
2
|
import type { IGlobBeanFile } from '@cabloy/module-info';
|
|
3
3
|
|
|
4
|
-
import { combineResourceName } from '@cabloy/utils';
|
|
5
|
-
import { toLowerCaseFirstChar, toUpperCaseFirstChar } from '@cabloy/word-utils';
|
|
6
4
|
import fse from 'fs-extra';
|
|
7
5
|
import path from 'node:path';
|
|
8
6
|
|
|
@@ -26,6 +24,7 @@ export async function generateFileComponent(options: IMetadataCustomGenerateOpti
|
|
|
26
24
|
hasModelValue,
|
|
27
25
|
generic,
|
|
28
26
|
genericKeys,
|
|
27
|
+
generateImports,
|
|
29
28
|
importRenderFirst,
|
|
30
29
|
hasRenderFirst,
|
|
31
30
|
classNameRenderFirst,
|
|
@@ -34,6 +33,9 @@ export async function generateFileComponent(options: IMetadataCustomGenerateOpti
|
|
|
34
33
|
classNameStyleFirst,
|
|
35
34
|
} = controllerInfo;
|
|
36
35
|
const contentImports: string[] = [];
|
|
36
|
+
if (generateImports) {
|
|
37
|
+
contentImports.push(...generateImports);
|
|
38
|
+
}
|
|
37
39
|
const genericDeclare = hasGeneric ? `<${generic}>` : '';
|
|
38
40
|
const genericArguments = hasGeneric ? `<${genericKeys?.join(', ')}>` : '';
|
|
39
41
|
const componentOptions = hasComponentOptions ? `Controller${nameCapitalize}.$componentOptions` : '';
|
|
@@ -129,6 +131,31 @@ export async function generateFileComponent(options: IMetadataCustomGenerateOpti
|
|
|
129
131
|
},
|
|
130
132
|
prepareComponentOptions(${componentOptions}),
|
|
131
133
|
);`;
|
|
134
|
+
// rest props
|
|
135
|
+
let contentRestPropsType = '';
|
|
136
|
+
if (hasProps) {
|
|
137
|
+
contentRestPropsType += `${nameProps}`;
|
|
138
|
+
}
|
|
139
|
+
if (hasModels) {
|
|
140
|
+
if (hasProps) {
|
|
141
|
+
contentRestPropsType += ' & ';
|
|
142
|
+
}
|
|
143
|
+
contentRestPropsType += `${nameModels} &
|
|
144
|
+
{
|
|
145
|
+
[KEY in keyof ${nameModels} as TypePropValueFromModel<KEY>]: ${nameModels}[KEY];
|
|
146
|
+
} &
|
|
147
|
+
{
|
|
148
|
+
[KEY in keyof ${nameModels} as TypePropUpdateFromModel<KEY>]: (value: ${nameModels}[KEY]) => void;
|
|
149
|
+
}`;
|
|
150
|
+
}
|
|
151
|
+
let contentRestProps = '';
|
|
152
|
+
if (contentRestPropsType) {
|
|
153
|
+
contentRestProps = `declare module 'zova-module-a-bean' {
|
|
154
|
+
export interface IVonaComponentRecord {
|
|
155
|
+
'${moduleName}:${name}': ${contentRestPropsType};
|
|
156
|
+
}
|
|
157
|
+
}`;
|
|
158
|
+
}
|
|
132
159
|
// content
|
|
133
160
|
const content = `${contentImports.join('\n')}
|
|
134
161
|
${contentTypeControllerPublicProps}
|
|
@@ -137,92 +164,21 @@ ${contentControllerInnerProps}
|
|
|
137
164
|
${contentControllerInterface}
|
|
138
165
|
${combineContentRenderAndStyle(controllerInfo, moduleName, className, genericDeclare, genericArguments)}
|
|
139
166
|
${contentComponent}
|
|
167
|
+
${contentRestProps}
|
|
140
168
|
`;
|
|
141
169
|
// restComponent
|
|
142
|
-
await generateRestComponent(options
|
|
170
|
+
await generateRestComponent(options);
|
|
143
171
|
// ok
|
|
144
172
|
return content;
|
|
145
173
|
}
|
|
146
174
|
|
|
147
|
-
async function generateRestComponent(
|
|
148
|
-
|
|
149
|
-
_globFile: IGlobBeanFile,
|
|
150
|
-
controllerInfo: IControllerInfo,
|
|
151
|
-
genericDeclare: string,
|
|
152
|
-
genericArguments: string,
|
|
153
|
-
_contentImportTypeController: string[],
|
|
154
|
-
) {
|
|
155
|
-
const { cli, moduleName, modulePath } = options;
|
|
156
|
-
// const { className } = globFile;
|
|
157
|
-
const { name, nameCapitalize, hasProps, nameProps, hasModels, nameModels } = controllerInfo;
|
|
158
|
-
// TypeControllerPublicProps
|
|
159
|
-
const typeControllerPublicPropsName = `TypeController${nameCapitalize}PublicProps`;
|
|
160
|
-
let contentTypeControllerPublicProps = `type ${typeControllerPublicPropsName}${genericDeclare} = TypeRenderComponentJsxPropsPublic`;
|
|
161
|
-
if (hasProps) {
|
|
162
|
-
contentTypeControllerPublicProps += `\n & ${nameProps}${genericArguments}`;
|
|
163
|
-
}
|
|
164
|
-
if (hasModels) {
|
|
165
|
-
contentTypeControllerPublicProps += `\n & ${nameModels}${genericArguments} &
|
|
166
|
-
{
|
|
167
|
-
[KEY in keyof ${nameModels}${genericArguments} as TypePropValueFromModel<KEY>]: ${nameModels}${genericArguments}[KEY];
|
|
168
|
-
} &
|
|
169
|
-
{
|
|
170
|
-
[KEY in keyof ${nameModels}${genericArguments} as TypePropUpdateFromModel<KEY>]: (value: ${nameModels}${genericArguments}[KEY]) => void;
|
|
171
|
-
}`;
|
|
172
|
-
}
|
|
173
|
-
contentTypeControllerPublicProps = `${contentTypeControllerPublicProps};`;
|
|
174
|
-
// import
|
|
175
|
-
const contentImports: string[] = [];
|
|
176
|
-
const _contentImportTypeZova: string[] = [];
|
|
177
|
-
if (hasModels) _contentImportTypeZova.push('TypePropUpdateFromModel', 'TypePropValueFromModel');
|
|
178
|
-
if (_contentImportTypeZova.length > 0) {
|
|
179
|
-
contentImports.push(`import type { ${_contentImportTypeZova.join(', ')} } from 'zova';`);
|
|
180
|
-
}
|
|
181
|
-
contentImports.push("import type { TypeRenderComponentJsxPropsPublic } from 'zova-jsx';");
|
|
182
|
-
if (_contentImportTypeController.length > 0) {
|
|
183
|
-
contentImports.push(`import type { ${_contentImportTypeController.join(', ')} } from 'zova-module-${moduleName}';`);
|
|
184
|
-
}
|
|
185
|
-
// component
|
|
186
|
-
let componentNamePrefix;
|
|
187
|
-
let componentName;
|
|
188
|
-
if (name !== 'formField' && name.startsWith('formField')) {
|
|
189
|
-
componentNamePrefix = 'BBF';
|
|
190
|
-
componentName = toLowerCaseFirstChar(name.substring('formField'.length));
|
|
191
|
-
} else if (name.startsWith('restPage')) {
|
|
192
|
-
componentNamePrefix = 'BBP';
|
|
193
|
-
componentName = toLowerCaseFirstChar(name.substring('restPage'.length));
|
|
194
|
-
} else {
|
|
195
|
-
componentNamePrefix = 'BBZ';
|
|
196
|
-
componentName = name;
|
|
197
|
-
}
|
|
198
|
-
const componentNameFull = `${componentNamePrefix}${toUpperCaseFirstChar(combineResourceName(componentName, moduleName, true, true))}`;
|
|
199
|
-
const contentComponent = `export function ${componentNameFull}${genericDeclare}(
|
|
200
|
-
_props: ${typeControllerPublicPropsName}${genericArguments},
|
|
201
|
-
) {
|
|
202
|
-
return '${moduleName}:${name}';
|
|
203
|
-
}`;
|
|
204
|
-
// content
|
|
205
|
-
const content = `${contentImports.join('\n')}
|
|
206
|
-
|
|
207
|
-
${contentTypeControllerPublicProps}
|
|
208
|
-
${contentComponent}
|
|
209
|
-
`;
|
|
210
|
-
// output
|
|
211
|
-
const fileDest = path.join(modulePath, `rest/component/${name}.ts`);
|
|
212
|
-
await fse.outputFile(fileDest, content);
|
|
213
|
-
await cli.helper.formatFile({ fileName: fileDest });
|
|
175
|
+
async function generateRestComponent(options: IMetadataCustomGenerateOptions) {
|
|
176
|
+
const { moduleName, modulePath } = options;
|
|
214
177
|
// components
|
|
215
178
|
const fileComponents = path.join(modulePath, 'rest/components.ts');
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
}
|
|
220
|
-
const exportContent = `export * from './component/${name}.js';`;
|
|
221
|
-
if (!contentComponents.includes(exportContent)) {
|
|
222
|
-
contentComponents = `${contentComponents}${exportContent}\n`;
|
|
223
|
-
await fse.outputFile(fileComponents, contentComponents);
|
|
224
|
-
await cli.helper.formatFile({ fileName: fileComponents });
|
|
225
|
-
}
|
|
179
|
+
if (fse.existsSync(fileComponents)) return;
|
|
180
|
+
const contentComponents = `export * from 'zova-module-${moduleName}';`;
|
|
181
|
+
await fse.outputFile(fileComponents, contentComponents);
|
|
226
182
|
// index
|
|
227
183
|
const exportIndexContent = "export * from './components.js';";
|
|
228
184
|
await generateRestIndex(options, modulePath, exportIndexContent);
|
|
@@ -5,7 +5,11 @@ import type { IControllerInfo } from './types.ts';
|
|
|
5
5
|
|
|
6
6
|
import { combineContentRenderAndStyle } from './utils.ts';
|
|
7
7
|
|
|
8
|
-
export async function generateFilePage(
|
|
8
|
+
export async function generateFilePage(
|
|
9
|
+
options: IMetadataCustomGenerateOptions,
|
|
10
|
+
globFile: IGlobBeanFile,
|
|
11
|
+
controllerInfo: IControllerInfo,
|
|
12
|
+
) {
|
|
9
13
|
const { moduleName } = options;
|
|
10
14
|
const { className } = globFile;
|
|
11
15
|
const {
|
|
@@ -23,7 +27,9 @@ export async function generateFilePage(options: IMetadataCustomGenerateOptions,
|
|
|
23
27
|
const contentImports: string[] = [];
|
|
24
28
|
// controller
|
|
25
29
|
contentImports.push("import { createZovaComponentPage } from 'zova';");
|
|
26
|
-
contentImports.push(
|
|
30
|
+
contentImports.push(
|
|
31
|
+
`import { ControllerPage${nameCapitalize} } from '../../page/${name}/controller${controllerExtJs}';`,
|
|
32
|
+
);
|
|
27
33
|
// render
|
|
28
34
|
if (hasRenderFirst) {
|
|
29
35
|
contentImports.push(importRenderFirst);
|
|
@@ -37,7 +43,9 @@ export async function generateFilePage(options: IMetadataCustomGenerateOptions,
|
|
|
37
43
|
if (hasSchemaParams) _contentImports_parts.push(nameSchemaParams);
|
|
38
44
|
if (hasSchemaQuery) _contentImports_parts.push(nameSchemaQuery);
|
|
39
45
|
if (_contentImports_parts.length > 0) {
|
|
40
|
-
contentImports.push(
|
|
46
|
+
contentImports.push(
|
|
47
|
+
`import { ${_contentImports_parts.join(', ')} } from '../../page/${name}/controller${controllerExtJs}';`,
|
|
48
|
+
);
|
|
41
49
|
}
|
|
42
50
|
//
|
|
43
51
|
const _contentRecords2_parts: string[] = [];
|
|
@@ -10,7 +10,10 @@ import type { IControllerInfo } from './types.ts';
|
|
|
10
10
|
|
|
11
11
|
import { generateRestIndex } from './utils.ts';
|
|
12
12
|
|
|
13
|
-
export async function generateMetaPage(
|
|
13
|
+
export async function generateMetaPage(
|
|
14
|
+
options: IMetadataCustomGenerateOptions,
|
|
15
|
+
globFiles: [IGlobBeanFile, IControllerInfo][],
|
|
16
|
+
) {
|
|
14
17
|
if (globFiles.length === 0) return '';
|
|
15
18
|
const { moduleName } = options;
|
|
16
19
|
const contentImports: string[] = [];
|
|
@@ -31,16 +34,27 @@ export async function generateMetaPage(options: IMetadataCustomGenerateOptions,
|
|
|
31
34
|
if (hasSchemaParams || hasSchemaQuery) {
|
|
32
35
|
contentImports.push(`import { ${namespace} } from './page/${name}.js';`);
|
|
33
36
|
// rest
|
|
34
|
-
const restIndexFileRelative = path.relative(
|
|
35
|
-
|
|
37
|
+
const restIndexFileRelative = path.relative(
|
|
38
|
+
srcDirRest,
|
|
39
|
+
path.join(options.modulePath, `src/.metadata/page/${name}.js`),
|
|
40
|
+
);
|
|
41
|
+
contentImportsRest.push(
|
|
42
|
+
`import { ${namespace} as ${namespaceRest} } from '${restIndexFileRelative}';`,
|
|
43
|
+
);
|
|
36
44
|
}
|
|
37
45
|
// controller.tsx
|
|
38
46
|
const { routePath, routeName } = _extractRoutePathOrName(options, globFile, controllerInfo);
|
|
39
47
|
// no matter that: route.meta?.absolute
|
|
40
|
-
const routePathFull = routePath
|
|
48
|
+
const routePathFull = routePath
|
|
49
|
+
? `/${moduleName.replace('-', '/')}/${routePath}`
|
|
50
|
+
: `/${moduleName.replace('-', '/')}`;
|
|
41
51
|
const routeNameFull = `${moduleName}:${routeName}`;
|
|
42
|
-
contentPathRecords.push(
|
|
43
|
-
|
|
52
|
+
contentPathRecords.push(
|
|
53
|
+
_combineContentPathRecord(routePathFull, hasSchemaParams, hasSchemaQuery, namespace),
|
|
54
|
+
);
|
|
55
|
+
contentPathRecordsRest.push(
|
|
56
|
+
_combineContentPathRecord(routePathFull, hasSchemaParams, hasSchemaQuery, namespaceRest),
|
|
57
|
+
);
|
|
44
58
|
if (!routeName) {
|
|
45
59
|
// contentPathRecords.push(_combineContentPathRecord(routePathFull, hasSchemaParams, hasSchemaQuery, className));
|
|
46
60
|
} else {
|
|
@@ -115,7 +129,11 @@ declare module 'zova-module-${moduleName}' {
|
|
|
115
129
|
return content;
|
|
116
130
|
}
|
|
117
131
|
|
|
118
|
-
async function generateRestMetaPage(
|
|
132
|
+
async function generateRestMetaPage(
|
|
133
|
+
options: IMetadataCustomGenerateOptions,
|
|
134
|
+
_contentImportsRest: string[],
|
|
135
|
+
contentPathRecordsRest: string[],
|
|
136
|
+
) {
|
|
119
137
|
if (contentPathRecordsRest.length === 0) return;
|
|
120
138
|
const { moduleName, modulePath } = options;
|
|
121
139
|
// pages
|
|
@@ -131,7 +149,11 @@ function _combineModuleNameControllerName(moduleName: string, className: string)
|
|
|
131
149
|
return `NS${toUpperCaseFirstChar(combineResourceName(className, moduleName, false, false))}`;
|
|
132
150
|
}
|
|
133
151
|
|
|
134
|
-
function _extractRoutePathOrName(
|
|
152
|
+
function _extractRoutePathOrName(
|
|
153
|
+
options: IMetadataCustomGenerateOptions,
|
|
154
|
+
_globFile: IGlobBeanFile,
|
|
155
|
+
controllerInfo: IControllerInfo,
|
|
156
|
+
) {
|
|
135
157
|
const cli = options.cli;
|
|
136
158
|
const targetFile = path.join(options.modulePath, 'src/routes.ts');
|
|
137
159
|
const content = fse.readFileSync(targetFile).toString('utf8');
|
|
@@ -146,7 +168,8 @@ function _extractRoutePathOrName(options: IMetadataCustomGenerateOptions, _globF
|
|
|
146
168
|
return (item.node as any).properties.some(prop => {
|
|
147
169
|
return (
|
|
148
170
|
prop.key.name === 'component' &&
|
|
149
|
-
(prop.value.name === controllerInfo.nameCapitalize ||
|
|
171
|
+
(prop.value.name === controllerInfo.nameCapitalize ||
|
|
172
|
+
prop.value.name === `ZPage${controllerInfo.nameCapitalize}`)
|
|
150
173
|
);
|
|
151
174
|
});
|
|
152
175
|
});
|
|
@@ -164,7 +187,12 @@ function _extractRoutePathOrName(options: IMetadataCustomGenerateOptions, _globF
|
|
|
164
187
|
return { routePath, routeName };
|
|
165
188
|
}
|
|
166
189
|
|
|
167
|
-
function _combineContentPathRecord(
|
|
190
|
+
function _combineContentPathRecord(
|
|
191
|
+
key: string,
|
|
192
|
+
hasSchemaParams,
|
|
193
|
+
hasSchemaQuery: boolean,
|
|
194
|
+
namespace: string,
|
|
195
|
+
) {
|
|
168
196
|
return `'${key}': TypePagePathSchema<${hasSchemaParams ? `${namespace}.ParamsInput` : 'undefined'},${hasSchemaQuery ? `${namespace}.QueryInput` : 'undefined'}>;`;
|
|
169
197
|
// return `'${key}': {
|
|
170
198
|
// path: ${value},
|
|
@@ -12,13 +12,24 @@ export function combineContentRenderAndStyle(
|
|
|
12
12
|
genericDeclare: string,
|
|
13
13
|
genericArguments: string,
|
|
14
14
|
) {
|
|
15
|
-
const {
|
|
15
|
+
const {
|
|
16
|
+
hasRenderFirst,
|
|
17
|
+
classNameRenderFirst,
|
|
18
|
+
classNameRenderOthers,
|
|
19
|
+
hasStyleFirst,
|
|
20
|
+
classNameStyleFirst,
|
|
21
|
+
classNameStyleOthers,
|
|
22
|
+
} = controllerInfo;
|
|
16
23
|
const contentControllerInterfaceRecords: string[] = [];
|
|
17
24
|
if (hasStyleFirst) {
|
|
18
|
-
contentControllerInterfaceRecords.push(
|
|
25
|
+
contentControllerInterfaceRecords.push(
|
|
26
|
+
`export interface ${classNameStyleFirst}${genericDeclare} extends ${className}${genericArguments} {}`,
|
|
27
|
+
);
|
|
19
28
|
}
|
|
20
29
|
for (const item of classNameStyleOthers) {
|
|
21
|
-
contentControllerInterfaceRecords.push(
|
|
30
|
+
contentControllerInterfaceRecords.push(
|
|
31
|
+
`export interface ${item}${genericDeclare} extends ${className}${genericArguments} {}`,
|
|
32
|
+
);
|
|
22
33
|
}
|
|
23
34
|
if (hasRenderFirst) {
|
|
24
35
|
if (hasStyleFirst) {
|
|
@@ -26,14 +37,20 @@ export function combineContentRenderAndStyle(
|
|
|
26
37
|
`export interface ${classNameRenderFirst}${genericDeclare} extends ${classNameStyleFirst}${genericArguments} {}`,
|
|
27
38
|
);
|
|
28
39
|
} else {
|
|
29
|
-
contentControllerInterfaceRecords.push(
|
|
40
|
+
contentControllerInterfaceRecords.push(
|
|
41
|
+
`export interface ${classNameRenderFirst}${genericDeclare} extends ${className}${genericArguments} {}`,
|
|
42
|
+
);
|
|
30
43
|
}
|
|
31
44
|
}
|
|
32
45
|
for (const item of classNameRenderOthers) {
|
|
33
46
|
if (hasStyleFirst) {
|
|
34
|
-
contentControllerInterfaceRecords.push(
|
|
47
|
+
contentControllerInterfaceRecords.push(
|
|
48
|
+
`export interface ${item}${genericDeclare} extends ${classNameStyleFirst}${genericArguments} {}`,
|
|
49
|
+
);
|
|
35
50
|
} else {
|
|
36
|
-
contentControllerInterfaceRecords.push(
|
|
51
|
+
contentControllerInterfaceRecords.push(
|
|
52
|
+
`export interface ${item}${genericDeclare} extends ${className}${genericArguments} {}`,
|
|
53
|
+
);
|
|
37
54
|
}
|
|
38
55
|
}
|
|
39
56
|
if (contentControllerInterfaceRecords.length === 0) return '';
|
|
@@ -42,7 +59,11 @@ export function combineContentRenderAndStyle(
|
|
|
42
59
|
}`;
|
|
43
60
|
}
|
|
44
61
|
|
|
45
|
-
export async function generateRestIndex(
|
|
62
|
+
export async function generateRestIndex(
|
|
63
|
+
options: IMetadataCustomGenerateOptions,
|
|
64
|
+
modulePath: string,
|
|
65
|
+
append: string,
|
|
66
|
+
) {
|
|
46
67
|
const { cli } = options;
|
|
47
68
|
// index
|
|
48
69
|
const fileIndex = path.join(modulePath, 'rest/index.ts');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sys.onion.d.ts","sourceRoot":"","sources":["../../src/bean/sys.onion.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAgB,MAAM,MAAM,CAAC;AAE9C,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"sys.onion.d.ts","sourceRoot":"","sources":["../../src/bean/sys.onion.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAgB,MAAM,MAAM,CAAC;AAE9C,OAAO,KAAK,EACV,mBAAmB,EACnB,kBAAkB,EAClB,iBAAiB,EAElB,MAAM,mBAAmB,CAAC;AAK3B,qBAEa,QAAS,SAAQ,QAAQ;IACpC,OAAO,CAAC,WAAW,CAA2B;IAE9C,SAAS,CAAC,OAAO,CAAC,IAAI,EAAE,MAAM;IAUvB,wBAAwB,CAC7B,OAAO,EAAE,mBAAmB,GAAG,kBAAkB,CAAC,GAAG,CAAC,EACtD,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,EAC3B,SAAS,CAAC,EAAE,GAAG,EACf,GAAG,SAAS,EAAE,GAAG,EAAE;IAcd,qBAAqB,CAAC,IAAI,CAAC,EAAE,iBAAiB;CAGtD"}
|