mushroom-cli 1.2.0-alpha.11 → 1.2.0-alpha.12
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 +233 -223
- package/dist/check-update.js +5 -0
- package/dist/common.js +260 -0
- package/dist/config.js +394 -0
- package/{docs → dist/docs}/doc-mt.js +471 -523
- package/dist/docs/docs.v2.js +1758 -0
- package/{docs → dist/docs}/mt-dom-1.0.js +1025 -1268
- package/{docs → dist/docs}/mt.extension.js +142 -174
- package/dist/gen/gen-api-docs-v1.js +106 -0
- package/dist/gen/gen-api-docs.js +292 -0
- package/{gen → dist/gen}/gen-csharp.js +1265 -1399
- package/{gen → dist/gen}/gen-db-docs.js +204 -222
- package/{gen → dist/gen}/gen-js-driver-tarball.js +81 -101
- package/{gen → dist/gen}/gen-js-driver.js +116 -133
- package/{gen → dist/gen}/gen-ts-driver.js +427 -467
- package/{gen.js → dist/gen.js} +109 -124
- package/{help.js → dist/help.js} +53 -55
- package/dist/init/init-json.js +91 -0
- package/dist/init/init-netcore.js +30 -0
- package/dist/init.js +23 -0
- package/dist/master-file/master-file.js +185 -0
- package/dist/merge.js +70 -0
- package/dist/mr.js +75 -0
- package/dist/types.js +1 -0
- package/dist/update/tsCode.js +82 -0
- package/dist/update.js +20 -0
- package/package.json +54 -29
- package/check-update.js +0 -9
- package/common.js +0 -283
- package/config.js +0 -445
- package/docs/docs.html +0 -5190
- package/docs/docs.v2.html +0 -5095
- package/docs/docs.v2.js +0 -1633
- package/gen/gen-api-docs-v1.js +0 -125
- package/gen/gen-api-docs.js +0 -298
- package/init/init-json.js +0 -106
- package/init/init-netcore.js +0 -32
- package/init.js +0 -28
- package/master-file/master-file.js +0 -234
- package/merge.js +0 -84
- package/mr.js +0 -82
- package/update/tsCode.js +0 -20
- package/update.js +0 -24
|
@@ -1,174 +1,142 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
args
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
xhr
|
|
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
|
-
xhr.
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
mt.modules = {};
|
|
47
|
-
mt.bindModule = function (module, dom, data, session) {
|
|
48
|
-
if (!module || !dom)
|
|
49
|
-
return;
|
|
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
|
-
function
|
|
106
|
-
if (
|
|
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
|
-
arg.dom.dataset.mtModuleError = "mtModule feature: missing module";
|
|
144
|
-
return;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
var params = mt.fnUtils.mergeData({ mask: arg.config.params, data: arg.data, session: arg.session });
|
|
148
|
-
mt.bindModule(arg.config.module, arg.dom, params, arg.session);
|
|
149
|
-
arg.mediator.skipInner = true;
|
|
150
|
-
|
|
151
|
-
delete arg.dom.dataset.mtModule;
|
|
152
|
-
});
|
|
153
|
-
//#endregion
|
|
154
|
-
|
|
155
|
-
//#region mt-inline-module
|
|
156
|
-
mt.inlineModuleTemplates = {};
|
|
157
|
-
mt.registerDomFeature("mtInlineModule", function (arg) {
|
|
158
|
-
var config = mt.fnUtils.mergeData({ mask: arg.config, data: arg.data, session: arg.session });
|
|
159
|
-
|
|
160
|
-
if (!config.module) {
|
|
161
|
-
arg.dom.dataset.mtInlineModuleError = "mtInlineModule feature: missing module";
|
|
162
|
-
return;
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
arg.dom.innerHTML = mt.inlineModuleTemplates[config.module] || "";
|
|
166
|
-
|
|
167
|
-
delete arg.dom.dataset.mtInlineModule;
|
|
168
|
-
|
|
169
|
-
mt.bindDom(arg.dom, config.params);
|
|
170
|
-
|
|
171
|
-
arg.mediator.skipInner = true;
|
|
172
|
-
});
|
|
173
|
-
//#endregion
|
|
174
|
-
})();
|
|
1
|
+
"use strict";
|
|
2
|
+
(function () {
|
|
3
|
+
var urls = {};
|
|
4
|
+
function loadFile(url, successCallback, errorCallback) {
|
|
5
|
+
if (url in urls) {
|
|
6
|
+
var args = urls[url];
|
|
7
|
+
args.cached = true;
|
|
8
|
+
setTimeout(successCallback, 1, args);
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
var xhr = new XMLHttpRequest();
|
|
12
|
+
xhr.onreadystatechange = function () {
|
|
13
|
+
if (this.readyState !== 4)
|
|
14
|
+
return;
|
|
15
|
+
if (this.status < 200 || this.status >= 300) {
|
|
16
|
+
if (typeof this.debugMode === "function" && this.debugMode())
|
|
17
|
+
console.error("Unable to load: " + url);
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
var args = { content: this.responseText };
|
|
21
|
+
urls[url] = args;
|
|
22
|
+
if (typeof successCallback === "function")
|
|
23
|
+
successCallback(args);
|
|
24
|
+
};
|
|
25
|
+
xhr.onerror = function () {
|
|
26
|
+
if (typeof this.debugMode === "function" && this.debugMode())
|
|
27
|
+
console.error("Error occurred when loading: " + url);
|
|
28
|
+
if (typeof errorCallback === "function")
|
|
29
|
+
errorCallback();
|
|
30
|
+
};
|
|
31
|
+
xhr.onabort = function () {
|
|
32
|
+
if (typeof this.debugMode === "function" && this.debugMode())
|
|
33
|
+
console.error("Connection aborted: " + url);
|
|
34
|
+
if (typeof errorCallback === "function")
|
|
35
|
+
errorCallback();
|
|
36
|
+
};
|
|
37
|
+
xhr.ontimeout = function () {
|
|
38
|
+
if (typeof this.debugMode === "function" && this.debugMode())
|
|
39
|
+
console.error("Connection timeout: " + url);
|
|
40
|
+
if (typeof errorCallback === "function")
|
|
41
|
+
errorCallback();
|
|
42
|
+
};
|
|
43
|
+
xhr.open("GET", url, true);
|
|
44
|
+
xhr.send(null);
|
|
45
|
+
}
|
|
46
|
+
mt.modules = {};
|
|
47
|
+
mt.bindModule = function (module, dom, data, session) {
|
|
48
|
+
if (!module || !dom)
|
|
49
|
+
return;
|
|
50
|
+
loadFile("/modules/" + module + "/" + module + "-view.html", function (response) {
|
|
51
|
+
dom.innerHTML = "<link rel='stylesheet' href='/modules/" + module + "/" + module + "-style.min.css' />" + response.content;
|
|
52
|
+
loadFile("/modules/" + module + "/" + module + "-script.js", function (resp) {
|
|
53
|
+
if (!resp.content)
|
|
54
|
+
return;
|
|
55
|
+
if (!resp.cached) {
|
|
56
|
+
try {
|
|
57
|
+
eval(resp.content);
|
|
58
|
+
}
|
|
59
|
+
catch (e) {
|
|
60
|
+
throw "Invalid module script";
|
|
61
|
+
}
|
|
62
|
+
if (!mt.modules[module])
|
|
63
|
+
throw "Invalid module script";
|
|
64
|
+
if (typeof mt.modules[module].init === "function")
|
|
65
|
+
mt.modules[module].init();
|
|
66
|
+
}
|
|
67
|
+
var config = mt.modules[module];
|
|
68
|
+
var args = { dom: dom, data: data, fnPool: config.fn, session: session };
|
|
69
|
+
if (typeof config.prebinding === "function") {
|
|
70
|
+
config.prebinding(args);
|
|
71
|
+
}
|
|
72
|
+
mt.bindDom(dom, args.data, args.fnPool, session);
|
|
73
|
+
if (typeof config.load === "function") {
|
|
74
|
+
args.dom = dom;
|
|
75
|
+
args.session = session;
|
|
76
|
+
config.load(args);
|
|
77
|
+
}
|
|
78
|
+
}, function () {
|
|
79
|
+
mt.bindDom(dom, data, null, session);
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
};
|
|
83
|
+
if (mt["default"] === undefined)
|
|
84
|
+
mt["default"] = {};
|
|
85
|
+
if (mt["default"].mtLink === undefined)
|
|
86
|
+
mt["default"].mtLink = {};
|
|
87
|
+
mt["default"].mtLink.itemClickHandler = function (dom, message, callback) {
|
|
88
|
+
if (confirm(message))
|
|
89
|
+
callback(dom);
|
|
90
|
+
};
|
|
91
|
+
function mtLinkHandler(dom) {
|
|
92
|
+
mt.bindModule(dom.__mtLinkConfig.module, document.getElementById("page-wrapper"), dom.__mtLinkConfig.params);
|
|
93
|
+
}
|
|
94
|
+
function mtLinkClicked(e) {
|
|
95
|
+
if (this.__mtLinkConfig.confirm)
|
|
96
|
+
mt["default"].mtLink.itemClickHandler(this, this.__mtLinkConfig.confirm, mtLinkHandler);
|
|
97
|
+
else
|
|
98
|
+
mtLinkHandler(this);
|
|
99
|
+
e = e || window.event;
|
|
100
|
+
e.stopPropagation();
|
|
101
|
+
e.preventDefault();
|
|
102
|
+
e.cancelBubble = true;
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
105
|
+
mt.registerDomFeature("mtLink", function (arg) {
|
|
106
|
+
if (arg.dom.nodeName !== "A") {
|
|
107
|
+
arg.dom.dataset.mtLinkError = "mtLink feature only affects <a> tag";
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
if (!arg.config.module) {
|
|
111
|
+
arg.dom.dataset.mtLinkError = "mtLink feature: missing module";
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
arg.dom.__mtLinkConfig = mt.fnUtils.mergeData({ mask: arg.config, data: arg.data, session: arg.session });
|
|
115
|
+
if (!arg.dom.href)
|
|
116
|
+
arg.dom.href = "javascript:void(0)";
|
|
117
|
+
mt.fnUtils.addEventListener(arg.dom, "click", mtLinkClicked, false);
|
|
118
|
+
delete arg.dom.dataset.mtLink;
|
|
119
|
+
});
|
|
120
|
+
mt.registerDomFeature("mtModule", function (arg) {
|
|
121
|
+
if (!arg.config.module) {
|
|
122
|
+
arg.dom.dataset.mtModuleError = "mtModule feature: missing module";
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
var params = mt.fnUtils.mergeData({ mask: arg.config.params, data: arg.data, session: arg.session });
|
|
126
|
+
mt.bindModule(arg.config.module, arg.dom, params, arg.session);
|
|
127
|
+
arg.mediator.skipInner = true;
|
|
128
|
+
delete arg.dom.dataset.mtModule;
|
|
129
|
+
});
|
|
130
|
+
mt.inlineModuleTemplates = {};
|
|
131
|
+
mt.registerDomFeature("mtInlineModule", function (arg) {
|
|
132
|
+
var config = mt.fnUtils.mergeData({ mask: arg.config, data: arg.data, session: arg.session });
|
|
133
|
+
if (!config.module) {
|
|
134
|
+
arg.dom.dataset.mtInlineModuleError = "mtInlineModule feature: missing module";
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
arg.dom.innerHTML = mt.inlineModuleTemplates[config.module] || "";
|
|
138
|
+
delete arg.dom.dataset.mtInlineModule;
|
|
139
|
+
mt.bindDom(arg.dom, config.params);
|
|
140
|
+
arg.mediator.skipInner = true;
|
|
141
|
+
});
|
|
142
|
+
})();
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import open from 'open';
|
|
3
|
+
import jsdom, { JSDOM } from 'jsdom';
|
|
4
|
+
import * as common from '../common.js';
|
|
5
|
+
function processGenDocs(aliasProject, entities, source, html, args, projectName, alias) {
|
|
6
|
+
common.logInfo('Received html');
|
|
7
|
+
common.logInfo('Parsing html');
|
|
8
|
+
const roles = aliasProject.allowRoles?.includes('*')
|
|
9
|
+
? source.roles
|
|
10
|
+
: source.roles?.filter((r) => aliasProject.allowRoles?.includes(r.name));
|
|
11
|
+
html = html.replace(/^\uFEFF/, '');
|
|
12
|
+
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>`);
|
|
13
|
+
html = html.replace('</body>', `<script data-mt-cond='{"x": 1}'>
|
|
14
|
+
window.data.name = ${JSON.stringify(source.name)};
|
|
15
|
+
window.data.description = ${JSON.stringify(source.description)};
|
|
16
|
+
window.data.rootUrl = ${JSON.stringify(common.getRootUrl(source))};
|
|
17
|
+
window.data.environmentVariables = ${JSON.stringify(source.environmentVariables)};
|
|
18
|
+
window.data.roles = ${JSON.stringify(roles)};
|
|
19
|
+
window.data.entities = ${JSON.stringify(entities)};
|
|
20
|
+
window.data.features = ${JSON.stringify(aliasProject.features)};
|
|
21
|
+
try {
|
|
22
|
+
console.info("MUSHROOM-CLI: START");
|
|
23
|
+
window.generateDocument();
|
|
24
|
+
console.info("MUSHROOM-CLI: FINISH");
|
|
25
|
+
}
|
|
26
|
+
catch (e) {
|
|
27
|
+
console.info("MUSHROOM-CLI: FAIL", e);
|
|
28
|
+
}
|
|
29
|
+
window.close();
|
|
30
|
+
</script></body>`);
|
|
31
|
+
return new Promise((resolve, reject) => {
|
|
32
|
+
const virtualConsole = new jsdom.VirtualConsole();
|
|
33
|
+
virtualConsole.on('info', function (msg, err) {
|
|
34
|
+
if (typeof msg != 'string')
|
|
35
|
+
return;
|
|
36
|
+
if (msg.indexOf('MUSHROOM-CLI:') === 0) {
|
|
37
|
+
common.logInfo('GenDocEngine:', msg.substring('MUSHROOM-CLI:'.length));
|
|
38
|
+
}
|
|
39
|
+
if (msg === 'MUSHROOM-CLI: FAIL') {
|
|
40
|
+
reject(err);
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
if (msg !== 'MUSHROOM-CLI: FINISH')
|
|
44
|
+
return;
|
|
45
|
+
const code = '<!DOCTYPE html>' + dom.window.document.documentElement.outerHTML;
|
|
46
|
+
if (args[3] === 'tmp') {
|
|
47
|
+
const htmlFilePath = aliasProject.output + '_tmp.html';
|
|
48
|
+
common.logInfo('Writing to', htmlFilePath);
|
|
49
|
+
fs.writeFile(htmlFilePath, code, (err) => {
|
|
50
|
+
if (err) {
|
|
51
|
+
reject(err);
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
common.logInfo('Opening file', htmlFilePath);
|
|
55
|
+
open(htmlFilePath)
|
|
56
|
+
.then(() => {
|
|
57
|
+
setTimeout(() => {
|
|
58
|
+
fs.unlink(htmlFilePath, (ex) => {
|
|
59
|
+
if (ex)
|
|
60
|
+
common.logError('Unable to delete file', htmlFilePath);
|
|
61
|
+
});
|
|
62
|
+
}, 1000);
|
|
63
|
+
})
|
|
64
|
+
.catch(() => common.logError('Unable to open', htmlFilePath));
|
|
65
|
+
resolve();
|
|
66
|
+
});
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
common.ensureFolder(aliasProject.output);
|
|
70
|
+
common.logInfo('Writing to', aliasProject.output);
|
|
71
|
+
fs.writeFile(aliasProject.output, code, (err) => {
|
|
72
|
+
if (err) {
|
|
73
|
+
reject(err);
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
common.logInfo(`Generated API docs for ${projectName}@${alias} to ${aliasProject.output}`);
|
|
77
|
+
resolve();
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
const dom = new JSDOM(html, {
|
|
81
|
+
runScripts: 'dangerously',
|
|
82
|
+
resources: 'usable',
|
|
83
|
+
virtualConsole: virtualConsole,
|
|
84
|
+
});
|
|
85
|
+
common.logInfo('Rendering API document');
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
export default async function genDocs(args, projectName, project, alias, source) {
|
|
89
|
+
const aliasProject = ((project.docs || {}).alias || {})[alias];
|
|
90
|
+
if (!aliasProject) {
|
|
91
|
+
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`);
|
|
92
|
+
}
|
|
93
|
+
common.logWarning('[DEPRECATED] Use GenDocEngine v1');
|
|
94
|
+
const entities = common.getEntities(source, aliasProject.allowRoles);
|
|
95
|
+
if (Array.isArray(aliasProject.entities)) {
|
|
96
|
+
for (const entityName in entities) {
|
|
97
|
+
if (Object.hasOwnProperty.call(entities, entityName)) {
|
|
98
|
+
if (aliasProject.entities.every((re) => !new RegExp(re).test(entityName))) {
|
|
99
|
+
delete entities[entityName];
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
const html = fs.readFileSync(__dirname + '/../docs/docs.html').toString();
|
|
105
|
+
await processGenDocs(aliasProject, entities, source, html, args, projectName, alias);
|
|
106
|
+
}
|