mushroom-cli 1.1.0 → 1.1.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/common.js CHANGED
@@ -12,7 +12,7 @@ function ensureFolder(path, isFolder) {
12
12
  return;
13
13
 
14
14
  if (!fs.existsSync(path)) {
15
- fs.mkdirSync(path, { recursive: true, mode: 0755 });
15
+ fs.mkdirSync(path, { recursive: true, mode: 493 }); // 493 = 755 in octa
16
16
  }
17
17
  }
18
18
 
@@ -41,7 +41,7 @@ function getEntities(projectApiConfiguration, roles, getAll) {
41
41
  return;
42
42
  }
43
43
 
44
- for (var actionName in entity.actions) {
44
+ for (const actionName in entity.actions) {
45
45
  if (!entity.actions.hasOwnProperty(actionName))
46
46
  continue;
47
47
 
@@ -49,7 +49,7 @@ function getEntities(projectApiConfiguration, roles, getAll) {
49
49
  if (!action.grant || !action.enabled || action.codeHint && action.codeHint.disabled)
50
50
  return;
51
51
 
52
- var allow = roles.indexOf("*") !== -1 || action.grant === "*";
52
+ let allow = roles.indexOf("*") !== -1 || action.grant === "*";
53
53
 
54
54
  if (!allow)
55
55
  action.grant.split("|").forEach(function (roleGroup) {
@@ -81,7 +81,7 @@ function getEntities(projectApiConfiguration, roles, getAll) {
81
81
 
82
82
  }
83
83
 
84
- for (var viewName in entity.views) {
84
+ for (const viewName in entity.views) {
85
85
  if (!entity.views.hasOwnProperty(viewName))
86
86
  continue;
87
87
 
@@ -89,7 +89,7 @@ function getEntities(projectApiConfiguration, roles, getAll) {
89
89
  if (!view.grant || !view.enabled)
90
90
  return;
91
91
 
92
- var allow = roles.indexOf("*") !== -1 || view.grant === "*";
92
+ let allow = roles.indexOf("*") !== -1 || view.grant === "*";
93
93
 
94
94
  view.grant.split("|").forEach(function (roleGroup) {
95
95
  if (!roleGroup)
@@ -186,7 +186,8 @@ function processSetCommand(command, variables) {
186
186
 
187
187
  function processSetGuidCommand(variable, variables) {
188
188
  variables[variable] = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, c => {
189
- var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
189
+ const r = Math.random() * 16 | 0;
190
+ const v = c == 'x' ? r : (r & 0x3 | 0x8);
190
191
  return v.toString(16);
191
192
  }).toUpperCase();
192
193
  }
@@ -203,7 +204,6 @@ function processDeleteCommand(command, basePath, variables) {
203
204
 
204
205
  const deletedPath = path.join(basePath, input);
205
206
  if (fs.lstatSync(deletedPath).isDirectory()) {
206
- // fs.rmdirSync(deletedPath, {recursive: true, force: true});
207
207
  fs.rmSync(deletedPath, {recursive: true, force: true});
208
208
  }
209
209
  else {
package/config.js CHANGED
@@ -4,7 +4,7 @@ const JSON5 = require("json5");
4
4
 
5
5
  //#region common function
6
6
  function saveConfig(mushroomConfig, success) {
7
- mushroomConfig["$schema"] = "http://schema.siten.vn/mushroom/mushroom-cli.json";
7
+ mushroomConfig["$schema"] = "https://schema.siten.vn/mushroom/mushroom-cli.json";
8
8
  fs.writeFile("./mushroom-config.json", JSON.stringify(mushroomConfig, null, " "), err => {
9
9
  if (err)
10
10
  throw err;
@@ -25,7 +25,7 @@ function configAdd(args) {
25
25
  }
26
26
 
27
27
  const fileContent = fs.readFileSync(filePath).toString();
28
- var project = JSON5.parse(fileContent);
28
+ const project = JSON5.parse(fileContent);
29
29
  if (!project.name) {
30
30
  throw new TypeError(`Missing name in ${filePath}`);
31
31
  }
package/docs/docs.html CHANGED
@@ -1,5 +1,5 @@
1
1
  <!DOCTYPE html>
2
- <html>
2
+ <html lang="vi">
3
3
  <head>
4
4
  <meta charset="utf-8" />
5
5
  <title>Restful API Document</title>
@@ -258,19 +258,19 @@
258
258
  <li>
259
259
  Web
260
260
  <ul>
261
- <li><a href="https://www.npmjs.com/package/mushroomjs" target="_blank">Mushroom js driver</a></li>
262
- <li><a href="https://www.npmjs.com/package/mushroomjs-auth" target="_blank">Extension Authentication</a></li>
263
- <li><a href="https://www.npmjs.com/package/mushroomjs-file" target="_blank">Extension File</a></li>
264
- <li><a href="http://api.siten.vn/js/mushroom.mailing.es6.js" target="_blank">Extension Mailing</a></li>
261
+ <li><a rel="noopener" href="https://www.npmjs.com/package/mushroomjs" target="_blank">Mushroom js driver</a></li>
262
+ <li><a rel="noopener" href="https://www.npmjs.com/package/mushroomjs-auth" target="_blank">Extension Authentication</a></li>
263
+ <li><a rel="noopener" href="https://www.npmjs.com/package/mushroomjs-file" target="_blank">Extension File</a></li>
264
+ <li><a rel="noopener" href="https://api.siten.vn/js/mushroom.mailing.es6.js" target="_blank">Extension Mailing</a></li>
265
265
  </ul>
266
266
  </li>
267
267
  <li>
268
268
  React Native
269
269
  <ul>
270
- <li><a href="https://www.npmjs.com/package/mushroomjs" target="_blank">Mushroom js driver</a></li>
271
- <li><a href="https://www.npmjs.com/package/mushroomjs-auth-rn" target="_blank">Extension Authentication</a></li>
272
- <li><a href="http://api.siten.vn/js/mushroom.file.react.js" target="_blank">Extension File</a></li>
273
- <li><a href="http://api.siten.vn/js/mushroom.mailing.es6.js" target="_blank">Extension Mailing</a></li>
270
+ <li><a rel="noopener" href="https://www.npmjs.com/package/mushroomjs" target="_blank">Mushroom js driver</a></li>
271
+ <li><a rel="noopener" href="https://www.npmjs.com/package/mushroomjs-auth-rn" target="_blank">Extension Authentication</a></li>
272
+ <li><a rel="noopener" href="https://api.siten.vn/js/mushroom.file.react.js" target="_blank">Extension File</a></li>
273
+ <li><a rel="noopener" href="https://api.siten.vn/js/mushroom.mailing.es6.js" target="_blank">Extension Mailing</a></li>
274
274
  </ul>
275
275
  </li>
276
276
  </ul>
@@ -282,7 +282,7 @@
282
282
  CSharp
283
283
  </div>
284
284
  <div class="panel-body">
285
- Sử dụng NUGET tại <a href="https://www.nuget.org/packages/Mushroom.Driver/" target="_blank">đây</a>
285
+ Sử dụng NUGET tại <a rel="noopener" href="https://www.nuget.org/packages/Mushroom.Driver/" target="_blank">đây</a>
286
286
  </div>
287
287
  </div>
288
288
  <div class="panel panel-primary" id="extension-$driver-java">
@@ -290,8 +290,8 @@
290
290
  Java
291
291
  </div>
292
292
  <div class="panel-body">
293
- Sử dụng Maven tại <a href="javascript:void(0)" target="_blank">đây (coming soon)</a><br />
294
- Sử dụng Gradle tại <a href="javascript:void(0)" target="_blank">đây (coming soon)</a>
293
+ Sử dụng Maven tại <a rel="noopener" href="javascript:void(0)" target="_blank">đây (coming soon)</a><br />
294
+ Sử dụng Gradle tại <a rel="noopener" href="javascript:void(0)" target="_blank">đây (coming soon)</a>
295
295
  </div>
296
296
  </div>
297
297
  </div>
@@ -4578,7 +4578,7 @@ BINARY|BASE64|FORMDATA</pre>
4578
4578
  <h4>Byte serving</h4>
4579
4579
  Hỗ trợ download một phần nội dung của file (hỗ trợ pause, resume download) bằng cách truyền lên thông số range qua request header:
4580
4580
  <pre>Range: string, optional, là định nghĩa khoảng dữ liệu mong muốn nhận được</pre>
4581
- Xem thêm tại <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Range" target="_blank">Range header document</a><br />
4581
+ Xem thêm tại <a rel="noopener" href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Range" target="_blank">Range header document</a><br />
4582
4582
  <br />
4583
4583
  Khi có thông số Range, response có định dạng sau:<br />
4584
4584
  Trường hợp có lỗi:<br />
@@ -235,6 +235,7 @@
235
235
  case "html-element":
236
236
  return x1 instanceof HTMLElement;
237
237
  }
238
+ return false;
238
239
  }
239
240
  case "in":
240
241
  {
@@ -1,6 +1,5 @@
1
1
  const fs = require("fs");
2
2
  const open = require("open");
3
- const fetch = require('node-fetch');
4
3
  const jsdom = require("jsdom");
5
4
  const { JSDOM } = jsdom;
6
5
  const common = require("../common.js");
@@ -117,7 +116,6 @@ async function genDocs(args, projectName, project, alias, source) {
117
116
  }
118
117
  }
119
118
 
120
- //const html = await fetch('https://api.siten.vn/gen/docs.html').then(res => res.text());
121
119
  const html = fs.readFileSync(__dirname + "/../docs/docs.html").toString();
122
120
  await processGenDocs(aliasProject, entities, source, html, args, projectName, alias);
123
121
  }
package/gen/gen-csharp.js CHANGED
@@ -1,6 +1,6 @@
1
1
  const fs = require("fs");
2
2
  const common = require("../common.js");
3
- const package = require("./../package.json");
3
+ const package_json = require("./../package.json");
4
4
 
5
5
  //#region shared function
6
6
  const newLine = `
@@ -31,7 +31,7 @@ function singleLine(str) {
31
31
  function toVietnameseNonTongue(str) {
32
32
  const signText = "ăâđêôơưàảãạáằẳẵặắầẩẫậấèẻẽẹéềểễệếìỉĩịíòỏõọóồổỗộốờởỡợớùủũụúừửữựứỳỷỹỵýĂÂĐÐÊÔƠƯÀẢÃẠÁẰẲẴẶẮẦẨẪẬẤÈẺẼẸÉỀỂỄỆẾÌỈĨỊÍÒỎÕỌÓỒỔỖỘỐỜỞỠỢỚÙỦŨỤÚỪỬỮỰỨỲỶỸỴÝ";
33
33
  const unsignedText = "aadeoouaaaaaaaaaaaaaaaeeeeeeeeeeiiiiiooooooooooooooouuuuuuuuuuyyyyyAADDEOOUAAAAAAAAAAAAAAAEEEEEEEEEEIIIIIOOOOOOOOOOOOOOOUUUUUUUUUUYYYYY";
34
- var returnValue = "";
34
+ let returnValue = "";
35
35
  for (let i = 0; i < str.length; i++) {
36
36
  const index = signText.indexOf(str.charAt(i));
37
37
  returnValue += index !== -1 ? unsignedText.charAt(index) : str.charAt(i);
@@ -118,7 +118,7 @@ function generateEnumClass(source, out, field, defaultClassName) {
118
118
  return "";
119
119
  }
120
120
 
121
- var type = getCSharpTypeFromMushroomType(source, mrType, true);
121
+ const type = getCSharpTypeFromMushroomType(source, mrType, true);
122
122
 
123
123
  validation.codeHint = validation.codeHint || {};
124
124
  if (validation.validValues) {
@@ -157,9 +157,9 @@ function generateEnumClass(source, out, field, defaultClassName) {
157
157
 
158
158
  //#region CSharp MongoDb Classes
159
159
  function generateCSharpClassMongoDb(source, className, fields, isRoot, description, out) {
160
- var strClasses = "";
160
+ let strClasses = "";
161
161
  let strEnumClasses = "";
162
- var content = "";
162
+ let content = "";
163
163
  if (description) {
164
164
  content +=
165
165
  ` /// <summary>
@@ -167,7 +167,7 @@ function generateCSharpClassMongoDb(source, className, fields, isRoot, descripti
167
167
  /// </summary>
168
168
  `;
169
169
  }
170
- var supperClass = "";
170
+ let supperClass = "";
171
171
  if (isRoot) {
172
172
  // thêm cho trường hợp không khai báo id hoặc id.type
173
173
  if (!fields.id) {
@@ -182,13 +182,13 @@ function generateCSharpClassMongoDb(source, className, fields, isRoot, descripti
182
182
  content += ` public class ${className}${supperClass}
183
183
  {
184
184
  `;
185
- for (var fieldName in fields) {
185
+ for (const fieldName in fields) {
186
186
  if (!fields.hasOwnProperty(fieldName))
187
187
  continue;
188
188
 
189
- var field = fields[fieldName];
190
- var type;
191
- var propertyName = toCSharpName(fieldName);
189
+ const field = fields[fieldName];
190
+ let type;
191
+ const propertyName = toCSharpName(fieldName);
192
192
  if (field.codeHint && field.codeHint.type && field.codeHint.type.csharp) {
193
193
  type = field.codeHint.type.csharp;
194
194
  }
@@ -252,7 +252,6 @@ function generateCSharpClassMongoDb(source, className, fields, isRoot, descripti
252
252
  out.strEnumClasses = out.strEnumClasses || "";
253
253
 
254
254
  out.strEnumClasses += strEnumClasses;
255
- //console.log("strEnumClasses("+typeof(strEnumClasses)+"):" + strEnumClasses);
256
255
  }
257
256
 
258
257
  return strClasses + newLine + content;
@@ -320,7 +319,7 @@ function genCSharpMongoDbClasses(args, projectName, project, alias, source) {
320
319
  return;
321
320
  if (typeof a.delegator === "string" && a.delegator.indexOf("lib:") === 0) {
322
321
  out.delegators = out.delegators || [];
323
- const method = a.delegator.substr(4, a.delegator.length - 4);
322
+ const method = a.delegator.substring(4);
324
323
  let type = a.codeHint && a.codeHint.delegator && a.codeHint.delegator.csharp
325
324
  ? a.codeHint.delegator.csharp.methodType
326
325
  : null;
@@ -332,7 +331,7 @@ function genCSharpMongoDbClasses(args, projectName, project, alias, source) {
332
331
  });
333
332
  }
334
333
 
335
- if (!a.events && !(typeof a.events === "object")) return;
334
+ if (!a.events && typeof a.events !== "object") return;
336
335
 
337
336
  for (let eventName in a.events) {
338
337
  if (!Array.isArray(a.events[eventName])) return;
@@ -340,7 +339,7 @@ function genCSharpMongoDbClasses(args, projectName, project, alias, source) {
340
339
  out.eventHandlers = out.eventHandlers || [];
341
340
  a.events[eventName].forEach((ev, i) => {
342
341
  if (typeof ev !== "string" || ev.indexOf("lib:") !== 0) return;
343
- const method = ev.substr(4, ev.length - 4);
342
+ const method = ev.substring(4);
344
343
  let type = a.codeHint && a.codeHint.events
345
344
  && Array.isArray(a.codeHint.events[eventName])
346
345
  && a.codeHint.events[eventName][i]
@@ -369,7 +368,7 @@ function genCSharpMongoDbClasses(args, projectName, project, alias, source) {
369
368
 
370
369
  if (typeof v.query === "string" && v.query.indexOf("lib:") === 0) {
371
370
  out.viewHandlers = out.viewHandlers || [];
372
- const method = v.query.substr(4, v.query.length - 4);
371
+ const method = v.query.substring(4);
373
372
  let type = v.codeHint && v.codeHint.query && v.codeHint.query.csharp
374
373
  ? v.codeHint.query.csharp.methodType
375
374
  : null;
@@ -389,7 +388,7 @@ function genCSharpMongoDbClasses(args, projectName, project, alias, source) {
389
388
  if (!channel.nativeBuilder || typeof channel.nativeBuilder !== "string" || channel.nativeBuilder.indexOf("lib:") !== 0) return;
390
389
 
391
390
  out.vnTextChannels = out.vnTextChannels || [];
392
- const method = channel.nativeBuilder.substr(4, channel.nativeBuilder.length - 4);
391
+ const method = channel.nativeBuilder.substring(4);
393
392
  let type = channel.codeHint && channel.codeHint.nativeBuilder && channel.codeHint.nativeBuilder.csharp
394
393
  ? channel.codeHint.nativeBuilder.csharp.methodType
395
394
  : null;
@@ -465,7 +464,7 @@ function genCSharpMongoDbClasses(args, projectName, project, alias, source) {
465
464
  .join(newLine)
466
465
  : "";
467
466
 
468
- const code = `// This file was generated by Mushroom CLI ${package.version} (https://www.npmjs.com/package/mushroom-cli), please do not modify
467
+ const code = `// This file was generated by Mushroom CLI ${package_json.version} (https://www.npmjs.com/package/mushroom-cli), please do not modify
469
468
 
470
469
  // NOTE: Compatible with Mushroom Server version 0.2.18 or higher (https://www.nuget.org/packages/Mushroom/)
471
470
 
@@ -566,7 +565,7 @@ ${strJobReferences}
566
565
  }
567
566
 
568
567
  function generateCSharpClassMongoDbToFolder(source, className, fields, isRoot, description, out, aliasProject) {
569
- var content = "";
568
+ let content = "";
570
569
  const namespace = toCSharpName(source.name);
571
570
  if (description) {
572
571
  content +=
@@ -575,7 +574,7 @@ function generateCSharpClassMongoDbToFolder(source, className, fields, isRoot, d
575
574
  /// </summary>
576
575
  `;
577
576
  }
578
- var supperClass = "";
577
+ let supperClass = "";
579
578
  if (isRoot) {
580
579
  // thêm cho trường hợp không khai báo id hoặc id.type
581
580
  if (!fields.id) {
@@ -590,23 +589,23 @@ function generateCSharpClassMongoDbToFolder(source, className, fields, isRoot, d
590
589
  content += ` public class ${className}${supperClass}
591
590
  {
592
591
  `;
593
- for (var fieldName in fields) {
592
+ for (const fieldName in fields) {
594
593
  if (!fields.hasOwnProperty(fieldName))
595
594
  continue;
596
595
 
597
- var field = fields[fieldName];
598
- var type;
599
- var propertyName = toCSharpName(fieldName);
596
+ const field = fields[fieldName];
597
+ let type;
598
+ const propertyName = toCSharpName(fieldName);
600
599
  if (field.codeHint && field.codeHint.type && field.codeHint.type.csharp) {
601
600
  type = field.codeHint.type.csharp;
602
601
  }
603
602
  else if (field.type === "object") {
604
- generateCSharpClassMongoDbToFolder(source, className + "_" + propertyName, field.fields, false, null, out, aliasProject) + newLine;
603
+ generateCSharpClassMongoDbToFolder(source, className + "_" + propertyName, field.fields, false, null, out, aliasProject);
605
604
  type = className + "_" + propertyName;
606
605
  }
607
606
  else if (field.type === "array") {
608
607
  if (field.items.type === "object") {
609
- generateCSharpClassMongoDbToFolder(source, className + "_" + propertyName, field.items.fields, false, null, out, aliasProject) + newLine;
608
+ generateCSharpClassMongoDbToFolder(source, className + "_" + propertyName, field.items.fields, false, null, out, aliasProject);
610
609
  type = `System.Collections.Generic.List<${className}_${propertyName}>`;
611
610
  } else {
612
611
  type = `System.Collections.Generic.List<${getCSharpTypeFromMushroomType(source, field.items.type, field.items.validation && field.items.validation.required)}>`;
@@ -674,7 +673,6 @@ ${strEnumClasses}
674
673
  }
675
674
  `;
676
675
 
677
- //return strClasses + newLine + content;
678
676
  common.ensureFolder(aliasProject.output + "/Resources", true);
679
677
 
680
678
  content = `${header}
@@ -708,11 +706,10 @@ function genCSharpMongoDbClassesToFolder(projectName, alias, source, aliasProjec
708
706
  fs.unlinkSync(aliasProject.output); // xóa file nếu có
709
707
  } catch(e) {}
710
708
  try {
711
- // fs.rmdirSync(aliasProject.output, { recursive: true, force: true }); // xóa thư mục nếu có
712
709
  fs.rmSync(aliasProject.output, { recursive: true, force: true }); // xóa thư mục nếu có
713
710
  } catch(e) {}
714
711
  }
715
- fs.mkdirSync(aliasProject.output, { recursive: true, mode: 0755 });
712
+ fs.mkdirSync(aliasProject.output, { recursive: true, mode: 493 }); // 493 = 755 in octa
716
713
 
717
714
  const entities = common.getEntities(source, aliasProject.allowRoles, true);
718
715
 
@@ -743,7 +740,6 @@ function genCSharpMongoDbClassesToFolder(projectName, alias, source, aliasProjec
743
740
  `;
744
741
  resourceNames += ` public static string ${className} => "${entityName}";
745
742
  `;
746
- //strClasses += generateCSharpClassMongoDbToFolder(source, className, entities[entityName].fields, true, entities[entityName].description, out);
747
743
 
748
744
  generateCSharpClassMongoDbToFolder(source, className, entities[entityName].fields, true, entities[entityName].description, out, aliasProject);
749
745
 
@@ -758,7 +754,7 @@ function genCSharpMongoDbClassesToFolder(projectName, alias, source, aliasProjec
758
754
  return;
759
755
  if (typeof a.delegator === "string" && a.delegator.indexOf("lib:") === 0) {
760
756
  out.delegators = out.delegators || [];
761
- const method = a.delegator.substr(4, a.delegator.length - 4);
757
+ const method = a.delegator.substring(4);
762
758
  let type = a.codeHint && a.codeHint.delegator && a.codeHint.delegator.csharp
763
759
  ? a.codeHint.delegator.csharp.methodType
764
760
  : null;
@@ -770,7 +766,7 @@ function genCSharpMongoDbClassesToFolder(projectName, alias, source, aliasProjec
770
766
  });
771
767
  }
772
768
 
773
- if (!a.events && !(typeof a.events === "object")) return;
769
+ if (!a.events && typeof a.events !== "object") return;
774
770
 
775
771
  for (let eventName in a.events) {
776
772
  if (!Array.isArray(a.events[eventName])) return;
@@ -778,7 +774,7 @@ function genCSharpMongoDbClassesToFolder(projectName, alias, source, aliasProjec
778
774
  out.eventHandlers = out.eventHandlers || [];
779
775
  a.events[eventName].forEach((ev, i) => {
780
776
  if (typeof ev !== "string" || ev.indexOf("lib:") !== 0) return;
781
- const method = ev.substr(4, ev.length - 4);
777
+ const method = ev.substring(4);
782
778
  let type = a.codeHint && a.codeHint.events
783
779
  && Array.isArray(a.codeHint.events[eventName])
784
780
  && a.codeHint.events[eventName][i]
@@ -807,7 +803,7 @@ function genCSharpMongoDbClassesToFolder(projectName, alias, source, aliasProjec
807
803
 
808
804
  if (typeof v.query === "string" && v.query.indexOf("lib:") === 0) {
809
805
  out.viewHandlers = out.viewHandlers || [];
810
- const method = v.query.substr(4, v.query.length - 4);
806
+ const method = v.query.substring(4);
811
807
  let type = v.codeHint && v.codeHint.query && v.codeHint.query.csharp
812
808
  ? v.codeHint.query.csharp.methodType
813
809
  : null;
@@ -827,7 +823,7 @@ function genCSharpMongoDbClassesToFolder(projectName, alias, source, aliasProjec
827
823
  if (!channel.nativeBuilder || typeof channel.nativeBuilder !== "string" || channel.nativeBuilder.indexOf("lib:") !== 0) return;
828
824
 
829
825
  out.vnTextChannels = out.vnTextChannels || [];
830
- const method = channel.nativeBuilder.substr(4, channel.nativeBuilder.length - 4);
826
+ const method = channel.nativeBuilder.substring(4);
831
827
  let type = channel.codeHint && channel.codeHint.nativeBuilder && channel.codeHint.nativeBuilder.csharp
832
828
  ? channel.codeHint.nativeBuilder.csharp.methodType
833
829
  : null;
@@ -970,7 +966,7 @@ ${strJobReferences}
970
966
  #endif
971
967
  `;
972
968
 
973
- const infoFileContent = `// Mushroom CLI version: ${package.version}${newLine}// Compatible with Mushroom Server version: 0.2.25.4 or higher (https://www.nuget.org/packages/Mushroom/)
969
+ const infoFileContent = `// Mushroom CLI version: ${package_json.version}${newLine}// Compatible with Mushroom Server version: 0.2.25.4 or higher (https://www.nuget.org/packages/Mushroom/)
974
970
  // For Mushroom Server 0.2.18 to 0.2.25.4: Please remove all FindById methods in DbConnector.cs`
975
971
 
976
972
  fs.writeFileSync(aliasProject.output + "/DbConnector.cs", dbConnectorFileContent);
@@ -985,9 +981,9 @@ ${strJobReferences}
985
981
 
986
982
  //#region CSharp Driver
987
983
  function generateCSharpClassDriver(source, className, fields, description, out) {
988
- var strClasses = "";
989
- var strEnumClasses = "";
990
- var content = "";
984
+ let strClasses = "";
985
+ let strEnumClasses = "";
986
+ let content = "";
991
987
  if (description) {
992
988
  content +=
993
989
  ` /// <summary>
@@ -1051,30 +1047,30 @@ function genCSharpDriver(args, projectName, project, alias, source) {
1051
1047
 
1052
1048
  const entities = common.getEntities(source, aliasProject.allowRoles);
1053
1049
 
1054
- var namespace = toCSharpName(source.name);
1050
+ const namespace = toCSharpName(source.name);
1055
1051
 
1056
- var strClasses = "";
1057
- var strEnumClasses = "";
1058
- var codeStaticCtor = "";
1059
- var codeStaticProperties = "";
1060
- var codeConnectors = "";
1061
- var codeExtraClasses = "";
1052
+ let strClasses = "";
1053
+ let strEnumClasses = "";
1054
+ let codeStaticCtor = "";
1055
+ let codeStaticProperties = "";
1056
+ let codeConnectors = "";
1057
+ let codeExtraClasses = "";
1062
1058
 
1063
- var out = {};
1059
+ const out = {};
1064
1060
 
1065
1061
  let accessModifier = aliasProject.accessModifier || "internal";
1066
1062
 
1067
- for (var entityName in entities) {
1063
+ for (const entityName in entities) {
1068
1064
  if (!entities.hasOwnProperty(entityName))
1069
1065
  continue;
1070
1066
 
1071
- var className = toCSharpName(entityName);
1067
+ const className = toCSharpName(entityName);
1072
1068
 
1073
1069
  strClasses += generateCSharpClassDriver(source, className, entities[entityName].fields, entities[entityName].description, out);
1074
1070
  codeStaticCtor += ` ${className} = new ${className}Connector(client);${newLine}`;
1075
1071
  codeStaticProperties += ` public static ${className}Connector ${className} { get; }${newLine}${newLine}`;
1076
1072
 
1077
- var entity = entities[entityName];
1073
+ const entity = entities[entityName];
1078
1074
 
1079
1075
  codeConnectors += ` ${accessModifier} partial class ${className}Connector : MushroomDriver.MushroomResourceConnector<${className}>
1080
1076
  {
@@ -1095,7 +1091,7 @@ function genCSharpDriver(args, projectName, project, alias, source) {
1095
1091
  `;
1096
1092
  }
1097
1093
 
1098
- for (var actionName in entity.actions) {
1094
+ for (const actionName in entity.actions) {
1099
1095
  if (!entity.actions.hasOwnProperty(actionName))
1100
1096
  continue;
1101
1097
 
@@ -1182,7 +1178,7 @@ function genCSharpDriver(args, projectName, project, alias, source) {
1182
1178
  if (actionName.indexOf("_raw_http_method_"))
1183
1179
  break;
1184
1180
 
1185
- var customMethod = toCSharpName(actionName.substring("_raw_http_method_".length));
1181
+ const customMethod = toCSharpName(actionName.substring("_raw_http_method_".length));
1186
1182
 
1187
1183
  codeConnectors += ` public async System.Threading.Tasks.Task<${className}${customMethod}Result> ${customMethod}(${className}${customMethod}Arg arg)
1188
1184
  {
@@ -1287,7 +1283,7 @@ function genCSharpDriver(args, projectName, project, alias, source) {
1287
1283
  {
1288
1284
  `;
1289
1285
  view.parameters.forEach(p => {
1290
- var type = getCSharpTypeFromMushroomType(source, p.type, p.validation && p.validation.required);
1286
+ let type = getCSharpTypeFromMushroomType(source, p.type, p.validation && p.validation.required);
1291
1287
  if (p.isArray)
1292
1288
  type = `System.Collections.Generic.List<${type}>`;
1293
1289
  viewExtraClass += ` [Newtonsoft.Json.JsonProperty(PropertyName = "${p.field}")]
@@ -1332,7 +1328,7 @@ ${viewExtraClass}`;
1332
1328
  if (out.strEnumClasses)
1333
1329
  strEnumClasses += out.strEnumClasses;
1334
1330
 
1335
- const code = `// This file was generated by Mushroom CLI ${package.version} (https://www.npmjs.com/package/mushroom-cli), please do not modify
1331
+ const code = `// This file was generated by Mushroom CLI ${package_json.version} (https://www.npmjs.com/package/mushroom-cli), please do not modify
1336
1332
 
1337
1333
  // Require package: Mushroom.Driver version 1.4.0 or later (https://www.nuget.org/packages/Mushroom.Driver/)
1338
1334
 
@@ -7,7 +7,7 @@ function encodeHtml(str) {
7
7
  return "";
8
8
  if (typeof str !== "string")
9
9
  str = str.toString();
10
- var html = str.replace(/&/g, "&amp;");
10
+ let html = str.replace(/&/g, "&amp;");
11
11
  html = html.replace(/</g, "&lt;");
12
12
  html = html.replace(/>/g, "&gt;");
13
13
  html = html.replace(/"/g, "&quot;");
@@ -1,9 +1,9 @@
1
1
  const fs = require("fs");
2
2
  const path = require('path');
3
- var targz = require('targz');
3
+ const targz = require('targz');
4
4
  const javascriptDriverGenerator = require("./gen-js-driver");
5
5
  const typescriptDriverGenerator = require("./gen-ts-driver");
6
- const package = require("./../package.json");
6
+ const package_json = require("./../package.json");
7
7
 
8
8
  function compressAsync(src, dest, folderName) {
9
9
  return new Promise((resolve, reject) => {
@@ -39,7 +39,7 @@ async function genJavascriptDriverTarball(args, projectName, project, alias, sou
39
39
 
40
40
  const dirPath = path.join(path.dirname(aliasProject.output), tarballName);
41
41
 
42
- const versionGroup = package.version.match(/([^-]+)(-(\w+).*)?/);
42
+ const versionGroup = package_json.version.match(/([^-]+)(-(\w+).*)?/);
43
43
  const currentDistTag = versionGroup[3] ? versionGroup[3] : "latest";
44
44
 
45
45
  const dependencies = [`"mushroomjs": "${currentDistTag}"`];
@@ -63,7 +63,6 @@ async function genJavascriptDriverTarball(args, projectName, project, alias, sou
63
63
 
64
64
  if (fs.existsSync(dirPath)) {
65
65
  console.log("Clean up tarball folder");
66
- // fs.rmdirSync(dirPath, { recursive: true });
67
66
  fs.rmSync(dirPath, { recursive: true });
68
67
  }
69
68
 
@@ -76,7 +75,7 @@ async function genJavascriptDriverTarball(args, projectName, project, alias, sou
76
75
 
77
76
  console.log("Creating tarball folder");
78
77
 
79
- fs.mkdirSync(dirPath, { recursive: true, mode: 0755 });
78
+ fs.mkdirSync(dirPath, { recursive: true, mode: 493 }); // 493 = 755 in octa
80
79
 
81
80
  console.log("Generating main file: " + tarballName + ".js");
82
81
  let code = javascriptDriverGenerator.genJavascriptDriverString(aliasProject, source);
@@ -93,7 +92,6 @@ async function genJavascriptDriverTarball(args, projectName, project, alias, sou
93
92
  await compressAsync(dirPath, tarballFileName, tarballName);
94
93
 
95
94
  console.log("Generated tarball file");
96
- // fs.rmdirSync(dirPath, { recursive: true });
97
95
  fs.rmSync(dirPath, { recursive: true });
98
96
  console.log("Cleaned up tarball folder");
99
97
  }
@@ -25,7 +25,7 @@ function isAllowCache(actions, defaultValue) {
25
25
  function toVietnameseNonTongue(str) {
26
26
  const signText = "ăâđêôơưàảãạáằẳẵặắầẩẫậấèẻẽẹéềểễệếìỉĩịíòỏõọóồổỗộốờởỡợớùủũụúừửữựứỳỷỹỵýĂÂĐÐÊÔƠƯÀẢÃẠÁẰẲẴẶẮẦẨẪẬẤÈẺẼẸÉỀỂỄỆẾÌỈĨỊÍÒỎÕỌÓỒỔỖỘỐỜỞỠỢỚÙỦŨỤÚỪỬỮỰỨỲỶỸỴÝ";
27
27
  const unsignedText = "aadeoouaaaaaaaaaaaaaaaeeeeeeeeeeiiiiiooooooooooooooouuuuuuuuuuyyyyyAADDEOOUAAAAAAAAAAAAAAAEEEEEEEEEEIIIIIOOOOOOOOOOOOOOOUUUUUUUUUUYYYYY";
28
- var returnValue = "";
28
+ let returnValue = "";
29
29
  for (let i = 0; i < str.length; i++) {
30
30
  const index = signText.indexOf(str.charAt(i));
31
31
  returnValue += index !== -1 ? unsignedText.charAt(index) : str.charAt(i);
package/gen.js CHANGED
@@ -55,7 +55,7 @@ async function gen(args) {
55
55
  if (!project.src)
56
56
  throw new Error("Project source (src) not found");
57
57
 
58
- var source;
58
+ let source;
59
59
  try {
60
60
  const sourceContent = fs.readFileSync(project.src).toString();
61
61
  source = JSON5.parse(sourceContent);
@@ -71,7 +71,6 @@ async function gen(args) {
71
71
  if (Array.isArray(source.fragments)) {
72
72
  console.log("Process master file: " + project.src);
73
73
  source = masterFile.processMasterFile(path.dirname(project.src), source);
74
- //console.log(source);
75
74
  }
76
75
 
77
76
  if (!source || typeof source !== "object") {
package/init/init-json.js CHANGED
@@ -17,8 +17,8 @@ function initJson(args) {
17
17
  }
18
18
 
19
19
  if (args[3] === "silent") {
20
- console.log("Fetch http://api.siten.vn/gen/template/default.json");
21
- fetch("http://api.siten.vn/gen/template/default.json").then(res => res.text()).then(text => {
20
+ console.log("Fetch https://api.siten.vn/gen/template/default.json");
21
+ fetch("https://api.siten.vn/gen/template/default.json").then(res => res.text()).then(text => {
22
22
  common.ensureFolder(path);
23
23
 
24
24
  fs.writeFile(path, text, err => {
@@ -30,8 +30,8 @@ function initJson(args) {
30
30
  return;
31
31
  }
32
32
 
33
- console.log("Fetch http://api.siten.vn/gen/template/template-def.json");
34
- fetch("http://api.siten.vn/gen/template/template-def.json").then(res => res.json()).then(templateConfig => {
33
+ console.log("Fetch https://api.siten.vn/gen/template/template-def.json");
34
+ fetch("https://api.siten.vn/gen/template/template-def.json").then(res => res.json()).then(templateConfig => {
35
35
  const info = {};
36
36
  templateConfig.fields.forEach(field => {
37
37
  while (true)
@@ -84,15 +84,13 @@ function initJson(args) {
84
84
  break;
85
85
  }
86
86
  });
87
- //console.log(info);
88
87
 
89
88
  console.log(`Fetch ${templateConfig.templateUrl}`);
90
89
  fetch(templateConfig.templateUrl).then(res => res.text()).then(json => {
91
- json = json.replace(/\"\$\{([\w]+)\}\"/g, (s0, s1) => JSON.stringify(info[s1]));
92
- json = json.replace(/\$\{([\w]+)\}/g, (s0, s1) => JSON.stringify(info[s1]).replace(/^\"|\"$/g, ""));
90
+ json = json.replace(/\"\$\{(\w+)\}\"/g, (s0, s1) => JSON.stringify(info[s1]));
91
+ json = json.replace(/\$\{(\w+)\}/g, (s0, s1) => JSON.stringify(info[s1]).replace(/(^")|("$)/g, ""));
93
92
 
94
93
  common.ensureFolder(path);
95
- //console.log(json);
96
94
 
97
95
  fs.writeFile(path, json, err => {
98
96
  if (err)
@@ -27,7 +27,7 @@ function transformEntityFieldNode(field) {
27
27
  if (!field.fields || typeof field.fields !== "object")
28
28
  return;
29
29
 
30
- for (var fieldName in field.fields) {
30
+ for (const fieldName in field.fields) {
31
31
  transformEntityFieldNode(field.fields[fieldName]);
32
32
  }
33
33
  }
@@ -48,7 +48,7 @@ function mergeApiProject(totalProject, fragmentProject, options) {
48
48
  if (fragmentProject.environmentVariables != null) {
49
49
  totalProject.environmentVariables = totalProject.environmentVariables || {};
50
50
 
51
- for (var name in fragmentProject.environmentVariables) {
51
+ for (const name in fragmentProject.environmentVariables) {
52
52
  if (name in totalProject.environmentVariables) {
53
53
  switch (options.environmentVariable.duplicateNameHandling) {
54
54
  case "override":
@@ -70,7 +70,7 @@ function mergeApiProject(totalProject, fragmentProject, options) {
70
70
 
71
71
  fragmentProject.entities.forEach(entity => {
72
72
 
73
- var found = totalProject.entities.some((entityInTotal, i) => {
73
+ const found = totalProject.entities.some((entityInTotal, i) => {
74
74
  if (entityInTotal.name !== entity.name){
75
75
  return false;
76
76
  }
@@ -89,12 +89,11 @@ function mergeApiProject(totalProject, fragmentProject, options) {
89
89
  return;
90
90
 
91
91
  totalProject.entities.push(entity);
92
- // console.log("add new entity: " + entity.name + "; totalProject.entities.length=" + totalProject.entities.length);
93
92
 
94
93
  if (!entity.fields || typeof entity.fields !== "object")
95
94
  return;
96
95
 
97
- for (var fieldName in entity.fields) {
96
+ for (const fieldName in entity.fields) {
98
97
  transformEntityFieldNode(entity.fields[fieldName]);
99
98
  }
100
99
  });
@@ -103,7 +102,7 @@ function mergeApiProject(totalProject, fragmentProject, options) {
103
102
  if (fragmentProject.views != null) {
104
103
  totalProject.views = totalProject.views || {};
105
104
 
106
- for (var viewName in fragmentProject.views)
105
+ for (const viewName in fragmentProject.views)
107
106
  {
108
107
  if (viewName in totalProject.views)
109
108
  {
@@ -131,7 +130,7 @@ function mergeApiProject(totalProject, fragmentProject, options) {
131
130
  }
132
131
 
133
132
 
134
- for (var name in fragmentProject) {
133
+ for (const name in fragmentProject) {
135
134
  if (name === "environmentVariables" || name === "entities" || name === "views" || name === "$schema")
136
135
  continue;
137
136
 
@@ -176,7 +175,7 @@ function processMasterFile(basePath, master) {
176
175
  if (apiProject == null)
177
176
  return null;
178
177
 
179
- apiProject["$schema"] = "http://schema.siten.vn/mushroom/project.json";
178
+ apiProject["$schema"] = "https://schema.siten.vn/mushroom/project.json";
180
179
 
181
180
  if (apiProject.entities == null)
182
181
  apiProject.entities = [];
package/mr.js CHANGED
@@ -36,7 +36,7 @@ async function run(args) {
36
36
  await init(args);
37
37
  break;
38
38
  case "config":
39
- await config(args);
39
+ config(args);
40
40
  break;
41
41
  case "gen":
42
42
  await gen(args);
@@ -64,7 +64,7 @@ async function run(args) {
64
64
 
65
65
  if (checkUpdateTask !== null)
66
66
  try {
67
- var data = await checkUpdateTask;
67
+ const data = await checkUpdateTask;
68
68
  if (data["dist-tags"] && data["dist-tags"][currentDistTag] && data["dist-tags"][currentDistTag] !== pkg.version) {
69
69
  console.warn(`YOUR mushroom-cli VERSION IS NOT LATEST (dist-tags: ${currentDistTag}). PLEASE RUN: npm i mushroom-cli@${data["dist-tags"][currentDistTag]} OR yarn add mushroom-cli@^${data["dist-tags"][currentDistTag]}`);
70
70
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mushroom-cli",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "description": "Mushroom CLI",
5
5
  "main": "mr.js",
6
6
  "scripts": {
@@ -17,7 +17,7 @@
17
17
  "author": "suco2007",
18
18
  "license": "ISC",
19
19
  "dependencies": {
20
- "jsdom": "^21.0.0",
20
+ "jsdom": "^24.1.1",
21
21
  "json5": "^2.2.3",
22
22
  "node-fetch": "^2.6.7",
23
23
  "open": "^8.4.0",
package/sonarqube.yml ADDED
@@ -0,0 +1,18 @@
1
+ pool:
2
+ name: SitenWindows
3
+
4
+ steps:
5
+ - task: SonarQubePrepare@6
6
+ inputs:
7
+ SonarQube: 'SonarQube-MushroomCLI'
8
+ scannerMode: 'CLI'
9
+ configMode: 'manual'
10
+ cliProjectKey: 'MushroomServer_mushroom-cli_AZBIWpTNDwLpW4gwuNzH'
11
+ cliProjectName: 'mushroom-cli'
12
+ cliSources: '.'
13
+
14
+ - task: SonarQubeAnalyze@6
15
+
16
+ - task: SonarQubePublish@6
17
+ inputs:
18
+ pollingTimeoutSec: '300'
package/update/tsCode.js CHANGED
@@ -2,19 +2,84 @@ const fs = require("fs");
2
2
  const fetch = require('node-fetch');
3
3
 
4
4
  async function updateTsCode(options) {
5
- if (!options.output) {
6
- console.error("Missing output file path");
5
+ if (options.input || options.output) {
6
+ // legacy way
7
+ if (!options.output) {
8
+ console.error("Missing output file path");
9
+ return;
10
+ }
11
+ if (!options.input) {
12
+ console.error("Missing remote url");
13
+ return;
14
+ }
15
+ pullAsync(options.input, output);
16
+ console.log("Finish update ts-code");
7
17
  return;
8
18
  }
9
- if (!options.input) {
10
- console.error("Missing remote url");
19
+
20
+ // new way, using mushroom-config.json file
21
+ if (!fs.existsSync("mushroom-config.json")) {
22
+ console.error("Missing mushroom-config.json file");
11
23
  return;
12
24
  }
13
- console.log(`Fetch ${options.input}`);
14
- const res = await fetch(options.input);
15
- console.log(`Write to ${options.output}`);
16
- fs.writeFileSync(options.output, await res.text());
17
- console.log(`Finish update ts-code`);
25
+ const configJson = fs.readFileSync("mushroom-config.json");
26
+ const config = JSON.parse(configJson);
27
+ if (!config.update) {
28
+ console.error("Missing 'update' in mushroom-config.json file");
29
+ return;
30
+ }
31
+ if (!config.update["ts-code"]) {
32
+ console.error("Missing 'update.ts-code' in mushroom-config.json file");
33
+ return;
34
+ }
35
+
36
+ const steps = config.update["ts-code"].steps;
37
+ if (!steps) {
38
+ console.error("Missing 'update.ts-code.steps' in mushroom-config.json file");
39
+ return;
40
+ }
41
+
42
+ for (let i = 0; i < steps.length; i++) {
43
+ const step = steps[i];
44
+ switch (step.action) {
45
+ case "pull":
46
+ await pullAsync(step.source, step.destination);
47
+ break;
48
+ case "replace-content":
49
+ replaceContent(step.source, step.search, step.replacement);
50
+ break;
51
+ case "replace-regex":
52
+ replaceContent(step.source, step.pattern, step.replacement);
53
+ break;
54
+ default:
55
+ console.warn(`Unsupported step action: ${step.action}`);
56
+ break;
57
+ }
58
+ }
59
+ console.log("Finish update ts-code");
60
+ }
61
+
62
+ async function pullAsync(input, output) {
63
+ console.log(`Fetch ${input}`);
64
+ const res = await fetch(input);
65
+ console.log(`Write to ${output}`);
66
+ fs.writeFileSync(output, await res.text());
67
+ }
68
+
69
+ function replaceContent(input, search, replacement) {
70
+ console.log(`Replace ${search} by ${replacement} in ${input} file`);
71
+ const content = fs.readFileSync(input).toString();
72
+ if (!content) return;
73
+ const output = content.replace(new RegExp(search.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), "g"), replacement);
74
+ fs.writeFileSync(input, output);
75
+ }
76
+
77
+ function replaceRegex(input, pattern, replacement) {
78
+ console.log(`Replace pattern ${pattern} by ${replacement} in ${input} file`);
79
+ const content = fs.readFileSync(input).toString();
80
+ if (!content) return;
81
+ const output = content.replace(new RegExp(pattern, "g"), replacement);
82
+ fs.writeFileSync(input, output);
18
83
  }
19
84
 
20
85
  module.exports = updateTsCode;