mushroom-cli 1.1.0-alpha.2 → 1.1.0-alpha.21
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 +30 -22
- package/check-update.js +1 -1
- package/common.js +109 -5
- package/config.js +8 -8
- package/docs/doc-mt.js +421 -0
- package/docs/docs.html +5129 -0
- package/docs/mt-dom-1.0.js +1268 -0
- package/docs/mt.extension.js +174 -0
- package/gen/gen-api-docs.js +15 -5
- package/gen/gen-csharp.js +557 -50
- package/gen/gen-db-docs.js +1 -1
- package/gen/gen-js-driver-tarball.js +17 -5
- package/gen/gen-js-driver.js +38 -7
- package/gen/gen-ts-driver.js +67 -22
- package/gen.js +2 -2
- package/help.js +14 -14
- package/init/init-json.js +106 -0
- package/init/init-netcore.js +32 -0
- package/init.js +4 -108
- package/master-file/master-file.js +2 -2
- package/mr.js +11 -5
- package/package.json +5 -5
- package/update/tsCode.js +20 -0
- package/update.js +24 -0
package/init.js
CHANGED
|
@@ -1,120 +1,16 @@
|
|
|
1
|
-
const fs = require("fs");
|
|
2
|
-
const fetch = require('node-fetch');
|
|
3
|
-
const readlineSync = require("readline-sync");
|
|
4
1
|
const help = require("./help.js");
|
|
5
|
-
const common = require("./common.js");
|
|
6
2
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
if (!path) {
|
|
10
|
-
help(args);
|
|
11
|
-
return;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
if (fs.existsSync(path)){
|
|
15
|
-
console.error(`File ${path} is already existed`);
|
|
16
|
-
return;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
if (args[3] === "silent") {
|
|
20
|
-
console.log("Fetch http://api.siten.vn/gen/template/default.json");
|
|
21
|
-
fetch("http://api.siten.vn/gen/template/default.json").then(res => res.text()).then(text => {
|
|
22
|
-
common.ensureFolder(path);
|
|
23
|
-
|
|
24
|
-
fs.writeFile(path, text, err => {
|
|
25
|
-
if (err)
|
|
26
|
-
throw err;
|
|
27
|
-
console.log(`Initialized json at ${path}`);
|
|
28
|
-
});
|
|
29
|
-
});
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
console.log("Fetch http://api.siten.vn/gen/template/template-def.json");
|
|
34
|
-
fetch("http://api.siten.vn/gen/template/template-def.json").then(res => res.json()).then(templateConfig => {
|
|
35
|
-
const info = {};
|
|
36
|
-
templateConfig.fields.forEach(field => {
|
|
37
|
-
while (true)
|
|
38
|
-
{
|
|
39
|
-
let question = `${field.required ? "[Required] " : ""}${field.label || field.name}`;
|
|
40
|
-
if (Array.isArray(field.list)) {
|
|
41
|
-
question += "\n";
|
|
42
|
-
let i = 1;
|
|
43
|
-
field.list.forEach(item => { question += "\t" + i++ + ". " + item + "\n"; });
|
|
44
|
-
question += "Please choose";
|
|
45
|
-
}
|
|
46
|
-
if (field.defaultValue !== undefined) {
|
|
47
|
-
question += ` (default: '${field.defaultValue}')`;
|
|
48
|
-
}
|
|
49
|
-
question += ": ";
|
|
50
|
-
let choice = readlineSync.question(question);
|
|
51
|
-
if (choice === "") {
|
|
52
|
-
if (field.defaultValue != undefined)
|
|
53
|
-
choice = field.defaultValue;
|
|
54
|
-
}
|
|
55
|
-
else if (Array.isArray(field.list)) {
|
|
56
|
-
if (choice !== null && choice !== "" && !isNaN(choice))
|
|
57
|
-
choice = field.list[choice - 1];
|
|
58
|
-
else
|
|
59
|
-
choice = undefined;
|
|
60
|
-
if (choice === undefined) {
|
|
61
|
-
console.warn("Invalid input");
|
|
62
|
-
continue;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
if (choice === "" || choice === undefined || choice == null) {
|
|
67
|
-
choice = "";
|
|
68
|
-
|
|
69
|
-
if (field.required) {
|
|
70
|
-
console.warn("Required input value");
|
|
71
|
-
continue;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
if (choice !== "" && field.pattern) {
|
|
76
|
-
const re = new RegExp(field.pattern, field.patternFlags);
|
|
77
|
-
if (!re.test(choice)) {
|
|
78
|
-
console.warn("Input doesn't match with pattern " + field.pattern);
|
|
79
|
-
continue;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
info[field.name] = choice;
|
|
84
|
-
break;
|
|
85
|
-
}
|
|
86
|
-
});
|
|
87
|
-
//console.log(info);
|
|
88
|
-
|
|
89
|
-
console.log(`Fetch ${templateConfig.templateUrl}`);
|
|
90
|
-
fetch(templateConfig.templateUrl).then(res => res.text()).then(json => {
|
|
91
|
-
json = json.replace(/\"\$\{([\w]+)\}\"/g, (s0, s1) => JSON.stringify(info[s1]));
|
|
92
|
-
json = json.replace(/\$\{([\w]+)\}/g, (s0, s1) => JSON.stringify(info[s1]).replace(/^\"|\"$/g, ""));
|
|
93
|
-
|
|
94
|
-
common.ensureFolder(path);
|
|
95
|
-
//console.log(json);
|
|
96
|
-
|
|
97
|
-
fs.writeFile(path, json, err => {
|
|
98
|
-
if (err)
|
|
99
|
-
throw err;
|
|
100
|
-
console.log(`Initialized json at ${path}`);
|
|
101
|
-
});
|
|
102
|
-
});
|
|
103
|
-
})
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
function initNetCore(args) {
|
|
107
|
-
console.log("init netcore is comming soon");
|
|
108
|
-
}
|
|
3
|
+
const initJson = require("./init/init-json");
|
|
4
|
+
const initNetCore = require("./init/init-netcore");
|
|
109
5
|
|
|
110
|
-
function init(args) {
|
|
6
|
+
async function init(args) {
|
|
111
7
|
const configCommand = args[1];
|
|
112
8
|
switch(configCommand) {
|
|
113
9
|
case "json":
|
|
114
10
|
initJson(args);
|
|
115
11
|
break;
|
|
116
12
|
case "netcore":
|
|
117
|
-
initNetCore(args);
|
|
13
|
+
await initNetCore(args);
|
|
118
14
|
break;
|
|
119
15
|
case "":
|
|
120
16
|
case undefined:
|
|
@@ -205,7 +205,7 @@ function processMasterFile(basePath, master) {
|
|
|
205
205
|
action.defaultSortings = action.sorting.split(',').map(f => {
|
|
206
206
|
const c = f.charAt(0);
|
|
207
207
|
return {
|
|
208
|
-
field: c === "+" || c === "-" ? f.
|
|
208
|
+
field: c === "+" || c === "-" ? f.substring(1) : f,
|
|
209
209
|
type: c === "-" ? "Desc" : "Asc"
|
|
210
210
|
}
|
|
211
211
|
});
|
|
@@ -216,7 +216,7 @@ function processMasterFile(basePath, master) {
|
|
|
216
216
|
action.allowSortings = action.allowSorting.split(',').map(f => {
|
|
217
217
|
const c = f.charAt(0);
|
|
218
218
|
return {
|
|
219
|
-
field: c === "+" || c === "-" ? f.
|
|
219
|
+
field: c === "+" || c === "-" ? f.substring(1) : f,
|
|
220
220
|
type: c === "-" ? "Desc" : c === "+" ? "Asc" : "Both"
|
|
221
221
|
}
|
|
222
222
|
});
|
package/mr.js
CHANGED
|
@@ -3,11 +3,16 @@
|
|
|
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
|
|
|
12
|
+
const versionGroup = pkg.version.match(/([^-]+)(-(\w+).*)?/);
|
|
13
|
+
const currentDistTag = versionGroup[3] ? versionGroup[3] : "latest";
|
|
14
|
+
console.log("Mushroom CLI version " + pkg.version);
|
|
15
|
+
|
|
11
16
|
async function run(args) {
|
|
12
17
|
let debugMode = false;
|
|
13
18
|
if (args.indexOf("--debug") !== -1) {
|
|
@@ -15,10 +20,8 @@ async function run(args) {
|
|
|
15
20
|
args = args.filter(arg => arg !== "--debug");
|
|
16
21
|
}
|
|
17
22
|
|
|
18
|
-
let noCheckUpdate = false;
|
|
19
23
|
let checkUpdateTask;
|
|
20
24
|
if (args.indexOf("--no-check-update") !== -1){
|
|
21
|
-
noCheckUpdate = true;
|
|
22
25
|
args = args.filter(arg => arg !== "--no-check-update");
|
|
23
26
|
checkUpdateTask = null;
|
|
24
27
|
}
|
|
@@ -38,6 +41,9 @@ async function run(args) {
|
|
|
38
41
|
case "gen":
|
|
39
42
|
await gen(args);
|
|
40
43
|
break;
|
|
44
|
+
case "update":
|
|
45
|
+
await update(args);
|
|
46
|
+
break;
|
|
41
47
|
case "":
|
|
42
48
|
case undefined:
|
|
43
49
|
console.log(`Mushroom CLI`);
|
|
@@ -59,8 +65,8 @@ async function run(args) {
|
|
|
59
65
|
if (checkUpdateTask !== null)
|
|
60
66
|
try {
|
|
61
67
|
var data = await checkUpdateTask;
|
|
62
|
-
if (data
|
|
63
|
-
console.warn(
|
|
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]}`);
|
|
64
70
|
}
|
|
65
71
|
}
|
|
66
72
|
catch(e) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mushroom-cli",
|
|
3
|
-
"version": "1.1.0-alpha.
|
|
3
|
+
"version": "1.1.0-alpha.21",
|
|
4
4
|
"description": "Mushroom CLI",
|
|
5
5
|
"main": "mr.js",
|
|
6
6
|
"scripts": {
|
|
@@ -17,10 +17,10 @@
|
|
|
17
17
|
"author": "suco2007",
|
|
18
18
|
"license": "ISC",
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"jsdom": "^
|
|
21
|
-
"json5": "^2.1
|
|
22
|
-
"node-fetch": "^2.6.
|
|
23
|
-
"open": "^
|
|
20
|
+
"jsdom": "^20.0.0",
|
|
21
|
+
"json5": "^2.2.1",
|
|
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/update/tsCode.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
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
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;
|