mushroom-cli 1.1.0-alpha.9 → 1.1.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.
- package/README.md +38 -22
- package/common.js +114 -10
- package/config.js +10 -10
- package/docs/doc-mt.js +421 -0
- package/docs/docs.html +5129 -0
- package/docs/mt-dom-1.0.js +1269 -0
- package/docs/mt.extension.js +174 -0
- package/gen/gen-api-docs.js +4 -6
- package/gen/gen-csharp.js +571 -82
- package/gen/gen-db-docs.js +2 -2
- package/gen/gen-js-driver-tarball.js +6 -6
- package/gen/gen-js-driver.js +23 -10
- package/gen/gen-ts-driver.js +15 -12
- package/gen.js +3 -4
- package/help.js +14 -14
- package/init/init-json.js +104 -0
- package/init/init-netcore.js +32 -0
- package/init.js +4 -108
- package/master-file/master-file.js +11 -12
- package/mr.js +11 -9
- package/package.json +6 -6
- package/sonarqube.yml +18 -0
- package/update/tsCode.js +85 -0
- package/update.js +24 -0
|
@@ -27,7 +27,7 @@ function transformEntityFieldNode(field) {
|
|
|
27
27
|
if (!field.fields || typeof field.fields !== "object")
|
|
28
28
|
return;
|
|
29
29
|
|
|
30
|
-
for (
|
|
30
|
+
for (const fieldName in field.fields) {
|
|
31
31
|
transformEntityFieldNode(field.fields[fieldName]);
|
|
32
32
|
}
|
|
33
33
|
}
|
|
@@ -41,14 +41,14 @@ function transformViewNode(view) {
|
|
|
41
41
|
|
|
42
42
|
function mergeApiProject(totalProject, fragmentProject, options) {
|
|
43
43
|
if (totalProject.name != null && fragmentProject.name != null && fragmentProject.name != totalProject.name)
|
|
44
|
-
throw new Error(`Unable merge project '${fragmentProject.name}' into '${totalProject.name}`);
|
|
44
|
+
throw new Error(`Unable merge project '${fragmentProject.name}' into '${totalProject.name}'`);
|
|
45
45
|
if (totalProject.version != null && fragmentProject.version != null && fragmentProject.version != totalProject.version)
|
|
46
|
-
throw new Error(`Unable merge project '${fragmentProject.version}' into '${totalProject.version}`);
|
|
46
|
+
throw new Error(`Unable merge project '${fragmentProject.version}' into '${totalProject.version}'`);
|
|
47
47
|
|
|
48
48
|
if (fragmentProject.environmentVariables != null) {
|
|
49
49
|
totalProject.environmentVariables = totalProject.environmentVariables || {};
|
|
50
50
|
|
|
51
|
-
for (
|
|
51
|
+
for (const name in fragmentProject.environmentVariables) {
|
|
52
52
|
if (name in totalProject.environmentVariables) {
|
|
53
53
|
switch (options.environmentVariable.duplicateNameHandling) {
|
|
54
54
|
case "override":
|
|
@@ -70,7 +70,7 @@ function mergeApiProject(totalProject, fragmentProject, options) {
|
|
|
70
70
|
|
|
71
71
|
fragmentProject.entities.forEach(entity => {
|
|
72
72
|
|
|
73
|
-
|
|
73
|
+
const found = totalProject.entities.some((entityInTotal, i) => {
|
|
74
74
|
if (entityInTotal.name !== entity.name){
|
|
75
75
|
return false;
|
|
76
76
|
}
|
|
@@ -89,12 +89,11 @@ function mergeApiProject(totalProject, fragmentProject, options) {
|
|
|
89
89
|
return;
|
|
90
90
|
|
|
91
91
|
totalProject.entities.push(entity);
|
|
92
|
-
// console.log("add new entity: " + entity.name + "; totalProject.entities.length=" + totalProject.entities.length);
|
|
93
92
|
|
|
94
93
|
if (!entity.fields || typeof entity.fields !== "object")
|
|
95
94
|
return;
|
|
96
95
|
|
|
97
|
-
for (
|
|
96
|
+
for (const fieldName in entity.fields) {
|
|
98
97
|
transformEntityFieldNode(entity.fields[fieldName]);
|
|
99
98
|
}
|
|
100
99
|
});
|
|
@@ -103,7 +102,7 @@ function mergeApiProject(totalProject, fragmentProject, options) {
|
|
|
103
102
|
if (fragmentProject.views != null) {
|
|
104
103
|
totalProject.views = totalProject.views || {};
|
|
105
104
|
|
|
106
|
-
for (
|
|
105
|
+
for (const viewName in fragmentProject.views)
|
|
107
106
|
{
|
|
108
107
|
if (viewName in totalProject.views)
|
|
109
108
|
{
|
|
@@ -131,7 +130,7 @@ function mergeApiProject(totalProject, fragmentProject, options) {
|
|
|
131
130
|
}
|
|
132
131
|
|
|
133
132
|
|
|
134
|
-
for (
|
|
133
|
+
for (const name in fragmentProject) {
|
|
135
134
|
if (name === "environmentVariables" || name === "entities" || name === "views" || name === "$schema")
|
|
136
135
|
continue;
|
|
137
136
|
|
|
@@ -176,7 +175,7 @@ function processMasterFile(basePath, master) {
|
|
|
176
175
|
if (apiProject == null)
|
|
177
176
|
return null;
|
|
178
177
|
|
|
179
|
-
apiProject["$schema"] = "
|
|
178
|
+
apiProject["$schema"] = "https://schema.siten.vn/mushroom/project.json";
|
|
180
179
|
|
|
181
180
|
if (apiProject.entities == null)
|
|
182
181
|
apiProject.entities = [];
|
|
@@ -205,7 +204,7 @@ function processMasterFile(basePath, master) {
|
|
|
205
204
|
action.defaultSortings = action.sorting.split(',').map(f => {
|
|
206
205
|
const c = f.charAt(0);
|
|
207
206
|
return {
|
|
208
|
-
field: c === "+" || c === "-" ? f.
|
|
207
|
+
field: c === "+" || c === "-" ? f.substring(1) : f,
|
|
209
208
|
type: c === "-" ? "Desc" : "Asc"
|
|
210
209
|
}
|
|
211
210
|
});
|
|
@@ -216,7 +215,7 @@ function processMasterFile(basePath, master) {
|
|
|
216
215
|
action.allowSortings = action.allowSorting.split(',').map(f => {
|
|
217
216
|
const c = f.charAt(0);
|
|
218
217
|
return {
|
|
219
|
-
field: c === "+" || c === "-" ? f.
|
|
218
|
+
field: c === "+" || c === "-" ? f.substring(1) : f,
|
|
220
219
|
type: c === "-" ? "Desc" : c === "+" ? "Asc" : "Both"
|
|
221
220
|
}
|
|
222
221
|
});
|
package/mr.js
CHANGED
|
@@ -3,14 +3,15 @@
|
|
|
3
3
|
const init = require("./init.js");
|
|
4
4
|
const config = require("./config.js");
|
|
5
5
|
const gen = require("./gen.js");
|
|
6
|
+
const update = require("./update.js");
|
|
6
7
|
const help = require("./help.js");
|
|
7
8
|
|
|
8
|
-
const
|
|
9
|
+
const pkg = require("./package.json");
|
|
9
10
|
const checkUpdate = require("./check-update");
|
|
10
11
|
|
|
11
|
-
const versionGroup =
|
|
12
|
+
const versionGroup = pkg.version.match(/([^-]+)(-(\w+).*)?/);
|
|
12
13
|
const currentDistTag = versionGroup[3] ? versionGroup[3] : "latest";
|
|
13
|
-
console.log("Mushroom CLI version " +
|
|
14
|
+
console.log("Mushroom CLI version " + pkg.version);
|
|
14
15
|
|
|
15
16
|
async function run(args) {
|
|
16
17
|
let debugMode = false;
|
|
@@ -19,10 +20,8 @@ async function run(args) {
|
|
|
19
20
|
args = args.filter(arg => arg !== "--debug");
|
|
20
21
|
}
|
|
21
22
|
|
|
22
|
-
let noCheckUpdate = false;
|
|
23
23
|
let checkUpdateTask;
|
|
24
24
|
if (args.indexOf("--no-check-update") !== -1){
|
|
25
|
-
noCheckUpdate = true;
|
|
26
25
|
args = args.filter(arg => arg !== "--no-check-update");
|
|
27
26
|
checkUpdateTask = null;
|
|
28
27
|
}
|
|
@@ -37,11 +36,14 @@ async function run(args) {
|
|
|
37
36
|
await init(args);
|
|
38
37
|
break;
|
|
39
38
|
case "config":
|
|
40
|
-
|
|
39
|
+
config(args);
|
|
41
40
|
break;
|
|
42
41
|
case "gen":
|
|
43
42
|
await gen(args);
|
|
44
43
|
break;
|
|
44
|
+
case "update":
|
|
45
|
+
await update(args);
|
|
46
|
+
break;
|
|
45
47
|
case "":
|
|
46
48
|
case undefined:
|
|
47
49
|
console.log(`Mushroom CLI`);
|
|
@@ -62,9 +64,9 @@ async function run(args) {
|
|
|
62
64
|
|
|
63
65
|
if (checkUpdateTask !== null)
|
|
64
66
|
try {
|
|
65
|
-
|
|
66
|
-
if (data["dist-tags"] && data["dist-tags"][currentDistTag] && data["dist-tags"][currentDistTag] !==
|
|
67
|
-
console.warn(`YOUR mushroom-cli VERSION IS NOT LATEST (dist-tags: ${currentDistTag}). PLEASE RUN: npm i mushroom-cli@${data["dist-tags"][currentDistTag]}`);
|
|
67
|
+
const data = await checkUpdateTask;
|
|
68
|
+
if (data["dist-tags"] && data["dist-tags"][currentDistTag] && data["dist-tags"][currentDistTag] !== pkg.version) {
|
|
69
|
+
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]}`);
|
|
68
70
|
}
|
|
69
71
|
}
|
|
70
72
|
catch(e) {
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mushroom-cli",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"description": "Mushroom CLI",
|
|
5
5
|
"main": "mr.js",
|
|
6
6
|
"scripts": {
|
|
7
|
-
"release": "npm publish --access public
|
|
7
|
+
"release": "npm publish --access public"
|
|
8
8
|
},
|
|
9
9
|
"keywords": [
|
|
10
10
|
"Mushroom",
|
|
@@ -17,10 +17,10 @@
|
|
|
17
17
|
"author": "suco2007",
|
|
18
18
|
"license": "ISC",
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"jsdom": "^
|
|
21
|
-
"json5": "^2.
|
|
22
|
-
"node-fetch": "^2.6.
|
|
23
|
-
"open": "^
|
|
20
|
+
"jsdom": "^24.1.1",
|
|
21
|
+
"json5": "^2.2.3",
|
|
22
|
+
"node-fetch": "^2.6.7",
|
|
23
|
+
"open": "^8.4.0",
|
|
24
24
|
"readline-sync": "^1.4.10",
|
|
25
25
|
"targz": "^1.0.1"
|
|
26
26
|
}
|
package/sonarqube.yml
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
pool:
|
|
2
|
+
name: SitenWindows
|
|
3
|
+
|
|
4
|
+
steps:
|
|
5
|
+
- task: SonarQubePrepare@6
|
|
6
|
+
inputs:
|
|
7
|
+
SonarQube: 'SonarQube-MushroomCLI'
|
|
8
|
+
scannerMode: 'CLI'
|
|
9
|
+
configMode: 'manual'
|
|
10
|
+
cliProjectKey: 'MushroomServer_mushroom-cli_AZBIWpTNDwLpW4gwuNzH'
|
|
11
|
+
cliProjectName: 'mushroom-cli'
|
|
12
|
+
cliSources: '.'
|
|
13
|
+
|
|
14
|
+
- task: SonarQubeAnalyze@6
|
|
15
|
+
|
|
16
|
+
- task: SonarQubePublish@6
|
|
17
|
+
inputs:
|
|
18
|
+
pollingTimeoutSec: '300'
|
package/update/tsCode.js
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
const fs = require("fs");
|
|
2
|
+
const fetch = require('node-fetch');
|
|
3
|
+
|
|
4
|
+
async function updateTsCode(options) {
|
|
5
|
+
if (options.input || options.output) {
|
|
6
|
+
// legacy way
|
|
7
|
+
if (!options.output) {
|
|
8
|
+
console.error("Missing output file path");
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
if (!options.input) {
|
|
12
|
+
console.error("Missing remote url");
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
pullAsync(options.input, output);
|
|
16
|
+
console.log("Finish update ts-code");
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// new way, using mushroom-config.json file
|
|
21
|
+
if (!fs.existsSync("mushroom-config.json")) {
|
|
22
|
+
console.error("Missing mushroom-config.json file");
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
const configJson = fs.readFileSync("mushroom-config.json");
|
|
26
|
+
const config = JSON.parse(configJson);
|
|
27
|
+
if (!config.update) {
|
|
28
|
+
console.error("Missing 'update' in mushroom-config.json file");
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
if (!config.update["ts-code"]) {
|
|
32
|
+
console.error("Missing 'update.ts-code' in mushroom-config.json file");
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const steps = config.update["ts-code"].steps;
|
|
37
|
+
if (!steps) {
|
|
38
|
+
console.error("Missing 'update.ts-code.steps' in mushroom-config.json file");
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
for (let i = 0; i < steps.length; i++) {
|
|
43
|
+
const step = steps[i];
|
|
44
|
+
switch (step.action) {
|
|
45
|
+
case "pull":
|
|
46
|
+
await pullAsync(step.source, step.destination);
|
|
47
|
+
break;
|
|
48
|
+
case "replace-content":
|
|
49
|
+
replaceContent(step.source, step.search, step.replacement);
|
|
50
|
+
break;
|
|
51
|
+
case "replace-regex":
|
|
52
|
+
replaceContent(step.source, step.pattern, step.replacement);
|
|
53
|
+
break;
|
|
54
|
+
default:
|
|
55
|
+
console.warn(`Unsupported step action: ${step.action}`);
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
console.log("Finish update ts-code");
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
async function pullAsync(input, output) {
|
|
63
|
+
console.log(`Fetch ${input}`);
|
|
64
|
+
const res = await fetch(input);
|
|
65
|
+
console.log(`Write to ${output}`);
|
|
66
|
+
fs.writeFileSync(output, await res.text());
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function replaceContent(input, search, replacement) {
|
|
70
|
+
console.log(`Replace ${search} by ${replacement} in ${input} file`);
|
|
71
|
+
const content = fs.readFileSync(input).toString();
|
|
72
|
+
if (!content) return;
|
|
73
|
+
const output = content.replace(new RegExp(search.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), "g"), replacement);
|
|
74
|
+
fs.writeFileSync(input, output);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function replaceRegex(input, pattern, replacement) {
|
|
78
|
+
console.log(`Replace pattern ${pattern} by ${replacement} in ${input} file`);
|
|
79
|
+
const content = fs.readFileSync(input).toString();
|
|
80
|
+
if (!content) return;
|
|
81
|
+
const output = content.replace(new RegExp(pattern, "g"), replacement);
|
|
82
|
+
fs.writeFileSync(input, output);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
module.exports = updateTsCode;
|
package/update.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
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;
|