mushroom-cli 1.2.0-alpha.9 → 1.2.1

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.
Files changed (52) hide show
  1. package/README.md +208 -161
  2. package/dist/check-update.js +6 -0
  3. package/dist/common.js +284 -0
  4. package/dist/config.js +394 -0
  5. package/dist/docs/bootstrap-theme.min.css +6 -0
  6. package/dist/docs/bootstrap.min.css +6 -0
  7. package/dist/docs/bootstrap.min.js +7 -0
  8. package/dist/docs/doc-mt.js +633 -0
  9. package/dist/docs/docs.html +5380 -0
  10. package/{docs → dist/docs}/docs.v2.html +5206 -5065
  11. package/dist/docs/docs.v2.js +2037 -0
  12. package/dist/docs/jquery.min.js +4 -0
  13. package/dist/docs/mt-dom-1.0.js +1398 -0
  14. package/dist/docs/mt.extension.js +199 -0
  15. package/dist/gen/gen-api-docs-v1.js +110 -0
  16. package/dist/gen/gen-api-docs.js +327 -0
  17. package/{gen → dist/gen}/gen-csharp.js +1256 -1399
  18. package/{gen → dist/gen}/gen-db-docs.js +204 -222
  19. package/{gen → dist/gen}/gen-js-driver-tarball.js +81 -101
  20. package/{gen → dist/gen}/gen-js-driver.js +116 -133
  21. package/dist/gen/gen-ts-driver.js +600 -0
  22. package/{gen.js → dist/gen.js} +109 -124
  23. package/{help.js → dist/help.js} +53 -55
  24. package/dist/init/init-json.js +92 -0
  25. package/dist/init/init-netcore.js +30 -0
  26. package/dist/init.js +23 -0
  27. package/dist/master-file/master-file.js +185 -0
  28. package/dist/merge.js +70 -0
  29. package/dist/mr.js +77 -0
  30. package/dist/types.js +1 -0
  31. package/dist/update/tsCode.js +82 -0
  32. package/dist/update.js +20 -0
  33. package/package.json +64 -29
  34. package/check-update.js +0 -9
  35. package/common.js +0 -273
  36. package/config.js +0 -445
  37. package/docs/doc-mt.js +0 -523
  38. package/docs/docs.html +0 -5190
  39. package/docs/docs.v2.js +0 -1558
  40. package/docs/mt-dom-1.0.js +0 -1268
  41. package/docs/mt.extension.js +0 -174
  42. package/gen/gen-api-docs-v1.js +0 -125
  43. package/gen/gen-api-docs.js +0 -298
  44. package/gen/gen-ts-driver.js +0 -471
  45. package/init/init-json.js +0 -106
  46. package/init/init-netcore.js +0 -32
  47. package/init.js +0 -28
  48. package/master-file/master-file.js +0 -234
  49. package/merge.js +0 -84
  50. package/mr.js +0 -82
  51. package/update/tsCode.js +0 -20
  52. package/update.js +0 -24
@@ -1,234 +0,0 @@
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")
7
- return;
8
-
9
- if (!("min" in validation) && "gte" in validation) {
10
- validation.min = validation.gte;
11
- }
12
-
13
- if (!("max" in validation) && "lte" in validation) {
14
- validation.max = validation.lte;
15
- }
16
- }
17
-
18
-
19
- function transformEntityFieldNode(field) {
20
- if (!field || typeof field !== "object")
21
- return;
22
-
23
- transformValidationNode(field.validation);
24
- if (Array.isArray(field.items))
25
- transformValidationNode(field.items.validation);
26
-
27
- if (!field.fields || typeof field.fields !== "object")
28
- return;
29
-
30
- for (var fieldName in field.fields) {
31
- transformEntityFieldNode(field.fields[fieldName]);
32
- }
33
- }
34
-
35
- function transformViewNode(view) {
36
- if (!view || !Array.isArray(view.parameters))
37
- return;
38
-
39
- view.parameters.forEach(p => transformValidationNode(p.validation));
40
- }
41
-
42
- function mergeApiProject(totalProject, fragmentProject, options) {
43
- if (totalProject.name != null && fragmentProject.name != null && fragmentProject.name != totalProject.name)
44
- throw new Error(`Unable merge project '${fragmentProject.name}' into '${totalProject.name}'`);
45
- if (totalProject.version != null && fragmentProject.version != null && fragmentProject.version != totalProject.version)
46
- throw new Error(`Unable merge project '${fragmentProject.version}' into '${totalProject.version}'`);
47
-
48
- if (fragmentProject.environmentVariables != null) {
49
- totalProject.environmentVariables = totalProject.environmentVariables || {};
50
-
51
- for (var name in fragmentProject.environmentVariables) {
52
- if (name in totalProject.environmentVariables) {
53
- switch (options.environmentVariable.duplicateNameHandling) {
54
- case "override":
55
- totalProject.environmentVariables[name] = fragmentProject.environmentVariables[name];
56
- break;
57
- case "ignore":
58
- break;
59
- default:
60
- throw new Error(`Duplicate environment variables: ${name}. Can config dublicate name handling behavior at options.environmentVariable.duplicateNameHandling`);
61
- }
62
- }
63
- else
64
- totalProject.environmentVariables[name] = fragmentProject.environmentVariables[name];
65
- }
66
- }
67
-
68
- if (fragmentProject.entities != null) {
69
- totalProject.entities = totalProject.entities || [];
70
-
71
- fragmentProject.entities.forEach(entity => {
72
-
73
- var found = totalProject.entities.some((entityInTotal, i) => {
74
- if (entityInTotal.name !== entity.name){
75
- return false;
76
- }
77
- switch (options.entity.duplicateNameHandling) {
78
- case "override":
79
- totalProject.entities[i] = entity;
80
- return true;
81
- case "ignore":
82
- return true;
83
- default:
84
- throw new Error("Duplicate entity: " + entity.name + ". Can config dublicate name handling behavior at options.entity.duplicateNameHandling");
85
- }
86
- });
87
-
88
- if (found)
89
- return;
90
-
91
- totalProject.entities.push(entity);
92
- // console.log("add new entity: " + entity.name + "; totalProject.entities.length=" + totalProject.entities.length);
93
-
94
- if (!entity.fields || typeof entity.fields !== "object")
95
- return;
96
-
97
- for (var fieldName in entity.fields) {
98
- transformEntityFieldNode(entity.fields[fieldName]);
99
- }
100
- });
101
- }
102
-
103
- if (fragmentProject.views != null) {
104
- totalProject.views = totalProject.views || {};
105
-
106
- for (var viewName in fragmentProject.views)
107
- {
108
- if (viewName in totalProject.views)
109
- {
110
- switch (options.view.duplicateNameHandling)
111
- {
112
- case "override":
113
- totalProject.views[viewName] = fragmentProject.views[viewName];
114
- break;
115
- case "ignore":
116
- continue;
117
- default:
118
- throw new Error("Duplicate global view: " + viewName + ". Can config dublicate name handling behavior at options.views.duplicateNameHandling");
119
- }
120
- }
121
- else
122
- totalProject.views[viewName] = fragmentProject.views[viewName];
123
-
124
- if (!fragmentProject.views[viewName] || Array.isArray(fragmentProject.views[viewName])) {
125
- delete fragmentProject.views[viewName];
126
- continue;
127
- }
128
-
129
- fragmentProject.views[viewName].forEach(transformViewNode);
130
- }
131
- }
132
-
133
-
134
- for (var name in fragmentProject) {
135
- if (name === "environmentVariables" || name === "entities" || name === "views" || name === "$schema")
136
- continue;
137
-
138
- totalProject[name] = fragmentProject[name];
139
- }
140
-
141
- return totalProject;
142
- }
143
-
144
- function processMasterFile(basePath, master) {
145
- if (master.fragments == null || master.fragments.Length == 0)
146
- return null;
147
-
148
- const options = master.options || {
149
- formatIndent: false
150
- };
151
- options.environmentVariable = options.environmentVariable || { duplicateNameHandling: "raiseException" };
152
- options.entity = options.entity || { duplicateNameHandling: "raiseException" };
153
- options.view = options.view || { duplicateNameHandling: "raiseException" };
154
-
155
- let apiProject = {};
156
- master.fragments.forEach(fragment => {
157
- let apiProjectFragment;
158
- const fragmentPath = path.join(basePath, fragment.path)
159
- console.log("merging fragment file: " + fragmentPath);
160
- try {
161
- const content = fs.readFileSync(fragmentPath).toString();
162
- apiProjectFragment = JSON5.parse(content);
163
- }
164
- catch (e) {
165
- if (fragment.optional){
166
- console.warn(fragmentPath + " not found or unable to parse");
167
- return;
168
- }
169
- console.error(fragmentPath + " not found or unable to parse");
170
- throw e;
171
- }
172
-
173
- apiProject = mergeApiProject(apiProject, apiProjectFragment, master.options);
174
- })
175
-
176
- if (apiProject == null)
177
- return null;
178
-
179
- apiProject["$schema"] = "http://schema.siten.vn/mushroom/project.json";
180
-
181
- if (apiProject.entities == null)
182
- apiProject.entities = [];
183
-
184
- apiProject.entities.forEach(entity => {
185
- if (entity.actions == null)
186
- entity.actions = [];
187
-
188
- for (let actionName in entity.actions) {
189
- if (actionName != "findMany" && actionName != "findById" || entity.actions[actionName] == null)
190
- continue;
191
-
192
- entity.actions[actionName].forEach(action => {
193
- if (action.fields) {
194
- action.defaultFields = action.fields.split(',');
195
- delete action.fields;
196
- }
197
- if (action.allowFields) {
198
- action.returnableFields = action.allowFields.split(',');
199
- delete action.allowFields;
200
- }
201
-
202
- if (actionName != "findMany")
203
- return;
204
- if (action.sorting) {
205
- action.defaultSortings = action.sorting.split(',').map(f => {
206
- const c = f.charAt(0);
207
- return {
208
- field: c === "+" || c === "-" ? f.substring(1) : f,
209
- type: c === "-" ? "Desc" : "Asc"
210
- }
211
- });
212
- delete action.sorting;
213
- }
214
- if (action.allowSorting)
215
- {
216
- action.allowSortings = action.allowSorting.split(',').map(f => {
217
- const c = f.charAt(0);
218
- return {
219
- field: c === "+" || c === "-" ? f.substring(1) : f,
220
- type: c === "-" ? "Desc" : c === "+" ? "Asc" : "Both"
221
- }
222
- });
223
- delete action.allowSorting;
224
- }
225
- });
226
- }
227
- });
228
-
229
- return apiProject;
230
- }
231
-
232
- module.exports = {
233
- processMasterFile: processMasterFile
234
- };
package/merge.js DELETED
@@ -1,84 +0,0 @@
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 DELETED
@@ -1,82 +0,0 @@
1
- #!/usr/bin/env node
2
-
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");
9
-
10
- const pkg = require("./package.json");
11
- const checkUpdate = require("./check-update");
12
-
13
- const versionGroup = pkg.version.match(/([^-]+)(-(\w+).*)?/);
14
- const currentDistTag = versionGroup[3] ? versionGroup[3] : "latest";
15
- console.log("Mushroom CLI version " + pkg.version);
16
-
17
- async function run(args) {
18
- let debugMode = false;
19
- if (args.indexOf("--debug") !== -1) {
20
- debugMode = true;
21
- args = args.filter(arg => arg !== "--debug");
22
- }
23
-
24
- let checkUpdateTask;
25
- if (args.indexOf("--no-check-update") !== -1){
26
- args = args.filter(arg => arg !== "--no-check-update");
27
- checkUpdateTask = null;
28
- }
29
- else{
30
- checkUpdateTask = checkUpdate();
31
- checkUpdateTask.catch(() => {});
32
- }
33
-
34
- const startTime = new Date().getTime();
35
- try {
36
- switch(args[0]) {
37
- case "init":
38
- await init(args);
39
- break;
40
- case "config":
41
- await config(args);
42
- break;
43
- case "gen":
44
- await gen(args);
45
- break;
46
- case "merge":
47
- merge(args);
48
- break;
49
- case "update":
50
- await update(args);
51
- break;
52
- case "help":
53
- case "man":
54
- help(args.slice(1).join());
55
- break;
56
- default:
57
- help(args, true);
58
- break;
59
- }
60
- }
61
- catch (e) {
62
- console.error(debugMode ? e : "ERROR: " + e.message);
63
- }
64
- finally {
65
- console.log("Processed in", new Date().getTime() - startTime, "ms.");
66
- }
67
-
68
-
69
- if (checkUpdateTask !== null)
70
- try {
71
- var data = await checkUpdateTask;
72
- if (data["dist-tags"] && data["dist-tags"][currentDistTag] && data["dist-tags"][currentDistTag] !== pkg.version) {
73
- console.warn(`YOUR mushroom-cli VERSION IS NOT LATEST (dist-tags: ${currentDistTag}). PLEASE RUN: npm i mushroom-cli@${data["dist-tags"][currentDistTag]} OR yarn add mushroom-cli@^${data["dist-tags"][currentDistTag]}`);
74
- }
75
- }
76
- catch(e) {
77
- if (debugMode) console.log(e);
78
- }
79
- }
80
-
81
- const [,, ...args] = process.argv;
82
- run(args);
package/update/tsCode.js DELETED
@@ -1,20 +0,0 @@
1
- const fs = require("fs");
2
- const fetch = require('node-fetch');
3
-
4
- async function updateTsCode(options) {
5
- if (!options.output) {
6
- console.error("Missing output file path");
7
- return;
8
- }
9
- if (!options.input) {
10
- console.error("Missing remote url");
11
- return;
12
- }
13
- console.log(`Fetch ${options.input}`);
14
- const res = await fetch(options.input);
15
- console.log(`Write to ${options.output}`);
16
- fs.writeFileSync(options.output, await res.text());
17
- console.log(`Finish update ts-code`);
18
- }
19
-
20
- module.exports = updateTsCode;
package/update.js DELETED
@@ -1,24 +0,0 @@
1
- const help = require("./help.js");
2
- const updateTsCode = require("./update/tsCode");
3
-
4
- async function update(args) {
5
- let command = args[1];
6
-
7
- switch (command) {
8
- case "ts-code":
9
- await updateTsCode({
10
- input: args[3],
11
- output: args[2]
12
- });
13
- break;
14
- case "help":
15
- case "man":
16
- help(args);
17
- break;
18
- default:
19
- help(args, true);
20
- break;
21
- }
22
- }
23
-
24
- module.exports = update;