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/gen/gen-api-docs.js
CHANGED
|
@@ -1,125 +1,157 @@
|
|
|
1
|
-
const fs = require("fs");
|
|
2
|
-
const open = require("open");
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
const
|
|
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
|
-
window.
|
|
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
|
-
|
|
1
|
+
const fs = require("fs");
|
|
2
|
+
const open = require("open");
|
|
3
|
+
const jsdom = require("jsdom");
|
|
4
|
+
const { JSDOM } = jsdom;
|
|
5
|
+
const common = require("../common.js");
|
|
6
|
+
|
|
7
|
+
function processGenDocs(
|
|
8
|
+
aliasProject,
|
|
9
|
+
entities,
|
|
10
|
+
source,
|
|
11
|
+
html,
|
|
12
|
+
args,
|
|
13
|
+
projectName,
|
|
14
|
+
alias,
|
|
15
|
+
) {
|
|
16
|
+
console.log("Received html");
|
|
17
|
+
console.log("Parsing html");
|
|
18
|
+
|
|
19
|
+
const roles = aliasProject.allowRoles.includes("*")
|
|
20
|
+
? source.roles
|
|
21
|
+
: source.roles?.filter((r) => aliasProject.allowRoles.includes(r.name));
|
|
22
|
+
|
|
23
|
+
html = html.replace(/^\uFEFF/, "");
|
|
24
|
+
html = html.replace(
|
|
25
|
+
/<script src="([^"]+)" data-mt-cond='\{"lazy-load": 1\}'><\/script>/g,
|
|
26
|
+
(scriptTag, src) =>
|
|
27
|
+
`<script data-mt-cond='{"x": 1}'>${fs.readFileSync(__dirname + "/../docs/" + src).toString()}</script>`,
|
|
28
|
+
);
|
|
29
|
+
html = html.replace(
|
|
30
|
+
"</body>",
|
|
31
|
+
`<script data-mt-cond='{"x": 1}'>
|
|
32
|
+
window.data.name = ${JSON.stringify(source.name)};
|
|
33
|
+
window.data.description = ${JSON.stringify(source.description)};
|
|
34
|
+
window.data.rootUrl = ${JSON.stringify(common.getRootUrl(source))};
|
|
35
|
+
window.data.environmentVariables = ${JSON.stringify(source.environmentVariables)};
|
|
36
|
+
window.data.roles = ${JSON.stringify(roles)};
|
|
37
|
+
window.data.entities = ${JSON.stringify(entities)};
|
|
38
|
+
window.data.features = ${JSON.stringify(aliasProject.features)};
|
|
39
|
+
try {
|
|
40
|
+
console.info("MUSHROOM-CLI: START");
|
|
41
|
+
window.generateDocument();
|
|
42
|
+
console.info("MUSHROOM-CLI: FINISH");
|
|
43
|
+
}
|
|
44
|
+
catch (e) {
|
|
45
|
+
console.info("MUSHROOM-CLI: FAIL", e);
|
|
46
|
+
}
|
|
47
|
+
window.close();
|
|
48
|
+
</script></body>`,
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
return new Promise((resolve, reject) => {
|
|
52
|
+
const virtualConsole = new jsdom.VirtualConsole();
|
|
53
|
+
virtualConsole.on("info", function (msg, err) {
|
|
54
|
+
if (typeof msg != "string") return;
|
|
55
|
+
|
|
56
|
+
if (msg.indexOf("MUSHROOM-CLI:") === 0) {
|
|
57
|
+
console.log("GenDocEngine:" + msg.substring("MUSHROOM-CLI:".length));
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (msg === "MUSHROOM-CLI: FAIL") {
|
|
61
|
+
dom = null;
|
|
62
|
+
reject(err);
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (msg !== "MUSHROOM-CLI: FINISH") return;
|
|
67
|
+
|
|
68
|
+
const code =
|
|
69
|
+
"<!DOCTYPE html>" + dom.window.document.documentElement.outerHTML;
|
|
70
|
+
|
|
71
|
+
dom = null;
|
|
72
|
+
|
|
73
|
+
if (args[3] === "tmp") {
|
|
74
|
+
const htmlFilePath = aliasProject.output + "_tmp.html";
|
|
75
|
+
console.log(`Writing to ${htmlFilePath}`);
|
|
76
|
+
fs.writeFile(htmlFilePath, code, (err) => {
|
|
77
|
+
if (err) {
|
|
78
|
+
reject(err);
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
console.log("Opening file " + htmlFilePath);
|
|
83
|
+
open(htmlFilePath)
|
|
84
|
+
.then(() => {
|
|
85
|
+
setTimeout(() => {
|
|
86
|
+
fs.unlink(htmlFilePath, (ex) => {
|
|
87
|
+
if (ex)
|
|
88
|
+
console.error("Unable to delete file " + htmlFilePath);
|
|
89
|
+
});
|
|
90
|
+
}, 1000);
|
|
91
|
+
})
|
|
92
|
+
.catch(() => console.error("Unable to open " + htmlFilePath));
|
|
93
|
+
resolve();
|
|
94
|
+
});
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
common.ensureFolder(aliasProject.output);
|
|
99
|
+
|
|
100
|
+
console.log(`Writing to ${aliasProject.output}`);
|
|
101
|
+
fs.writeFile(aliasProject.output, code, (err) => {
|
|
102
|
+
if (err) {
|
|
103
|
+
reject(err);
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
console.log(
|
|
107
|
+
`Generated API docs for ${projectName}@${alias} to ${aliasProject.output}`,
|
|
108
|
+
);
|
|
109
|
+
resolve();
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
let dom = new JSDOM(html, {
|
|
114
|
+
runScripts: "dangerously",
|
|
115
|
+
resources: "usable",
|
|
116
|
+
virtualConsole: virtualConsole,
|
|
117
|
+
});
|
|
118
|
+
console.log("Rendering API document");
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
async function genDocs(args, projectName, project, alias, source) {
|
|
123
|
+
const aliasProject = ((project.docs || {}).alias || {})[alias];
|
|
124
|
+
|
|
125
|
+
if (!aliasProject) {
|
|
126
|
+
throw new Error(
|
|
127
|
+
`Not found gen docs configuration. Please run 'npx mushroom-cli config ${projectName} gen docs OUTPUT_FILE.html${alias === "default" ? "" : " alias " + alias}' first`,
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
const entities = common.getEntities(source, aliasProject.allowRoles);
|
|
132
|
+
|
|
133
|
+
if (Array.isArray(aliasProject.entities)) {
|
|
134
|
+
for (const entityName in entities) {
|
|
135
|
+
if (Object.hasOwnProperty.call(entities, entityName)) {
|
|
136
|
+
if (
|
|
137
|
+
aliasProject.entities.every((re) => !new RegExp(re).test(entityName))
|
|
138
|
+
) {
|
|
139
|
+
delete entities[entityName];
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
const html = fs.readFileSync(__dirname + "/../docs/docs.html").toString();
|
|
146
|
+
await processGenDocs(
|
|
147
|
+
aliasProject,
|
|
148
|
+
entities,
|
|
149
|
+
source,
|
|
150
|
+
html,
|
|
151
|
+
args,
|
|
152
|
+
projectName,
|
|
153
|
+
alias,
|
|
154
|
+
);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
module.exports = genDocs;
|