mushroom-cli 1.1.0-alpha.15 → 1.1.0-alpha.18

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/docs/docs.html CHANGED
@@ -5037,6 +5037,10 @@ creatorId: IdRef - optional, mã người tạo
5037
5037
  holder.appendChild(copyButton);
5038
5038
  $(this).prepend(holder);
5039
5039
  copyButton.onclick = function() {
5040
+ if (location.protocol !== 'https:' && location.protocol !== 'file:') {
5041
+ alert("Can not copy, please use https protocol!");
5042
+ return;
5043
+ }
5040
5044
  const pre = $(this).parent().parent();
5041
5045
  const commandBar = $(this).parent().detach();
5042
5046
  const content = pre.text();
@@ -5052,6 +5056,10 @@ creatorId: IdRef - optional, mã người tạo
5052
5056
  copyButton.innerHTML = "Copy (without comment)";
5053
5057
  $(this).prepend(copyButton);
5054
5058
  copyButton.onclick = function() {
5059
+ if (location.protocol !== 'https:' && location.protocol !== 'file:') {
5060
+ alert("Can not copy, please use https protocol!");
5061
+ return;
5062
+ }
5055
5063
  const pre = $(this).parent().parent();
5056
5064
  const commandBar = $(this).parent().detach();
5057
5065
  pre.find(".code-comment").each(function() {
@@ -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="([^"]+)" data-mt-cond='\{"lazy-load": 1\}'><\/script>/g, (scriptTag, src) => `<script data-mt-cond='{"x": 1}'>${fs.readFileSync("./docs/" + src).toString()}</script>`);
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)};
@@ -118,7 +118,7 @@ async function genDocs(args, projectName, project, alias, source) {
118
118
  }
119
119
 
120
120
  //const html = await fetch('https://api.siten.vn/gen/docs.html').then(res => res.text());
121
- const html = fs.readFileSync("./docs/docs.html").toString();
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
 
package/gen/gen-csharp.js CHANGED
@@ -20,13 +20,7 @@ const header = `// NOTE: Please do not modify this file
20
20
  // ReSharper disable UnusedMember.Local
21
21
  // ReSharper disable UnusedParameter.Local
22
22
  // ReSharper disable UnusedTypeParameter
23
-
24
-
25
- using MongoDB.Bson;
26
- using MongoDB.Bson.Serialization.Attributes;
27
- using MongoDB.Driver;
28
- using JsonPropertyAttribute = Newtonsoft.Json.JsonPropertyAttribute;
29
- using NullValueHandling = Newtonsoft.Json.NullValueHandling;`;
23
+ `;
30
24
 
31
25
  function singleLine(str) {
32
26
  if (!str)
@@ -216,30 +210,30 @@ function generateCSharpClassMongoDb(source, className, fields, isRoot, descripti
216
210
  `;
217
211
 
218
212
  if (isRoot && fieldName === "id") {
219
- content += ` [BsonId${field.type === "AutoId" && source.idType === "GUID" ? "(IdGenerator = typeof(MongoDB.Bson.Serialization.IdGenerators.GuidGenerator))" : ""}]${newLine}`;
213
+ content += ` [MongoDB.Bson.Serialization.Attributes.BsonId${field.type === "AutoId" && source.idType === "GUID" ? "(IdGenerator = typeof(MongoDB.Bson.Serialization.IdGenerators.GuidGenerator))" : ""}]${newLine}`;
220
214
  }
221
- content += ` [BsonElement("${isRoot && fieldName === "id" ? "_id" : fieldName}")]
222
- [BsonIgnoreIfNull]
223
- [JsonProperty(PropertyName = "${fieldName}", NullValueHandling = NullValueHandling.Ignore)]
215
+ content += ` [MongoDB.Bson.Serialization.Attributes.BsonElement("${isRoot && fieldName === "id" ? "_id" : fieldName}")]
216
+ [MongoDB.Bson.Serialization.Attributes.BsonIgnoreIfNull]
217
+ [Newtonsoft.Json.JsonProperty(PropertyName = "${fieldName}", NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
224
218
  `;
225
219
  if ((field.type === "AutoId" || field.type === "IdRef") && source.idType === "ObjectId") {
226
- content += " [BsonRepresentation(BsonType.ObjectId)]" + newLine;
220
+ content += " [MongoDB.Bson.Serialization.Attributes.BsonRepresentation(MongoDB.Bson.BsonType.ObjectId)]" + newLine;
227
221
  }
228
222
  if (field.type === "AutoId" && source.idType === "GUID") {
229
- content += " [BsonRepresentation(BsonType.String)]" + newLine;
223
+ content += " [MongoDB.Bson.Serialization.Attributes.BsonRepresentation(MongoDB.Bson.BsonType.String)]" + newLine;
230
224
  }
231
225
  if (field.type === "datetime") {
232
- content += " [BsonDateTimeOptions(Kind = System.DateTimeKind.Local)]" + newLine;
226
+ content += " [MongoDB.Bson.Serialization.Attributes.BsonDateTimeOptions(Kind = System.DateTimeKind.Local)]" + newLine;
233
227
  }
234
228
  if (field.type === "array") {
235
229
  if ((field.items.type === "AutoId" || field.items.type === "IdRef") && source.idType === "ObjectId") {
236
- content += " [BsonRepresentation(BsonType.ObjectId)]" + newLine;
230
+ content += " [MongoDB.Bson.Serialization.Attributes.BsonRepresentation(MongoDB.Bson.BsonType.ObjectId)]" + newLine;
237
231
  }
238
232
  if (field.items.type === "AutoId" && source.idType === "GUID") {
239
- content += " [BsonRepresentation(BsonType.String)]" + newLine;
233
+ content += " [MongoDB.Bson.Serialization.Attributes.BsonRepresentation(MongoDB.Bson.BsonType.String)]" + newLine;
240
234
  }
241
235
  if (field.items.type === "datetime") {
242
- content += " [BsonDateTimeOptions(Kind = System.DateTimeKind.Local)]" + newLine;
236
+ content += " [MongoDB.Bson.Serialization.Attributes.BsonDateTimeOptions(Kind = System.DateTimeKind.Local)]" + newLine;
243
237
  }
244
238
  }
245
239
 
@@ -247,7 +241,7 @@ function generateCSharpClassMongoDb(source, className, fields, isRoot, descripti
247
241
 
248
242
  strEnumClasses += generateEnumClass(source, out, field, `${className.toUpperCase()}_${propertyName.toUpperCase()}_ENUM`);
249
243
  }
250
- content += ` [BsonExtraElements]
244
+ content += ` [MongoDB.Bson.Serialization.Attributes.BsonExtraElements]
251
245
  public System.Collections.Generic.Dictionary<string, object> Mushroom_ExtraProperties { get; set; }
252
246
 
253
247
  }
@@ -452,14 +446,10 @@ function genCSharpMongoDbClasses(args, projectName, project, alias, source) {
452
446
  // ReSharper disable CommentTypo
453
447
  // ReSharper disable EmptyNamespace
454
448
 
455
- using MongoDB.Bson;
456
- using MongoDB.Bson.Serialization.Attributes;
457
- using MongoDB.Driver;
458
- using JsonPropertyAttribute = Newtonsoft.Json.JsonPropertyAttribute;
459
- using NullValueHandling = Newtonsoft.Json.NullValueHandling;
460
-
461
449
  namespace ${namespace}
462
450
  {
451
+ using MongoDB.Driver;
452
+
463
453
  public static class DbConnector
464
454
  {
465
455
  ${collectionNames}
@@ -590,30 +580,30 @@ function generateCSharpClassMongoDbToFolder(source, className, fields, isRoot, d
590
580
  `;
591
581
 
592
582
  if (isRoot && fieldName === "id") {
593
- content += ` [BsonId${field.type === "AutoId" && source.idType === "GUID" ? "(IdGenerator = typeof(MongoDB.Bson.Serialization.IdGenerators.GuidGenerator))" : ""}]${newLine}`;
583
+ content += ` [MongoDB.Bson.Serialization.Attributes.BsonId${field.type === "AutoId" && source.idType === "GUID" ? "(IdGenerator = typeof(MongoDB.Bson.Serialization.IdGenerators.GuidGenerator))" : ""}]${newLine}`;
594
584
  }
595
- content += ` [BsonElement("${isRoot && fieldName === "id" ? "_id" : fieldName}")]
596
- [BsonIgnoreIfNull]
597
- [JsonProperty(PropertyName = "${fieldName}", NullValueHandling = NullValueHandling.Ignore)]
585
+ content += ` [MongoDB.Bson.Serialization.Attributes.BsonElement("${isRoot && fieldName === "id" ? "_id" : fieldName}")]
586
+ [MongoDB.Bson.Serialization.Attributes.BsonIgnoreIfNull]
587
+ [Newtonsoft.Json.JsonProperty(PropertyName = "${fieldName}", NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
598
588
  `;
599
589
  if ((field.type === "AutoId" || field.type === "IdRef") && source.idType === "ObjectId") {
600
- content += " [BsonRepresentation(BsonType.ObjectId)]" + newLine;
590
+ content += " [MongoDB.Bson.Serialization.Attributes.BsonRepresentation(MongoDB.Bson.BsonType.ObjectId)]" + newLine;
601
591
  }
602
592
  if (field.type === "AutoId" && source.idType === "GUID") {
603
- content += " [BsonRepresentation(BsonType.String)]" + newLine;
593
+ content += " [MongoDB.Bson.Serialization.Attributes.BsonRepresentation(MongoDB.Bson.BsonType.String)]" + newLine;
604
594
  }
605
595
  if (field.type === "datetime") {
606
- content += " [BsonDateTimeOptions(Kind = System.DateTimeKind.Local)]" + newLine;
596
+ content += " [MongoDB.Bson.Serialization.Attributes.BsonDateTimeOptions(Kind = System.DateTimeKind.Local)]" + newLine;
607
597
  }
608
598
  if (field.type === "array") {
609
599
  if ((field.items.type === "AutoId" || field.items.type === "IdRef") && source.idType === "ObjectId") {
610
- content += " [BsonRepresentation(BsonType.ObjectId)]" + newLine;
600
+ content += " [MongoDB.Bson.Serialization.Attributes.BsonRepresentation(MongoDB.Bson.BsonType.ObjectId)]" + newLine;
611
601
  }
612
602
  if (field.items.type === "AutoId" && source.idType === "GUID") {
613
- content += " [BsonRepresentation(BsonType.String)]" + newLine;
603
+ content += " [MongoDB.Bson.Serialization.Attributes.BsonRepresentation(MongoDB.Bson.BsonType.String)]" + newLine;
614
604
  }
615
605
  if (field.items.type === "datetime") {
616
- content += " [BsonDateTimeOptions(Kind = System.DateTimeKind.Local)]" + newLine;
606
+ content += " [MongoDB.Bson.Serialization.Attributes.BsonDateTimeOptions(Kind = System.DateTimeKind.Local)]" + newLine;
617
607
  }
618
608
  }
619
609
 
@@ -637,8 +627,8 @@ ${strEnumClasses}
637
627
  fs.writeFileSync(aliasProject.output + "/Enums/" + match[1] + ".cs", strEnumClasses);
638
628
  }
639
629
 
640
- content += ` [BsonExtraElements]
641
- [JsonIgnore]
630
+ content += ` [MongoDB.Bson.Serialization.Attributes.BsonExtraElements]
631
+ [Newtonsoft.Json.JsonIgnore]
642
632
  public System.Collections.Generic.Dictionary<string, object> Mushroom_ExtraProperties { get; set; }
643
633
 
644
634
  }
@@ -655,7 +645,20 @@ ${content}
655
645
  }
656
646
  `;
657
647
 
658
- fs.writeFileSync(aliasProject.output + "/Resources/" + className + ".cs", content);
648
+ out.allClasses = out.allClasses || [];
649
+
650
+ const normalizedName = className.toLowerCase();
651
+ const duplicate = out.allClasses.find(c => c.normalizedName == normalizedName);
652
+ if (duplicate) {
653
+ fs.appendFileSync(aliasProject.output + "/Resources/" + duplicate.className + ".cs", content);
654
+ }
655
+ else {
656
+ out.allClasses.push({
657
+ className,
658
+ normalizedName
659
+ });
660
+ fs.writeFileSync(aliasProject.output + "/Resources/" + className + ".cs", content);
661
+ }
659
662
  }
660
663
 
661
664
  function genCSharpMongoDbClassesToFolder(projectName, alias, source, aliasProject) {
@@ -826,6 +829,7 @@ function genCSharpMongoDbClassesToFolder(projectName, alias, source, aliasProjec
826
829
  : "";
827
830
 
828
831
  const dbConnectorFileContent = `${header}
832
+ using MongoDB.Driver;
829
833
 
830
834
  namespace ${namespace}
831
835
  {
@@ -955,7 +959,7 @@ function generateCSharpClassDriver(source, className, fields, description, out)
955
959
  ` /// <summary>
956
960
  /// ${singleLine(field.description)}
957
961
  /// </summary>
958
- [JsonProperty(PropertyName ="${fieldName}", NullValueHandling = NullValueHandling.Ignore)]
962
+ [Newtonsoft.Json.JsonProperty(PropertyName ="${fieldName}", NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
959
963
  public ${type} ${propertyName} { get; set; }
960
964
 
961
965
  `;
@@ -1221,7 +1225,7 @@ function genCSharpDriver(args, projectName, project, alias, source) {
1221
1225
  var type = getCSharpTypeFromMushroomType(source, p.type, p.validation && p.validation.required);
1222
1226
  if (p.isArray)
1223
1227
  type = `System.Collections.Generic.List<${type}>`;
1224
- viewExtraClass += ` [JsonProperty(PropertyName = "${p.field}")]
1228
+ viewExtraClass += ` [Newtonsoft.Json.JsonProperty(PropertyName = "${p.field}")]
1225
1229
  public ${type} ${toCSharpName(p.field)} { get; set; }
1226
1230
 
1227
1231
  `;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mushroom-cli",
3
- "version": "1.1.0-alpha.15",
3
+ "version": "1.1.0-alpha.18",
4
4
  "description": "Mushroom CLI",
5
5
  "main": "mr.js",
6
6
  "scripts": {