mushroom-cli 1.2.0-alpha.1 → 1.2.0-alpha.3

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
@@ -70,6 +70,10 @@ Generate entities for CSharp project which calls Mushroom API
70
70
 
71
71
  npx mushroom-cli gen projectName[@aliasName] c#-driver
72
72
 
73
+ ## Merge
74
+
75
+ npx mushroom-cli merge output-path.json
76
+
73
77
  ## Update
74
78
 
75
79
  Update ts code
@@ -84,9 +88,23 @@ Disable checking for update:
84
88
 
85
89
  ## Version
86
90
 
91
+ ### 1.2.0-alpha.3
92
+
93
+ Fixed bugs:
94
+
95
+ * Generate wrong required field for view parameter
96
+
97
+ ### 1.2.0-alpha.2
98
+
99
+ New features:
100
+
101
+ * Support merge command
102
+
87
103
  ### 1.2.0-alpha.1
88
104
 
89
- Support type for View result
105
+ New features:
106
+
107
+ * Support type for View result
90
108
 
91
109
  ### 1.1.0
92
110
 
@@ -93,7 +93,7 @@ function generateTypescriptClass(objectDefination, indent, options) {
93
93
 
94
94
  function generateTypescriptClassFromViewParameters(parameters) {
95
95
  if (Array.isArray(parameters)){
96
- return '{\n' + parameters.map(p => ` ${p.field}${p.validation?.required ? "" : "?"}: ${getCSharpTypeFromMushroomType(p.type || "string")}${p.isArray ? "[]" : ""}`).join(',\n') + '\n}';
96
+ return '{\n' + parameters.map(p => ` ${p.field}${p.validation?.required && p.defaultValue === undefined ? "" : "?"}: ${getCSharpTypeFromMushroomType(p.type || "string")}${p.isArray ? "[]" : ""}`).join(',\n') + '\n}';
97
97
  }
98
98
  return '{}';
99
99
  }
package/merge.js ADDED
@@ -0,0 +1,84 @@
1
+ const fs = require("fs");
2
+ const path = require('path');
3
+ const JSON5 = require("json5");
4
+ const common = require("./common.js");
5
+ const help = require("./help.js");
6
+
7
+ const masterFile = require("./master-file/master-file");
8
+
9
+ async function merge(args) {
10
+ let projectName = args[1];
11
+ const output = args[2];
12
+
13
+ if (!projectName || !output) {
14
+ help(args);
15
+ return;
16
+ }
17
+
18
+ let alias = "default";
19
+ const atIndex = projectName.indexOf("@");
20
+ if (atIndex !== -1) {
21
+ alias = projectName.substring(atIndex + 1);
22
+ projectName = projectName.substring(0, atIndex);
23
+ if (!projectName) {
24
+ help(args);
25
+ return;
26
+ }
27
+
28
+ if (!alias)
29
+ alias = "default";
30
+ }
31
+
32
+ let mushroomConfig;
33
+ try {
34
+ const mushroomConfigContent = fs.readFileSync("./mushroom-config.json").toString();
35
+ mushroomConfig = JSON.parse(mushroomConfigContent);
36
+ }
37
+ catch (e) {
38
+ console.error("mushroom-config.json not found or unable to parse");
39
+ throw e;
40
+ }
41
+
42
+ if (!mushroomConfig || typeof mushroomConfig !== "object")
43
+ throw new Error(`Invalid configuration. Please re-check file mushroom-config.json`);
44
+
45
+ if (!mushroomConfig || !mushroomConfig.projects || !mushroomConfig.projects[projectName])
46
+ throw new Error(`Project not found (${projectName})`);
47
+
48
+ const project = mushroomConfig.projects[projectName];
49
+ if (!project.src)
50
+ throw new Error("Project source (src) not found");
51
+
52
+ var source;
53
+ try {
54
+ const sourceContent = fs.readFileSync(project.src).toString();
55
+ source = JSON5.parse(sourceContent);
56
+ }
57
+ catch(e) {
58
+ console.error(project.src + " not found or unable to parse");
59
+ throw e;
60
+ }
61
+
62
+ if (!source || typeof source !== "object")
63
+ throw new Error(`Invalid api project configuration. Please re-check file ${project.src}`);
64
+
65
+ if (Array.isArray(source.fragments)) {
66
+ console.log("Process master file: " + project.src);
67
+ source = masterFile.processMasterFile(path.dirname(project.src), source);
68
+ }
69
+
70
+ if (!source || typeof source !== "object") {
71
+ throw new Error(`${!source}\t${typeof source}\tInvalid api project configuration. Please re-check file ${project.src}`);
72
+ }
73
+
74
+ if (source.name !== projectName) {
75
+ throw new Error(`Project name is mismatched (${projectName} & ${source.name})`);
76
+ }
77
+
78
+ common.ensureFolder(output);
79
+
80
+ fs.writeFileSync(output, JSON.stringify(source));
81
+ console.log(`Merged ${projectName}@${alias} then saved to ${output}`);
82
+ }
83
+
84
+ module.exports = merge;
package/mr.js CHANGED
@@ -1,10 +1,11 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- const init = require("./init.js");
4
- const config = require("./config.js");
5
- const gen = require("./gen.js");
6
- const update = require("./update.js");
7
- const help = require("./help.js");
3
+ const init = require("./init");
4
+ const config = require("./config");
5
+ const gen = require("./gen");
6
+ const merge = require("./merge");
7
+ const update = require("./update");
8
+ const help = require("./help");
8
9
 
9
10
  const pkg = require("./package.json");
10
11
  const checkUpdate = require("./check-update");
@@ -41,6 +42,9 @@ async function run(args) {
41
42
  case "gen":
42
43
  await gen(args);
43
44
  break;
45
+ case "merge":
46
+ merge(args);
47
+ break;
44
48
  case "update":
45
49
  await update(args);
46
50
  break;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mushroom-cli",
3
- "version": "1.2.0-alpha.1",
3
+ "version": "1.2.0-alpha.3",
4
4
  "description": "Mushroom CLI",
5
5
  "main": "mr.js",
6
6
  "scripts": {