mushroom-cli 1.2.0-alpha.1 → 1.2.0-alpha.11
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 +148 -20
- package/common.js +49 -2
- package/docs/doc-mt.js +103 -1
- package/docs/docs.html +83 -22
- package/docs/docs.v2.html +5095 -0
- package/docs/docs.v2.js +1633 -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 +37 -30
- package/gen.js +5 -1
- package/merge.js +84 -0
- package/mr.js +81 -77
- package/package.json +6 -4
|
@@ -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,226 @@
|
|
|
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");
|
|
4
|
+
const minify = require("minify");
|
|
5
|
+
const path = require("path");
|
|
7
6
|
|
|
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");
|
|
7
|
+
function reserveWhitelist(obj, whitelist) {
|
|
8
|
+
if (obj === null && typeof obj !== "object") return null;
|
|
9
|
+
for (let m in obj) {
|
|
10
|
+
if (!whitelist.includes(m)) delete obj[m];
|
|
28
11
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
window.close();
|
|
33
|
-
</script></body>`);
|
|
12
|
+
return obj;
|
|
13
|
+
}
|
|
34
14
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
15
|
+
const environmentVariableWhitelist = ["type", "description"];
|
|
16
|
+
function filterEnvironmentVariables(environmentVariables) {
|
|
17
|
+
Object.values(environmentVariables).forEach(env => reserveWhitelist(env, environmentVariableWhitelist));
|
|
18
|
+
}
|
|
39
19
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
20
|
+
const entityWhitelist = ["name", "description", "actions", "views", "features", "fields"];
|
|
21
|
+
const actionWhitelist = ["grant", "deny", "matches", "description", "exclude"];
|
|
22
|
+
const findByIdWhitelist = [ ...actionWhitelist, "returnableFields", "defaultFields"];
|
|
23
|
+
const findManyWhitelist = [ ...findByIdWhitelist, "allowFilteringFields", "requiredFilteringFields", "allowSortings", "defaultSortings", "pagingType", "maxPageSize", "pageSize", "includeTotal", "cache"];
|
|
24
|
+
const generalWhitelist = [ ...actionWhitelist, "codeHint" ];
|
|
25
|
+
const entityFeatureWhitelist = ["vn_text"];
|
|
26
|
+
const vnTextWhitelist = ["fields", "channels"];
|
|
27
|
+
const vnTextChannelWhitelist = ["fields", "name"];
|
|
28
|
+
const actionCodeHintWhitelist = ["delegator"];
|
|
29
|
+
const actionCodeHintDelegatorWhitelist = ["param", "requestBody"];
|
|
30
|
+
const fieldsOnlyWhitelist = ["fields"];
|
|
31
|
+
const viewWhitelist = [ "grant", "deny", "description", "parameters", "emptyResult", "codeHint"]
|
|
32
|
+
const viewCodeHintWhitelist = ["output"];
|
|
43
33
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
34
|
+
function filterEntities(entities) {
|
|
35
|
+
Object.values(entities).forEach(entity => {
|
|
36
|
+
filterEntityFields(entity);
|
|
37
|
+
if (!reserveWhitelist(entity, entityWhitelist)) return;
|
|
38
|
+
Object.keys(entity.actions).forEach(actionName => {
|
|
39
|
+
const actions = entity.actions[actionName];
|
|
40
|
+
switch (actionName) {
|
|
41
|
+
case "findMany":
|
|
42
|
+
actions.forEach(action => reserveWhitelist(action, findManyWhitelist));
|
|
43
|
+
break;
|
|
44
|
+
case "findById":
|
|
45
|
+
actions.forEach(action => reserveWhitelist(action, findByIdWhitelist));
|
|
46
|
+
break;
|
|
47
|
+
case "createOne":
|
|
48
|
+
case "createMany":
|
|
49
|
+
case "updateOne":
|
|
50
|
+
case "updateMany":
|
|
51
|
+
case "updatePartially":
|
|
52
|
+
case "deleteOne":
|
|
53
|
+
case "deleteMany":
|
|
54
|
+
actions.forEach(action => reserveWhitelist(action, actionWhitelist));
|
|
55
|
+
break;
|
|
56
|
+
default:
|
|
57
|
+
actions.forEach(action => {
|
|
58
|
+
reserveWhitelist(action, generalWhitelist);
|
|
59
|
+
if (!reserveWhitelist(action.codeHint, actionCodeHintWhitelist)) return;
|
|
60
|
+
if (!reserveWhitelist(action.codeHint.delegator, actionCodeHintDelegatorWhitelist)) return;
|
|
61
|
+
reserveWhitelist(action.codeHint.delegator.param, fieldsOnlyWhitelist)
|
|
62
|
+
reserveWhitelist(action.codeHint.delegator.requestBody, fieldsOnlyWhitelist)
|
|
63
|
+
});
|
|
64
|
+
break;
|
|
48
65
|
}
|
|
49
66
|
|
|
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
67
|
});
|
|
68
|
+
Object.keys(entity.views).forEach(viewName => {
|
|
69
|
+
const views = entity.views[viewName];
|
|
70
|
+
views.forEach(view => {
|
|
71
|
+
reserveWhitelist(view, viewWhitelist);
|
|
72
|
+
if (!reserveWhitelist(view.codeHint, viewCodeHintWhitelist)) return;
|
|
73
|
+
reserveWhitelist(view.codeHint.output, fieldsOnlyWhitelist)
|
|
74
|
+
});
|
|
75
|
+
})
|
|
76
|
+
if (!reserveWhitelist(entity.features, entityFeatureWhitelist)) return;
|
|
77
|
+
if (!reserveWhitelist(entity.features.vn_text, vnTextWhitelist)) return;
|
|
78
|
+
entity.features.vn_text.channels?.forEach(channel => reserveWhitelist(channel, vnTextChannelWhitelist));
|
|
79
|
+
});
|
|
80
|
+
}
|
|
91
81
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
82
|
+
function flattenFields(fields, dict, prefix) {
|
|
83
|
+
dict ??= {};
|
|
84
|
+
prefix ??= "";
|
|
85
|
+
|
|
86
|
+
for (let m in fields) {
|
|
87
|
+
const path = prefix ? prefix + "." + m : m;
|
|
88
|
+
dict[path] = false;
|
|
89
|
+
const config = fields[m];
|
|
90
|
+
if (config.type == "object") {
|
|
91
|
+
flattenFields(config.fields ?? {}, dict, path);
|
|
92
|
+
}
|
|
93
|
+
else if (config.type == "array" && config.items && config.items.type == "object") {
|
|
94
|
+
flattenFields(config.items.fields ?? {}, dict, path);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return dict;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function removeDisallowedFields(fields, dict) {
|
|
102
|
+
const allowFields = Object.keys(dict);
|
|
103
|
+
if (!allowFields.length) return;
|
|
104
|
+
reserveWhitelist(fields, allowFields);
|
|
105
|
+
for (let m in fields) {
|
|
106
|
+
const config = fields[m];
|
|
107
|
+
if (config.type == "object") {
|
|
108
|
+
removeDisallowedFields(config.fields ?? {}, dict[m]);
|
|
109
|
+
}
|
|
110
|
+
else if (config.type == "array" && config.items && config.items.type == "object") {
|
|
111
|
+
removeDisallowedFields(config.items.fields ?? {}, dict[m]);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function markAllowFields(allowFields, dict) {
|
|
117
|
+
if (!Array.isArray(allowFields)) return;
|
|
118
|
+
allowFields.forEach(field => dict[field] = true);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function markIncludedFields(excludedFields, dict) {
|
|
122
|
+
if (!Array.isArray(excludedFields)) return;
|
|
123
|
+
for (let m in dict) {
|
|
124
|
+
if (!dict[m] && !excludedFields.includes(m)) dict[m] = true;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function filterEntityFields(entity) {
|
|
129
|
+
const dict = flattenFields(entity.fields);
|
|
130
|
+
Object.keys(entity.actions).forEach(actionName => {
|
|
131
|
+
const actions = entity.actions[actionName];
|
|
132
|
+
switch (actionName) {
|
|
133
|
+
case "findMany":
|
|
134
|
+
case "findById":
|
|
135
|
+
actions.forEach(action => {
|
|
136
|
+
markAllowFields(action.returnableFields, dict);
|
|
137
|
+
markAllowFields(action.defaultFields, dict);
|
|
138
|
+
});
|
|
139
|
+
break;
|
|
140
|
+
case "createOne":
|
|
141
|
+
case "createMany":
|
|
142
|
+
case "updateOne":
|
|
143
|
+
case "updateMany":
|
|
144
|
+
case "updatePartially":
|
|
145
|
+
actions.forEach(action => markIncludedFields(action.exclude, dict));
|
|
146
|
+
break;
|
|
147
|
+
}
|
|
98
148
|
});
|
|
149
|
+
const allowFields = Object.keys(dict).filter(m => dict[m]);
|
|
150
|
+
[...allowFields].forEach(shortField => {
|
|
151
|
+
shortField += ".";
|
|
152
|
+
allowFields.map((longerField, i) => longerField.includes(shortField) ? i : -1)
|
|
153
|
+
.filter(i => i !== -1)
|
|
154
|
+
.reverse()
|
|
155
|
+
.forEach(i => allowFields.splice(i, 1));
|
|
156
|
+
});
|
|
157
|
+
const whitelist = { };
|
|
158
|
+
allowFields.forEach(fields => {
|
|
159
|
+
let obj = whitelist;
|
|
160
|
+
fields.split('.').forEach(name => {
|
|
161
|
+
let child = obj[name];
|
|
162
|
+
if (!child) child = obj[name] = {};
|
|
163
|
+
obj = child;
|
|
164
|
+
})
|
|
165
|
+
})
|
|
166
|
+
Object.keys(entity.actions).forEach(actionName => {
|
|
167
|
+
const actions = entity.actions[actionName];
|
|
168
|
+
switch (actionName) {
|
|
169
|
+
case "createOne":
|
|
170
|
+
case "createMany":
|
|
171
|
+
case "updateOne":
|
|
172
|
+
case "updateMany":
|
|
173
|
+
case "updatePartially":
|
|
174
|
+
actions.forEach(action => action.exclude = action.exclude?.filter(field => allowFields.includes(field)));
|
|
175
|
+
break;
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
removeDisallowedFields(entity.fields, whitelist);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
async function writeDocs(filePath, strTemplate, strData) {
|
|
182
|
+
//const placeholder = "/*INJECT-JAVASCRIPT-HERE*/";
|
|
183
|
+
/*const idx = strTemplate.indexOf(placeholder);
|
|
184
|
+
fs.writeFileSync(filePath, strTemplate.substr(0, idx));
|
|
185
|
+
fs.appendFileSync(filePath, "window.docs = ");
|
|
186
|
+
fs.appendFileSync(filePath, strData);
|
|
187
|
+
fs.appendFileSync(filePath, ";\n");
|
|
188
|
+
fs.appendFileSync(filePath, await minify(path.join(__dirname, "../docs/docs.v2.js"), {
|
|
189
|
+
js: {
|
|
190
|
+
compress: true
|
|
191
|
+
}
|
|
192
|
+
}));
|
|
193
|
+
fs.appendFileSync(filePath, strTemplate.substr(idx + placeholder.length));*/
|
|
194
|
+
|
|
195
|
+
const placeholder = '<script id="INJECT-JAVASCRIPT-HERE"></script>';
|
|
196
|
+
const idx = strTemplate.indexOf(placeholder);
|
|
197
|
+
fs.writeFileSync(filePath, strTemplate.substr(0, idx));
|
|
198
|
+
fs.appendFileSync(filePath, "<script>window.docs = ");
|
|
199
|
+
fs.appendFileSync(filePath, strData);
|
|
200
|
+
fs.appendFileSync(filePath, ";\n");
|
|
201
|
+
fs.appendFileSync(filePath, fs.readFileSync(path.join(__dirname, "../docs/docs.v2.js")));
|
|
202
|
+
fs.appendFileSync(filePath, "</script>");
|
|
203
|
+
fs.appendFileSync(filePath, strTemplate.substr(idx + placeholder.length));
|
|
204
|
+
|
|
205
|
+
fs.writeFileSync(filePath, await minify(filePath, {
|
|
206
|
+
"html": {
|
|
207
|
+
"removeComments": true,
|
|
208
|
+
"removeCommentsFromCDATA": true,
|
|
209
|
+
"removeCDATASectionsFromCDATA": true,
|
|
210
|
+
"collapseWhitespace": true,
|
|
211
|
+
"collapseBooleanAttributes": true,
|
|
212
|
+
"removeAttributeQuotes": true,
|
|
213
|
+
"removeRedundantAttributes": true,
|
|
214
|
+
"useShortDoctype": true,
|
|
215
|
+
"removeEmptyAttributes": true,
|
|
216
|
+
"removeEmptyElements": false,
|
|
217
|
+
"removeOptionalTags": true,
|
|
218
|
+
"removeScriptTypeAttributes": false,
|
|
219
|
+
"removeStyleLinkTypeAttributes": true,
|
|
220
|
+
"minifyJS": true,
|
|
221
|
+
"minifyCSS": true
|
|
222
|
+
}
|
|
223
|
+
}));
|
|
99
224
|
}
|
|
100
225
|
|
|
101
226
|
async function genDocs(args, projectName, project, alias, source) {
|
|
@@ -105,6 +230,8 @@ async function genDocs(args, projectName, project, alias, source) {
|
|
|
105
230
|
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
231
|
}
|
|
107
232
|
|
|
233
|
+
console.log("Use GenDocEngine v1.2");
|
|
234
|
+
|
|
108
235
|
const entities = common.getEntities(source, aliasProject.allowRoles);
|
|
109
236
|
|
|
110
237
|
if (Array.isArray(aliasProject.entities)) {
|
|
@@ -117,9 +244,55 @@ async function genDocs(args, projectName, project, alias, source) {
|
|
|
117
244
|
}
|
|
118
245
|
}
|
|
119
246
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
247
|
+
filterEnvironmentVariables(source.environmentVariables);
|
|
248
|
+
filterEntities(entities);
|
|
249
|
+
|
|
250
|
+
const data = JSON.stringify({
|
|
251
|
+
info: {
|
|
252
|
+
name: source.name,
|
|
253
|
+
rootUrl: source.codeHint?.rootUrl ?? source.rootUrl,
|
|
254
|
+
description: source.description,
|
|
255
|
+
security: source.security === undefined ? undefined : {
|
|
256
|
+
crossDomain: source.security.crossDomain,
|
|
257
|
+
allowOrigins: source.security.allowOrigins
|
|
258
|
+
}
|
|
259
|
+
},
|
|
260
|
+
features: aliasProject.features,
|
|
261
|
+
roles: common.filterRoles(source.roles ?? [], aliasProject.allowRoles),
|
|
262
|
+
environmentVariables: source.environmentVariables,
|
|
263
|
+
entities: entities
|
|
264
|
+
});
|
|
265
|
+
// fs.writeFileSync(__dirname + "/../docs/sample.json", data);
|
|
266
|
+
|
|
267
|
+
const html = fs.readFileSync(__dirname + "/../docs/docs.v2.html").toString();
|
|
268
|
+
|
|
269
|
+
if (args[3] === "tmp") {
|
|
270
|
+
const htmlFilePath = aliasProject.output + "_tmp.html";
|
|
271
|
+
console.log(`Writing to ${htmlFilePath}`);
|
|
272
|
+
await writeDocs(htmlFilePath, html, data);
|
|
273
|
+
|
|
274
|
+
console.log("Opening file " + htmlFilePath);
|
|
275
|
+
try {
|
|
276
|
+
await open(htmlFilePath);
|
|
277
|
+
|
|
278
|
+
setTimeout(() => {
|
|
279
|
+
fs.unlink(htmlFilePath, ex => {
|
|
280
|
+
if (ex)
|
|
281
|
+
console.error("Unable to delete file " + htmlFilePath)
|
|
282
|
+
});
|
|
283
|
+
}, 1000);
|
|
284
|
+
} catch(_) {
|
|
285
|
+
console.error("Unable to open " + htmlFilePath)
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
return;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
common.ensureFolder(aliasProject.output);
|
|
292
|
+
|
|
293
|
+
console.log(`Writing to ${aliasProject.output}`);
|
|
294
|
+
await writeDocs(aliasProject.output, html, data);
|
|
295
|
+
console.log(`Generated API docs for ${projectName}@${alias} to ${aliasProject.output}`)
|
|
123
296
|
}
|
|
124
297
|
|
|
125
298
|
module.exports = genDocs;
|
package/gen/gen-csharp.js
CHANGED
|
@@ -134,7 +134,7 @@ function generateEnumClass(source, out, field, defaultClassName) {
|
|
|
134
134
|
strEnumClasses += ` /// <summary>
|
|
135
135
|
/// ${singleLine(validation.codeHint.validValues.description || field.description)}
|
|
136
136
|
/// </summary>
|
|
137
|
-
public class ${enumClassName}
|
|
137
|
+
public partial class ${enumClassName}
|
|
138
138
|
{
|
|
139
139
|
private ${enumClassName}() { }
|
|
140
140
|
|
|
@@ -179,7 +179,7 @@ function generateCSharpClassMongoDb(source, className, fields, isRoot, descripti
|
|
|
179
179
|
|
|
180
180
|
supperClass = " : Mushroom.Models.IResource<" + getCSharpTypeFromMushroomType(source, fields.id.type, true) + ">";
|
|
181
181
|
}
|
|
182
|
-
content += ` public class ${className}${supperClass}
|
|
182
|
+
content += ` public partial class ${className}${supperClass}
|
|
183
183
|
{
|
|
184
184
|
`;
|
|
185
185
|
for (var fieldName in fields) {
|
|
@@ -488,21 +488,6 @@ namespace ${namespace}
|
|
|
488
488
|
{
|
|
489
489
|
${collectionNames}
|
|
490
490
|
public static IMongoDatabase GetDatabase() => Mushroom.MushroomDaoFactory.GetDbAdapter() as IMongoDatabase;
|
|
491
|
-
|
|
492
|
-
public static async System.Threading.Tasks.Task<T> FindByIdAsync<T, TId>(this IMongoCollection<T> collection, TId id) where T : Mushroom.Models.IResource<TId>
|
|
493
|
-
{
|
|
494
|
-
return await (await collection.FindAsync(Builders<T>.Filter.Eq(doc => doc.Id, id))).FirstOrDefaultAsync();
|
|
495
|
-
}
|
|
496
|
-
|
|
497
|
-
public static async System.Threading.Tasks.Task<T> FindByIdAsync<T, TId>(this IMongoCollection<T> collection, TId id, FindOptions<T> findOptions) where T : Mushroom.Models.IResource<TId>
|
|
498
|
-
{
|
|
499
|
-
return await (await collection.FindAsync(Builders<T>.Filter.Eq(doc => doc.Id, id), findOptions)).FirstOrDefaultAsync();
|
|
500
|
-
}
|
|
501
|
-
|
|
502
|
-
public static async System.Threading.Tasks.Task<T> FindByIdAsync<T, TId>(this IMongoCollection<T> collection, TId id, ProjectionDefinition<T> projection) where T : Mushroom.Models.IResource<TId>
|
|
503
|
-
{
|
|
504
|
-
return await (await collection.FindAsync(Builders<T>.Filter.Eq(doc => doc.Id, id), new FindOptions<T> { Projection = projection })).FirstOrDefaultAsync();
|
|
505
|
-
}
|
|
506
491
|
}
|
|
507
492
|
|
|
508
493
|
public class ResourceNames
|
|
@@ -587,7 +572,7 @@ function generateCSharpClassMongoDbToFolder(source, className, fields, isRoot, d
|
|
|
587
572
|
|
|
588
573
|
supperClass = " : Mushroom.Models.IResource<" + getCSharpTypeFromMushroomType(source, fields.id.type, true) + ">";
|
|
589
574
|
}
|
|
590
|
-
content += ` public class ${className}${supperClass}
|
|
575
|
+
content += ` public partial class ${className}${supperClass}
|
|
591
576
|
{
|
|
592
577
|
`;
|
|
593
578
|
for (var fieldName in fields) {
|
|
@@ -653,7 +638,7 @@ function generateCSharpClassMongoDbToFolder(source, className, fields, isRoot, d
|
|
|
653
638
|
|
|
654
639
|
let strEnumClasses = generateEnumClass(source, {}, field, `${className.toUpperCase()}_${propertyName.toUpperCase()}_ENUM`);
|
|
655
640
|
|
|
656
|
-
const match = strEnumClasses.match(/public class\s+(\w+)/);
|
|
641
|
+
const match = strEnumClasses.match(/public partial class\s+(\w+)/);
|
|
657
642
|
if (!match) continue;
|
|
658
643
|
common.ensureFolder(aliasProject.output + "/Enums", true);
|
|
659
644
|
strEnumClasses = `${header}
|