zova-module-a-bean 5.1.16 → 5.1.17
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/generateFileComponent.ts +1 -18
- package/cli/controller/metadata/generateMetaPage.ts +9 -53
- package/cli/controller/metadata/utils.ts +6 -47
- package/dist-cli/controller/metadata/generateFileComponent.js +1 -17
- package/dist-cli/controller/metadata/generateMetaPage.js +2 -20
- package/dist-cli/controller/metadata/utils.js +1 -17
- package/package.json +2 -3
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
import type { IMetadataCustomGenerateOptions } from '@cabloy/cli';
|
|
2
2
|
import type { IGlobBeanFile } from '@cabloy/module-info';
|
|
3
3
|
|
|
4
|
-
import fse from 'fs-extra';
|
|
5
|
-
import path from 'node:path';
|
|
6
|
-
|
|
7
4
|
import type { IControllerInfo } from './types.ts';
|
|
8
5
|
|
|
9
|
-
import { combineContentRenderAndStyle
|
|
6
|
+
import { combineContentRenderAndStyle } from './utils.ts';
|
|
10
7
|
|
|
11
8
|
export async function generateFileComponent(options: IMetadataCustomGenerateOptions, globFile: IGlobBeanFile, controllerInfo: IControllerInfo) {
|
|
12
9
|
const { moduleName } = options;
|
|
@@ -166,20 +163,6 @@ ${combineContentRenderAndStyle(controllerInfo, moduleName, className, genericDec
|
|
|
166
163
|
${contentComponent}
|
|
167
164
|
${contentRestProps}
|
|
168
165
|
`;
|
|
169
|
-
// restComponent
|
|
170
|
-
await generateRestComponent(options);
|
|
171
166
|
// ok
|
|
172
167
|
return content;
|
|
173
168
|
}
|
|
174
|
-
|
|
175
|
-
async function generateRestComponent(options: IMetadataCustomGenerateOptions) {
|
|
176
|
-
const { moduleName, modulePath } = options;
|
|
177
|
-
// components
|
|
178
|
-
const fileComponents = path.join(modulePath, 'rest/components.ts');
|
|
179
|
-
if (fse.existsSync(fileComponents)) return;
|
|
180
|
-
const contentComponents = `export * from 'zova-module-${moduleName}';`;
|
|
181
|
-
await fse.outputFile(fileComponents, contentComponents);
|
|
182
|
-
// index
|
|
183
|
-
const exportIndexContent = "export * from './components.js';";
|
|
184
|
-
await generateRestIndex(options, modulePath, exportIndexContent);
|
|
185
|
-
}
|
|
@@ -8,12 +8,7 @@ import path from 'node:path';
|
|
|
8
8
|
|
|
9
9
|
import type { IControllerInfo } from './types.ts';
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
export async function generateMetaPage(
|
|
14
|
-
options: IMetadataCustomGenerateOptions,
|
|
15
|
-
globFiles: [IGlobBeanFile, IControllerInfo][],
|
|
16
|
-
) {
|
|
11
|
+
export async function generateMetaPage(options: IMetadataCustomGenerateOptions, globFiles: [IGlobBeanFile, IControllerInfo][]) {
|
|
17
12
|
if (globFiles.length === 0) return '';
|
|
18
13
|
const { moduleName } = options;
|
|
19
14
|
const contentImports: string[] = [];
|
|
@@ -34,27 +29,16 @@ export async function generateMetaPage(
|
|
|
34
29
|
if (hasSchemaParams || hasSchemaQuery) {
|
|
35
30
|
contentImports.push(`import { ${namespace} } from './page/${name}.js';`);
|
|
36
31
|
// rest
|
|
37
|
-
const restIndexFileRelative = path.relative(
|
|
38
|
-
|
|
39
|
-
path.join(options.modulePath, `src/.metadata/page/${name}.js`),
|
|
40
|
-
);
|
|
41
|
-
contentImportsRest.push(
|
|
42
|
-
`import { ${namespace} as ${namespaceRest} } from '${restIndexFileRelative}';`,
|
|
43
|
-
);
|
|
32
|
+
const restIndexFileRelative = path.relative(srcDirRest, path.join(options.modulePath, `src/.metadata/page/${name}.js`));
|
|
33
|
+
contentImportsRest.push(`import { ${namespace} as ${namespaceRest} } from '${restIndexFileRelative}';`);
|
|
44
34
|
}
|
|
45
35
|
// controller.tsx
|
|
46
36
|
const { routePath, routeName } = _extractRoutePathOrName(options, globFile, controllerInfo);
|
|
47
37
|
// no matter that: route.meta?.absolute
|
|
48
|
-
const routePathFull = routePath
|
|
49
|
-
? `/${moduleName.replace('-', '/')}/${routePath}`
|
|
50
|
-
: `/${moduleName.replace('-', '/')}`;
|
|
38
|
+
const routePathFull = routePath ? `/${moduleName.replace('-', '/')}/${routePath}` : `/${moduleName.replace('-', '/')}`;
|
|
51
39
|
const routeNameFull = `${moduleName}:${routeName}`;
|
|
52
|
-
contentPathRecords.push(
|
|
53
|
-
|
|
54
|
-
);
|
|
55
|
-
contentPathRecordsRest.push(
|
|
56
|
-
_combineContentPathRecord(routePathFull, hasSchemaParams, hasSchemaQuery, namespaceRest),
|
|
57
|
-
);
|
|
40
|
+
contentPathRecords.push(_combineContentPathRecord(routePathFull, hasSchemaParams, hasSchemaQuery, namespace));
|
|
41
|
+
contentPathRecordsRest.push(_combineContentPathRecord(routePathFull, hasSchemaParams, hasSchemaQuery, namespaceRest));
|
|
58
42
|
if (!routeName) {
|
|
59
43
|
// contentPathRecords.push(_combineContentPathRecord(routePathFull, hasSchemaParams, hasSchemaQuery, className));
|
|
60
44
|
} else {
|
|
@@ -124,36 +108,14 @@ declare module 'zova-module-${moduleName}' {
|
|
|
124
108
|
}
|
|
125
109
|
/** pages: end */
|
|
126
110
|
`;
|
|
127
|
-
// restComponent
|
|
128
|
-
await generateRestMetaPage(options, contentImportsRest, contentPathRecordsRest);
|
|
129
111
|
return content;
|
|
130
112
|
}
|
|
131
113
|
|
|
132
|
-
async function generateRestMetaPage(
|
|
133
|
-
options: IMetadataCustomGenerateOptions,
|
|
134
|
-
_contentImportsRest: string[],
|
|
135
|
-
contentPathRecordsRest: string[],
|
|
136
|
-
) {
|
|
137
|
-
if (contentPathRecordsRest.length === 0) return;
|
|
138
|
-
const { moduleName, modulePath } = options;
|
|
139
|
-
// pages
|
|
140
|
-
const contentPages = `export * from 'zova-module-${moduleName}';\n`;
|
|
141
|
-
const filePages = path.join(modulePath, 'rest/pages.ts');
|
|
142
|
-
await fse.outputFile(filePages, contentPages);
|
|
143
|
-
// index
|
|
144
|
-
const exportIndexContent = "export * from './pages.js';";
|
|
145
|
-
await generateRestIndex(options, modulePath, exportIndexContent);
|
|
146
|
-
}
|
|
147
|
-
|
|
148
114
|
function _combineModuleNameControllerName(moduleName: string, className: string) {
|
|
149
115
|
return `NS${toUpperCaseFirstChar(combineResourceName(className, moduleName, false, false))}`;
|
|
150
116
|
}
|
|
151
117
|
|
|
152
|
-
function _extractRoutePathOrName(
|
|
153
|
-
options: IMetadataCustomGenerateOptions,
|
|
154
|
-
_globFile: IGlobBeanFile,
|
|
155
|
-
controllerInfo: IControllerInfo,
|
|
156
|
-
) {
|
|
118
|
+
function _extractRoutePathOrName(options: IMetadataCustomGenerateOptions, _globFile: IGlobBeanFile, controllerInfo: IControllerInfo) {
|
|
157
119
|
const cli = options.cli;
|
|
158
120
|
const targetFile = path.join(options.modulePath, 'src/routes.ts');
|
|
159
121
|
const content = fse.readFileSync(targetFile).toString('utf8');
|
|
@@ -168,8 +130,7 @@ function _extractRoutePathOrName(
|
|
|
168
130
|
return (item.node as any).properties.some(prop => {
|
|
169
131
|
return (
|
|
170
132
|
prop.key.name === 'component' &&
|
|
171
|
-
(prop.value.name === controllerInfo.nameCapitalize ||
|
|
172
|
-
prop.value.name === `ZPage${controllerInfo.nameCapitalize}`)
|
|
133
|
+
(prop.value.name === controllerInfo.nameCapitalize || prop.value.name === `ZPage${controllerInfo.nameCapitalize}`)
|
|
173
134
|
);
|
|
174
135
|
});
|
|
175
136
|
});
|
|
@@ -187,12 +148,7 @@ function _extractRoutePathOrName(
|
|
|
187
148
|
return { routePath, routeName };
|
|
188
149
|
}
|
|
189
150
|
|
|
190
|
-
function _combineContentPathRecord(
|
|
191
|
-
key: string,
|
|
192
|
-
hasSchemaParams,
|
|
193
|
-
hasSchemaQuery: boolean,
|
|
194
|
-
namespace: string,
|
|
195
|
-
) {
|
|
151
|
+
function _combineContentPathRecord(key: string, hasSchemaParams, hasSchemaQuery: boolean, namespace: string) {
|
|
196
152
|
return `'${key}': TypePagePathSchema<${hasSchemaParams ? `${namespace}.ParamsInput` : 'undefined'},${hasSchemaQuery ? `${namespace}.QueryInput` : 'undefined'}>;`;
|
|
197
153
|
// return `'${key}': {
|
|
198
154
|
// path: ${value},
|
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
import type { IMetadataCustomGenerateOptions } from '@cabloy/cli';
|
|
2
|
-
|
|
3
|
-
import fse from 'fs-extra';
|
|
4
|
-
import path from 'node:path';
|
|
5
|
-
|
|
6
1
|
import type { IControllerInfo } from './types.ts';
|
|
7
2
|
|
|
8
3
|
export function combineContentRenderAndStyle(
|
|
@@ -12,24 +7,13 @@ export function combineContentRenderAndStyle(
|
|
|
12
7
|
genericDeclare: string,
|
|
13
8
|
genericArguments: string,
|
|
14
9
|
) {
|
|
15
|
-
const {
|
|
16
|
-
hasRenderFirst,
|
|
17
|
-
classNameRenderFirst,
|
|
18
|
-
classNameRenderOthers,
|
|
19
|
-
hasStyleFirst,
|
|
20
|
-
classNameStyleFirst,
|
|
21
|
-
classNameStyleOthers,
|
|
22
|
-
} = controllerInfo;
|
|
10
|
+
const { hasRenderFirst, classNameRenderFirst, classNameRenderOthers, hasStyleFirst, classNameStyleFirst, classNameStyleOthers } = controllerInfo;
|
|
23
11
|
const contentControllerInterfaceRecords: string[] = [];
|
|
24
12
|
if (hasStyleFirst) {
|
|
25
|
-
contentControllerInterfaceRecords.push(
|
|
26
|
-
`export interface ${classNameStyleFirst}${genericDeclare} extends ${className}${genericArguments} {}`,
|
|
27
|
-
);
|
|
13
|
+
contentControllerInterfaceRecords.push(`export interface ${classNameStyleFirst}${genericDeclare} extends ${className}${genericArguments} {}`);
|
|
28
14
|
}
|
|
29
15
|
for (const item of classNameStyleOthers) {
|
|
30
|
-
contentControllerInterfaceRecords.push(
|
|
31
|
-
`export interface ${item}${genericDeclare} extends ${className}${genericArguments} {}`,
|
|
32
|
-
);
|
|
16
|
+
contentControllerInterfaceRecords.push(`export interface ${item}${genericDeclare} extends ${className}${genericArguments} {}`);
|
|
33
17
|
}
|
|
34
18
|
if (hasRenderFirst) {
|
|
35
19
|
if (hasStyleFirst) {
|
|
@@ -37,20 +21,14 @@ export function combineContentRenderAndStyle(
|
|
|
37
21
|
`export interface ${classNameRenderFirst}${genericDeclare} extends ${classNameStyleFirst}${genericArguments} {}`,
|
|
38
22
|
);
|
|
39
23
|
} else {
|
|
40
|
-
contentControllerInterfaceRecords.push(
|
|
41
|
-
`export interface ${classNameRenderFirst}${genericDeclare} extends ${className}${genericArguments} {}`,
|
|
42
|
-
);
|
|
24
|
+
contentControllerInterfaceRecords.push(`export interface ${classNameRenderFirst}${genericDeclare} extends ${className}${genericArguments} {}`);
|
|
43
25
|
}
|
|
44
26
|
}
|
|
45
27
|
for (const item of classNameRenderOthers) {
|
|
46
28
|
if (hasStyleFirst) {
|
|
47
|
-
contentControllerInterfaceRecords.push(
|
|
48
|
-
`export interface ${item}${genericDeclare} extends ${classNameStyleFirst}${genericArguments} {}`,
|
|
49
|
-
);
|
|
29
|
+
contentControllerInterfaceRecords.push(`export interface ${item}${genericDeclare} extends ${classNameStyleFirst}${genericArguments} {}`);
|
|
50
30
|
} else {
|
|
51
|
-
contentControllerInterfaceRecords.push(
|
|
52
|
-
`export interface ${item}${genericDeclare} extends ${className}${genericArguments} {}`,
|
|
53
|
-
);
|
|
31
|
+
contentControllerInterfaceRecords.push(`export interface ${item}${genericDeclare} extends ${className}${genericArguments} {}`);
|
|
54
32
|
}
|
|
55
33
|
}
|
|
56
34
|
if (contentControllerInterfaceRecords.length === 0) return '';
|
|
@@ -58,22 +36,3 @@ export function combineContentRenderAndStyle(
|
|
|
58
36
|
${contentControllerInterfaceRecords.join('\n')}
|
|
59
37
|
}`;
|
|
60
38
|
}
|
|
61
|
-
|
|
62
|
-
export async function generateRestIndex(
|
|
63
|
-
options: IMetadataCustomGenerateOptions,
|
|
64
|
-
modulePath: string,
|
|
65
|
-
append: string,
|
|
66
|
-
) {
|
|
67
|
-
const { cli } = options;
|
|
68
|
-
// index
|
|
69
|
-
const fileIndex = path.join(modulePath, 'rest/index.ts');
|
|
70
|
-
let contentIndex = '';
|
|
71
|
-
if (fse.existsSync(fileIndex)) {
|
|
72
|
-
contentIndex = (await fse.readFile(fileIndex)).toString();
|
|
73
|
-
}
|
|
74
|
-
if (!contentIndex.includes(append)) {
|
|
75
|
-
contentIndex = `${contentIndex}${append}\n`;
|
|
76
|
-
await fse.outputFile(fileIndex, contentIndex);
|
|
77
|
-
await cli.helper.formatFile({ fileName: fileIndex });
|
|
78
|
-
}
|
|
79
|
-
}
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import path from 'node:path';
|
|
3
|
-
import { combineContentRenderAndStyle, generateRestIndex } from "./utils.js";
|
|
1
|
+
import { combineContentRenderAndStyle } from "./utils.js";
|
|
4
2
|
export async function generateFileComponent(options, globFile, controllerInfo) {
|
|
5
3
|
const { moduleName } = options;
|
|
6
4
|
const { className } = globFile;
|
|
@@ -139,20 +137,6 @@ ${combineContentRenderAndStyle(controllerInfo, moduleName, className, genericDec
|
|
|
139
137
|
${contentComponent}
|
|
140
138
|
${contentRestProps}
|
|
141
139
|
`;
|
|
142
|
-
// restComponent
|
|
143
|
-
await generateRestComponent(options);
|
|
144
140
|
// ok
|
|
145
141
|
return content;
|
|
146
142
|
}
|
|
147
|
-
async function generateRestComponent(options) {
|
|
148
|
-
const { moduleName, modulePath } = options;
|
|
149
|
-
// components
|
|
150
|
-
const fileComponents = path.join(modulePath, 'rest/components.ts');
|
|
151
|
-
if (fse.existsSync(fileComponents))
|
|
152
|
-
return;
|
|
153
|
-
const contentComponents = `export * from 'zova-module-${moduleName}';`;
|
|
154
|
-
await fse.outputFile(fileComponents, contentComponents);
|
|
155
|
-
// index
|
|
156
|
-
const exportIndexContent = "export * from './components.js';";
|
|
157
|
-
await generateRestIndex(options, modulePath, exportIndexContent);
|
|
158
|
-
}
|
|
@@ -2,7 +2,6 @@ import { combineResourceName } from '@cabloy/utils';
|
|
|
2
2
|
import { toUpperCaseFirstChar } from '@cabloy/word-utils';
|
|
3
3
|
import fse from 'fs-extra';
|
|
4
4
|
import path from 'node:path';
|
|
5
|
-
import { generateRestIndex } from "./utils.js";
|
|
6
5
|
export async function generateMetaPage(options, globFiles) {
|
|
7
6
|
if (globFiles.length === 0)
|
|
8
7
|
return '';
|
|
@@ -31,9 +30,7 @@ export async function generateMetaPage(options, globFiles) {
|
|
|
31
30
|
// controller.tsx
|
|
32
31
|
const { routePath, routeName } = _extractRoutePathOrName(options, globFile, controllerInfo);
|
|
33
32
|
// no matter that: route.meta?.absolute
|
|
34
|
-
const routePathFull = routePath
|
|
35
|
-
? `/${moduleName.replace('-', '/')}/${routePath}`
|
|
36
|
-
: `/${moduleName.replace('-', '/')}`;
|
|
33
|
+
const routePathFull = routePath ? `/${moduleName.replace('-', '/')}/${routePath}` : `/${moduleName.replace('-', '/')}`;
|
|
37
34
|
const routeNameFull = `${moduleName}:${routeName}`;
|
|
38
35
|
contentPathRecords.push(_combineContentPathRecord(routePathFull, hasSchemaParams, hasSchemaQuery, namespace));
|
|
39
36
|
contentPathRecordsRest.push(_combineContentPathRecord(routePathFull, hasSchemaParams, hasSchemaQuery, namespaceRest));
|
|
@@ -110,22 +107,8 @@ declare module 'zova-module-${moduleName}' {
|
|
|
110
107
|
}
|
|
111
108
|
/** pages: end */
|
|
112
109
|
`;
|
|
113
|
-
// restComponent
|
|
114
|
-
await generateRestMetaPage(options, contentImportsRest, contentPathRecordsRest);
|
|
115
110
|
return content;
|
|
116
111
|
}
|
|
117
|
-
async function generateRestMetaPage(options, _contentImportsRest, contentPathRecordsRest) {
|
|
118
|
-
if (contentPathRecordsRest.length === 0)
|
|
119
|
-
return;
|
|
120
|
-
const { moduleName, modulePath } = options;
|
|
121
|
-
// pages
|
|
122
|
-
const contentPages = `export * from 'zova-module-${moduleName}';\n`;
|
|
123
|
-
const filePages = path.join(modulePath, 'rest/pages.ts');
|
|
124
|
-
await fse.outputFile(filePages, contentPages);
|
|
125
|
-
// index
|
|
126
|
-
const exportIndexContent = "export * from './pages.js';";
|
|
127
|
-
await generateRestIndex(options, modulePath, exportIndexContent);
|
|
128
|
-
}
|
|
129
112
|
function _combineModuleNameControllerName(moduleName, className) {
|
|
130
113
|
return `NS${toUpperCaseFirstChar(combineResourceName(className, moduleName, false, false))}`;
|
|
131
114
|
}
|
|
@@ -143,8 +126,7 @@ function _extractRoutePathOrName(options, _globFile, controllerInfo) {
|
|
|
143
126
|
const astMatch = astMatches.find(item => {
|
|
144
127
|
return item.node.properties.some(prop => {
|
|
145
128
|
return (prop.key.name === 'component' &&
|
|
146
|
-
(prop.value.name === controllerInfo.nameCapitalize ||
|
|
147
|
-
prop.value.name === `ZPage${controllerInfo.nameCapitalize}`));
|
|
129
|
+
(prop.value.name === controllerInfo.nameCapitalize || prop.value.name === `ZPage${controllerInfo.nameCapitalize}`));
|
|
148
130
|
});
|
|
149
131
|
});
|
|
150
132
|
if (!astMatch) {
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import fse from 'fs-extra';
|
|
2
|
-
import path from 'node:path';
|
|
3
1
|
export function combineContentRenderAndStyle(controllerInfo, moduleName, className, genericDeclare, genericArguments) {
|
|
4
|
-
const { hasRenderFirst, classNameRenderFirst, classNameRenderOthers, hasStyleFirst, classNameStyleFirst, classNameStyleOthers
|
|
2
|
+
const { hasRenderFirst, classNameRenderFirst, classNameRenderOthers, hasStyleFirst, classNameStyleFirst, classNameStyleOthers } = controllerInfo;
|
|
5
3
|
const contentControllerInterfaceRecords = [];
|
|
6
4
|
if (hasStyleFirst) {
|
|
7
5
|
contentControllerInterfaceRecords.push(`export interface ${classNameStyleFirst}${genericDeclare} extends ${className}${genericArguments} {}`);
|
|
@@ -31,17 +29,3 @@ export function combineContentRenderAndStyle(controllerInfo, moduleName, classNa
|
|
|
31
29
|
${contentControllerInterfaceRecords.join('\n')}
|
|
32
30
|
}`;
|
|
33
31
|
}
|
|
34
|
-
export async function generateRestIndex(options, modulePath, append) {
|
|
35
|
-
const { cli } = options;
|
|
36
|
-
// index
|
|
37
|
-
const fileIndex = path.join(modulePath, 'rest/index.ts');
|
|
38
|
-
let contentIndex = '';
|
|
39
|
-
if (fse.existsSync(fileIndex)) {
|
|
40
|
-
contentIndex = (await fse.readFile(fileIndex)).toString();
|
|
41
|
-
}
|
|
42
|
-
if (!contentIndex.includes(append)) {
|
|
43
|
-
contentIndex = `${contentIndex}${append}\n`;
|
|
44
|
-
await fse.outputFile(fileIndex, contentIndex);
|
|
45
|
-
await cli.helper.formatFile({ fileName: fileIndex });
|
|
46
|
-
}
|
|
47
|
-
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zova-module-a-bean",
|
|
3
|
-
"version": "5.1.
|
|
4
|
-
"gitHead": "
|
|
3
|
+
"version": "5.1.17",
|
|
4
|
+
"gitHead": "343c61ad189fe3f0fc997ee9f4c710567657e05c",
|
|
5
5
|
"description": "",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"Zova Module"
|
|
@@ -14,7 +14,6 @@
|
|
|
14
14
|
"src",
|
|
15
15
|
"icons",
|
|
16
16
|
"assets",
|
|
17
|
-
"rest",
|
|
18
17
|
"dist-cli"
|
|
19
18
|
],
|
|
20
19
|
"type": "module",
|