mushroom-cli 1.2.4 → 1.2.5
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 +6 -0
- package/dist/common.js +10 -0
- package/dist/gen/gen-api-docs.js +1 -1
- package/dist/gen/gen-csharp.js +1 -11
- package/dist/gen/gen-js-driver.js +4 -4
- package/dist/gen/gen-ts-driver.js +14 -24
- package/package.json +3 -3
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
|
+
}
|
package/dist/gen/gen-api-docs.js
CHANGED
|
@@ -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
|
: {
|
package/dist/gen/gen-csharp.js
CHANGED
|
@@ -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 = [];
|
|
27
|
-
const extensionsExportLines = [];
|
|
28
|
-
const extensionsCodeLines = [];
|
|
26
|
+
const extensionsImportLines = ['/* import all mushroom extensions */'];
|
|
27
|
+
const extensionsExportLines = ['/* export all mushroom extensions */'];
|
|
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";');
|
|
@@ -94,7 +94,7 @@ exports.extensions = extensions;
|
|
|
94
94
|
for (const viewName in entity.views) {
|
|
95
95
|
views[viewName] = {};
|
|
96
96
|
}
|
|
97
|
-
code += `defineAsyncResource({name:${JSON.stringify(entityName)},actions:${JSON.stringify(actions)},views:${JSON.stringify(views)}});
|
|
97
|
+
code += `defineAsyncResource({name:${JSON.stringify(entityName)},actions:${JSON.stringify(actions)},views:${JSON.stringify(views)}}, mushroom);
|
|
98
98
|
`;
|
|
99
99
|
}
|
|
100
100
|
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
|
|
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<${
|
|
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, ${
|
|
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, ${
|
|
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<${
|
|
128
|
+
code += ` ${fieldName}${optionalMark}: Array<${getTypescriptTypeFromMushroomType(field.items?.type ?? 'string')}${itemNullType}>${nullType};\n`;
|
|
139
129
|
}
|
|
140
130
|
}
|
|
141
131
|
else {
|
|
142
|
-
code += ` ${fieldName}${optionalMark}: ${
|
|
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 ? '' : '?'}: ${
|
|
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 =
|
|
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 = [];
|
|
245
|
-
const extensionsExportLines = [];
|
|
246
|
-
const extensionsTypes = [];
|
|
247
|
-
const extensionsCodeLines = [];
|
|
234
|
+
const extensionsImportLines = ['/* import all mushroom extensions */'];
|
|
235
|
+
const extensionsExportLines = ['/* export all mushroom extensions */'];
|
|
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";');
|
|
@@ -404,7 +394,7 @@ export interface CustomMethodBodyRequest<TBody> extends MushroomRequest {
|
|
|
404
394
|
}
|
|
405
395
|
iApiClassBody += `,
|
|
406
396
|
`;
|
|
407
|
-
code += `defineAsyncResource<${typescriptClassName}>(${JSON.stringify({ name: entityName, actions: actions, views: views })});
|
|
397
|
+
code += `defineAsyncResource<${typescriptClassName}>(${JSON.stringify({ name: entityName, actions: actions, views: views })}, mushroom);
|
|
408
398
|
|
|
409
399
|
`;
|
|
410
400
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mushroom-cli",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.5",
|
|
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": "^
|
|
36
|
+
"jsdom": "^29.0.2",
|
|
37
37
|
"json5": "^2.2.3",
|
|
38
|
-
"minify": "^15.
|
|
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",
|