mushroom-cli 1.1.0 → 1.1.2
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/.vscode/settings.json +3 -0
- package/README.md +91 -91
- package/check-update.js +9 -9
- package/common.js +237 -236
- package/config.js +475 -445
- package/docs/doc-mt.js +526 -421
- package/docs/docs.html +5380 -5129
- package/docs/mt-dom-1.0.js +1398 -1268
- package/docs/mt.extension.js +199 -174
- package/gen/gen-api-docs.js +157 -125
- package/gen/gen-csharp.js +1687 -1414
- package/gen/gen-db-docs.js +238 -222
- package/gen/gen-js-driver-tarball.js +119 -101
- package/gen/gen-js-driver.js +154 -133
- package/gen/gen-ts-driver.js +482 -451
- package/gen.js +146 -120
- package/help.js +51 -55
- package/init/init-json.js +110 -106
- package/init/init-netcore.js +37 -32
- package/init.js +27 -28
- package/master-file/master-file.js +254 -234
- package/mr.js +80 -78
- package/package.json +27 -27
- package/update/tsCode.js +90 -20
- package/update.js +24 -24
package/init/init-netcore.js
CHANGED
|
@@ -1,32 +1,37 @@
|
|
|
1
|
-
const fs = require("fs");
|
|
2
|
-
const { spawn } = require("child_process");
|
|
3
|
-
const common = require("../common.js");
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
|
|
1
|
+
const fs = require("fs");
|
|
2
|
+
const { spawn } = require("child_process");
|
|
3
|
+
const common = require("../common.js");
|
|
4
|
+
|
|
5
|
+
function fetchFromGit() {
|
|
6
|
+
return new Promise((resolve, reject) => {
|
|
7
|
+
const git = spawn("git", [
|
|
8
|
+
"clone",
|
|
9
|
+
"https://tfs.siten.vn/tfs/Siten/CodeBase/_git/Mushroom",
|
|
10
|
+
"-b",
|
|
11
|
+
"full_extensions",
|
|
12
|
+
"--single-branch",
|
|
13
|
+
]);
|
|
14
|
+
git.stdout.on("data", (data) => {
|
|
15
|
+
console.log(`GIT: ${data}`);
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
git.stderr.on("data", (data) => {
|
|
19
|
+
console.error(`GIT: ${data}`);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
git.on("close", (code) => {
|
|
23
|
+
if (code) {
|
|
24
|
+
reject(new Error(`GIT exited with code ${code}`));
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
resolve();
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
async function initNetCore(args) {
|
|
33
|
+
await fetchFromGit();
|
|
34
|
+
common.processTemplate("Mushroom", "mushroom-template.json");
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
module.exports = initNetCore;
|
package/init.js
CHANGED
|
@@ -1,28 +1,27 @@
|
|
|
1
|
-
const help = require("./help.js");
|
|
2
|
-
|
|
3
|
-
const initJson = require("./init/init-json");
|
|
4
|
-
const initNetCore = require("./init/init-netcore");
|
|
5
|
-
|
|
6
|
-
async function init(args) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
module.exports = init;
|
|
1
|
+
const help = require("./help.js");
|
|
2
|
+
|
|
3
|
+
const initJson = require("./init/init-json");
|
|
4
|
+
const initNetCore = require("./init/init-netcore");
|
|
5
|
+
|
|
6
|
+
async function init(args) {
|
|
7
|
+
const configCommand = args[1];
|
|
8
|
+
switch (configCommand) {
|
|
9
|
+
case "json":
|
|
10
|
+
initJson(args);
|
|
11
|
+
break;
|
|
12
|
+
case "netcore":
|
|
13
|
+
await initNetCore(args);
|
|
14
|
+
break;
|
|
15
|
+
case "":
|
|
16
|
+
case undefined:
|
|
17
|
+
case "help":
|
|
18
|
+
case "man":
|
|
19
|
+
help("init");
|
|
20
|
+
break;
|
|
21
|
+
default:
|
|
22
|
+
help(args, true);
|
|
23
|
+
break;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
module.exports = init;
|
|
@@ -1,234 +1,254 @@
|
|
|
1
|
-
const fs = require("fs");
|
|
2
|
-
const path = require(
|
|
3
|
-
const JSON5 = require("json5");
|
|
4
|
-
|
|
5
|
-
function transformValidationNode(validation) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
}
|
|
1
|
+
const fs = require("fs");
|
|
2
|
+
const path = require("path");
|
|
3
|
+
const JSON5 = require("json5");
|
|
4
|
+
|
|
5
|
+
function transformValidationNode(validation) {
|
|
6
|
+
if (!validation || typeof validation !== "object") return;
|
|
7
|
+
|
|
8
|
+
if (!("min" in validation) && "gte" in validation) {
|
|
9
|
+
validation.min = validation.gte;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
if (!("max" in validation) && "lte" in validation) {
|
|
13
|
+
validation.max = validation.lte;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function transformEntityFieldNode(field) {
|
|
18
|
+
if (!field || typeof field !== "object") return;
|
|
19
|
+
|
|
20
|
+
transformValidationNode(field.validation);
|
|
21
|
+
if (Array.isArray(field.items))
|
|
22
|
+
transformValidationNode(field.items.validation);
|
|
23
|
+
|
|
24
|
+
if (!field.fields || typeof field.fields !== "object") return;
|
|
25
|
+
|
|
26
|
+
for (const fieldName in field.fields) {
|
|
27
|
+
transformEntityFieldNode(field.fields[fieldName]);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function transformViewNode(view) {
|
|
32
|
+
if (!view || !Array.isArray(view.parameters)) return;
|
|
33
|
+
|
|
34
|
+
view.parameters.forEach((p) => transformValidationNode(p.validation));
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function mergeApiProject(totalProject, fragmentProject, options) {
|
|
38
|
+
if (
|
|
39
|
+
totalProject.name != null &&
|
|
40
|
+
fragmentProject.name != null &&
|
|
41
|
+
fragmentProject.name != totalProject.name
|
|
42
|
+
)
|
|
43
|
+
throw new Error(
|
|
44
|
+
`Unable merge project '${fragmentProject.name}' into '${totalProject.name}'`,
|
|
45
|
+
);
|
|
46
|
+
if (
|
|
47
|
+
totalProject.version != null &&
|
|
48
|
+
fragmentProject.version != null &&
|
|
49
|
+
fragmentProject.version != totalProject.version
|
|
50
|
+
)
|
|
51
|
+
throw new Error(
|
|
52
|
+
`Unable merge project '${fragmentProject.version}' into '${totalProject.version}'`,
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
if (fragmentProject.environmentVariables != null) {
|
|
56
|
+
totalProject.environmentVariables = totalProject.environmentVariables || {};
|
|
57
|
+
|
|
58
|
+
for (const name in fragmentProject.environmentVariables) {
|
|
59
|
+
if (name in totalProject.environmentVariables) {
|
|
60
|
+
switch (options.environmentVariable.duplicateNameHandling) {
|
|
61
|
+
case "override":
|
|
62
|
+
totalProject.environmentVariables[name] =
|
|
63
|
+
fragmentProject.environmentVariables[name];
|
|
64
|
+
break;
|
|
65
|
+
case "ignore":
|
|
66
|
+
break;
|
|
67
|
+
default:
|
|
68
|
+
throw new Error(
|
|
69
|
+
`Duplicate environment variables: ${name}. Can config dublicate name handling behavior at options.environmentVariable.duplicateNameHandling`,
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
} else
|
|
73
|
+
totalProject.environmentVariables[name] =
|
|
74
|
+
fragmentProject.environmentVariables[name];
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (fragmentProject.entities != null) {
|
|
79
|
+
totalProject.entities = totalProject.entities || [];
|
|
80
|
+
|
|
81
|
+
fragmentProject.entities.forEach((entity) => {
|
|
82
|
+
const found = totalProject.entities.some((entityInTotal, i) => {
|
|
83
|
+
if (entityInTotal.name !== entity.name) {
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
switch (options.entity.duplicateNameHandling) {
|
|
87
|
+
case "override":
|
|
88
|
+
totalProject.entities[i] = entity;
|
|
89
|
+
return true;
|
|
90
|
+
case "ignore":
|
|
91
|
+
return true;
|
|
92
|
+
default:
|
|
93
|
+
throw new Error(
|
|
94
|
+
"Duplicate entity: " +
|
|
95
|
+
entity.name +
|
|
96
|
+
". Can config dublicate name handling behavior at options.entity.duplicateNameHandling",
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
if (found) return;
|
|
102
|
+
|
|
103
|
+
totalProject.entities.push(entity);
|
|
104
|
+
|
|
105
|
+
if (!entity.fields || typeof entity.fields !== "object") return;
|
|
106
|
+
|
|
107
|
+
for (const fieldName in entity.fields) {
|
|
108
|
+
transformEntityFieldNode(entity.fields[fieldName]);
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
if (fragmentProject.views != null) {
|
|
114
|
+
totalProject.views = totalProject.views || {};
|
|
115
|
+
|
|
116
|
+
for (const viewName in fragmentProject.views) {
|
|
117
|
+
if (viewName in totalProject.views) {
|
|
118
|
+
switch (options.view.duplicateNameHandling) {
|
|
119
|
+
case "override":
|
|
120
|
+
totalProject.views[viewName] = fragmentProject.views[viewName];
|
|
121
|
+
break;
|
|
122
|
+
case "ignore":
|
|
123
|
+
continue;
|
|
124
|
+
default:
|
|
125
|
+
throw new Error(
|
|
126
|
+
"Duplicate global view: " +
|
|
127
|
+
viewName +
|
|
128
|
+
". Can config dublicate name handling behavior at options.views.duplicateNameHandling",
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
} else totalProject.views[viewName] = fragmentProject.views[viewName];
|
|
132
|
+
|
|
133
|
+
if (
|
|
134
|
+
!fragmentProject.views[viewName] ||
|
|
135
|
+
Array.isArray(fragmentProject.views[viewName])
|
|
136
|
+
) {
|
|
137
|
+
delete fragmentProject.views[viewName];
|
|
138
|
+
continue;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
fragmentProject.views[viewName].forEach(transformViewNode);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
for (const name in fragmentProject) {
|
|
146
|
+
if (
|
|
147
|
+
name === "environmentVariables" ||
|
|
148
|
+
name === "entities" ||
|
|
149
|
+
name === "views" ||
|
|
150
|
+
name === "$schema"
|
|
151
|
+
)
|
|
152
|
+
continue;
|
|
153
|
+
|
|
154
|
+
totalProject[name] = fragmentProject[name];
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
return totalProject;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function processMasterFile(basePath, master) {
|
|
161
|
+
if (master.fragments == null || master.fragments.Length == 0) return null;
|
|
162
|
+
|
|
163
|
+
const options = master.options || {
|
|
164
|
+
formatIndent: false,
|
|
165
|
+
};
|
|
166
|
+
options.environmentVariable = options.environmentVariable || {
|
|
167
|
+
duplicateNameHandling: "raiseException",
|
|
168
|
+
};
|
|
169
|
+
options.entity = options.entity || {
|
|
170
|
+
duplicateNameHandling: "raiseException",
|
|
171
|
+
};
|
|
172
|
+
options.view = options.view || { duplicateNameHandling: "raiseException" };
|
|
173
|
+
|
|
174
|
+
let apiProject = {};
|
|
175
|
+
master.fragments.forEach((fragment) => {
|
|
176
|
+
let apiProjectFragment;
|
|
177
|
+
const fragmentPath = path.join(basePath, fragment.path);
|
|
178
|
+
console.log("merging fragment file: " + fragmentPath);
|
|
179
|
+
try {
|
|
180
|
+
const content = fs.readFileSync(fragmentPath).toString();
|
|
181
|
+
apiProjectFragment = JSON5.parse(content);
|
|
182
|
+
} catch (e) {
|
|
183
|
+
if (fragment.optional) {
|
|
184
|
+
console.warn(fragmentPath + " not found or unable to parse");
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
console.error(fragmentPath + " not found or unable to parse");
|
|
188
|
+
throw e;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
apiProject = mergeApiProject(
|
|
192
|
+
apiProject,
|
|
193
|
+
apiProjectFragment,
|
|
194
|
+
master.options,
|
|
195
|
+
);
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
if (apiProject == null) return null;
|
|
199
|
+
|
|
200
|
+
apiProject["$schema"] = "https://schema.siten.vn/mushroom/project.json";
|
|
201
|
+
|
|
202
|
+
if (apiProject.entities == null) apiProject.entities = [];
|
|
203
|
+
|
|
204
|
+
apiProject.entities.forEach((entity) => {
|
|
205
|
+
if (entity.actions == null) entity.actions = [];
|
|
206
|
+
|
|
207
|
+
for (let actionName in entity.actions) {
|
|
208
|
+
if (
|
|
209
|
+
(actionName != "findMany" && actionName != "findById") ||
|
|
210
|
+
entity.actions[actionName] == null
|
|
211
|
+
)
|
|
212
|
+
continue;
|
|
213
|
+
|
|
214
|
+
entity.actions[actionName].forEach((action) => {
|
|
215
|
+
if (action.fields) {
|
|
216
|
+
action.defaultFields = action.fields.split(",");
|
|
217
|
+
delete action.fields;
|
|
218
|
+
}
|
|
219
|
+
if (action.allowFields) {
|
|
220
|
+
action.returnableFields = action.allowFields.split(",");
|
|
221
|
+
delete action.allowFields;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
if (actionName != "findMany") return;
|
|
225
|
+
if (action.sorting) {
|
|
226
|
+
action.defaultSortings = action.sorting.split(",").map((f) => {
|
|
227
|
+
const c = f.charAt(0);
|
|
228
|
+
return {
|
|
229
|
+
field: c === "+" || c === "-" ? f.substring(1) : f,
|
|
230
|
+
type: c === "-" ? "Desc" : "Asc",
|
|
231
|
+
};
|
|
232
|
+
});
|
|
233
|
+
delete action.sorting;
|
|
234
|
+
}
|
|
235
|
+
if (action.allowSorting) {
|
|
236
|
+
action.allowSortings = action.allowSorting.split(",").map((f) => {
|
|
237
|
+
const c = f.charAt(0);
|
|
238
|
+
return {
|
|
239
|
+
field: c === "+" || c === "-" ? f.substring(1) : f,
|
|
240
|
+
type: c === "-" ? "Desc" : c === "+" ? "Asc" : "Both",
|
|
241
|
+
};
|
|
242
|
+
});
|
|
243
|
+
delete action.allowSorting;
|
|
244
|
+
}
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
return apiProject;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
module.exports = {
|
|
253
|
+
processMasterFile: processMasterFile,
|
|
254
|
+
};
|