mushroom-cli 1.2.0-alpha.1 → 1.2.0-alpha.10
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 +136 -20
- package/common.js +38 -1
- package/docs/doc-mt.js +103 -1
- package/docs/docs.html +83 -22
- package/docs/docs.v2.html +5066 -0
- package/docs/docs.v2.js +1563 -0
- package/gen/gen-api-docs-v1.js +125 -0
- package/gen/gen-api-docs.js +261 -88
- package/gen/gen-csharp.js +4 -19
- package/gen/gen-ts-driver.js +16 -5
- package/gen.js +5 -1
- package/merge.js +84 -0
- package/mr.js +81 -77
- package/package.json +6 -4
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,78 +1,82 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
const init = require("./init
|
|
4
|
-
const config = require("./config
|
|
5
|
-
const gen = require("./gen
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
checkUpdateTask
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
case "
|
|
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
|
-
|
|
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;
|
|
78
82
|
run(args);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mushroom-cli",
|
|
3
|
-
"version": "1.2.0-alpha.
|
|
3
|
+
"version": "1.2.0-alpha.10",
|
|
4
4
|
"description": "Mushroom CLI",
|
|
5
5
|
"main": "mr.js",
|
|
6
6
|
"scripts": {
|
|
@@ -16,11 +16,13 @@
|
|
|
16
16
|
},
|
|
17
17
|
"author": "suco2007",
|
|
18
18
|
"license": "ISC",
|
|
19
|
+
"dependencies-comments": "node-fetch: 2.x; open: 8.x; minify: 7.x",
|
|
19
20
|
"dependencies": {
|
|
20
|
-
"jsdom": "^
|
|
21
|
+
"jsdom": "^24.1.1",
|
|
21
22
|
"json5": "^2.2.3",
|
|
22
|
-
"
|
|
23
|
-
"
|
|
23
|
+
"minify": "7.2.2",
|
|
24
|
+
"node-fetch": "^2.6.11",
|
|
25
|
+
"open": "^8.4.2",
|
|
24
26
|
"readline-sync": "^1.4.10",
|
|
25
27
|
"targz": "^1.0.1"
|
|
26
28
|
}
|