mushroom-cli 1.2.0-alpha.7 → 1.2.0-alpha.8
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 +10 -2
- package/common.js +12 -0
- package/docs/docs.v2.html +6616 -0
- package/gen/gen-api-docs-v1.js +125 -0
- package/gen/gen-api-docs.js +222 -88
- package/gen.js +5 -1
- package/mr.js +4 -0
- package/package.json +3 -2
|
@@ -0,0 +1,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(aliasProject, entities, source, html, args, projectName, alias) {
|
|
8
|
+
console.log('Received html');
|
|
9
|
+
console.log("Parsing html");
|
|
10
|
+
|
|
11
|
+
const roles = aliasProject.allowRoles.includes("*") ? source.roles : source.roles?.filter(r => aliasProject.allowRoles.includes(r.name));
|
|
12
|
+
|
|
13
|
+
html = html.replace(/^\uFEFF/, '');
|
|
14
|
+
html = html.replace(/<script src="([^"]+)" data-mt-cond='\{"lazy-load": 1\}'><\/script>/g, (scriptTag, src) => `<script data-mt-cond='{"x": 1}'>${fs.readFileSync(__dirname + "/../docs/" + src).toString()}</script>`);
|
|
15
|
+
html = html.replace("</body>", `<script data-mt-cond='{"x": 1}'>
|
|
16
|
+
window.data.name = ${JSON.stringify(source.name)};
|
|
17
|
+
window.data.description = ${JSON.stringify(source.description)};
|
|
18
|
+
window.data.rootUrl = ${JSON.stringify(common.getRootUrl(source))};
|
|
19
|
+
window.data.environmentVariables = ${JSON.stringify(source.environmentVariables)};
|
|
20
|
+
window.data.roles = ${JSON.stringify(roles)};
|
|
21
|
+
window.data.entities = ${JSON.stringify(entities)};
|
|
22
|
+
window.data.features = ${JSON.stringify(aliasProject.features)};
|
|
23
|
+
try {
|
|
24
|
+
console.info("MUSHROOM-CLI: START");
|
|
25
|
+
window.generateDocument();
|
|
26
|
+
console.info("MUSHROOM-CLI: FINISH");
|
|
27
|
+
}
|
|
28
|
+
catch (e) {
|
|
29
|
+
console.info("MUSHROOM-CLI: FAIL", e);
|
|
30
|
+
}
|
|
31
|
+
window.close();
|
|
32
|
+
</script></body>`);
|
|
33
|
+
|
|
34
|
+
return new Promise((resolve, reject) => {
|
|
35
|
+
const virtualConsole = new jsdom.VirtualConsole();
|
|
36
|
+
virtualConsole.on("info", function(msg, err) {
|
|
37
|
+
if (typeof msg != "string") return;
|
|
38
|
+
|
|
39
|
+
if (msg.indexOf("MUSHROOM-CLI:") === 0) {
|
|
40
|
+
console.log("GenDocEngine:" + msg.substring("MUSHROOM-CLI:".length));
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (msg === "MUSHROOM-CLI: FAIL"){
|
|
44
|
+
dom = null;
|
|
45
|
+
reject(err);
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (msg !== "MUSHROOM-CLI: FINISH") return;
|
|
50
|
+
|
|
51
|
+
const code = "<!DOCTYPE html>" + dom.window.document.documentElement.outerHTML;
|
|
52
|
+
|
|
53
|
+
dom = null;
|
|
54
|
+
|
|
55
|
+
if (args[3] === "tmp") {
|
|
56
|
+
const htmlFilePath = aliasProject.output + "_tmp.html";
|
|
57
|
+
console.log(`Writing to ${htmlFilePath}`);
|
|
58
|
+
fs.writeFile(htmlFilePath, code, err => {
|
|
59
|
+
if (err) {
|
|
60
|
+
reject(err);
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
console.log("Opening file " + htmlFilePath);
|
|
65
|
+
open(htmlFilePath).then(() => {
|
|
66
|
+
setTimeout(() => {
|
|
67
|
+
fs.unlink(htmlFilePath, ex => {
|
|
68
|
+
if (ex)
|
|
69
|
+
console.error("Unable to delete file " + htmlFilePath)
|
|
70
|
+
});
|
|
71
|
+
}, 1000);
|
|
72
|
+
}).catch(() => console.error("Unable to open " + htmlFilePath));
|
|
73
|
+
resolve();
|
|
74
|
+
});
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
common.ensureFolder(aliasProject.output);
|
|
79
|
+
|
|
80
|
+
console.log(`Writing to ${aliasProject.output}`);
|
|
81
|
+
fs.writeFile(aliasProject.output, code, err => {
|
|
82
|
+
if (err) {
|
|
83
|
+
reject(err);
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
console.log(`Generated API docs for ${projectName}@${alias} to ${aliasProject.output}`);
|
|
87
|
+
resolve();
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
let dom = new JSDOM(html, {
|
|
92
|
+
runScripts: "dangerously",
|
|
93
|
+
resources: "usable",
|
|
94
|
+
virtualConsole: virtualConsole
|
|
95
|
+
});
|
|
96
|
+
console.log('Rendering API document');
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
async function genDocs(args, projectName, project, alias, source) {
|
|
101
|
+
const aliasProject = ((project.docs || {}).alias || {})[alias];
|
|
102
|
+
|
|
103
|
+
if (!aliasProject) {
|
|
104
|
+
throw new Error(`Not found gen docs configuration. Please run 'npx mushroom-cli config ${projectName} gen docs OUTPUT_FILE.html${alias === "default" ? "" : " alias " + alias}' first`);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
console.log("Use GenDocEngine v1");
|
|
108
|
+
|
|
109
|
+
const entities = common.getEntities(source, aliasProject.allowRoles);
|
|
110
|
+
|
|
111
|
+
if (Array.isArray(aliasProject.entities)) {
|
|
112
|
+
for (const entityName in entities) {
|
|
113
|
+
if (Object.hasOwnProperty.call(entities, entityName)) {
|
|
114
|
+
if (aliasProject.entities.every(re => !new RegExp(re).test(entityName))){
|
|
115
|
+
delete entities[entityName];
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
const html = fs.readFileSync(__dirname + "/../docs/docs.html").toString();
|
|
122
|
+
await processGenDocs(aliasProject, entities, source, html, args, projectName, alias);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
module.exports = genDocs;
|
package/gen/gen-api-docs.js
CHANGED
|
@@ -1,101 +1,187 @@
|
|
|
1
1
|
const fs = require("fs");
|
|
2
2
|
const open = require("open");
|
|
3
|
-
const fetch = require('node-fetch');
|
|
4
|
-
const jsdom = require("jsdom");
|
|
5
|
-
const { JSDOM } = jsdom;
|
|
6
3
|
const common = require("../common.js");
|
|
7
4
|
|
|
8
|
-
function
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const roles = aliasProject.allowRoles.includes("*") ? source.roles : source.roles?.filter(r => aliasProject.allowRoles.includes(r.name));
|
|
13
|
-
|
|
14
|
-
html = html.replace(/^\uFEFF/, '');
|
|
15
|
-
html = html.replace(/<script src="([^"]+)" data-mt-cond='\{"lazy-load": 1\}'><\/script>/g, (scriptTag, src) => `<script data-mt-cond='{"x": 1}'>${fs.readFileSync(__dirname + "/../docs/" + src).toString()}</script>`);
|
|
16
|
-
html = html.replace("</body>", `<script data-mt-cond='{"x": 1}'>
|
|
17
|
-
window.data.name = ${JSON.stringify(source.name)};
|
|
18
|
-
window.data.description = ${JSON.stringify(source.description)};
|
|
19
|
-
window.data.rootUrl = ${JSON.stringify(common.getRootUrl(source))};
|
|
20
|
-
window.data.environmentVariables = ${JSON.stringify(source.environmentVariables)};
|
|
21
|
-
window.data.roles = ${JSON.stringify(roles)};
|
|
22
|
-
window.data.entities = ${JSON.stringify(entities)};
|
|
23
|
-
window.data.features = ${JSON.stringify(aliasProject.features)};
|
|
24
|
-
try {
|
|
25
|
-
console.info("MUSHROOM-CLI: START");
|
|
26
|
-
window.generateDocument();
|
|
27
|
-
console.info("MUSHROOM-CLI: FINISH");
|
|
5
|
+
function reserveWhitelist(obj, whitelist) {
|
|
6
|
+
if (obj === null && typeof obj !== "object") return null;
|
|
7
|
+
for (let m in obj) {
|
|
8
|
+
if (!whitelist.includes(m)) delete obj[m];
|
|
28
9
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
window.close();
|
|
33
|
-
</script></body>`);
|
|
10
|
+
return obj;
|
|
11
|
+
}
|
|
34
12
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
13
|
+
const environmentVariableWhitelist = ["type", "description"];
|
|
14
|
+
function filterEnvironmentVariables(environmentVariables) {
|
|
15
|
+
Object.values(environmentVariables).forEach(env => reserveWhitelist(env, environmentVariableWhitelist));
|
|
16
|
+
}
|
|
39
17
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
18
|
+
const entityWhitelist = ["name", "description", "actions", "views", "features", "fields"];
|
|
19
|
+
const actionWhitelist = ["grant", "deny", "matches", "description", "exclude"];
|
|
20
|
+
const findByIdWhitelist = [ ...actionWhitelist, "returnableFields", "defaultFields"];
|
|
21
|
+
const findManyWhitelist = [ ...findByIdWhitelist, "allowFilteringFields", "requiredFilteringFields", "allowSortings", "defaultSortings", "pagingType", "maxPageSize", "pageSize", "includeTotal", "cache"];
|
|
22
|
+
const generalWhitelist = [ ...actionWhitelist, "codeHint" ];
|
|
23
|
+
const entityFeatureWhitelist = ["vn_text"];
|
|
24
|
+
const vnTextWhitelist = ["fields", "channels"];
|
|
25
|
+
const vnTextChannelWhitelist = ["fields", "name"];
|
|
26
|
+
const actionCodeHintWhitelist = ["delegator"];
|
|
27
|
+
const actionCodeHintDelegatorWhitelist = ["param", "requestBody"];
|
|
28
|
+
const fieldsOnlyWhitelist = ["fields"];
|
|
29
|
+
const viewWhitelist = [ "grant", "deny", "description", "parameters", "emptyResult", "codeHint"]
|
|
30
|
+
const viewCodeHintWhitelist = ["output"];
|
|
43
31
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
32
|
+
function filterEntities(entities) {
|
|
33
|
+
Object.values(entities).forEach(entity => {
|
|
34
|
+
filterEntityFields(entity);
|
|
35
|
+
if (!reserveWhitelist(entity, entityWhitelist)) return;
|
|
36
|
+
Object.keys(entity.actions).forEach(actionName => {
|
|
37
|
+
const actions = entity.actions[actionName];
|
|
38
|
+
switch (actionName) {
|
|
39
|
+
case "findMany":
|
|
40
|
+
actions.forEach(action => reserveWhitelist(action, findManyWhitelist));
|
|
41
|
+
break;
|
|
42
|
+
case "findById":
|
|
43
|
+
actions.forEach(action => reserveWhitelist(action, findByIdWhitelist));
|
|
44
|
+
break;
|
|
45
|
+
case "createOne":
|
|
46
|
+
case "createMany":
|
|
47
|
+
case "updateOne":
|
|
48
|
+
case "updateMany":
|
|
49
|
+
case "updatePartially":
|
|
50
|
+
case "deleteOne":
|
|
51
|
+
case "deleteMany":
|
|
52
|
+
actions.forEach(action => reserveWhitelist(action, actionWhitelist));
|
|
53
|
+
break;
|
|
54
|
+
default:
|
|
55
|
+
actions.forEach(action => {
|
|
56
|
+
reserveWhitelist(action, generalWhitelist);
|
|
57
|
+
if (!reserveWhitelist(action.codeHint, actionCodeHintWhitelist)) return;
|
|
58
|
+
if (!reserveWhitelist(action.codeHint.delegator, actionCodeHintDelegatorWhitelist)) return;
|
|
59
|
+
reserveWhitelist(action.codeHint.delegator.param, fieldsOnlyWhitelist)
|
|
60
|
+
reserveWhitelist(action.codeHint.delegator.requestBody, fieldsOnlyWhitelist)
|
|
61
|
+
});
|
|
62
|
+
break;
|
|
48
63
|
}
|
|
49
64
|
|
|
50
|
-
if (msg !== "MUSHROOM-CLI: FINISH") return;
|
|
51
|
-
|
|
52
|
-
const code = "<!DOCTYPE html>" + dom.window.document.documentElement.outerHTML;
|
|
53
|
-
|
|
54
|
-
dom = null;
|
|
55
|
-
|
|
56
|
-
if (args[3] === "tmp") {
|
|
57
|
-
const htmlFilePath = aliasProject.output + "_tmp.html";
|
|
58
|
-
console.log(`Writing to ${htmlFilePath}`);
|
|
59
|
-
fs.writeFile(htmlFilePath, code, err => {
|
|
60
|
-
if (err) {
|
|
61
|
-
reject(err);
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
console.log("Opening file " + htmlFilePath);
|
|
66
|
-
open(htmlFilePath).then(() => {
|
|
67
|
-
setTimeout(() => {
|
|
68
|
-
fs.unlink(htmlFilePath, ex => {
|
|
69
|
-
if (ex)
|
|
70
|
-
console.error("Unable to delete file " + htmlFilePath)
|
|
71
|
-
});
|
|
72
|
-
}, 1000);
|
|
73
|
-
}).catch(() => console.error("Unable to open " + htmlFilePath));
|
|
74
|
-
resolve();
|
|
75
|
-
});
|
|
76
|
-
return;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
common.ensureFolder(aliasProject.output);
|
|
80
|
-
|
|
81
|
-
console.log(`Writing to ${aliasProject.output}`);
|
|
82
|
-
fs.writeFile(aliasProject.output, code, err => {
|
|
83
|
-
if (err) {
|
|
84
|
-
reject(err);
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
|
-
console.log(`Generated API docs for ${projectName}@${alias} to ${aliasProject.output}`);
|
|
88
|
-
resolve();
|
|
89
|
-
});
|
|
90
65
|
});
|
|
66
|
+
Object.keys(entity.views).forEach(viewName => {
|
|
67
|
+
const views = entity.views[viewName];
|
|
68
|
+
views.forEach(view => {
|
|
69
|
+
reserveWhitelist(view, viewWhitelist);
|
|
70
|
+
if (!reserveWhitelist(view.codeHint, viewCodeHintWhitelist)) return;
|
|
71
|
+
reserveWhitelist(view.codeHint.output, fieldsOnlyWhitelist)
|
|
72
|
+
});
|
|
73
|
+
})
|
|
74
|
+
if (!reserveWhitelist(entity.features, entityFeatureWhitelist)) return;
|
|
75
|
+
if (!reserveWhitelist(entity.features.vn_text, vnTextWhitelist)) return;
|
|
76
|
+
entity.features.vn_text.channels?.forEach(channel => reserveWhitelist(channel, vnTextChannelWhitelist));
|
|
77
|
+
});
|
|
78
|
+
}
|
|
91
79
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
80
|
+
function flattenFields(fields, dict, prefix) {
|
|
81
|
+
dict ??= {};
|
|
82
|
+
prefix ??= "";
|
|
83
|
+
|
|
84
|
+
for (let m in fields) {
|
|
85
|
+
const path = prefix ? prefix + "." + m : m;
|
|
86
|
+
dict[path] = false;
|
|
87
|
+
const config = fields[m];
|
|
88
|
+
if (config.type == "object") {
|
|
89
|
+
flattenFields(config.fields ?? {}, dict, path);
|
|
90
|
+
}
|
|
91
|
+
else if (config.type == "array" && config.items && config.items.type == "object") {
|
|
92
|
+
flattenFields(config.items.fields ?? {}, dict, path);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return dict;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function removeDisallowedFields(fields, dict) {
|
|
100
|
+
const allowFields = Object.keys(dict);
|
|
101
|
+
if (allowFields.length) return;
|
|
102
|
+
reserveWhitelist(fields, allowFields);
|
|
103
|
+
for (let m in fields) {
|
|
104
|
+
const config = fields[m];
|
|
105
|
+
if (config.type == "object") {
|
|
106
|
+
removeDisallowedFields(config.fields ?? {}, dict[m]);
|
|
107
|
+
}
|
|
108
|
+
else if (config.type == "array" && config.items && config.items.type == "object") {
|
|
109
|
+
removeDisallowedFields(config.items.fields ?? {}, dict[m]);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function markAllowFields(allowFields, dict) {
|
|
115
|
+
if (!Array.isArray(allowFields)) return;
|
|
116
|
+
allowFields.forEach(field => dict[field] = true);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function markIncludedFields(excludedFields, dict) {
|
|
120
|
+
if (!Array.isArray(excludedFields)) return;
|
|
121
|
+
for (let m in dict) {
|
|
122
|
+
if (!dict[m] && !excludedFields.includes(m)) dict[m] = true;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function filterEntityFields(entity) {
|
|
127
|
+
const dict = flattenFields(entity.fields);
|
|
128
|
+
Object.keys(entity.actions).forEach(actionName => {
|
|
129
|
+
const actions = entity.actions[actionName];
|
|
130
|
+
switch (actionName) {
|
|
131
|
+
case "findMany":
|
|
132
|
+
case "findById":
|
|
133
|
+
actions.forEach(action => {
|
|
134
|
+
markAllowFields(action.returnableFields, dict);
|
|
135
|
+
markAllowFields(action.defaultFields, dict);
|
|
136
|
+
});
|
|
137
|
+
break;
|
|
138
|
+
case "createOne":
|
|
139
|
+
case "createMany":
|
|
140
|
+
case "updateOne":
|
|
141
|
+
case "updateMany":
|
|
142
|
+
case "updatePartially":
|
|
143
|
+
actions.forEach(action => markIncludedFields(action.exclude, dict));
|
|
144
|
+
break;
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
const allowFields = Object.keys(dict).filter(m => dict[m]);
|
|
148
|
+
[...allowFields].forEach(shortField => {
|
|
149
|
+
shortField += ".";
|
|
150
|
+
allowFields.map((longerField, i) => longerField.includes(shortField) ? i : -1)
|
|
151
|
+
.filter(i => i !== -1)
|
|
152
|
+
.reverse()
|
|
153
|
+
.forEach(i => allowFields.splice(i, 1));
|
|
154
|
+
});
|
|
155
|
+
const whitelist = { };
|
|
156
|
+
allowFields.forEach(fields => {
|
|
157
|
+
let obj = whitelist;
|
|
158
|
+
fields.split('.').forEach(name => {
|
|
159
|
+
let child = obj[name];
|
|
160
|
+
if (!child) child = obj[name] = {};
|
|
161
|
+
obj = child;
|
|
162
|
+
})
|
|
163
|
+
})
|
|
164
|
+
Object.keys(entity.actions).forEach(actionName => {
|
|
165
|
+
const actions = entity.actions[actionName];
|
|
166
|
+
switch (actionName) {
|
|
167
|
+
case "createOne":
|
|
168
|
+
case "createMany":
|
|
169
|
+
case "updateOne":
|
|
170
|
+
case "updateMany":
|
|
171
|
+
case "updatePartially":
|
|
172
|
+
actions.forEach(action => action.exclude = action.exclude?.filter(field => allowFields.includes(field)));
|
|
173
|
+
break;
|
|
174
|
+
}
|
|
98
175
|
});
|
|
176
|
+
removeDisallowedFields(entity.fields, whitelist);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
function writeDocs(filePath, strTemplate, strData) {
|
|
180
|
+
const placeholder = "undefined/*INJECT-HERE*/";
|
|
181
|
+
const idx = strTemplate.indexOf(placeholder);
|
|
182
|
+
fs.writeFileSync(filePath, strTemplate.substr(0, idx));
|
|
183
|
+
fs.appendFileSync(filePath, strData);
|
|
184
|
+
fs.appendFileSync(filePath, strTemplate.substr(idx + placeholder.length));
|
|
99
185
|
}
|
|
100
186
|
|
|
101
187
|
async function genDocs(args, projectName, project, alias, source) {
|
|
@@ -105,6 +191,8 @@ async function genDocs(args, projectName, project, alias, source) {
|
|
|
105
191
|
throw new Error(`Not found gen docs configuration. Please run 'npx mushroom-cli config ${projectName} gen docs OUTPUT_FILE.html${alias === "default" ? "" : " alias " + alias}' first`);
|
|
106
192
|
}
|
|
107
193
|
|
|
194
|
+
console.log("Use GenDocEngine v1.2");
|
|
195
|
+
|
|
108
196
|
const entities = common.getEntities(source, aliasProject.allowRoles);
|
|
109
197
|
|
|
110
198
|
if (Array.isArray(aliasProject.entities)) {
|
|
@@ -117,9 +205,55 @@ async function genDocs(args, projectName, project, alias, source) {
|
|
|
117
205
|
}
|
|
118
206
|
}
|
|
119
207
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
208
|
+
filterEnvironmentVariables(source.environmentVariables);
|
|
209
|
+
filterEntities(entities);
|
|
210
|
+
|
|
211
|
+
const data = JSON.stringify({
|
|
212
|
+
info: {
|
|
213
|
+
name: source.name,
|
|
214
|
+
rootUrl: source.codeHint?.rootUrl ?? source.rootUrl,
|
|
215
|
+
description: source.description,
|
|
216
|
+
security: source.security === undefined ? undefined : {
|
|
217
|
+
crossDomain: source.security.crossDomain,
|
|
218
|
+
allowOrigins: source.security.allowOrigins
|
|
219
|
+
}
|
|
220
|
+
},
|
|
221
|
+
features: aliasProject.features,
|
|
222
|
+
roles: source.roles,
|
|
223
|
+
environmentVariables: source.environmentVariables,
|
|
224
|
+
entities: entities
|
|
225
|
+
});
|
|
226
|
+
// fs.writeFileSync(__dirname + "/../docs/sample.json", data);
|
|
227
|
+
|
|
228
|
+
const html = fs.readFileSync(__dirname + "/../docs/docs.v2.html").toString();
|
|
229
|
+
|
|
230
|
+
if (args[3] === "tmp") {
|
|
231
|
+
const htmlFilePath = aliasProject.output + "_tmp.html";
|
|
232
|
+
console.log(`Writing to ${htmlFilePath}`);
|
|
233
|
+
writeDocs(htmlFilePath, html, data);
|
|
234
|
+
|
|
235
|
+
console.log("Opening file " + htmlFilePath);
|
|
236
|
+
try {
|
|
237
|
+
await open(htmlFilePath);
|
|
238
|
+
|
|
239
|
+
setTimeout(() => {
|
|
240
|
+
fs.unlink(htmlFilePath, ex => {
|
|
241
|
+
if (ex)
|
|
242
|
+
console.error("Unable to delete file " + htmlFilePath)
|
|
243
|
+
});
|
|
244
|
+
}, 1000);
|
|
245
|
+
} catch(_) {
|
|
246
|
+
console.error("Unable to open " + htmlFilePath)
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
common.ensureFolder(aliasProject.output);
|
|
253
|
+
|
|
254
|
+
console.log(`Writing to ${aliasProject.output}`);
|
|
255
|
+
writeDocs(aliasProject.output, html, data);
|
|
256
|
+
console.log(`Generated API docs for ${projectName}@${alias} to ${aliasProject.output}`)
|
|
123
257
|
}
|
|
124
258
|
|
|
125
259
|
module.exports = genDocs;
|
package/gen.js
CHANGED
|
@@ -6,6 +6,7 @@ const help = require("./help.js");
|
|
|
6
6
|
const masterFile = require("./master-file/master-file");
|
|
7
7
|
|
|
8
8
|
const genApiDocs = require("./gen/gen-api-docs");
|
|
9
|
+
const genApiDocsV1 = require("./gen/gen-api-docs-v1");
|
|
9
10
|
const genDatabaseDocs = require("./gen/gen-db-docs");
|
|
10
11
|
const javascriptDriverGenerator = require("./gen/gen-js-driver");
|
|
11
12
|
const genJavascriptDriverTarball = require("./gen/gen-js-driver-tarball");
|
|
@@ -85,7 +86,10 @@ async function gen(args) {
|
|
|
85
86
|
const type = args[2];
|
|
86
87
|
switch (type) {
|
|
87
88
|
case "docs":
|
|
88
|
-
|
|
89
|
+
if (args.includes("v1"))
|
|
90
|
+
await genApiDocsV1(args.filter(p => p != "v1"), projectName, project, alias, source);
|
|
91
|
+
else
|
|
92
|
+
await genApiDocs(args, projectName, project, alias, source);
|
|
89
93
|
break;
|
|
90
94
|
case "db-docs":
|
|
91
95
|
genDatabaseDocs(args, projectName, project, alias, source);
|
package/mr.js
CHANGED
|
@@ -31,6 +31,7 @@ async function run(args) {
|
|
|
31
31
|
checkUpdateTask.catch(() => {});
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
+
const startTime = new Date().getTime();
|
|
34
35
|
try {
|
|
35
36
|
switch(args[0]) {
|
|
36
37
|
case "init":
|
|
@@ -64,6 +65,9 @@ async function run(args) {
|
|
|
64
65
|
catch (e) {
|
|
65
66
|
console.error(debugMode ? e : e.message);
|
|
66
67
|
}
|
|
68
|
+
finally {
|
|
69
|
+
console.log("Processed in", new Date().getTime() - startTime, "ms.");
|
|
70
|
+
}
|
|
67
71
|
|
|
68
72
|
|
|
69
73
|
if (checkUpdateTask !== null)
|
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.8",
|
|
4
4
|
"description": "Mushroom CLI",
|
|
5
5
|
"main": "mr.js",
|
|
6
6
|
"scripts": {
|
|
@@ -16,11 +16,12 @@
|
|
|
16
16
|
},
|
|
17
17
|
"author": "suco2007",
|
|
18
18
|
"license": "ISC",
|
|
19
|
+
"dependencies-comments": "node-fetch: 2.x; open: 8.x",
|
|
19
20
|
"dependencies": {
|
|
20
21
|
"jsdom": "^22.1.0",
|
|
21
22
|
"json5": "^2.2.3",
|
|
22
23
|
"node-fetch": "^2.6.11",
|
|
23
|
-
"open": "^
|
|
24
|
+
"open": "^8.4.2",
|
|
24
25
|
"readline-sync": "^1.4.10",
|
|
25
26
|
"targz": "^1.0.1"
|
|
26
27
|
}
|