@salesforce/plugin-custom-metadata 1.1.0 → 2.0.0

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.
Files changed (52) hide show
  1. package/CHANGELOG.md +14 -12
  2. package/LICENSE.txt +2 -2
  3. package/README.md +137 -133
  4. package/lib/commands/force/cmdt/create.d.ts +8 -2
  5. package/lib/commands/force/cmdt/create.js +15 -21
  6. package/lib/commands/force/cmdt/create.js.map +1 -1
  7. package/lib/commands/force/cmdt/field/create.d.ts +7 -2
  8. package/lib/commands/force/cmdt/field/create.js +15 -20
  9. package/lib/commands/force/cmdt/field/create.js.map +1 -1
  10. package/lib/commands/force/cmdt/generate.d.ts +6 -2
  11. package/lib/commands/force/cmdt/generate.js +79 -150
  12. package/lib/commands/force/cmdt/generate.js.map +1 -1
  13. package/lib/commands/force/cmdt/record/create.d.ts +14 -3
  14. package/lib/commands/force/cmdt/record/create.js +25 -33
  15. package/lib/commands/force/cmdt/record/create.js.map +1 -1
  16. package/lib/commands/force/cmdt/record/insert.d.ts +2 -2
  17. package/lib/commands/force/cmdt/record/insert.js +28 -40
  18. package/lib/commands/force/cmdt/record/insert.js.map +1 -1
  19. package/lib/lib/helpers/createUtil.d.ts +10 -6
  20. package/lib/lib/helpers/createUtil.js +48 -100
  21. package/lib/lib/helpers/createUtil.js.map +1 -1
  22. package/lib/lib/helpers/fileWriter.d.ts +11 -11
  23. package/lib/lib/helpers/fileWriter.js +14 -24
  24. package/lib/lib/helpers/fileWriter.js.map +1 -1
  25. package/lib/lib/helpers/metadataUtil.d.ts +25 -51
  26. package/lib/lib/helpers/metadataUtil.js +55 -131
  27. package/lib/lib/helpers/metadataUtil.js.map +1 -1
  28. package/lib/lib/helpers/validationUtil.d.ts +25 -26
  29. package/lib/lib/helpers/validationUtil.js +66 -43
  30. package/lib/lib/helpers/validationUtil.js.map +1 -1
  31. package/lib/lib/interfaces/createConfig.d.ts +3 -2
  32. package/lib/lib/templates/templates.d.ts +8 -99
  33. package/lib/lib/templates/templates.js +38 -67
  34. package/lib/lib/templates/templates.js.map +1 -1
  35. package/messages/createField.json +22 -31
  36. package/messages/generate.json +38 -51
  37. package/messages/template.json +2 -2
  38. package/messages/validation.json +5 -0
  39. package/oclif.manifest.json +1 -1
  40. package/package.json +53 -42
  41. package/lib/lib/interfaces/customField.d.ts +0 -7
  42. package/lib/lib/interfaces/customField.js +0 -9
  43. package/lib/lib/interfaces/customField.js.map +0 -1
  44. package/lib/lib/interfaces/errorMessage.d.ts +0 -4
  45. package/lib/lib/interfaces/errorMessage.js +0 -9
  46. package/lib/lib/interfaces/errorMessage.js.map +0 -1
  47. package/lib/lib/interfaces/record.d.ts +0 -3
  48. package/lib/lib/interfaces/record.js +0 -9
  49. package/lib/lib/interfaces/record.js.map +0 -1
  50. package/lib/lib/interfaces/saveResults.d.ts +0 -5
  51. package/lib/lib/interfaces/saveResults.js +0 -9
  52. package/lib/lib/interfaces/saveResults.js.map +0 -1
@@ -1,11 +1,13 @@
1
1
  "use strict";
2
+ var _a;
3
+ Object.defineProperty(exports, "__esModule", { value: true });
2
4
  /*
3
5
  * Copyright (c) 2020, salesforce.com, inc.
4
6
  * All rights reserved.
5
7
  * Licensed under the BSD 3-Clause license.
6
8
  * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
7
9
  */
8
- Object.defineProperty(exports, "__esModule", { value: true });
10
+ const fs = require("fs");
9
11
  const command_1 = require("@salesforce/command");
10
12
  const core_1 = require("@salesforce/core");
11
13
  const fileWriter_1 = require("../../../lib/helpers/fileWriter");
@@ -17,31 +19,19 @@ core_1.Messages.importMessagesDirectory(__dirname);
17
19
  // or any library that is using the messages framework can also be loaded this way.
18
20
  const messages = core_1.Messages.loadMessages('@salesforce/plugin-custom-metadata', 'createType');
19
21
  class Create extends command_1.SfdxCommand {
22
+ // eslint-disable-next-line @typescript-eslint/member-ordering
20
23
  async run() {
24
+ var _b, _c;
21
25
  const typename = this.flags.typename; // this should become the new file name
22
- const label = this.flags.label || this.flags.typename.replace('__mdt', ''); // If a label is not provided default using the dev name. trim __mdt out
23
- const pluralLabel = this.flags.plurallabel || label;
24
- const visibility = this.flags.visibility || 'Public';
25
- const dir = this.flags.outputdir || '';
26
+ const label = (_b = this.flags.label) !== null && _b !== void 0 ? _b : typename.replace('__mdt', ''); // If a label is not provided default using the dev name. trim __mdt out
27
+ const visibility = this.flags.visibility;
28
+ const pluralLabel = (_c = this.flags.plurallabel) !== null && _c !== void 0 ? _c : label;
26
29
  const templates = new templates_1.Templates();
27
30
  const fileWriter = new fileWriter_1.FileWriter();
28
- let saveResults;
29
- const validator = new validationUtil_1.ValidationUtil();
30
- if (!validator.validateMetadataTypeName(typename)) {
31
- throw new core_1.SfdxError(messages.getMessage('errorNotValidAPIName', [typename]));
32
- }
33
- if (!validator.validateLessThanForty(label)) {
34
- throw new core_1.SfdxError(messages.getMessage('errorNotValidLabelName', [label]));
35
- }
36
- if (!validator.validateLessThanForty(pluralLabel)) {
37
- throw new core_1.SfdxError(messages.getMessage('errorNotValidPluralLabelName', [pluralLabel]));
38
- }
39
31
  const objectXML = templates.createObjectXML({ label, pluralLabel }, visibility);
40
- saveResults = await fileWriter.writeTypeFile(core_1.fs, dir, typename, objectXML);
32
+ const saveResults = await fileWriter.writeTypeFile(fs, this.flags.outputdir, typename, objectXML);
41
33
  this.ux.log(messages.getMessage('targetDirectory', [saveResults.dir]));
42
- this.ux.log(messages.getMessage(saveResults.updated ? 'fileUpdate' : 'fileCreated', [
43
- saveResults.fileName,
44
- ]));
34
+ this.ux.log(messages.getMessage(saveResults.updated ? 'fileUpdate' : 'fileCreated', [saveResults.fileName]));
45
35
  return {
46
36
  typename,
47
37
  label,
@@ -51,6 +41,7 @@ class Create extends command_1.SfdxCommand {
51
41
  }
52
42
  }
53
43
  exports.default = Create;
44
+ _a = Create;
54
45
  Create.description = messages.getMessage('commandDescription');
55
46
  Create.longDescription = messages.getMessage('commandLongDescription');
56
47
  Create.examples = [
@@ -71,16 +62,19 @@ Create.flagsConfig = {
71
62
  description: messages.getMessage('nameFlagDescription'),
72
63
  longDescription: messages.getMessage('nameFlagLongDescription'),
73
64
  required: true,
65
+ parse: async (input) => Promise.resolve((0, validationUtil_1.validateMetadataTypeName)(input)),
74
66
  }),
75
67
  label: command_1.flags.string({
76
68
  char: 'l',
77
69
  description: messages.getMessage('labelFlagDescription'),
78
70
  longDescription: messages.getMessage('labelFlagLongDescription'),
71
+ parse: async (input) => Promise.resolve((0, validationUtil_1.validateLessThanForty)(input, messages.getMessage('errorNotValidLabelName', [input]))),
79
72
  }),
80
73
  plurallabel: command_1.flags.string({
81
74
  char: 'p',
82
75
  description: messages.getMessage('plurallabelFlagDescription'),
83
76
  longDescription: messages.getMessage('plurallabelFlagLongDescription'),
77
+ parse: async (input) => Promise.resolve((0, validationUtil_1.validateLessThanForty)(input, messages.getMessage('errorNotValidPluralLabelName', [input]))),
84
78
  }),
85
79
  visibility: command_1.flags.enum({
86
80
  char: 'v',
@@ -93,8 +87,8 @@ Create.flagsConfig = {
93
87
  char: 'd',
94
88
  description: messages.getMessage('outputDirectoryFlagDescription'),
95
89
  longDescription: messages.getMessage('outputDirectoryFlagLongDescription'),
90
+ default: '',
96
91
  }),
97
92
  };
98
- // Set this to true if your command requires a project workspace; 'requiresProject' is false by default
99
93
  Create.requiresProject = true;
100
94
  //# sourceMappingURL=create.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"create.js","sourceRoot":"","sources":["../../../../src/commands/force/cmdt/create.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AAEH,iDAAyD;AACzD,2CAA2D;AAE3D,gEAA6D;AAC7D,wEAAqE;AAErE,gEAA6D;AAE7D,wDAAwD;AACxD,eAAQ,CAAC,uBAAuB,CAAC,SAAS,CAAC,CAAC;AAE5C,iGAAiG;AACjG,mFAAmF;AACnF,MAAM,QAAQ,GAAG,eAAQ,CAAC,YAAY,CACpC,oCAAoC,EACpC,YAAY,CACb,CAA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Q,CAAC,UAAU,CAAC,wBAAwB,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;KACxG,CAAC;IACF,WAAW,EAAE,eAAK,CAAC,MAAM,CAAC;QACxB,IAAI,EAAE,GAAG;QACT,WAAW,EAAE,QAAQ,CAAC,UAAU,CAAC,4BAA4B,CAAC;QAC9D,eAAe,EAAE,QAAQ,CAAC,UAAU,CAAC,gCAAgC,CAAC;QACtE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,CACrB,OAAO,CAAC,OAAO,CAAC,IAAA,sCAAqB,EAAC,KAAK,EAAE,QAAQ,CAAC,UAAU,CAAC,8BAA8B,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;KAC9G,CAAC;IACF,UAAU,EAAE,eAAK,CAAC,IAAI,CAAC;QACrB,IAAI,EAAE,GAAG;QACT,WAAW,EAAE,QAAQ,CAAC,UAAU,CAAC,2BAA2B,CAAC;QAC7D,eAAe,EAAE,QAAQ,CAAC,UAAU,CAAC,+BAA+B,CAAC;QACrE,OAAO,EAAE,CAAC,kBAAkB,EAAE,WAAW,EAAE,QAAQ,CAAC;QACpD,OAAO,EAAE,QAAQ;KAClB,CAAC;IACF,SAAS,EAAE,eAAK,CAAC,SAAS,CAAC;QACzB,IAAI,EAAE,GAAG;QACT,WAAW,EAAE,QAAQ,CAAC,UAAU,CAAC,gCAAgC,CAAC;QAClE,eAAe,EAAE,QAAQ,CAAC,UAAU,CAAC,oCAAoC,CAAC;QAC1E,OAAO,EAAE,EAAE;KACZ,CAAC;CACF,CAAA;AAEe,sBAAe,GAAG,IAAK,CAAA"}
@@ -1,5 +1,9 @@
1
1
  import { flags, SfdxCommand } from '@salesforce/command';
2
- import { AnyJson } from '@salesforce/ts-types';
2
+ interface CmdtFieldCreateResponse {
3
+ fieldName: string;
4
+ label: string;
5
+ fieldtype: string;
6
+ }
3
7
  export default class Create extends SfdxCommand {
4
8
  static description: string;
5
9
  static longDescription: string;
@@ -16,5 +20,6 @@ export default class Create extends SfdxCommand {
16
20
  outputdir: flags.Discriminated<flags.String>;
17
21
  };
18
22
  protected static requiresProject: boolean;
19
- run(): Promise<AnyJson>;
23
+ run(): Promise<CmdtFieldCreateResponse>;
20
24
  }
25
+ export {};
@@ -1,11 +1,13 @@
1
1
  "use strict";
2
+ var _a;
3
+ Object.defineProperty(exports, "__esModule", { value: true });
2
4
  /*
3
5
  * Copyright (c) 2020, salesforce.com, inc.
4
6
  * All rights reserved.
5
7
  * Licensed under the BSD 3-Clause license.
6
8
  * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
7
9
  */
8
- Object.defineProperty(exports, "__esModule", { value: true });
10
+ const fs = require("fs");
9
11
  const command_1 = require("@salesforce/command");
10
12
  const core_1 = require("@salesforce/core");
11
13
  const fileWriter_1 = require("../../../../lib/helpers/fileWriter");
@@ -17,34 +19,24 @@ core_1.Messages.importMessagesDirectory(__dirname);
17
19
  // or any library that is using the messages framework can also be loaded this way.
18
20
  const messages = core_1.Messages.loadMessages('@salesforce/plugin-custom-metadata', 'createField');
19
21
  class Create extends command_1.SfdxCommand {
22
+ // eslint-disable-next-line @typescript-eslint/member-ordering
20
23
  async run() {
24
+ var _b, _c;
21
25
  const fieldName = this.flags.fieldname; // this should become the new file name
22
- const label = this.flags.label || this.flags.fieldname;
26
+ const label = (_b = this.flags.label) !== null && _b !== void 0 ? _b : fieldName;
23
27
  const fieldtype = this.flags.fieldtype;
24
- const picklistvalues = this.flags.picklistvalues || [];
25
- const decimalplaces = this.flags.decimalplaces || 0;
26
- const dir = this.flags.outputdir || '';
27
- let saveResults;
28
- const validator = new validationUtil_1.ValidationUtil();
29
- if (!validator.validateAPIName(fieldName)) {
30
- throw new core_1.SfdxError(messages.getMessage('invalidCustomFieldError', [fieldName]));
31
- }
28
+ const picklistvalues = (_c = this.flags.picklistvalues) !== null && _c !== void 0 ? _c : [];
29
+ const decimalplaces = this.flags.decimalplaces;
32
30
  if (fieldtype === 'Picklist' && picklistvalues.length === 0) {
33
- throw new core_1.SfdxError(messages.getMessage('picklistValuesNotSuppliedError'));
34
- }
35
- if (decimalplaces < 0) {
36
- throw new core_1.SfdxError(messages.getMessage('invalidDecimalError'));
31
+ throw new core_1.SfError(messages.getMessage('picklistValuesNotSuppliedError'));
37
32
  }
38
33
  const templates = new templates_1.Templates();
39
34
  const data = templates.createDefaultTypeStructure(fieldName, fieldtype, label, picklistvalues, decimalplaces);
40
35
  const fieldXML = templates.createFieldXML(data, false);
41
36
  const writer = new fileWriter_1.FileWriter();
42
- saveResults = await writer.writeFieldFile(core_1.fs, dir, fieldName, fieldXML);
37
+ const saveResults = await writer.writeFieldFile(fs, this.flags.outputdir, fieldName, fieldXML);
43
38
  this.ux.log(messages.getMessage('targetDirectory', [saveResults.dir]));
44
- this.ux.log(messages.getMessage(saveResults.updated ? 'fileUpdate' : 'fileCreated', [
45
- saveResults.fileName,
46
- ]));
47
- // Return an object to be displayed with --json
39
+ this.ux.log(messages.getMessage(saveResults.updated ? 'fileUpdate' : 'fileCreated', [saveResults.fileName]));
48
40
  return {
49
41
  fieldName,
50
42
  label,
@@ -53,6 +45,7 @@ class Create extends command_1.SfdxCommand {
53
45
  }
54
46
  }
55
47
  exports.default = Create;
48
+ _a = Create;
56
49
  Create.description = messages.getMessage('commandDescription');
57
50
  Create.longDescription = messages.getMessage('commandLongDescription');
58
51
  Create.examples = [
@@ -70,6 +63,7 @@ Create.flagsConfig = {
70
63
  required: true,
71
64
  description: messages.getMessage('nameFlagDescription'),
72
65
  longDescription: messages.getMessage('nameFlagLongDescription'),
66
+ parse: async (input) => Promise.resolve((0, validationUtil_1.validateAPIName)(input, messages.getMessage('invalidCustomFieldError', [input]))),
73
67
  }),
74
68
  fieldtype: command_1.flags.enum({
75
69
  char: 'f',
@@ -101,6 +95,7 @@ Create.flagsConfig = {
101
95
  description: messages.getMessage('decimalplacesFlagDescription'),
102
96
  longDescription: messages.getMessage('decimalplacesFlagLongDescription'),
103
97
  default: 0,
98
+ min: 0,
104
99
  }),
105
100
  label: command_1.flags.string({
106
101
  char: 'l',
@@ -111,8 +106,8 @@ Create.flagsConfig = {
111
106
  char: 'd',
112
107
  description: messages.getMessage('outputDirectoryFlagDescription'),
113
108
  longDescription: messages.getMessage('outputDirectoryFlagLongDescription'),
109
+ default: '',
114
110
  }),
115
111
  };
116
- // Set this to true if your command requires a project workspace; 'requiresProject' is false by default
117
112
  Create.requiresProject = true;
118
113
  //# sourceMappingURL=create.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"create.js","sourceRoot":"","sources":["../../../../../src/commands/force/cmdt/field/create.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AAEH,iDAAyD;AACzD,2CAA2D;AAE3D,mEAAgE;AAChE,2EAAwE;AAExE,mEAAgE;AAEhE,wDAAwD;AACxD,eAAQ,CAAC,uBAAuB,CAAC,SAAS,CAAC,CAAC;AAE5C,iGAAiG;AACjG,mFAAmF;AACnF,MAAM,QAAQ,GAAG,eAAQ,CAAC,YAAY,CACpC,oCAAoC,EACpC,aAAa,CACd,CAAC;AAEF,MAAqB,MAAO,SAAQ,qBAAW;IAsEtC,KAAK,CAAC,GAAG;QACd,MAAM,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,uCAAuC;QAC/E,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC;QACvD,MAAM,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC;QACvC,MAAM,cAAc,GAAG,IAAI,CAAC,KAAK,CAAC,cAAc,IAAI,EAAE,CAAC;QACvD,MAAM,aAAa,GAAG,IAAI,CAAC,KAAK,CAAC,aAAa,IAAI,CAAC,CAAC;QACpD,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,SAAS,IAAI,EAAE,CAAC;QACvC,IAAI,WAAwB,CAAC;QAE7B,MAAM,SAAS,GAAG,I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,CAAC;IACF,cAAc,EAAE,eAAK,CAAC,KAAK,CAAC;QAC1B,IAAI,EAAE,GAAG;QACT,WAAW,EAAE,QAAQ,CAAC,UAAU,CAAC,+BAA+B,CAAC;QACjE,eAAe,EAAE,QAAQ,CAAC,UAAU,CAAC,mCAAmC,CAAC;KAC1E,CAAC;IACF,aAAa,EAAE,eAAK,CAAC,MAAM,CAAC;QAC1B,IAAI,EAAE,GAAG;QACT,WAAW,EAAE,QAAQ,CAAC,UAAU,CAAC,8BAA8B,CAAC;QAChE,eAAe,EAAE,QAAQ,CAAC,UAAU,CAAC,kCAAkC,CAAC;QACxE,OAAO,EAAE,CAAC;QACV,GAAG,EAAE,CAAC;KACP,CAAC;IACF,KAAK,EAAE,eAAK,CAAC,MAAM,CAAC;QAClB,IAAI,EAAE,GAAG;QACT,WAAW,EAAE,QAAQ,CAAC,UAAU,CAAC,sBAAsB,CAAC;QACxD,eAAe,EAAE,QAAQ,CAAC,UAAU,CAAC,0BAA0B,CAAC;KACjE,CAAC;IACF,SAAS,EAAE,eAAK,CAAC,SAAS,CAAC;QACzB,IAAI,EAAE,GAAG;QACT,WAAW,EAAE,QAAQ,CAAC,UAAU,CAAC,gCAAgC,CAAC;QAClE,eAAe,EAAE,QAAQ,CAAC,UAAU,CAAC,oCAAoC,CAAC;QAC1E,OAAO,EAAE,EAAE;KACZ,CAAC;CACF,CAAA;AAEe,sBAAe,GAAG,IAAK,CAAA"}
@@ -1,5 +1,8 @@
1
1
  import { flags, SfdxCommand } from '@salesforce/command';
2
- import { AnyJson } from '@salesforce/ts-types';
2
+ interface CmdtGenerateResponse {
3
+ outputDir: string;
4
+ recordsOutputDir: string;
5
+ }
3
6
  export default class Generate extends SfdxCommand {
4
7
  static description: string;
5
8
  static longDescription: string;
@@ -19,5 +22,6 @@ export default class Generate extends SfdxCommand {
19
22
  };
20
23
  protected static requiresUsername: boolean;
21
24
  protected static requiresProject: boolean;
22
- run(): Promise<AnyJson>;
25
+ run(): Promise<CmdtGenerateResponse>;
23
26
  }
27
+ export {};
@@ -1,15 +1,17 @@
1
1
  "use strict";
2
+ var _a;
3
+ Object.defineProperty(exports, "__esModule", { value: true });
2
4
  /*
3
5
  * Copyright (c) 2020, salesforce.com, inc.
4
6
  * All rights reserved.
5
7
  * Licensed under the BSD 3-Clause license.
6
8
  * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
7
9
  */
8
- Object.defineProperty(exports, "__esModule", { value: true });
10
+ const fs = require("fs");
11
+ const path = require("path");
9
12
  const command_1 = require("@salesforce/command");
10
13
  const core_1 = require("@salesforce/core");
11
14
  const kit_1 = require("@salesforce/kit");
12
- const ts_types_1 = require("@salesforce/ts-types");
13
15
  const createUtil_1 = require("../../../lib/helpers/createUtil");
14
16
  const fileWriter_1 = require("../../../lib/helpers/fileWriter");
15
17
  const metadataUtil_1 = require("../../../lib/helpers/metadataUtil");
@@ -21,193 +23,96 @@ core_1.Messages.importMessagesDirectory(__dirname);
21
23
  // or any library that is using the messages framework can also be loaded this way.
22
24
  const messages = core_1.Messages.loadMessages('@salesforce/plugin-custom-metadata', 'generate');
23
25
  class Generate extends command_1.SfdxCommand {
26
+ // eslint-disable-next-line @typescript-eslint/member-ordering
24
27
  async run() {
25
- // this.org is guaranteed because requiresUsername=true, as opposed to supportsUsername
28
+ var _b, _c;
26
29
  const conn = this.org.getConnection();
27
- // to validate different flags provided by the user
28
- const validator = new validationUtil_1.ValidationUtil();
29
30
  const objname = this.flags.sobjectname;
30
- const cmdttype = this.flags.devname;
31
- const sourceuser = this.flags.targetusername;
31
+ const devName = this.flags.devname;
32
32
  const ignoreFields = this.flags.ignoreunsupported;
33
- let username;
34
- let sourceOrgConn;
35
- let describeObj;
36
- // check whether username or alias is provided as targetusername
37
- if (sourceuser) {
38
- if (sourceuser.substr(sourceuser.length - 4) !== '.com') {
39
- username = await core_1.Aliases.fetch(sourceuser); // if alias is provided get the corresponding username
40
- if (username === undefined) {
41
- throw core_1.SfdxError.create('@salesforce/plugin-custom-metadata', 'generate', 'sourceusernameError', [sourceuser]);
42
- }
43
- }
44
- else {
45
- username = sourceuser;
46
- }
47
- }
48
- if (username) {
49
- try {
50
- // connect to source org if source user name provided
51
- sourceOrgConn = await core_1.Connection.create({
52
- authInfo: await core_1.AuthInfo.create({ username }),
53
- });
54
- }
55
- catch (err) {
56
- const errMsg = messages.getMessage('sourceuserAuthenticationError', [
57
- sourceuser,
58
- err.message,
59
- ]);
60
- throw new core_1.SfdxError(errMsg, 'sourceuserAuthenticationError');
61
- }
62
- }
63
- if (!validator.validateAPIName(objname)) {
64
- throw core_1.SfdxError.create('@salesforce/plugin-custom-metadata', 'generate', 'sobjectnameFlagError', [objname]);
65
- }
66
- let devName;
67
- if (!validator.validateMetadataTypeName(cmdttype)) {
68
- throw core_1.SfdxError.create('@salesforce/plugin-custom-metadata', 'generate', 'typenameFlagError', [cmdttype]);
69
- }
70
- if (cmdttype.endsWith('__mdt') || cmdttype.endsWith('__MDT')) {
71
- devName = cmdttype.substring(0, cmdttype.indexOf('__mdt'));
72
- }
73
- else {
74
- devName = cmdttype;
75
- }
76
- let metadataUtil;
77
- // get defined only if there is source username provided
78
- if (!sourceOrgConn) {
79
- metadataUtil = new metadataUtil_1.MetadataUtil(conn);
80
- }
81
- else {
82
- metadataUtil = new metadataUtil_1.MetadataUtil(sourceOrgConn);
83
- }
84
33
  // use default target org connection to get object describe if no source is provided.
85
- describeObj = await metadataUtil.describeObj(objname);
34
+ const describeObj = await conn.metadata.read('CustomObject', objname);
86
35
  // throw error if the object doesnot exist(empty json as response from the describe call.)
87
- if ((0, kit_1.isEmpty)(describeObj)) {
36
+ if ((0, kit_1.isEmpty)(describeObj.fields)) {
88
37
  const errMsg = messages.getMessage('sobjectnameNoResultError', [objname]);
89
- throw new core_1.SfdxError(errMsg, 'sobjectnameNoResultError');
38
+ throw new core_1.SfError(errMsg, 'sobjectnameNoResultError');
90
39
  }
91
40
  // check for custom setting
92
- if (describeObj['customSettingsType'] !== undefined) {
41
+ if (describeObj.customSettingsType) {
93
42
  // if custom setting check for type and visbility
94
- if (!metadataUtil.validCustomSettingType(describeObj)) {
43
+ if (!(0, metadataUtil_1.validCustomSettingType)(describeObj)) {
95
44
  const errMsg = messages.getMessage('customSettingTypeError', [objname]);
96
- throw new core_1.SfdxError(errMsg, 'customSettingTypeError');
45
+ throw new core_1.SfError(errMsg, 'customSettingTypeError');
97
46
  }
98
47
  }
99
- const visibility = this.flags.visibility || 'Public';
100
- const label = this.flags.label || devName;
101
- const pluralLabel = this.flags.plurallabel || label;
102
- const outputDir = this.flags.typeoutputdir || 'force-app/main/default/objects/';
103
- const recordsOutputDir = this.flags.recordsoutputdir || 'force-app/main/default/customMetadata';
48
+ const visibility = this.flags.visibility;
49
+ const label = (_b = this.flags.label) !== null && _b !== void 0 ? _b : devName;
50
+ const pluralLabel = (_c = this.flags.plurallabel) !== null && _c !== void 0 ? _c : label;
51
+ const outputDir = this.flags.typeoutputdir;
52
+ const recordsOutputDir = this.flags.recordsoutputdir;
104
53
  try {
105
- this.ux.startSpinner('custom metadata generation in progress');
54
+ this.ux.startSpinner('creating the CMDT object');
106
55
  // create custom metadata type
107
56
  const templates = new templates_1.Templates();
108
57
  const objectXML = templates.createObjectXML({ label, pluralLabel }, visibility);
109
58
  const fileWriter = new fileWriter_1.FileWriter();
110
- await fileWriter.writeTypeFile(core_1.fs, outputDir, devName, objectXML);
111
- // get all the field details before creating feild metadata
112
- const describeAllFields = metadataUtil.describeObjFields(describeObj);
113
- let sObjectRecords;
114
- // query records from source
115
- sObjectRecords = await metadataUtil.queryRecords(describeObj);
116
- if (sObjectRecords.errorCode && sObjectRecords.errorCode !== null) {
117
- const errMsg = messages.getMessage('queryError', [
118
- objname,
119
- (0, ts_types_1.asString)(sObjectRecords.errorMsg),
120
- ]);
121
- throw new core_1.SfdxError(errMsg, 'queryError');
122
- }
59
+ await fileWriter.writeTypeFile(fs, outputDir, devName, objectXML);
60
+ this.ux.setSpinnerStatus('creating the CMDT fields');
61
+ // get all the field details before creating field metadata
62
+ const fields = (0, metadataUtil_1.describeObjFields)(describeObj)
63
+ // added type check here to skip the creation of un supported fields
64
+ .filter((f) => !ignoreFields || templates.canConvert(f['type']))
65
+ .flatMap((f) =>
123
66
  // check for Geo Location fields before hand and create two different fields for longitude and latitude.
124
- const fields = (0, ts_types_1.ensureJsonArray)(describeAllFields);
125
- fields.map((field) => {
126
- if (field['type'] === 'Location') {
127
- const lat = {
128
- fullName: 'Lat_' + field['fullName'],
129
- label: 'Lat ' + field['label'],
130
- required: field['required'],
131
- trackHistory: field['trackHistory'],
132
- trackTrending: field['trackTrending'],
133
- type: 'Text',
134
- length: '40',
135
- };
136
- fields.push(lat);
137
- const long = {
138
- fullName: 'Long_' + field['fullName'],
139
- label: 'Long_' + field['label'],
140
- required: field['required'],
141
- trackHistory: field['trackHistory'],
142
- trackTrending: field['trackTrending'],
143
- type: 'Text',
144
- length: '40',
145
- };
146
- fields.push(long);
147
- }
148
- });
67
+ f.type !== 'Location' ? [f] : convertLocationFieldToText(f));
149
68
  // create custom metdata fields
150
- for (const field of fields) {
151
- // added type check here to skip the creation of geo location field and un supported fields as we are adding it as lat and long field above.
152
- if ((templates.canConvert(field['type']) || !ignoreFields) &&
153
- field['type'] !== 'Location') {
154
- const recordname = field['fullName'];
155
- const fieldXML = templates.createFieldXML(field, !ignoreFields);
156
- const targetDir = `${outputDir}${devName}__mdt`;
157
- await fileWriter.writeFieldFile(core_1.fs, targetDir, recordname, fieldXML);
158
- }
159
- }
69
+ await Promise.all(fields.map((f) => fileWriter.writeFieldFile(fs, path.join(outputDir, `${devName}__mdt`), f.fullName, templates.createFieldXML(f, !ignoreFields))));
70
+ this.ux.setSpinnerStatus('creating the CMDT records');
160
71
  const createUtil = new createUtil_1.CreateUtil();
161
72
  // if customMetadata folder does not exist, create it
162
- await core_1.fs.mkdirp(recordsOutputDir);
163
- const security = visibility !== 'Public';
164
- const typename = devName;
165
- const fieldDirPath = `${fileWriter.createDir(outputDir)}${typename}__mdt/fields`;
166
- const fileNames = await core_1.fs.readdir(fieldDirPath);
73
+ await fs.promises.mkdir(recordsOutputDir, { recursive: true });
74
+ const fieldDirPath = path.join(outputDir, `${devName}__mdt`, 'fields');
75
+ const fileNames = await fs.promises.readdir(fieldDirPath);
167
76
  const fileData = await createUtil.getFileData(fieldDirPath, fileNames);
168
- for (const rec of sObjectRecords.records) {
169
- const record = metadataUtil.cleanQueryResponse(rec, describeObj);
77
+ // query records from source
78
+ const sObjectRecords = await conn.query(getSoqlQuery(describeObj));
79
+ await Promise.all(sObjectRecords.records.map((rec) => {
80
+ const record = (0, metadataUtil_1.cleanQueryResponse)(rec, describeObj);
170
81
  const lblName = rec['Name'];
171
- let recordName = rec['Name'];
172
- if (!validator.validateMetadataRecordName(rec['Name'])) {
173
- recordName = recordName.replace(/ +/g, '_');
174
- }
175
- await createUtil.createRecord({
176
- typename,
82
+ const recordName = (0, validationUtil_1.isValidMetadataRecordName)(lblName) ? lblName : lblName.replace(/ +/g, '_');
83
+ return createUtil.createRecord({
84
+ typename: devName,
177
85
  recordname: recordName,
178
86
  label: lblName,
179
87
  inputdir: outputDir,
180
88
  outputdir: recordsOutputDir,
181
- protected: security,
89
+ protected: visibility !== 'Public',
182
90
  varargs: record,
183
91
  fileData,
184
92
  ignorefields: ignoreFields,
185
93
  });
186
- }
94
+ }));
187
95
  this.ux.stopSpinner('custom metadata type and records creation in completed');
188
96
  this.ux.log(`Congrats! Created a ${devName} custom metadata type with ${sObjectRecords.records.length} records!`);
189
97
  }
190
98
  catch (e) {
191
- await core_1.fs.remove(`${outputDir}${devName}__mdt`);
192
- const fileNames = await core_1.fs.readdir(recordsOutputDir);
193
- for (const file of fileNames) {
194
- if (file.startsWith(devName)) {
195
- try {
196
- await core_1.fs.unlink(`${recordsOutputDir}/${file}`);
197
- }
198
- catch (e) {
199
- this.ux.log(e.message);
200
- }
201
- }
99
+ const targetDir = `${outputDir}${devName}__mdt`;
100
+ // dir might not exist if we never got to the creation step
101
+ if (fs.existsSync(targetDir)) {
102
+ await fs.promises.rm(targetDir, { recursive: true });
202
103
  }
104
+ await Promise.all((await fs.promises.readdir(recordsOutputDir))
105
+ .filter((f) => f.startsWith(devName))
106
+ .map((f) => fs.promises.unlink(path.join(recordsOutputDir, f))));
203
107
  this.ux.stopSpinner('generate command failed to run');
204
- const errMsg = messages.getMessage('generateError', [e.message]);
205
- throw new core_1.SfdxError(errMsg, 'generateError');
108
+ const errMsg = messages.getMessage('generateError', [e instanceof Error ? e.message : 'unknown error']);
109
+ throw new core_1.SfError(errMsg, 'generateError');
206
110
  }
207
111
  return { outputDir, recordsOutputDir };
208
112
  }
209
113
  }
210
114
  exports.default = Generate;
115
+ _a = Generate;
211
116
  Generate.description = messages.getMessage('commandDescription');
212
117
  Generate.longDescription = messages.getMessage('commandLongDescription');
213
118
  Generate.examples = [
@@ -243,6 +148,7 @@ Generate.flagsConfig = {
243
148
  required: true,
244
149
  description: messages.getMessage('devnameFlagDescription'),
245
150
  longDescription: messages.getMessage('devnameFlagLongDescription'),
151
+ parse: async (input) => Promise.resolve((0, validationUtil_1.validateMetadataTypeName)(input)),
246
152
  }),
247
153
  label: command_1.flags.string({
248
154
  char: 'l',
@@ -266,6 +172,7 @@ Generate.flagsConfig = {
266
172
  required: true,
267
173
  description: messages.getMessage('sobjectnameFlagDescription'),
268
174
  longDescription: messages.getMessage('sobjectnameFlagLongDescription'),
175
+ parse: async (sobjectname) => Promise.resolve((0, validationUtil_1.validateAPIName)(sobjectname)),
269
176
  }),
270
177
  ignoreunsupported: command_1.flags.boolean({
271
178
  char: 'i',
@@ -276,17 +183,39 @@ Generate.flagsConfig = {
276
183
  char: 'd',
277
184
  description: messages.getMessage('typeoutputdirFlagDescription'),
278
185
  longDescription: messages.getMessage('typeoutputdirFlagLongDescription'),
279
- default: 'force-app/main/default/objects/',
186
+ default: path.join('force-app', 'main', 'default', 'objects'),
280
187
  }),
281
188
  recordsoutputdir: command_1.flags.directory({
282
189
  char: 'r',
283
190
  description: messages.getMessage('recordsoutputdirFlagDescription'),
284
191
  longDescription: messages.getMessage('recordsoutputdirFlagLongDescription'),
285
- default: 'force-app/main/default/customMetadata/',
192
+ default: path.join('force-app', 'main', 'default', 'customMetadata'),
286
193
  }),
287
194
  };
288
- // Comment this out if your command does not require an org username
289
195
  Generate.requiresUsername = true;
290
- // Set this to true if your command requires a project workspace; 'requiresProject' is false by default
291
196
  Generate.requiresProject = true;
197
+ const getSoqlQuery = (describeResult) => {
198
+ const fieldNames = describeResult.fields
199
+ .map((field) => {
200
+ return field.fullName;
201
+ })
202
+ .join(',');
203
+ // Added Name hardcoded as Name field is not retrieved as part of object describe.
204
+ return `SELECT Name, ${fieldNames} FROM ${describeResult.fullName}`;
205
+ };
206
+ const convertLocationFieldToText = (field) => {
207
+ const baseTextField = {
208
+ required: field['required'],
209
+ trackHistory: field['trackHistory'],
210
+ trackTrending: field['trackTrending'],
211
+ type: 'Text',
212
+ length: 40,
213
+ summaryFilterItems: [],
214
+ };
215
+ return ['Lat_', 'Long_'].map((prefix) => ({
216
+ ...baseTextField,
217
+ fullName: `${prefix}${field.fullName}`,
218
+ label: `${prefix}${field.label}`,
219
+ }));
220
+ };
292
221
  //# sourceMappingURL=generate.js.map