zova-module-a-bean 5.1.12 → 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.
@@ -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
 
@@ -133,6 +131,31 @@ export async function generateFileComponent(options: IMetadataCustomGenerateOpti
133
131
  },
134
132
  prepareComponentOptions(${componentOptions}),
135
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
+ }
136
159
  // content
137
160
  const content = `${contentImports.join('\n')}
138
161
  ${contentTypeControllerPublicProps}
@@ -141,96 +164,21 @@ ${contentControllerInnerProps}
141
164
  ${contentControllerInterface}
142
165
  ${combineContentRenderAndStyle(controllerInfo, moduleName, className, genericDeclare, genericArguments)}
143
166
  ${contentComponent}
167
+ ${contentRestProps}
144
168
  `;
145
169
  // restComponent
146
- await generateRestComponent(options, globFile, controllerInfo, genericDeclare, genericArguments, generateImports, _contentImportTypeController);
170
+ await generateRestComponent(options);
147
171
  // ok
148
172
  return content;
149
173
  }
150
174
 
151
- async function generateRestComponent(
152
- options: IMetadataCustomGenerateOptions,
153
- _globFile: IGlobBeanFile,
154
- controllerInfo: IControllerInfo,
155
- genericDeclare: string,
156
- genericArguments: string,
157
- generateImports: string[] | null | undefined,
158
- _contentImportTypeController: string[],
159
- ) {
160
- const { cli, moduleName, modulePath } = options;
161
- // const { className } = globFile;
162
- const { name, nameCapitalize, hasProps, nameProps, hasModels, nameModels } = controllerInfo;
163
- // TypeControllerPublicProps
164
- const typeControllerPublicPropsName = `TypeController${nameCapitalize}PublicProps`;
165
- let contentTypeControllerPublicProps = `type ${typeControllerPublicPropsName}${genericDeclare} = TypeRenderComponentJsxPropsPublic`;
166
- if (hasProps) {
167
- contentTypeControllerPublicProps += `\n & ${nameProps}${genericArguments}`;
168
- }
169
- if (hasModels) {
170
- contentTypeControllerPublicProps += `\n & ${nameModels}${genericArguments} &
171
- {
172
- [KEY in keyof ${nameModels}${genericArguments} as TypePropValueFromModel<KEY>]: ${nameModels}${genericArguments}[KEY];
173
- } &
174
- {
175
- [KEY in keyof ${nameModels}${genericArguments} as TypePropUpdateFromModel<KEY>]: (value: ${nameModels}${genericArguments}[KEY]) => void;
176
- }`;
177
- }
178
- contentTypeControllerPublicProps = `${contentTypeControllerPublicProps};`;
179
- // import
180
- const contentImports: string[] = [];
181
- if (generateImports) {
182
- contentImports.push(...generateImports);
183
- }
184
- const _contentImportTypeZova: string[] = [];
185
- if (hasModels) _contentImportTypeZova.push('TypePropUpdateFromModel', 'TypePropValueFromModel');
186
- if (_contentImportTypeZova.length > 0) {
187
- contentImports.push(`import type { ${_contentImportTypeZova.join(', ')} } from 'zova';`);
188
- }
189
- contentImports.push("import type { TypeRenderComponentJsxPropsPublic } from 'zova-jsx';");
190
- if (_contentImportTypeController.length > 0) {
191
- contentImports.push(`import type { ${_contentImportTypeController.join(', ')} } from 'zova-module-${moduleName}';`);
192
- }
193
- // component
194
- let componentNamePrefix;
195
- let componentName;
196
- if (name !== 'formField' && name.startsWith('formField')) {
197
- componentNamePrefix = 'BBF';
198
- componentName = toLowerCaseFirstChar(name.substring('formField'.length));
199
- } else if (name.startsWith('restPage')) {
200
- componentNamePrefix = 'BBP';
201
- componentName = toLowerCaseFirstChar(name.substring('restPage'.length));
202
- } else {
203
- componentNamePrefix = 'BBZ';
204
- componentName = name;
205
- }
206
- const componentNameFull = `${componentNamePrefix}${toUpperCaseFirstChar(combineResourceName(componentName, moduleName, true, true))}`;
207
- const contentComponent = `export function ${componentNameFull}${genericDeclare}(
208
- _props: ${typeControllerPublicPropsName}${genericArguments},
209
- ) {
210
- return '${moduleName}:${name}';
211
- }`;
212
- // content
213
- const content = `${contentImports.join('\n')}
214
-
215
- ${contentTypeControllerPublicProps}
216
- ${contentComponent}
217
- `;
218
- // output
219
- const fileDest = path.join(modulePath, `rest/component/${name}.ts`);
220
- await fse.outputFile(fileDest, content);
221
- await cli.helper.formatFile({ fileName: fileDest });
175
+ async function generateRestComponent(options: IMetadataCustomGenerateOptions) {
176
+ const { moduleName, modulePath } = options;
222
177
  // components
223
178
  const fileComponents = path.join(modulePath, 'rest/components.ts');
224
- let contentComponents = '';
225
- if (fse.existsSync(fileComponents)) {
226
- contentComponents = (await fse.readFile(fileComponents)).toString();
227
- }
228
- const exportContent = `export * from './component/${name}.js';`;
229
- if (!contentComponents.includes(exportContent)) {
230
- contentComponents = `${contentComponents}${exportContent}\n`;
231
- await fse.outputFile(fileComponents, contentComponents);
232
- await cli.helper.formatFile({ fileName: fileComponents });
233
- }
179
+ if (fse.existsSync(fileComponents)) return;
180
+ const contentComponents = `export * from 'zova-module-${moduleName}';`;
181
+ await fse.outputFile(fileComponents, contentComponents);
234
182
  // index
235
183
  const exportIndexContent = "export * from './components.js';";
236
184
  await generateRestIndex(options, modulePath, exportIndexContent);
@@ -0,0 +1,13 @@
1
+ import { types } from 'typestyle';
2
+ import { TypeRenderComponentJsxPropsPublic } from 'zova-jsx';
3
+ export interface IVonaComponentRecord {
4
+ }
5
+ export type TypeComponentOptions<K extends keyof IVonaComponentRecord> = {
6
+ name: K;
7
+ options?: IVonaComponentRecord[K];
8
+ } & TypeComponentOptionsProps;
9
+ export interface TypeComponentOptionsProps extends TypeRenderComponentJsxPropsPublic {
10
+ class?: any;
11
+ style?: types.NestedCSSProperties;
12
+ }
13
+ //# sourceMappingURL=component.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"component.d.ts","sourceRoot":"","sources":["../../src/types/component.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,iCAAiC,EAAE,MAAM,UAAU,CAAC;AAE7D,MAAM,WAAW,oBAAoB;CAAG;AAExC,MAAM,MAAM,oBAAoB,CAAC,CAAC,SAAS,MAAM,oBAAoB,IAAI;IACvE,IAAI,EAAE,CAAC,CAAC;IACR,OAAO,CAAC,EAAE,oBAAoB,CAAC,CAAC,CAAC,CAAC;CACnC,GAAG,yBAAyB,CAAC;AAE9B,MAAM,WAAW,yBAA0B,SAAQ,iCAAiC;IAClF,KAAK,CAAC,EAAE,GAAG,CAAC;IACZ,KAAK,CAAC,EAAE,KAAK,CAAC,mBAAmB,CAAC;CACnC"}
@@ -3,4 +3,5 @@ export * from './aopMethod.js';
3
3
  export * from './bean.js';
4
4
  export * from './onion.js';
5
5
  export * from './service.js';
6
+ export * from './component.js';
6
7
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC"}
@@ -1,5 +1,3 @@
1
- import { combineResourceName } from '@cabloy/utils';
2
- import { toLowerCaseFirstChar, toUpperCaseFirstChar } from '@cabloy/word-utils';
3
1
  import fse from 'fs-extra';
4
2
  import path from 'node:path';
5
3
  import { combineContentRenderAndStyle, generateRestIndex } from "./utils.js";
@@ -106,6 +104,31 @@ export async function generateFileComponent(options, globFile, controllerInfo) {
106
104
  },
107
105
  prepareComponentOptions(${componentOptions}),
108
106
  );`;
107
+ // rest props
108
+ let contentRestPropsType = '';
109
+ if (hasProps) {
110
+ contentRestPropsType += `${nameProps}`;
111
+ }
112
+ if (hasModels) {
113
+ if (hasProps) {
114
+ contentRestPropsType += ' & ';
115
+ }
116
+ contentRestPropsType += `${nameModels} &
117
+ {
118
+ [KEY in keyof ${nameModels} as TypePropValueFromModel<KEY>]: ${nameModels}[KEY];
119
+ } &
120
+ {
121
+ [KEY in keyof ${nameModels} as TypePropUpdateFromModel<KEY>]: (value: ${nameModels}[KEY]) => void;
122
+ }`;
123
+ }
124
+ let contentRestProps = '';
125
+ if (contentRestPropsType) {
126
+ contentRestProps = `declare module 'zova-module-a-bean' {
127
+ export interface IVonaComponentRecord {
128
+ '${moduleName}:${name}': ${contentRestPropsType};
129
+ }
130
+ }`;
131
+ }
109
132
  // content
110
133
  const content = `${contentImports.join('\n')}
111
134
  ${contentTypeControllerPublicProps}
@@ -114,90 +137,21 @@ ${contentControllerInnerProps}
114
137
  ${contentControllerInterface}
115
138
  ${combineContentRenderAndStyle(controllerInfo, moduleName, className, genericDeclare, genericArguments)}
116
139
  ${contentComponent}
140
+ ${contentRestProps}
117
141
  `;
118
142
  // restComponent
119
- await generateRestComponent(options, globFile, controllerInfo, genericDeclare, genericArguments, generateImports, _contentImportTypeController);
143
+ await generateRestComponent(options);
120
144
  // ok
121
145
  return content;
122
146
  }
123
- async function generateRestComponent(options, _globFile, controllerInfo, genericDeclare, genericArguments, generateImports, _contentImportTypeController) {
124
- const { cli, moduleName, modulePath } = options;
125
- // const { className } = globFile;
126
- const { name, nameCapitalize, hasProps, nameProps, hasModels, nameModels } = controllerInfo;
127
- // TypeControllerPublicProps
128
- const typeControllerPublicPropsName = `TypeController${nameCapitalize}PublicProps`;
129
- let contentTypeControllerPublicProps = `type ${typeControllerPublicPropsName}${genericDeclare} = TypeRenderComponentJsxPropsPublic`;
130
- if (hasProps) {
131
- contentTypeControllerPublicProps += `\n & ${nameProps}${genericArguments}`;
132
- }
133
- if (hasModels) {
134
- contentTypeControllerPublicProps += `\n & ${nameModels}${genericArguments} &
135
- {
136
- [KEY in keyof ${nameModels}${genericArguments} as TypePropValueFromModel<KEY>]: ${nameModels}${genericArguments}[KEY];
137
- } &
138
- {
139
- [KEY in keyof ${nameModels}${genericArguments} as TypePropUpdateFromModel<KEY>]: (value: ${nameModels}${genericArguments}[KEY]) => void;
140
- }`;
141
- }
142
- contentTypeControllerPublicProps = `${contentTypeControllerPublicProps};`;
143
- // import
144
- const contentImports = [];
145
- if (generateImports) {
146
- contentImports.push(...generateImports);
147
- }
148
- const _contentImportTypeZova = [];
149
- if (hasModels)
150
- _contentImportTypeZova.push('TypePropUpdateFromModel', 'TypePropValueFromModel');
151
- if (_contentImportTypeZova.length > 0) {
152
- contentImports.push(`import type { ${_contentImportTypeZova.join(', ')} } from 'zova';`);
153
- }
154
- contentImports.push("import type { TypeRenderComponentJsxPropsPublic } from 'zova-jsx';");
155
- if (_contentImportTypeController.length > 0) {
156
- contentImports.push(`import type { ${_contentImportTypeController.join(', ')} } from 'zova-module-${moduleName}';`);
157
- }
158
- // component
159
- let componentNamePrefix;
160
- let componentName;
161
- if (name !== 'formField' && name.startsWith('formField')) {
162
- componentNamePrefix = 'BBF';
163
- componentName = toLowerCaseFirstChar(name.substring('formField'.length));
164
- }
165
- else if (name.startsWith('restPage')) {
166
- componentNamePrefix = 'BBP';
167
- componentName = toLowerCaseFirstChar(name.substring('restPage'.length));
168
- }
169
- else {
170
- componentNamePrefix = 'BBZ';
171
- componentName = name;
172
- }
173
- const componentNameFull = `${componentNamePrefix}${toUpperCaseFirstChar(combineResourceName(componentName, moduleName, true, true))}`;
174
- const contentComponent = `export function ${componentNameFull}${genericDeclare}(
175
- _props: ${typeControllerPublicPropsName}${genericArguments},
176
- ) {
177
- return '${moduleName}:${name}';
178
- }`;
179
- // content
180
- const content = `${contentImports.join('\n')}
181
-
182
- ${contentTypeControllerPublicProps}
183
- ${contentComponent}
184
- `;
185
- // output
186
- const fileDest = path.join(modulePath, `rest/component/${name}.ts`);
187
- await fse.outputFile(fileDest, content);
188
- await cli.helper.formatFile({ fileName: fileDest });
147
+ async function generateRestComponent(options) {
148
+ const { moduleName, modulePath } = options;
189
149
  // components
190
150
  const fileComponents = path.join(modulePath, 'rest/components.ts');
191
- let contentComponents = '';
192
- if (fse.existsSync(fileComponents)) {
193
- contentComponents = (await fse.readFile(fileComponents)).toString();
194
- }
195
- const exportContent = `export * from './component/${name}.js';`;
196
- if (!contentComponents.includes(exportContent)) {
197
- contentComponents = `${contentComponents}${exportContent}\n`;
198
- await fse.outputFile(fileComponents, contentComponents);
199
- await cli.helper.formatFile({ fileName: fileComponents });
200
- }
151
+ if (fse.existsSync(fileComponents))
152
+ return;
153
+ const contentComponents = `export * from 'zova-module-${moduleName}';`;
154
+ await fse.outputFile(fileComponents, contentComponents);
201
155
  // index
202
156
  const exportIndexContent = "export * from './components.js';";
203
157
  await generateRestIndex(options, modulePath, exportIndexContent);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "zova-module-a-bean",
3
- "version": "5.1.12",
4
- "gitHead": "a247f88a55c663d313296039f874560ee5a13e01",
3
+ "version": "5.1.13",
4
+ "gitHead": "6162f8e212146d3e5f98145fcf43adc52912694e",
5
5
  "description": "",
6
6
  "keywords": [
7
7
  "Zova Module"
@@ -0,0 +1,14 @@
1
+ import { types } from 'typestyle';
2
+ import { TypeRenderComponentJsxPropsPublic } from 'zova-jsx';
3
+
4
+ export interface IVonaComponentRecord {}
5
+
6
+ export type TypeComponentOptions<K extends keyof IVonaComponentRecord> = {
7
+ name: K;
8
+ options?: IVonaComponentRecord[K];
9
+ } & TypeComponentOptionsProps;
10
+
11
+ export interface TypeComponentOptionsProps extends TypeRenderComponentJsxPropsPublic {
12
+ class?: any;
13
+ style?: types.NestedCSSProperties;
14
+ }
@@ -3,3 +3,4 @@ export * from './aopMethod.js';
3
3
  export * from './bean.js';
4
4
  export * from './onion.js';
5
5
  export * from './service.js';
6
+ export * from './component.js';