mushroom-cli 1.2.4 → 1.2.6

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/README.md CHANGED
@@ -132,6 +132,12 @@ npx mushroom-cli parameters --no-check-update
132
132
 
133
133
  ## Version
134
134
 
135
+ ### 1.2.5
136
+
137
+ Improvement
138
+
139
+ - gen ts-driver, js-driver: add anchors in generated code to make easier to modify code by update-ts
140
+
135
141
  ### 1.2.4
136
142
 
137
143
  Improvement
package/dist/common.js CHANGED
@@ -282,3 +282,13 @@ export function logWarning(message, ...parameters) {
282
282
  export function logError(message, ...parameters) {
283
283
  console.error(message, ...parameters);
284
284
  }
285
+ export function toVietnameseNonTongue(str) {
286
+ const signText = 'ăâđêôơưàảãạáằẳẵặắầẩẫậấèẻẽẹéềểễệếìỉĩịíòỏõọóồổỗộốờởỡợớùủũụúừửữựứỳỷỹỵýĂÂĐÐÊÔƠƯÀẢÃẠÁẰẲẴẶẮẦẨẪẬẤÈẺẼẸÉỀỂỄỆẾÌỈĨỊÍÒỎÕỌÓỒỔỖỘỐỜỞỠỢỚÙỦŨỤÚỪỬỮỰỨỲỶỸỴÝ';
287
+ const unsignedText = 'aadeoouaaaaaaaaaaaaaaaeeeeeeeeeeiiiiiooooooooooooooouuuuuuuuuuyyyyyAADDEOOUAAAAAAAAAAAAAAAEEEEEEEEEEIIIIIOOOOOOOOOOOOOOOUUUUUUUUUUYYYYY';
288
+ let returnValue = '';
289
+ for (let i = 0; i < str.length; i++) {
290
+ const index = signText.indexOf(str.charAt(i));
291
+ returnValue += index !== -1 ? unsignedText.charAt(index) : str.charAt(i);
292
+ }
293
+ return returnValue;
294
+ }
@@ -287,7 +287,7 @@ export default async function genDocs(args, projectName, project, alias, source)
287
287
  info: {
288
288
  name: source.name,
289
289
  rootUrl: source.codeHint?.rootUrl ?? source.rootUrl,
290
- description: source.description,
290
+ description: source.description ?? '',
291
291
  security: source.security === undefined
292
292
  ? undefined
293
293
  : {
@@ -23,20 +23,10 @@ function singleLine(str) {
23
23
  return '';
24
24
  return str.replace(/\r/g, '').replace(/\n/g, '<br/>');
25
25
  }
26
- function toVietnameseNonTongue(str) {
27
- const signText = 'ăâđêôơưàảãạáằẳẵặắầẩẫậấèẻẽẹéềểễệếìỉĩịíòỏõọóồổỗộốờởỡợớùủũụúừửữựứỳỷỹỵýĂÂĐÐÊÔƠƯÀẢÃẠÁẰẲẴẶẮẦẨẪẬẤÈẺẼẸÉỀỂỄỆẾÌỈĨỊÍÒỎÕỌÓỒỔỖỘỐỜỞỠỢỚÙỦŨỤÚỪỬỮỰỨỲỶỸỴÝ';
28
- const unsignedText = 'aadeoouaaaaaaaaaaaaaaaeeeeeeeeeeiiiiiooooooooooooooouuuuuuuuuuyyyyyAADDEOOUAAAAAAAAAAAAAAAEEEEEEEEEEIIIIIOOOOOOOOOOOOOOOUUUUUUUUUUYYYYY';
29
- let returnValue = '';
30
- for (let i = 0; i < str.length; i++) {
31
- const index = signText.indexOf(str.charAt(i));
32
- returnValue += index !== -1 ? unsignedText.charAt(index) : str.charAt(i);
33
- }
34
- return returnValue;
35
- }
36
26
  function toCSharpName(str) {
37
27
  if (!str)
38
28
  return '_';
39
- const name = toVietnameseNonTongue(str).replace(/\W/g, '_');
29
+ const name = common.toVietnameseNonTongue(str).replace(/\W/g, '_');
40
30
  const c = name.charAt(0);
41
31
  return ('0' <= c && c <= '9' ? '_' : '') + c.toUpperCase() + name.substring(1);
42
32
  }
@@ -23,9 +23,9 @@ export function genJavascriptDriverString(aliasProject, source) {
23
23
  return '';
24
24
  }
25
25
  const entities = common.getEntities(source, aliasProject.allowRoles);
26
- const extensionsImportLines = [];
26
+ const extensionsImportLines = ['/* import all mushroom extensions */'];
27
27
  const extensionsExportLines = [];
28
- const extensionsCodeLines = [];
28
+ const extensionsCodeLines = ['/* using all mushroom extensions */'];
29
29
  if (Array.isArray(aliasProject.features)) {
30
30
  if (aliasProject.features.includes('auth')) {
31
31
  extensionsImportLines.push('//import * as AuthExtension from "mushroomjs-auth";');
@@ -52,6 +52,7 @@ for (var m in mushroom_1) exports[m] = mushroom_1[m];
52
52
  ${extensionsImportLines.join('\n')}
53
53
  //export const extensions = {
54
54
  var extensions = {
55
+ /* export all mushroom extensions */
55
56
  ${extensionsExportLines.join(',\n ')}
56
57
  };
57
58
  exports.extensions = extensions;
@@ -94,7 +95,7 @@ exports.extensions = extensions;
94
95
  for (const viewName in entity.views) {
95
96
  views[viewName] = {};
96
97
  }
97
- code += `defineAsyncResource({name:${JSON.stringify(entityName)},actions:${JSON.stringify(actions)},views:${JSON.stringify(views)}});
98
+ code += `defineAsyncResource({name:${JSON.stringify(entityName)},actions:${JSON.stringify(actions)},views:${JSON.stringify(views)}}, mushroom);
98
99
  `;
99
100
  }
100
101
  code += `
@@ -17,24 +17,14 @@ function isAllowCache(actions, defaultValue) {
17
17
  }
18
18
  return result;
19
19
  }
20
- function toVietnameseNonTongue(str) {
21
- const signText = 'ăâđêôơưàảãạáằẳẵặắầẩẫậấèẻẽẹéềểễệếìỉĩịíòỏõọóồổỗộốờởỡợớùủũụúừửữựứỳỷỹỵýĂÂĐÐÊÔƠƯÀẢÃẠÁẰẲẴẶẮẦẨẪẬẤÈẺẼẸÉỀỂỄỆẾÌỈĨỊÍÒỎÕỌÓỒỔỖỘỐỜỞỠỢỚÙỦŨỤÚỪỬỮỰỨỲỶỸỴÝ';
22
- const unsignedText = 'aadeoouaaaaaaaaaaaaaaaeeeeeeeeeeiiiiiooooooooooooooouuuuuuuuuuyyyyyAADDEOOUAAAAAAAAAAAAAAAEEEEEEEEEEIIIIIOOOOOOOOOOOOOOOUUUUUUUUUUYYYYY';
23
- let returnValue = '';
24
- for (let i = 0; i < str.length; i++) {
25
- const index = signText.indexOf(str.charAt(i));
26
- returnValue += index !== -1 ? unsignedText.charAt(index) : str.charAt(i);
27
- }
28
- return returnValue;
29
- }
30
20
  function toTypeScriptClassName(str) {
31
21
  if (!str)
32
22
  return '_';
33
- const name = toVietnameseNonTongue(str).replace(/\W/g, '_');
23
+ const name = common.toVietnameseNonTongue(str).replace(/\W/g, '_');
34
24
  const c = name.charAt(0);
35
25
  return ('0' <= c && c <= '9' ? '_' : '') + c.toUpperCase() + name.substring(1);
36
26
  }
37
- function getCSharpTypeFromMushroomType(type) {
27
+ function getTypescriptTypeFromMushroomType(type) {
38
28
  switch (type) {
39
29
  case 'string':
40
30
  return 'string';
@@ -102,11 +92,11 @@ function generateTypescriptClass(objectDefination, className, options) {
102
92
  childrenCode += generateTypescriptClass(field.values.items.fields ?? {}, fieldClassName, options);
103
93
  }
104
94
  else {
105
- code += ` ${fieldName}${optionalMark}: Record<string, Array<${getCSharpTypeFromMushroomType(field.values.items?.type ?? 'string')}${itemNullType}>${valueNullType}>${nullType};\n`;
95
+ code += ` ${fieldName}${optionalMark}: Record<string, Array<${getTypescriptTypeFromMushroomType(field.values.items?.type ?? 'string')}${itemNullType}>${valueNullType}>${nullType};\n`;
106
96
  }
107
97
  }
108
98
  else {
109
- code += ` ${fieldName}${optionalMark}: Record<string, ${getCSharpTypeFromMushroomType(field.values?.type ?? 'string')}${valueNullType}>${nullType};\n`;
99
+ code += ` ${fieldName}${optionalMark}: Record<string, ${getTypescriptTypeFromMushroomType(field.values?.type ?? 'string')}${valueNullType}>${nullType};\n`;
110
100
  }
111
101
  }
112
102
  else if (field.type == 'array') {
@@ -131,15 +121,15 @@ function generateTypescriptClass(objectDefination, className, options) {
131
121
  childrenCode += generateTypescriptClass(field.items.values.fields ?? {}, fieldClassName, options);
132
122
  }
133
123
  else {
134
- code += ` ${fieldName}${optionalMark}: Array<Record<string, ${getCSharpTypeFromMushroomType(field.items.type ?? 'string')}${valueNullType}>${itemNullType}>${nullType};\n`;
124
+ code += ` ${fieldName}${optionalMark}: Array<Record<string, ${getTypescriptTypeFromMushroomType(field.items.type ?? 'string')}${valueNullType}>${itemNullType}>${nullType};\n`;
135
125
  }
136
126
  }
137
127
  else {
138
- code += ` ${fieldName}${optionalMark}: Array<${getCSharpTypeFromMushroomType(field.items?.type ?? 'string')}${itemNullType}>${nullType};\n`;
128
+ code += ` ${fieldName}${optionalMark}: Array<${getTypescriptTypeFromMushroomType(field.items?.type ?? 'string')}${itemNullType}>${nullType};\n`;
139
129
  }
140
130
  }
141
131
  else {
142
- code += ` ${fieldName}${optionalMark}: ${getCSharpTypeFromMushroomType(field.type ?? 'string')}${nullType};\n`;
132
+ code += ` ${fieldName}${optionalMark}: ${getTypescriptTypeFromMushroomType(field.type ?? 'string')}${nullType};\n`;
143
133
  }
144
134
  }
145
135
  code += '}\n\n';
@@ -149,7 +139,7 @@ function generateTypescriptClassFromViewParameters(parameters) {
149
139
  if (Array.isArray(parameters)) {
150
140
  return ('{\n' +
151
141
  parameters
152
- .map((p) => `${generateDescription(p.description)} ${p.field}${p.validation?.required && p.defaultValue === undefined ? '' : '?'}: ${getCSharpTypeFromMushroomType(p.type || 'string')}${p.isArray ? '[]' : ''}${p.validation?.required && p.defaultValue === undefined ? '' : ' | null'};`)
142
+ .map((p) => `${generateDescription(p.description)} ${p.field}${p.validation?.required && p.defaultValue === undefined ? '' : '?'}: ${getTypescriptTypeFromMushroomType(p.type || 'string')}${p.isArray ? '[]' : ''}${p.validation?.required && p.defaultValue === undefined ? '' : ' | null'};`)
153
143
  .join('\n') +
154
144
  '\n}');
155
145
  }
@@ -186,7 +176,7 @@ function generateTopCustomClass(config, entityName, methodName, grantRole, postf
186
176
  }
187
177
  }
188
178
  else
189
- inputClassName = getCSharpTypeFromMushroomType(type);
179
+ inputClassName = getTypescriptTypeFromMushroomType(type);
190
180
  return isKeyValue
191
181
  ? isArray
192
182
  ? 'Record<string, ' + inputClassName + '[]>'
@@ -241,10 +231,10 @@ export function genTypescriptDriverString(aliasProject, source) {
241
231
  return '';
242
232
  }
243
233
  const entities = common.getEntities(source, aliasProject.allowRoles);
244
- const extensionsImportLines = [];
234
+ const extensionsImportLines = ['/* import all mushroom extensions */'];
245
235
  const extensionsExportLines = [];
246
- const extensionsTypes = [];
247
- const extensionsCodeLines = [];
236
+ const extensionsTypes = ['/* all mushroom extensions types */'];
237
+ const extensionsCodeLines = ['/* using all mushroom extensions */'];
248
238
  if (Array.isArray(aliasProject.features)) {
249
239
  if (aliasProject.features.includes('auth')) {
250
240
  extensionsImportLines.push('import * as AuthExtension from "mushroomjs-auth";');
@@ -264,6 +254,7 @@ import type { IdType, IMushroom, MushroomRequest, MushroomRequestSetting, Mushro
264
254
  ${extensionsImportLines.join('\n')}
265
255
  export * from "mushroomjs";
266
256
  export const extensions = {
257
+ /* export all mushroom extensions */
267
258
  ${extensionsExportLines.join(',\n ')}
268
259
  };
269
260
 
@@ -404,7 +395,7 @@ export interface CustomMethodBodyRequest<TBody> extends MushroomRequest {
404
395
  }
405
396
  iApiClassBody += `,
406
397
  `;
407
- code += `defineAsyncResource<${typescriptClassName}>(${JSON.stringify({ name: entityName, actions: actions, views: views })});
398
+ code += `defineAsyncResource<${typescriptClassName}>(${JSON.stringify({ name: entityName, actions: actions, views: views })}, mushroom);
408
399
 
409
400
  `;
410
401
  }
@@ -447,6 +438,7 @@ export function genDtsString(aliasProject, source) {
447
438
  ${extensionsImportLines.join('\n')}
448
439
  export * from "mushroomjs";
449
440
  export declare const extensions = {
441
+ /* export all mushroom extensions */
450
442
  ${extensionsExportLines.join(',\n ')}
451
443
  };
452
444
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mushroom-cli",
3
- "version": "1.2.4",
3
+ "version": "1.2.6",
4
4
  "description": "Mushroom CLI",
5
5
  "main": "dist/mr.js",
6
6
  "type": "module",
@@ -33,9 +33,9 @@
33
33
  "author": "suco2007",
34
34
  "license": "ISC",
35
35
  "dependencies": {
36
- "jsdom": "^28.1.0",
36
+ "jsdom": "^29.0.2",
37
37
  "json5": "^2.2.3",
38
- "minify": "^15.0.1",
38
+ "minify": "^15.2.1",
39
39
  "node-fetch": "^3.3.2",
40
40
  "open": "^11.0.0",
41
41
  "readline-sync": "^1.4.10",