mushroom-cli 1.1.0-alpha.9 → 1.2.0-alpha.1
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 +42 -22
- package/common.js +109 -5
- package/config.js +8 -8
- package/docs/doc-mt.js +421 -0
- package/docs/docs.html +5129 -0
- package/docs/mt-dom-1.0.js +1268 -0
- package/docs/mt.extension.js +174 -0
- package/gen/gen-api-docs.js +5 -5
- package/gen/gen-csharp.js +543 -50
- package/gen/gen-db-docs.js +1 -1
- package/gen/gen-js-driver-tarball.js +4 -2
- package/gen/gen-js-driver.js +23 -10
- package/gen/gen-ts-driver.js +37 -25
- package/gen.js +2 -2
- package/help.js +14 -14
- package/init/init-json.js +106 -0
- package/init/init-netcore.js +32 -0
- package/init.js +4 -108
- package/master-file/master-file.js +4 -4
- package/mr.js +9 -7
- package/package.json +5 -5
- package/update/tsCode.js +20 -0
- package/update.js +24 -0
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
(function () {
|
|
2
|
+
var urls = {};
|
|
3
|
+
function loadFile(url, successCallback, errorCallback) {
|
|
4
|
+
if (url in urls) {
|
|
5
|
+
var args = urls[url];
|
|
6
|
+
args.cached = true;
|
|
7
|
+
setTimeout(successCallback, 1, args);
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
var xhr = new XMLHttpRequest();
|
|
11
|
+
xhr.onreadystatechange = function () {
|
|
12
|
+
if (this.readyState !== 4)
|
|
13
|
+
return;
|
|
14
|
+
if (this.status < 200 || this.status >= 300) {
|
|
15
|
+
if (typeof this.debugMode === "function" && this.debugMode())
|
|
16
|
+
console.error("Unable to load: " + url);
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
var args = { content: this.responseText };
|
|
20
|
+
urls[url] = args;
|
|
21
|
+
if (typeof successCallback === "function")
|
|
22
|
+
successCallback(args);
|
|
23
|
+
};
|
|
24
|
+
xhr.onerror = function () {
|
|
25
|
+
if (typeof this.debugMode === "function" && this.debugMode())
|
|
26
|
+
console.error("Error occurred when loading: " + url);
|
|
27
|
+
if (typeof errorCallback === "function")
|
|
28
|
+
errorCallback();
|
|
29
|
+
};
|
|
30
|
+
xhr.onabort = function () {
|
|
31
|
+
if (typeof this.debugMode === "function" && this.debugMode())
|
|
32
|
+
console.error("Connection aborted: " + url);
|
|
33
|
+
if (typeof errorCallback === "function")
|
|
34
|
+
errorCallback();
|
|
35
|
+
};
|
|
36
|
+
xhr.ontimeout = function () {
|
|
37
|
+
if (typeof this.debugMode === "function" && this.debugMode())
|
|
38
|
+
console.error("Connection timeout: " + url);
|
|
39
|
+
if (typeof errorCallback === "function")
|
|
40
|
+
errorCallback();
|
|
41
|
+
};
|
|
42
|
+
xhr.open("GET", url, true);
|
|
43
|
+
xhr.send(null);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
mt.modules = {};
|
|
47
|
+
mt.bindModule = function (module, dom, data, session) {
|
|
48
|
+
if (!module || !dom)
|
|
49
|
+
return;
|
|
50
|
+
|
|
51
|
+
loadFile("/modules/" + module + "/" + module + "-view.html", function (response) {
|
|
52
|
+
dom.innerHTML = "<link rel='stylesheet' href='/modules/" + module + "/" + module + "-style.min.css' />" + response.content;
|
|
53
|
+
loadFile("/modules/" + module + "/" + module + "-script.js", function (resp) {
|
|
54
|
+
if (!resp.content)
|
|
55
|
+
return;
|
|
56
|
+
|
|
57
|
+
if (!resp.cached) {
|
|
58
|
+
try {
|
|
59
|
+
eval(resp.content);
|
|
60
|
+
} catch (e) {
|
|
61
|
+
throw "Invalid module script";
|
|
62
|
+
}
|
|
63
|
+
if (!mt.modules[module])
|
|
64
|
+
throw "Invalid module script";
|
|
65
|
+
if (typeof mt.modules[module].init === "function")
|
|
66
|
+
mt.modules[module].init();
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
var config = mt.modules[module];
|
|
70
|
+
|
|
71
|
+
var args = { dom: dom, data: data, fnPool: config.fn, session: session };
|
|
72
|
+
if (typeof config.prebinding === "function") {
|
|
73
|
+
config.prebinding(args);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
mt.bindDom(dom, args.data, args.fnPool, session);
|
|
77
|
+
|
|
78
|
+
if (typeof config.load === "function") {
|
|
79
|
+
args.dom = dom;
|
|
80
|
+
args.session = session;
|
|
81
|
+
config.load(args);
|
|
82
|
+
}
|
|
83
|
+
}, function () {
|
|
84
|
+
mt.bindDom(dom, data, null, session);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
//#region mt-link
|
|
93
|
+
if (mt["default"] === undefined) mt["default"] = {};
|
|
94
|
+
if (mt["default"].mtLink === undefined) mt["default"].mtLink = {};
|
|
95
|
+
// cho phép mở rộng được về sau: ví dụ thay thế bằng custom dialog
|
|
96
|
+
mt["default"].mtLink.itemClickHandler = function (dom, message, callback) {
|
|
97
|
+
if (confirm(message))
|
|
98
|
+
callback(dom);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function mtLinkHandler(dom) {
|
|
102
|
+
mt.bindModule(dom.__mtLinkConfig.module, document.getElementById("page-wrapper"), dom.__mtLinkConfig.params);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function mtLinkClicked(e) {
|
|
106
|
+
if (this.__mtLinkConfig.confirm)
|
|
107
|
+
mt["default"].mtLink.itemClickHandler(this, this.__mtLinkConfig.confirm, mtLinkHandler);
|
|
108
|
+
else
|
|
109
|
+
mtLinkHandler(this);
|
|
110
|
+
|
|
111
|
+
e = e || window.event;
|
|
112
|
+
e.stopPropagation();
|
|
113
|
+
e.preventDefault();
|
|
114
|
+
e.cancelBubble = true;
|
|
115
|
+
return false;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
mt.registerDomFeature("mtLink", function (arg) {
|
|
119
|
+
if (arg.dom.nodeName !== "A") {
|
|
120
|
+
arg.dom.dataset.mtLinkError = "mtLink feature only affects <a> tag";
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (!arg.config.module) {
|
|
125
|
+
arg.dom.dataset.mtLinkError = "mtLink feature: missing module";
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
arg.dom.__mtLinkConfig = mt.fnUtils.mergeData({ mask: arg.config, data: arg.data, session: arg.session });
|
|
130
|
+
|
|
131
|
+
if (!arg.dom.href)
|
|
132
|
+
arg.dom.href = "javascript:void(0)";
|
|
133
|
+
|
|
134
|
+
mt.fnUtils.addEventListener(arg.dom, "click", mtLinkClicked, false);
|
|
135
|
+
|
|
136
|
+
delete arg.dom.dataset.mtLink;
|
|
137
|
+
});
|
|
138
|
+
//#endregion
|
|
139
|
+
|
|
140
|
+
//#region mt-module
|
|
141
|
+
mt.registerDomFeature("mtModule", function (arg) {
|
|
142
|
+
if (!arg.config.module) {
|
|
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
|
+
})();
|
package/gen/gen-api-docs.js
CHANGED
|
@@ -12,7 +12,7 @@ function processGenDocs(aliasProject, entities, source, html, args, projectName,
|
|
|
12
12
|
const roles = aliasProject.allowRoles.includes("*") ? source.roles : source.roles?.filter(r => aliasProject.allowRoles.includes(r.name));
|
|
13
13
|
|
|
14
14
|
html = html.replace(/^\uFEFF/, '');
|
|
15
|
-
html = html.replace(/<script src=(["
|
|
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
16
|
html = html.replace("</body>", `<script data-mt-cond='{"x": 1}'>
|
|
17
17
|
window.data.name = ${JSON.stringify(source.name)};
|
|
18
18
|
window.data.description = ${JSON.stringify(source.description)};
|
|
@@ -38,7 +38,7 @@ function processGenDocs(aliasProject, entities, source, html, args, projectName,
|
|
|
38
38
|
if (typeof msg != "string") return;
|
|
39
39
|
|
|
40
40
|
if (msg.indexOf("MUSHROOM-CLI:") === 0) {
|
|
41
|
-
console.log("GenDocEngine:" + msg.
|
|
41
|
+
console.log("GenDocEngine:" + msg.substring("MUSHROOM-CLI:".length));
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
if (msg === "MUSHROOM-CLI: FAIL"){
|
|
@@ -102,7 +102,7 @@ async function genDocs(args, projectName, project, alias, source) {
|
|
|
102
102
|
const aliasProject = ((project.docs || {}).alias || {})[alias];
|
|
103
103
|
|
|
104
104
|
if (!aliasProject) {
|
|
105
|
-
throw new Error(`Not found gen docs configuration. Please run 'npx
|
|
105
|
+
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
106
|
}
|
|
107
107
|
|
|
108
108
|
const entities = common.getEntities(source, aliasProject.allowRoles);
|
|
@@ -117,8 +117,8 @@ async function genDocs(args, projectName, project, alias, source) {
|
|
|
117
117
|
}
|
|
118
118
|
}
|
|
119
119
|
|
|
120
|
-
|
|
121
|
-
const html =
|
|
120
|
+
//const html = await fetch('https://api.siten.vn/gen/docs.html').then(res => res.text());
|
|
121
|
+
const html = fs.readFileSync(__dirname + "/../docs/docs.html").toString();
|
|
122
122
|
await processGenDocs(aliasProject, entities, source, html, args, projectName, alias);
|
|
123
123
|
}
|
|
124
124
|
|