@lwc-bolts/sf2ts 0.0.3 → 0.0.4

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.
@@ -2,6 +2,7 @@ export { ApexClass } from "./apex-class.mjs";
2
2
  export { ContentAsset } from "./content-asset.mjs";
3
3
  export { CustomPermission } from "./custom-permission.mjs";
4
4
  export { CustomField } from "./custom-field.mjs";
5
+ export { CustomLabel } from "./custom-label.mjs";
5
6
  export { CustomLabels } from "./custom-labels.mjs";
6
7
  export { CustomObject } from "./custom-object.mjs";
7
8
  export { StaticResource } from "./static-resource.mjs";
@@ -0,0 +1,62 @@
1
+ /** @import { Component, ConvertedComponent } from "../index.mjs" */
2
+ import { parseString } from "xml2js";
3
+ import { PositionAwareTextBuilder } from "../util.mjs";
4
+
5
+ /**
6
+ *
7
+ * @param {Component} component
8
+ * @returns {ConvertedComponent}
9
+ */
10
+ export function CustomLabel(component) {
11
+ // generate d.ts
12
+ /** @type {any} */
13
+ let labels;
14
+ parseString(component.content, (error, result) => {
15
+ if (error) {
16
+ throw error;
17
+ }
18
+ labels = result;
19
+ });
20
+ console.log(labels.CustomLabel);
21
+ const builder = new PositionAwareTextBuilder();
22
+ getDtsFromLabel(builder, component.content, labels.CustomLabel);
23
+ return {
24
+ declarationContent: builder.build(),
25
+ mapData: builder.getMappings(),
26
+ ...component,
27
+ };
28
+ }
29
+
30
+ /**
31
+ *
32
+ * @param {PositionAwareTextBuilder} builder
33
+ * @param {string} content
34
+ * @param {any} label
35
+ */
36
+ export function getDtsFromLabel(builder, content, label) {
37
+ const labelName = label.fullName[0];
38
+ const namePosStart =
39
+ content.indexOf(`<fullName>${labelName}`) + `<fullName>`.length;
40
+ const namePosEnd = namePosStart + labelName.length;
41
+
42
+ builder.addText(`declare module `);
43
+ builder.addText(
44
+ `"@salesforce/label/c.${labelName}"`,
45
+ namePosStart,
46
+ namePosEnd
47
+ );
48
+ builder.addText(
49
+ ` {
50
+ /**
51
+ * @description ${label.shortDescription}
52
+ */
53
+ const `
54
+ );
55
+ builder.addText(`lbl${label.fullName}`, namePosStart, namePosEnd);
56
+ builder.addText(
57
+ ` = '${label.value}';
58
+ export default lbl${label.fullName};
59
+ }
60
+ `
61
+ );
62
+ }
@@ -1,6 +1,7 @@
1
1
  /** @import { Component, ConvertedComponent } from "../index.mjs" */
2
2
  import { parseString } from "xml2js";
3
3
  import { PositionAwareTextBuilder } from "../util.mjs";
4
+ import { getDtsFromLabel } from "./custom-label.mjs";
4
5
 
5
6
  /**
6
7
  *
@@ -23,31 +24,7 @@ export function CustomLabels(component) {
23
24
 
24
25
  const builder = new PositionAwareTextBuilder();
25
26
  for (let label of labels.CustomLabels.labels) {
26
- const labelName = label.fullName[0];
27
- const namePosStart =
28
- component.content.indexOf(`<fullName>${labelName}`) + `<fullName>`.length;
29
- const namePosEnd = namePosStart + labelName.length;
30
-
31
- builder.addText(`declare module `);
32
- builder.addText(
33
- `"@salesforce/label/c.${labelName}"`,
34
- namePosStart,
35
- namePosEnd
36
- );
37
- builder.addText(
38
- ` {
39
- /**
40
- * @description ${label.shortDescription}
41
- */
42
- const `
43
- );
44
- builder.addText(`lbl${label.fullName}`, namePosStart, namePosEnd);
45
- builder.addText(
46
- ` = '${label.value}';
47
- export default lbl${label.fullName};
48
- }
49
- `
50
- );
27
+ getDtsFromLabel(builder, component.content, label);
51
28
  }
52
29
  return {
53
30
  declarationContent: builder.build(),
@@ -705,7 +705,7 @@ function CustomField(component) {
705
705
  * @param {Component} component
706
706
  * @returns {ConvertedComponent}
707
707
  */
708
- function CustomLabels(component) {
708
+ function CustomLabel(component) {
709
709
  // generate d.ts
710
710
  /** @type {any} */
711
711
  let labels;
@@ -715,37 +715,74 @@ function CustomLabels(component) {
715
715
  }
716
716
  labels = result;
717
717
  });
718
- if (!Array.isArray(labels.CustomLabels.labels)) {
719
- labels.CustomLabels.labels = [labels.CustomLabels.labels];
720
- }
721
-
718
+ console.log(labels.CustomLabel);
722
719
  const builder = new PositionAwareTextBuilder();
723
- for (let label of labels.CustomLabels.labels) {
724
- const labelName = label.fullName[0];
725
- const namePosStart =
726
- component.content.indexOf(`<fullName>${labelName}`) + `<fullName>`.length;
727
- const namePosEnd = namePosStart + labelName.length;
720
+ getDtsFromLabel(builder, component.content, labels.CustomLabel);
721
+ return {
722
+ declarationContent: builder.build(),
723
+ mapData: builder.getMappings(),
724
+ ...component,
725
+ };
726
+ }
728
727
 
729
- builder.addText(`declare module `);
730
- builder.addText(
731
- `"@salesforce/label/c.${labelName}"`,
732
- namePosStart,
733
- namePosEnd
734
- );
735
- builder.addText(
736
- ` {
728
+ /**
729
+ *
730
+ * @param {PositionAwareTextBuilder} builder
731
+ * @param {string} content
732
+ * @param {any} label
733
+ */
734
+ function getDtsFromLabel(builder, content, label) {
735
+ const labelName = label.fullName[0];
736
+ const namePosStart =
737
+ content.indexOf(`<fullName>${labelName}`) + `<fullName>`.length;
738
+ const namePosEnd = namePosStart + labelName.length;
739
+
740
+ builder.addText(`declare module `);
741
+ builder.addText(
742
+ `"@salesforce/label/c.${labelName}"`,
743
+ namePosStart,
744
+ namePosEnd
745
+ );
746
+ builder.addText(
747
+ ` {
737
748
  /**
738
749
  * @description ${label.shortDescription}
739
750
  */
740
751
  const `
741
- );
742
- builder.addText(`lbl${label.fullName}`, namePosStart, namePosEnd);
743
- builder.addText(
744
- ` = '${label.value}';
752
+ );
753
+ builder.addText(`lbl${label.fullName}`, namePosStart, namePosEnd);
754
+ builder.addText(
755
+ ` = '${label.value}';
745
756
  export default lbl${label.fullName};
746
757
  }
747
758
  `
748
- );
759
+ );
760
+ }
761
+
762
+ /** @import { Component, ConvertedComponent } from "../index.mjs" */
763
+
764
+ /**
765
+ *
766
+ * @param {Component} component
767
+ * @returns {ConvertedComponent}
768
+ */
769
+ function CustomLabels(component) {
770
+ // generate d.ts
771
+ /** @type {any} */
772
+ let labels;
773
+ xml2js.parseString(component.content, (error, result) => {
774
+ if (error) {
775
+ throw error;
776
+ }
777
+ labels = result;
778
+ });
779
+ if (!Array.isArray(labels.CustomLabels.labels)) {
780
+ labels.CustomLabels.labels = [labels.CustomLabels.labels];
781
+ }
782
+
783
+ const builder = new PositionAwareTextBuilder();
784
+ for (let label of labels.CustomLabels.labels) {
785
+ getDtsFromLabel(builder, component.content, label);
749
786
  }
750
787
  return {
751
788
  declarationContent: builder.build(),
@@ -864,6 +901,7 @@ var converters = /*#__PURE__*/Object.freeze({
864
901
  ApexClass: ApexClass,
865
902
  ContentAsset: ContentAsset,
866
903
  CustomField: CustomField,
904
+ CustomLabel: CustomLabel,
867
905
  CustomLabels: CustomLabels,
868
906
  CustomObject: CustomObject,
869
907
  CustomPermission: CustomPermission,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lwc-bolts/sf2ts",
3
- "version": "0.0.3",
3
+ "version": "0.0.4",
4
4
  "private": false,
5
5
  "description": "Convert Salesforce metadata to TypeScript declarations",
6
6
  "exports": {
@@ -30,7 +30,7 @@
30
30
  },
31
31
  "license": "MIT",
32
32
  "dependencies": {
33
- "web-tree-sitter-sfapex": "2.4.0",
33
+ "web-tree-sitter-sfapex": "2.4.1",
34
34
  "xml2js": "^0.6.2"
35
35
  },
36
36
  "devDependencies": {