mushroom-cli 1.2.0-alpha.12 → 1.2.0-alpha.14
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 +6 -0
- package/dist/check-update.js +2 -1
- package/dist/docs/doc-mt.js +523 -471
- package/dist/docs/docs.html +5190 -0
- package/dist/docs/docs.v2.html +5095 -0
- package/dist/docs/docs.v2.js +1907 -1758
- package/dist/docs/mt-dom-1.0.js +1268 -1025
- package/dist/docs/mt.extension.js +174 -142
- package/dist/gen/gen-api-docs-v1.js +4 -0
- package/dist/gen/gen-api-docs.js +4 -1
- package/dist/gen/gen-csharp.js +47 -52
- package/dist/gen/gen-js-driver-tarball.js +15 -2
- package/dist/init/init-json.js +2 -1
- package/dist/init/init-netcore.js +2 -2
- package/dist/mr.js +21 -4
- package/package.json +8 -8
|
@@ -1,142 +1,174 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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
|
-
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
|
-
|
|
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
|
-
|
|
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
|
+
})();
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import fs from 'fs';
|
|
2
2
|
import open from 'open';
|
|
3
3
|
import jsdom, { JSDOM } from 'jsdom';
|
|
4
|
+
import { fileURLToPath } from 'url';
|
|
5
|
+
import path from 'path';
|
|
4
6
|
import * as common from '../common.js';
|
|
7
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
8
|
+
const __dirname = path.dirname(__filename);
|
|
5
9
|
function processGenDocs(aliasProject, entities, source, html, args, projectName, alias) {
|
|
6
10
|
common.logInfo('Received html');
|
|
7
11
|
common.logInfo('Parsing html');
|
package/dist/gen/gen-api-docs.js
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import fs from 'fs';
|
|
2
2
|
import open from 'open';
|
|
3
|
-
import * as common from '../common.js';
|
|
4
3
|
import { minify } from 'minify';
|
|
4
|
+
import { fileURLToPath } from 'url';
|
|
5
5
|
import path from 'path';
|
|
6
|
+
import * as common from '../common.js';
|
|
7
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
8
|
+
const __dirname = path.dirname(__filename);
|
|
6
9
|
function reserveWhitelist(obj, whitelist) {
|
|
7
10
|
if (!obj && typeof obj !== 'object')
|
|
8
11
|
return null;
|
package/dist/gen/gen-csharp.js
CHANGED
|
@@ -1,6 +1,20 @@
|
|
|
1
1
|
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import { fileURLToPath } from 'url';
|
|
2
4
|
import * as common from '../common.js';
|
|
3
|
-
|
|
5
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
6
|
+
const __dirname = path.dirname(__filename);
|
|
7
|
+
function getPackageVersion() {
|
|
8
|
+
try {
|
|
9
|
+
const content = fs.readFileSync(path.join(__dirname, '../package.json')).toString();
|
|
10
|
+
const pkg = JSON.parse(content);
|
|
11
|
+
return pkg.version;
|
|
12
|
+
}
|
|
13
|
+
catch {
|
|
14
|
+
return '<!unable to get package version>';
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
const packageVersion = getPackageVersion();
|
|
4
18
|
const newLine = '\n';
|
|
5
19
|
const header = `// NOTE: Please do not modify this file
|
|
6
20
|
// NOTE: Version and compatibility information: please see in Info.cs file
|
|
@@ -208,42 +222,36 @@ function generateCSharpClassMongoDb(source, className, fields, isRoot, descripti
|
|
|
208
222
|
/// </summary>
|
|
209
223
|
`;
|
|
210
224
|
if (isRoot && fieldName === 'id') {
|
|
211
|
-
content += ` [MongoDB.Bson.Serialization.Attributes.BsonId${field.type === 'AutoId' && source.idType === 'GUID' ? '(IdGenerator = typeof(MongoDB.Bson.Serialization.IdGenerators.GuidGenerator))' : ''}]
|
|
225
|
+
content += ` [MongoDB.Bson.Serialization.Attributes.BsonId${field.type === 'AutoId' && source.idType === 'GUID' ? '(IdGenerator = typeof(MongoDB.Bson.Serialization.IdGenerators.GuidGenerator))' : ''}]\n`;
|
|
212
226
|
}
|
|
213
227
|
content += ` [MongoDB.Bson.Serialization.Attributes.BsonElement("${isRoot && fieldName === 'id' ? '_id' : fieldName}")]
|
|
214
228
|
[MongoDB.Bson.Serialization.Attributes.BsonIgnoreIfNull]
|
|
215
229
|
[Newtonsoft.Json.JsonProperty(PropertyName = "${fieldName}", NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore${type === 'System.DateTime' ? ', DefaultValueHandling = Newtonsoft.Json.DefaultValueHandling.Ignore' : ''})]
|
|
216
230
|
`;
|
|
217
231
|
if ((field.type === 'AutoId' || field.type === 'IdRef') && source.idType === 'ObjectId') {
|
|
218
|
-
content +=
|
|
219
|
-
' [MongoDB.Bson.Serialization.Attributes.BsonRepresentation(MongoDB.Bson.BsonType.ObjectId)]' + newLine;
|
|
232
|
+
content += ' [MongoDB.Bson.Serialization.Attributes.BsonRepresentation(MongoDB.Bson.BsonType.ObjectId)]\n';
|
|
220
233
|
}
|
|
221
234
|
if (field.type === 'AutoId' && source.idType === 'GUID') {
|
|
222
|
-
content +=
|
|
223
|
-
' [MongoDB.Bson.Serialization.Attributes.BsonRepresentation(MongoDB.Bson.BsonType.String)]' + newLine;
|
|
235
|
+
content += ' [MongoDB.Bson.Serialization.Attributes.BsonRepresentation(MongoDB.Bson.BsonType.String)]\n';
|
|
224
236
|
}
|
|
225
237
|
if (field.type === 'datetime') {
|
|
226
238
|
content +=
|
|
227
|
-
' [MongoDB.Bson.Serialization.Attributes.BsonDateTimeOptions(Kind = System.DateTimeKind.Local)]'
|
|
228
|
-
newLine;
|
|
239
|
+
' [MongoDB.Bson.Serialization.Attributes.BsonDateTimeOptions(Kind = System.DateTimeKind.Local)]\n';
|
|
229
240
|
}
|
|
230
241
|
if (field.type === 'array' && field.items) {
|
|
231
242
|
if ((field.items.type === 'AutoId' || field.items.type === 'IdRef') && source.idType === 'ObjectId') {
|
|
232
243
|
content +=
|
|
233
|
-
' [MongoDB.Bson.Serialization.Attributes.BsonRepresentation(MongoDB.Bson.BsonType.ObjectId)]'
|
|
234
|
-
newLine;
|
|
244
|
+
' [MongoDB.Bson.Serialization.Attributes.BsonRepresentation(MongoDB.Bson.BsonType.ObjectId)]\n';
|
|
235
245
|
}
|
|
236
246
|
if (field.items.type === 'AutoId' && source.idType === 'GUID') {
|
|
237
|
-
content +=
|
|
238
|
-
' [MongoDB.Bson.Serialization.Attributes.BsonRepresentation(MongoDB.Bson.BsonType.String)]' + newLine;
|
|
247
|
+
content += ' [MongoDB.Bson.Serialization.Attributes.BsonRepresentation(MongoDB.Bson.BsonType.String)]\n';
|
|
239
248
|
}
|
|
240
249
|
if (field.items.type === 'datetime') {
|
|
241
250
|
content +=
|
|
242
|
-
' [MongoDB.Bson.Serialization.Attributes.BsonDateTimeOptions(Kind = System.DateTimeKind.Local)]'
|
|
243
|
-
newLine;
|
|
251
|
+
' [MongoDB.Bson.Serialization.Attributes.BsonDateTimeOptions(Kind = System.DateTimeKind.Local)]\n';
|
|
244
252
|
}
|
|
245
253
|
}
|
|
246
|
-
content += ` public ${type} ${propertyName} { get; set; }
|
|
254
|
+
content += ` public ${type} ${propertyName} { get; set; }\n\n`;
|
|
247
255
|
strEnumClasses += generateEnumClass(source, out, field, `${className.toUpperCase()}_${propertyName.toUpperCase()}_ENUM`);
|
|
248
256
|
}
|
|
249
257
|
content += ` [MongoDB.Bson.Serialization.Attributes.BsonExtraElements]
|
|
@@ -299,7 +307,7 @@ export function genCSharpMongoDbClasses(args, projectName, project, alias, sourc
|
|
|
299
307
|
collectionNames += ` public static string ${className}CollectionName => "${entities[entityName].storageName}";
|
|
300
308
|
public static IMongoCollection<Resources.${className}> ${className}Collection => GetDatabase().GetCollection<Resources.${className}>(${className}CollectionName);
|
|
301
309
|
`;
|
|
302
|
-
resourceNames += ` public static string ${className} => "${entityName}"
|
|
310
|
+
resourceNames += ` public static string ${className} => "${entityName}";\n`;
|
|
303
311
|
strClasses += generateCSharpClassMongoDb(source, className, entities[entityName].fields, true, entities[entityName].description, out);
|
|
304
312
|
const actions = entities[entityName].actions || {};
|
|
305
313
|
for (const actionName in actions) {
|
|
@@ -400,26 +408,22 @@ export function genCSharpMongoDbClasses(args, projectName, project, alias, sourc
|
|
|
400
408
|
const delegators = groupCSharpMethodHandlerByMethod(out.delegators);
|
|
401
409
|
const strDelegatorReferences = Object.keys(delegators)
|
|
402
410
|
.map((method) => delegators[method].map((ev) => ` // ${ev.source}`).join(newLine) +
|
|
403
|
-
|
|
404
|
-
` RegisterCustomMethod(${getCSharpFunc(method, delegators[method][0].type)});`)
|
|
411
|
+
`\n RegisterCustomMethod(${getCSharpFunc(method, delegators[method][0].type)});`)
|
|
405
412
|
.join(newLine);
|
|
406
413
|
const viewHandlers = groupCSharpMethodHandlerByMethod(out.viewHandlers);
|
|
407
414
|
const strViewHandlerReferences = Object.keys(viewHandlers)
|
|
408
415
|
.map((method) => viewHandlers[method].map((ev) => ` // ${ev.source}`).join(newLine) +
|
|
409
|
-
|
|
410
|
-
` RegisterCustomViewMethod(${getCSharpFunc(method, viewHandlers[method][0].type)});`)
|
|
416
|
+
`\n RegisterCustomViewMethod(${getCSharpFunc(method, viewHandlers[method][0].type)});`)
|
|
411
417
|
.join(newLine);
|
|
412
418
|
const vnTextChannels = groupCSharpMethodHandlerByMethod(out.vnTextChannels);
|
|
413
419
|
const strVnTextChannels = Object.keys(vnTextChannels)
|
|
414
420
|
.map((method) => vnTextChannels[method].map((channel) => ` // ${channel.source}`).join(newLine) +
|
|
415
|
-
|
|
416
|
-
` RegisterCustomVnTextBuilderMethod(${getCSharpFunc(method, vnTextChannels[method][0].type)});`)
|
|
421
|
+
`\n RegisterCustomVnTextBuilderMethod(${getCSharpFunc(method, vnTextChannels[method][0].type)});`)
|
|
417
422
|
.join(newLine);
|
|
418
423
|
const eventHandlers = groupCSharpMethodHandlerByMethod(out.eventHandlers);
|
|
419
424
|
const strEventHandlerReferences = Object.keys(eventHandlers)
|
|
420
425
|
.map((method) => eventHandlers[method].map((ev) => ` // ${ev.source}`).join(newLine) +
|
|
421
|
-
|
|
422
|
-
` RegisterEvent(${getCSharpFunc(method, eventHandlers[method][0].type)});`)
|
|
426
|
+
`\n RegisterEvent(${getCSharpFunc(method, eventHandlers[method][0].type)});`)
|
|
423
427
|
.join(newLine);
|
|
424
428
|
const strJobReferences = Array.isArray(source.jobs)
|
|
425
429
|
? source.jobs
|
|
@@ -431,7 +435,7 @@ export function genCSharpMongoDbClasses(args, projectName, project, alias, sourc
|
|
|
431
435
|
.map((job) => ` RegisterJob<${job.action.substring(4).split(',')[0]}>();`)
|
|
432
436
|
.join(newLine)
|
|
433
437
|
: '';
|
|
434
|
-
const code = `// This file was generated by Mushroom CLI ${
|
|
438
|
+
const code = `// This file was generated by Mushroom CLI ${packageVersion} (https://www.npmjs.com/package/mushroom-cli), please do not modify
|
|
435
439
|
|
|
436
440
|
// NOTE: Compatible with Mushroom Server version 0.2.18 or higher (https://www.nuget.org/packages/Mushroom/)
|
|
437
441
|
|
|
@@ -563,39 +567,33 @@ function generateCSharpClassMongoDbToFolder(source, className, fields, isRoot, d
|
|
|
563
567
|
/// </summary>
|
|
564
568
|
`;
|
|
565
569
|
if (isRoot && fieldName === 'id') {
|
|
566
|
-
content += ` [MongoDB.Bson.Serialization.Attributes.BsonId${field.type === 'AutoId' && source.idType === 'GUID' ? '(IdGenerator = typeof(MongoDB.Bson.Serialization.IdGenerators.GuidGenerator))' : ''}]
|
|
570
|
+
content += ` [MongoDB.Bson.Serialization.Attributes.BsonId${field.type === 'AutoId' && source.idType === 'GUID' ? '(IdGenerator = typeof(MongoDB.Bson.Serialization.IdGenerators.GuidGenerator))' : ''}]\n`;
|
|
567
571
|
}
|
|
568
572
|
content += ` [MongoDB.Bson.Serialization.Attributes.BsonElement("${isRoot && fieldName === 'id' ? '_id' : fieldName}")]
|
|
569
573
|
[MongoDB.Bson.Serialization.Attributes.BsonIgnoreIfNull]
|
|
570
574
|
[Newtonsoft.Json.JsonProperty(PropertyName = "${fieldName}", NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore${type === 'System.DateTime' ? ', DefaultValueHandling = Newtonsoft.Json.DefaultValueHandling.Ignore' : ''})]
|
|
571
575
|
`;
|
|
572
576
|
if ((field.type === 'AutoId' || field.type === 'IdRef') && source.idType === 'ObjectId') {
|
|
573
|
-
content +=
|
|
574
|
-
' [MongoDB.Bson.Serialization.Attributes.BsonRepresentation(MongoDB.Bson.BsonType.ObjectId)]' + newLine;
|
|
577
|
+
content += ' [MongoDB.Bson.Serialization.Attributes.BsonRepresentation(MongoDB.Bson.BsonType.ObjectId)]\n';
|
|
575
578
|
}
|
|
576
579
|
if (field.type === 'AutoId' && source.idType === 'GUID') {
|
|
577
|
-
content +=
|
|
578
|
-
' [MongoDB.Bson.Serialization.Attributes.BsonRepresentation(MongoDB.Bson.BsonType.String)]' + newLine;
|
|
580
|
+
content += ' [MongoDB.Bson.Serialization.Attributes.BsonRepresentation(MongoDB.Bson.BsonType.String)]\n';
|
|
579
581
|
}
|
|
580
582
|
if (field.type === 'datetime') {
|
|
581
583
|
content +=
|
|
582
|
-
' [MongoDB.Bson.Serialization.Attributes.BsonDateTimeOptions(Kind = System.DateTimeKind.Local)]'
|
|
583
|
-
newLine;
|
|
584
|
+
' [MongoDB.Bson.Serialization.Attributes.BsonDateTimeOptions(Kind = System.DateTimeKind.Local)]\n';
|
|
584
585
|
}
|
|
585
586
|
if (field.type === 'array') {
|
|
586
587
|
if ((field.items?.type === 'AutoId' || field.items?.type === 'IdRef') && source.idType === 'ObjectId') {
|
|
587
588
|
content +=
|
|
588
|
-
' [MongoDB.Bson.Serialization.Attributes.BsonRepresentation(MongoDB.Bson.BsonType.ObjectId)]'
|
|
589
|
-
newLine;
|
|
589
|
+
' [MongoDB.Bson.Serialization.Attributes.BsonRepresentation(MongoDB.Bson.BsonType.ObjectId)]\n';
|
|
590
590
|
}
|
|
591
591
|
if (field.items?.type === 'AutoId' && source.idType === 'GUID') {
|
|
592
|
-
content +=
|
|
593
|
-
' [MongoDB.Bson.Serialization.Attributes.BsonRepresentation(MongoDB.Bson.BsonType.String)]' + newLine;
|
|
592
|
+
content += ' [MongoDB.Bson.Serialization.Attributes.BsonRepresentation(MongoDB.Bson.BsonType.String)]\n';
|
|
594
593
|
}
|
|
595
594
|
if (field.items?.type === 'datetime') {
|
|
596
595
|
content +=
|
|
597
|
-
' [MongoDB.Bson.Serialization.Attributes.BsonDateTimeOptions(Kind = System.DateTimeKind.Local)]'
|
|
598
|
-
newLine;
|
|
596
|
+
' [MongoDB.Bson.Serialization.Attributes.BsonDateTimeOptions(Kind = System.DateTimeKind.Local)]\n';
|
|
599
597
|
}
|
|
600
598
|
}
|
|
601
599
|
content += ` public ${type} ${propertyName} { get; set; }
|
|
@@ -776,26 +774,22 @@ function genCSharpMongoDbClassesToFolder(projectName, alias, source, aliasProjec
|
|
|
776
774
|
const delegators = groupCSharpMethodHandlerByMethod(out.delegators);
|
|
777
775
|
const strDelegatorReferences = Object.keys(delegators)
|
|
778
776
|
.map((method) => delegators[method].map((ev) => ` // ${ev.source}`).join(newLine) +
|
|
779
|
-
|
|
780
|
-
` RegisterCustomMethod(${getCSharpFunc(method, delegators[method][0].type)});`)
|
|
777
|
+
`\n RegisterCustomMethod(${getCSharpFunc(method, delegators[method][0].type)});`)
|
|
781
778
|
.join(newLine);
|
|
782
779
|
const viewHandlers = groupCSharpMethodHandlerByMethod(out.viewHandlers);
|
|
783
780
|
const strViewHandlerReferences = Object.keys(viewHandlers)
|
|
784
781
|
.map((method) => viewHandlers[method].map((ev) => ` // ${ev.source}`).join(newLine) +
|
|
785
|
-
|
|
786
|
-
` RegisterCustomViewMethod(${getCSharpFunc(method, viewHandlers[method][0].type)});`)
|
|
782
|
+
`\n RegisterCustomViewMethod(${getCSharpFunc(method, viewHandlers[method][0].type)});`)
|
|
787
783
|
.join(newLine);
|
|
788
784
|
const vnTextChannels = groupCSharpMethodHandlerByMethod(out.vnTextChannels);
|
|
789
785
|
const strVnTextChannels = Object.keys(vnTextChannels)
|
|
790
786
|
.map((method) => vnTextChannels[method].map((channel) => ` // ${channel.source}`).join(newLine) +
|
|
791
|
-
|
|
792
|
-
` RegisterCustomVnTextBuilderMethod(${getCSharpFunc(method, vnTextChannels[method][0].type)});`)
|
|
787
|
+
`\n RegisterCustomVnTextBuilderMethod(${getCSharpFunc(method, vnTextChannels[method][0].type)});`)
|
|
793
788
|
.join(newLine);
|
|
794
789
|
const eventHandlers = groupCSharpMethodHandlerByMethod(out.eventHandlers);
|
|
795
790
|
const strEventHandlerReferences = Object.keys(eventHandlers)
|
|
796
791
|
.map((method) => eventHandlers[method].map((ev) => ` // ${ev.source}`).join(newLine) +
|
|
797
|
-
|
|
798
|
-
` RegisterEvent(${getCSharpFunc(method, eventHandlers[method][0].type)});`)
|
|
792
|
+
`\n RegisterEvent(${getCSharpFunc(method, eventHandlers[method][0].type)});`)
|
|
799
793
|
.join(newLine);
|
|
800
794
|
const strJobReferences = Array.isArray(source.jobs)
|
|
801
795
|
? source.jobs
|
|
@@ -871,7 +865,8 @@ ${strJobReferences}
|
|
|
871
865
|
}
|
|
872
866
|
#endif
|
|
873
867
|
`;
|
|
874
|
-
const infoFileContent = `// Mushroom CLI version: ${
|
|
868
|
+
const infoFileContent = `// Mushroom CLI version: ${packageVersion}
|
|
869
|
+
// Compatible with Mushroom Server version: 0.2.25.4 or higher (https://www.nuget.org/packages/Mushroom/)
|
|
875
870
|
// For Mushroom Server 0.2.18 to 0.2.25.4: Please remove all FindById methods in DbConnector.cs`;
|
|
876
871
|
fs.writeFileSync(aliasProject.output + '/DbConnector.cs', dbConnectorFileContent);
|
|
877
872
|
fs.writeFileSync(aliasProject.output + '/ResourceNames.cs', resourceNamesFileContent);
|
|
@@ -928,7 +923,7 @@ function generateCSharpClassDriver(source, className, fields, description, out)
|
|
|
928
923
|
out.strEnumClasses ?? (out.strEnumClasses = '');
|
|
929
924
|
out.strEnumClasses += strEnumClasses;
|
|
930
925
|
}
|
|
931
|
-
content += ' }'
|
|
926
|
+
content += ' }\n';
|
|
932
927
|
return strClasses + newLine + content;
|
|
933
928
|
}
|
|
934
929
|
export function genCSharpDriver(args, projectName, project, alias, source) {
|
|
@@ -949,8 +944,8 @@ export function genCSharpDriver(args, projectName, project, alias, source) {
|
|
|
949
944
|
for (const entityName in entities) {
|
|
950
945
|
const className = toCSharpName(entityName);
|
|
951
946
|
strClasses += generateCSharpClassDriver(source, className, entities[entityName].fields, entities[entityName].description, out);
|
|
952
|
-
codeStaticCtor += ` ${className} = new ${className}Connector(client)
|
|
953
|
-
codeStaticProperties += ` public static ${className}Connector ${className} { get; }
|
|
947
|
+
codeStaticCtor += ` ${className} = new ${className}Connector(client);\n`;
|
|
948
|
+
codeStaticProperties += ` public static ${className}Connector ${className} { get; }\n\n`;
|
|
954
949
|
const entity = entities[entityName];
|
|
955
950
|
codeConnectors += ` ${accessModifier} partial class ${className}Connector : MushroomDriver.MushroomResourceConnector<${className}>
|
|
956
951
|
{
|
|
@@ -1187,11 +1182,11 @@ export function genCSharpDriver(args, projectName, project, alias, source) {
|
|
|
1187
1182
|
|
|
1188
1183
|
${viewExtraClass}`;
|
|
1189
1184
|
}
|
|
1190
|
-
codeConnectors += ' }'
|
|
1185
|
+
codeConnectors += ' }\n\n';
|
|
1191
1186
|
}
|
|
1192
1187
|
if (out.strEnumClasses)
|
|
1193
1188
|
strEnumClasses += out.strEnumClasses;
|
|
1194
|
-
const code = `// This file was generated by Mushroom CLI ${
|
|
1189
|
+
const code = `// This file was generated by Mushroom CLI ${packageVersion} (https://www.npmjs.com/package/mushroom-cli), please do not modify
|
|
1195
1190
|
|
|
1196
1191
|
// Require package: Mushroom.Driver version 1.4.0 or later (https://www.nuget.org/packages/Mushroom.Driver/)
|
|
1197
1192
|
|
|
@@ -1,10 +1,23 @@
|
|
|
1
1
|
import fs from 'fs';
|
|
2
2
|
import path from 'path';
|
|
3
|
+
import { fileURLToPath } from 'url';
|
|
3
4
|
import targz from 'targz';
|
|
4
5
|
import * as common from '../common.js';
|
|
5
6
|
import * as javascriptDriverGenerator from './gen-js-driver.js';
|
|
6
7
|
import * as typescriptDriverGenerator from './gen-ts-driver.js';
|
|
7
|
-
|
|
8
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
9
|
+
const __dirname = path.dirname(__filename);
|
|
10
|
+
function getPackageVersion() {
|
|
11
|
+
try {
|
|
12
|
+
const content = fs.readFileSync(path.join(__dirname, '../package.json')).toString();
|
|
13
|
+
const pkg = JSON.parse(content);
|
|
14
|
+
return pkg.version;
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
return '<!unable to get package version>';
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
const packageVersion = getPackageVersion();
|
|
8
21
|
function compressAsync(src, dest, folderName) {
|
|
9
22
|
return new Promise((resolve, reject) => {
|
|
10
23
|
const options = {
|
|
@@ -35,7 +48,7 @@ export default async function genJavascriptDriverTarball(args, projectName, proj
|
|
|
35
48
|
let tarballName = aliasProject.tarballName ? aliasProject.tarballName : projectName;
|
|
36
49
|
tarballName = tarballName.toLowerCase().replace(/[^a-z-]/g, '-');
|
|
37
50
|
const dirPath = path.join(path.dirname(aliasProject.output), tarballName);
|
|
38
|
-
const versionGroup =
|
|
51
|
+
const versionGroup = packageVersion.match(/([^-]+)(-(\w+).*)?/);
|
|
39
52
|
const currentDistTag = versionGroup?.[3] ? versionGroup[3] : 'latest';
|
|
40
53
|
const dependencies = [`"mushroomjs": "${currentDistTag}"`];
|
|
41
54
|
if (Array.isArray(aliasProject.features) && aliasProject.features.includes('auth')) {
|
package/dist/init/init-json.js
CHANGED
|
@@ -30,7 +30,8 @@ export default function initJson(args) {
|
|
|
30
30
|
common.logInfo('Fetch https://api.siten.vn/gen/template/template-def.json');
|
|
31
31
|
fetch('https://api.siten.vn/gen/template/template-def.json')
|
|
32
32
|
.then((res) => res.json())
|
|
33
|
-
.then((
|
|
33
|
+
.then((templateDefination) => {
|
|
34
|
+
const templateConfig = templateDefination;
|
|
34
35
|
const info = {};
|
|
35
36
|
templateConfig.fields.forEach((field) => {
|
|
36
37
|
while (true) {
|