mushroom-cli 1.2.0-alpha.15 → 1.2.0-alpha.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/README.md CHANGED
@@ -132,6 +132,12 @@ npx mushroom-cli parameters --no-check-update
132
132
 
133
133
  ## Version
134
134
 
135
+ ### 1.2.0-alpha.17
136
+
137
+ Improvement:
138
+
139
+ - gen-ts: add null value for nullable field type
140
+
135
141
  ### 1.2.0-alpha.15
136
142
 
137
143
  Improvement:
@@ -241,7 +241,7 @@ async function writeDocs(filePath, strTemplate, strData) {
241
241
  }
242
242
  const copyStaticFiles = (folderPath, files) => {
243
243
  files.forEach((file) => {
244
- fs.copyFileSync(path.join(folderPath, file), path.join(__dirname, '../docs/', file));
244
+ fs.copyFileSync(path.join(__dirname, '../docs/', file), path.join(folderPath, file));
245
245
  });
246
246
  };
247
247
  export default async function genDocs(args, projectName, project, alias, source) {
@@ -59,24 +59,26 @@ function generateTypescriptClass(objectDefination, className, options) {
59
59
  let childrenCode = '';
60
60
  let code = `export interface ${className} {\n`;
61
61
  for (const fieldName in objectDefination) {
62
- const optionalMark = options?.checkRequired && objectDefination[fieldName].required ? '' : '?';
62
+ const optionalMark = options?.checkRequired && objectDefination[fieldName].required
63
+ ? ''
64
+ : ' | null | undefined';
63
65
  if (objectDefination[fieldName].type == 'object') {
64
66
  const fieldClassName = className + '_' + toTypeScriptClassName(fieldName);
65
- code += ` ${fieldName}${optionalMark}: ${fieldClassName},\n`;
67
+ code += ` ${fieldName}: ${fieldClassName}${optionalMark};\n`;
66
68
  childrenCode += generateTypescriptClass(objectDefination[fieldName].fields ?? {}, fieldClassName);
67
69
  }
68
70
  else if (objectDefination[fieldName].type == 'array') {
69
71
  if (objectDefination[fieldName].items?.type == 'object') {
70
72
  const fieldClassName = className + '_' + toTypeScriptClassName(fieldName);
71
- code += ` ${fieldName}${optionalMark}: ${fieldClassName}[],\n`;
73
+ code += ` ${fieldName}: ${fieldClassName}[]${optionalMark};\n`;
72
74
  childrenCode += generateTypescriptClass(objectDefination[fieldName].items?.fields ?? {}, fieldClassName);
73
75
  }
74
76
  else {
75
- code += ` ${fieldName}${optionalMark}: ${getCSharpTypeFromMushroomType(objectDefination[fieldName].items?.type ?? '')}[],\n`;
77
+ code += ` ${fieldName}: ${getCSharpTypeFromMushroomType(objectDefination[fieldName].items?.type ?? '')}[]${optionalMark};\n`;
76
78
  }
77
79
  }
78
80
  else {
79
- code += ` ${fieldName}${optionalMark}: ${getCSharpTypeFromMushroomType(objectDefination[fieldName].type)},\n`;
81
+ code += ` ${fieldName}: ${getCSharpTypeFromMushroomType(objectDefination[fieldName].type)}${optionalMark};\n`;
80
82
  }
81
83
  }
82
84
  code += '}\n\n';
@@ -86,8 +88,8 @@ function generateTypescriptClassFromViewParameters(parameters) {
86
88
  if (Array.isArray(parameters)) {
87
89
  return ('{\n' +
88
90
  parameters
89
- .map((p) => ` ${p.field}${p.validation?.required && p.defaultValue === undefined ? '' : '?'}: ${getCSharpTypeFromMushroomType(p.type || 'string')}${p.isArray ? '[]' : ''}`)
90
- .join(',\n') +
91
+ .map((p) => ` ${p.field}: ${getCSharpTypeFromMushroomType(p.type || 'string')}${p.isArray ? '[]' : ''}${p.validation?.required && p.defaultValue === undefined ? '' : ' | null | undefined'};`)
92
+ .join('\n') +
91
93
  '\n}');
92
94
  }
93
95
  return '{}';
@@ -193,8 +195,7 @@ export type IdValue = ${source.idType == 'AutoIncInt' || source.idType == 'AutoI
193
195
  }
194
196
  default: {
195
197
  if (actionName.indexOf('_raw_http_method_') === 0) {
196
- customMethodCode += ` ${actionName.substring('_raw_http_method_'.length)}Async: (rawRequest: MushroomRequest) => Promise<MushroomResponse<any>>,
197
- `;
198
+ customMethodCode += ` ${actionName.substring('_raw_http_method_'.length)}Async: (rawRequest: MushroomRequest) => Promise<MushroomResponse<any>>;\n`;
198
199
  break;
199
200
  }
200
201
  else {
@@ -229,7 +230,7 @@ ${customMethodCode}}
229
230
  return `MushroomViewFunction<${outputType}, ${inputType}>`;
230
231
  });
231
232
  viewCode += `
232
- ${viewName}Async: ${viewParameterTypes.join(' | ')},`;
233
+ ${viewName}Async: ${viewParameterTypes.join(' | ')};`;
233
234
  }
234
235
  if (viewCode) {
235
236
  code += `export interface ${typescriptClassName}$ViewsResource {
@@ -358,8 +359,7 @@ export declare type IdValue = ${source.idType == 'AutoIncInt' || source.idType =
358
359
  }
359
360
  default: {
360
361
  if (actionName.indexOf('_raw_http_method_') === 0) {
361
- customMethodCode += ` ${actionName.substring('_raw_http_method_'.length)}Async: (rawRequest: MushroomRequest) => Promise<MushroomResponse<any>>,
362
- `;
362
+ customMethodCode += ` ${actionName.substring('_raw_http_method_'.length)}Async: (rawRequest: MushroomRequest) => Promise<MushroomResponse<any>>;\n`;
363
363
  break;
364
364
  }
365
365
  else {
package/package.json CHANGED
@@ -1,15 +1,23 @@
1
1
  {
2
2
  "name": "mushroom-cli",
3
- "version": "1.2.0-alpha.15",
3
+ "version": "1.2.0-alpha.17",
4
4
  "description": "Mushroom CLI",
5
5
  "main": "dist/mr.js",
6
6
  "type": "module",
7
7
  "scripts": {
8
8
  "build": "tsc && copyfiles -u 2 ./src/docs/* ./dist/docs/",
9
- "format": "prettier --write \"**/*.{ts,js,json,md}\"",
10
- "lint": "eslint ./src",
9
+ "format": "prettier --write **/*",
10
+ "lint": "eslint ./src/**/*.ts",
11
11
  "release": "npm run build && npm publish --access public --tag alpha",
12
- "prepare": "husky install"
12
+ "preinstall": "npx only-allow npm",
13
+ "prepare": "husky"
14
+ },
15
+ "lint-staged": {
16
+ "!(*.ts)": "prettier --write --ignore-unknown",
17
+ "src/**/*.ts": [
18
+ "eslint --quiet",
19
+ "prettier --write"
20
+ ]
13
21
  },
14
22
  "files": [
15
23
  "dist"
@@ -25,28 +33,30 @@
25
33
  "author": "suco2007",
26
34
  "license": "ISC",
27
35
  "dependencies": {
28
- "jsdom": "^25.0.0",
36
+ "jsdom": "^25.0.1",
29
37
  "json5": "^2.2.3",
30
- "minify": "^11.4.0",
38
+ "minify": "^11.4.1",
31
39
  "node-fetch": "^3.3.2",
32
40
  "open": "^10.1.0",
33
41
  "readline-sync": "^1.4.10",
34
42
  "targz": "^1.0.1"
35
43
  },
36
44
  "devDependencies": {
37
- "@eslint/js": "^9.9.1",
45
+ "@eslint/js": "^9.11.1",
38
46
  "@types/jsdom": "^21.1.7",
39
47
  "@types/minify": "^9.1.4",
40
- "@types/node": "^22.5.0",
48
+ "@types/node": "^22.7.4",
41
49
  "@types/node-fetch": "^2.6.11",
42
50
  "@types/readline-sync": "^1.4.8",
43
51
  "@types/targz": "^1.0.4",
44
52
  "copyfiles": "^2.4.1",
45
- "eslint": "^9.9.1",
46
- "husky": "^8.0.3",
53
+ "eslint": "^9.11.1",
54
+ "husky": "^9.1.6",
55
+ "lint-staged": "^15.2.10",
56
+ "only-allow": "^1.2.1",
47
57
  "prettier": "^3.3.3",
48
- "typescript": "^5.5.4",
49
- "typescript-eslint": "^8.3.0"
58
+ "typescript": "^5.6.2",
59
+ "typescript-eslint": "^8.8.0"
50
60
  },
51
61
  "engines": {
52
62
  "node": ">=14.0.0"