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-db-docs.js
CHANGED
|
@@ -1,222 +1,238 @@
|
|
|
1
|
-
const fs = require("fs");
|
|
2
|
-
const open = require("open");
|
|
3
|
-
const common = require("../common.js");
|
|
4
|
-
|
|
5
|
-
function encodeHtml(str) {
|
|
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
|
-
|
|
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
|
-
<td valign="top">${
|
|
85
|
-
<td valign="top">${isArray ?
|
|
86
|
-
<td valign="top"
|
|
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
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
:
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
|
|
1
|
+
const fs = require("fs");
|
|
2
|
+
const open = require("open");
|
|
3
|
+
const common = require("../common.js");
|
|
4
|
+
|
|
5
|
+
function encodeHtml(str) {
|
|
6
|
+
if (str === null || str === undefined) return "";
|
|
7
|
+
if (typeof str !== "string") str = str.toString();
|
|
8
|
+
let html = str.replace(/&/g, "&");
|
|
9
|
+
html = html.replace(/</g, "<");
|
|
10
|
+
html = html.replace(/>/g, ">");
|
|
11
|
+
html = html.replace(/"/g, """);
|
|
12
|
+
html = html.replace(/'/g, "'");
|
|
13
|
+
return html;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function getConstrains(valField) {
|
|
17
|
+
const constraints = [];
|
|
18
|
+
|
|
19
|
+
if (valField.reference)
|
|
20
|
+
constraints.push(
|
|
21
|
+
`Ref to <a href="#${valField.reference}">${encodeHtml(valField.reference)}</a>`,
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
if (valField.validation) {
|
|
25
|
+
if (valField.validation.required) constraints.push("Not null");
|
|
26
|
+
if (
|
|
27
|
+
valField.validation.validValues &&
|
|
28
|
+
valField.validation.validValues.length
|
|
29
|
+
)
|
|
30
|
+
constraints.push(
|
|
31
|
+
`Enum: ${valField.validation.validValues.map(encodeHtml).join(", ")}`,
|
|
32
|
+
);
|
|
33
|
+
if (
|
|
34
|
+
valField.validation.invalidValues &&
|
|
35
|
+
valField.validation.invalidValues.length
|
|
36
|
+
)
|
|
37
|
+
constraints.push(
|
|
38
|
+
`Invalid values: ${valField.validation.invalidValues.map(encodeHtml).join(", ")}`,
|
|
39
|
+
);
|
|
40
|
+
if (valField.validation.length !== undefined)
|
|
41
|
+
constraints.push(`Length: ${valField.validation.length}`);
|
|
42
|
+
if (valField.validation.minLength !== undefined)
|
|
43
|
+
constraints.push(`Min length: ${valField.validation.minLength}`);
|
|
44
|
+
if (valField.validation.maxLength !== undefined)
|
|
45
|
+
constraints.push(`Max length: ${valField.validation.maxLength}`);
|
|
46
|
+
if (valField.validation.gt !== undefined)
|
|
47
|
+
constraints.push(`GT: ${encodeHtml(valField.validation.gt)}`);
|
|
48
|
+
if (valField.validation.lt !== undefined)
|
|
49
|
+
constraints.push(`LT: ${encodeHtml(valField.validation.lt)}`);
|
|
50
|
+
if (valField.validation.min !== undefined)
|
|
51
|
+
constraints.push(`Min: ${encodeHtml(valField.validation.min)}`);
|
|
52
|
+
if (valField.validation.max !== undefined)
|
|
53
|
+
constraints.push(`Max: ${encodeHtml(valField.validation.max)}`);
|
|
54
|
+
if (valField.validation.pattern)
|
|
55
|
+
constraints.push(`Pattern: ${encodeHtml(valField.validation.pattern)}`);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (valField.defaultValue)
|
|
59
|
+
constraints.push(`Default (${encodeHtml(valField.defaultValue)})`);
|
|
60
|
+
|
|
61
|
+
return constraints.join("<br/>");
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function getMongoTableDocs(valTable) {
|
|
65
|
+
let str = `
|
|
66
|
+
<table border="1" cellspacing="0" cellpadding="8" width="100%" bordercolor="#999">
|
|
67
|
+
<tr>
|
|
68
|
+
<th style="width: 1.75in">Column</th>
|
|
69
|
+
<th style="width: 1in">DataType</th>
|
|
70
|
+
<th style="width: 2in">Constraints</th>
|
|
71
|
+
<th>Description</th>
|
|
72
|
+
</tr>`;
|
|
73
|
+
for (let keyField in valTable) {
|
|
74
|
+
const valField = valTable[keyField];
|
|
75
|
+
const isObject =
|
|
76
|
+
valField.type === "object" ||
|
|
77
|
+
(valField.type === "array" && valField.items.type === "object");
|
|
78
|
+
const isArray = valField.type === "array";
|
|
79
|
+
|
|
80
|
+
if (isObject) {
|
|
81
|
+
str += `
|
|
82
|
+
<tr>
|
|
83
|
+
<td valign="top" rowspan="2">${keyField}</td>
|
|
84
|
+
<td valign="top">${isArray ? "array of " : ""}object</td>
|
|
85
|
+
<td valign="top">${getConstrains(isArray ? valField.items : valField)}</td>
|
|
86
|
+
<td valign="top" style="word-break: break-word">${encodeHtml(valField.description)}</td>
|
|
87
|
+
</tr>
|
|
88
|
+
<tr>
|
|
89
|
+
<td colspan="3">${getMongoTableDocs(isArray ? valField.items.fields : valField.fields)}</td>
|
|
90
|
+
</tr>`;
|
|
91
|
+
} else {
|
|
92
|
+
str += `
|
|
93
|
+
<tr>
|
|
94
|
+
<td valign="top">${keyField}</td>
|
|
95
|
+
<td valign="top">${isArray ? "array of " + valField.items.type : valField.type}</td>
|
|
96
|
+
<td valign="top">${getConstrains(valField)}${isArray ? "<hr/>Array items:<br/>" + getConstrains(valField.items) : ""}</td>
|
|
97
|
+
<td valign="top" style="word-break: break-word">${encodeHtml(valField.description)}</td>
|
|
98
|
+
</tr>`;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
str += `</table>`;
|
|
102
|
+
return str;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function getMongoDbDocs(entities, source) {
|
|
106
|
+
let htmlStr = "";
|
|
107
|
+
let toc = "";
|
|
108
|
+
for (let keyTable in entities) {
|
|
109
|
+
const valTable = entities[keyTable];
|
|
110
|
+
const des = encodeHtml(valTable.description);
|
|
111
|
+
htmlStr += `
|
|
112
|
+
<h2 id="${keyTable}">${keyTable}</h2>
|
|
113
|
+
<div>${des}</div>
|
|
114
|
+
${getMongoTableDocs(valTable.fields)}
|
|
115
|
+
<br>`;
|
|
116
|
+
toc += `<li><a href="#${keyTable}">${keyTable}</a> <span class="des">- ${des}</span></li>`;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
return `
|
|
120
|
+
<!DOCTYPE html>
|
|
121
|
+
<html>
|
|
122
|
+
<head>
|
|
123
|
+
<meta charset=utf-8>
|
|
124
|
+
<style>
|
|
125
|
+
* {box-sizing: border-box}
|
|
126
|
+
html, body {margin: 0 0; padding: 0 0; font-family: Calibri, 'helvetica neue', Arial, serifs}
|
|
127
|
+
h2{background-color: #ccc;margin: 30px -20px 0;padding: 5px 10px;}
|
|
128
|
+
hr{border-width: 0; border-top: 1px solid #ccc;}
|
|
129
|
+
table {border-collapse: collapse;margin-top: 5px;}
|
|
130
|
+
th{background-color: #d7d7d7}
|
|
131
|
+
a{color: #000; text-decoration: none}
|
|
132
|
+
a:hover{color: blue; text-decoration: underline}
|
|
133
|
+
|
|
134
|
+
.nav{position: fixed; top: 0; left: 0; bottom: 0; width: 200px; z-index: 100; overflow: auto;border-right: 1px solid #bbb;background-color: #eee}
|
|
135
|
+
ul#nav-toc{padding: 0;margin: 0}
|
|
136
|
+
ul#nav-toc li{list-style: none;padding: 0;margin: 0;}
|
|
137
|
+
ul#nav-toc a{display: block;padding: 5px 10px;}
|
|
138
|
+
ul#nav-toc a:hover{background-color: #aaa; color: #fff; text-decoration: none}
|
|
139
|
+
ul#nav-toc .des{display: none}
|
|
140
|
+
|
|
141
|
+
:target {
|
|
142
|
+
-webkit-animation: target-fade 2s 1;
|
|
143
|
+
-moz-animation: target-fade 2s 1;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
@-webkit-keyframes target-fade {
|
|
147
|
+
0% { background-color: #ff0; }
|
|
148
|
+
100% { background-color: #ccc; }
|
|
149
|
+
}
|
|
150
|
+
@-moz-keyframes target-fade {
|
|
151
|
+
0% { background-color: #ff0; }
|
|
152
|
+
100% { background-color: #ccc; }
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
body{padding-left: 200px}
|
|
156
|
+
.paper{padding: 0 20px}
|
|
157
|
+
|
|
158
|
+
ul#main-toc a{font-weight: bold}
|
|
159
|
+
|
|
160
|
+
@media print {
|
|
161
|
+
body{padding-left: 0}
|
|
162
|
+
.nav{display: none}
|
|
163
|
+
}
|
|
164
|
+
@media only screen and (max-width: 768px) {
|
|
165
|
+
body{padding-left: 0}
|
|
166
|
+
.nav{display: none}
|
|
167
|
+
}
|
|
168
|
+
</style>
|
|
169
|
+
<head>
|
|
170
|
+
<body>
|
|
171
|
+
<div class="nav">
|
|
172
|
+
<ul id="nav-toc">${toc}</ul>
|
|
173
|
+
</div>
|
|
174
|
+
<div class="paper">
|
|
175
|
+
<h1 style="text-align: center">Đặc tả Cơ sở dữ liệu</h1>
|
|
176
|
+
Hệ quản trị cơ sở dữ liệu: <b>${source.db}</b>
|
|
177
|
+
<ul id="main-toc">${toc}</ul>
|
|
178
|
+
${htmlStr}
|
|
179
|
+
</div>
|
|
180
|
+
</body>
|
|
181
|
+
</html>`;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
function genDatabaseDocs(args, projectName, project, alias, source) {
|
|
185
|
+
const aliasProject = ((project.dbDocs || {}).alias || {})[alias];
|
|
186
|
+
|
|
187
|
+
if (!aliasProject) {
|
|
188
|
+
throw new Error(
|
|
189
|
+
`Not found gen db-docs configuration. Please run 'npx mushroom-cli config ${projectName} gen db-docs OUTPUT_FILE.html${alias === "default" ? "" : " alias " + alias}' first`,
|
|
190
|
+
);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
const entities = common.getEntities(source, aliasProject.allowRoles, true);
|
|
194
|
+
|
|
195
|
+
let code;
|
|
196
|
+
switch (source.db) {
|
|
197
|
+
case "MongoDB":
|
|
198
|
+
code = getMongoDbDocs(entities, source);
|
|
199
|
+
break;
|
|
200
|
+
//case "SqlServer":
|
|
201
|
+
// break;
|
|
202
|
+
case undefined:
|
|
203
|
+
case null:
|
|
204
|
+
case "":
|
|
205
|
+
throw new Error(`Missing db configuration in ${aliasProject.output}`);
|
|
206
|
+
default:
|
|
207
|
+
throw new Error(`Unsupported gen db-docs for '${source.db}'`);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
if (args[3] === "tmp") {
|
|
211
|
+
const htmlFilePath = aliasProject.output + "_tmp.html";
|
|
212
|
+
fs.writeFile(htmlFilePath, code, (err) => {
|
|
213
|
+
if (err) throw err;
|
|
214
|
+
open(htmlFilePath)
|
|
215
|
+
.then(() => {
|
|
216
|
+
setTimeout(() => {
|
|
217
|
+
fs.unlink(htmlFilePath, (ex) => {
|
|
218
|
+
if (ex) console.error(ex);
|
|
219
|
+
});
|
|
220
|
+
}, 2000);
|
|
221
|
+
})
|
|
222
|
+
.catch((err) => {
|
|
223
|
+
console.error(err);
|
|
224
|
+
});
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
common.ensureFolder(aliasProject.output);
|
|
231
|
+
|
|
232
|
+
fs.writeFileSync(aliasProject.output, code);
|
|
233
|
+
console.log(
|
|
234
|
+
`Generated Database docs for ${projectName}@${alias} to ${aliasProject.output}`,
|
|
235
|
+
);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
module.exports = genDatabaseDocs;
|