@salesforce/plugin-custom-metadata 2.0.9 → 2.0.11

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 (77) hide show
  1. package/README.md +0 -1
  2. package/lib/commands/generate/cmdt/field.d.ts +23 -0
  3. package/lib/commands/generate/cmdt/field.js +100 -0
  4. package/lib/commands/generate/cmdt/field.js.map +1 -0
  5. package/lib/commands/generate/cmdt/fromorg.d.ts +26 -0
  6. package/lib/commands/generate/cmdt/fromorg.js +184 -0
  7. package/lib/commands/generate/cmdt/fromorg.js.map +1 -0
  8. package/lib/commands/generate/cmdt/object.d.ts +23 -0
  9. package/lib/commands/generate/cmdt/object.js +79 -0
  10. package/lib/commands/generate/cmdt/object.js.map +1 -0
  11. package/lib/commands/generate/cmdt/record.d.ts +29 -0
  12. package/lib/commands/generate/cmdt/record.js +111 -0
  13. package/lib/commands/generate/cmdt/record.js.map +1 -0
  14. package/lib/commands/generate/cmdt/records.d.ts +18 -0
  15. package/lib/commands/generate/cmdt/records.js +105 -0
  16. package/lib/commands/generate/cmdt/records.js.map +1 -0
  17. package/lib/shared/helpers/createUtil.d.ts +51 -0
  18. package/lib/shared/helpers/createUtil.js +168 -0
  19. package/lib/shared/helpers/createUtil.js.map +1 -0
  20. package/lib/shared/helpers/fileWriter.d.ts +24 -0
  21. package/lib/shared/helpers/fileWriter.js +59 -0
  22. package/lib/shared/helpers/fileWriter.js.map +1 -0
  23. package/lib/{lib → shared}/helpers/metadataUtil.d.ts +1 -1
  24. package/lib/{lib → shared}/helpers/metadataUtil.js +1 -1
  25. package/lib/shared/helpers/metadataUtil.js.map +1 -0
  26. package/lib/{lib → shared}/helpers/validationUtil.d.ts +0 -0
  27. package/lib/{lib → shared}/helpers/validationUtil.js +0 -0
  28. package/lib/shared/helpers/validationUtil.js.map +1 -0
  29. package/lib/{lib → shared}/interfaces/createConfig.d.ts +3 -2
  30. package/lib/{lib → shared}/interfaces/createConfig.js +0 -0
  31. package/lib/shared/interfaces/createConfig.js.map +1 -0
  32. package/lib/shared/templates/templates.d.ts +20 -0
  33. package/lib/shared/templates/templates.js +208 -0
  34. package/lib/shared/templates/templates.js.map +1 -0
  35. package/messages/field.md +79 -0
  36. package/messages/fromorg.md +87 -0
  37. package/messages/object.md +73 -0
  38. package/messages/record.md +53 -0
  39. package/messages/records.md +49 -0
  40. package/messages/template.md +3 -0
  41. package/messages/validation.md +11 -0
  42. package/oclif.manifest.json +1 -1
  43. package/package.json +17 -16
  44. package/lib/commands/force/cmdt/create.d.ts +0 -25
  45. package/lib/commands/force/cmdt/create.js +0 -94
  46. package/lib/commands/force/cmdt/create.js.map +0 -1
  47. package/lib/commands/force/cmdt/field/create.d.ts +0 -25
  48. package/lib/commands/force/cmdt/field/create.js +0 -113
  49. package/lib/commands/force/cmdt/field/create.js.map +0 -1
  50. package/lib/commands/force/cmdt/generate.d.ts +0 -27
  51. package/lib/commands/force/cmdt/generate.js +0 -219
  52. package/lib/commands/force/cmdt/generate.js.map +0 -1
  53. package/lib/commands/force/cmdt/record/create.d.ts +0 -32
  54. package/lib/commands/force/cmdt/record/create.js +0 -140
  55. package/lib/commands/force/cmdt/record/create.js.map +0 -1
  56. package/lib/commands/force/cmdt/record/insert.d.ts +0 -16
  57. package/lib/commands/force/cmdt/record/insert.js +0 -110
  58. package/lib/commands/force/cmdt/record/insert.js.map +0 -1
  59. package/lib/lib/helpers/createUtil.d.ts +0 -62
  60. package/lib/lib/helpers/createUtil.js +0 -170
  61. package/lib/lib/helpers/createUtil.js.map +0 -1
  62. package/lib/lib/helpers/fileWriter.d.ts +0 -27
  63. package/lib/lib/helpers/fileWriter.js +0 -63
  64. package/lib/lib/helpers/fileWriter.js.map +0 -1
  65. package/lib/lib/helpers/metadataUtil.js.map +0 -1
  66. package/lib/lib/helpers/validationUtil.js.map +0 -1
  67. package/lib/lib/interfaces/createConfig.js.map +0 -1
  68. package/lib/lib/templates/templates.d.ts +0 -37
  69. package/lib/lib/templates/templates.js +0 -221
  70. package/lib/lib/templates/templates.js.map +0 -1
  71. package/messages/createField.json +0 -24
  72. package/messages/createRecord.json +0 -32
  73. package/messages/createType.json +0 -33
  74. package/messages/generate.json +0 -40
  75. package/messages/insertRecord.json +0 -26
  76. package/messages/template.json +0 -3
  77. package/messages/validation.json +0 -5
@@ -1,219 +0,0 @@
1
- "use strict";
2
- var _a;
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- /*
5
- * Copyright (c) 2020, salesforce.com, inc.
6
- * All rights reserved.
7
- * Licensed under the BSD 3-Clause license.
8
- * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
9
- */
10
- const fs = require("fs");
11
- const path = require("path");
12
- const command_1 = require("@salesforce/command");
13
- const core_1 = require("@salesforce/core");
14
- const kit_1 = require("@salesforce/kit");
15
- const createUtil_1 = require("../../../lib/helpers/createUtil");
16
- const fileWriter_1 = require("../../../lib/helpers/fileWriter");
17
- const metadataUtil_1 = require("../../../lib/helpers/metadataUtil");
18
- const validationUtil_1 = require("../../../lib/helpers/validationUtil");
19
- const templates_1 = require("../../../lib/templates/templates");
20
- // Initialize Messages with the current plugin directory
21
- core_1.Messages.importMessagesDirectory(__dirname);
22
- // Load the specific messages for this file. Messages from @salesforce/command, @salesforce/core,
23
- // or any library that is using the messages framework can also be loaded this way.
24
- const messages = core_1.Messages.loadMessages('@salesforce/plugin-custom-metadata', 'generate');
25
- class Generate extends command_1.SfdxCommand {
26
- // eslint-disable-next-line @typescript-eslint/member-ordering
27
- async run() {
28
- var _b, _c;
29
- const conn = this.org.getConnection();
30
- const objname = this.flags.sobjectname;
31
- const devName = this.flags.devname;
32
- const ignoreFields = this.flags.ignoreunsupported;
33
- // use default target org connection to get object describe if no source is provided.
34
- const describeObj = await conn.metadata.read('CustomObject', objname);
35
- // throw error if the object doesnot exist(empty json as response from the describe call.)
36
- if ((0, kit_1.isEmpty)(describeObj.fields)) {
37
- const errMsg = messages.getMessage('sobjectnameNoResultError', [objname]);
38
- throw new core_1.SfError(errMsg, 'sobjectnameNoResultError');
39
- }
40
- // check for custom setting
41
- if (describeObj.customSettingsType) {
42
- // if custom setting check for type and visbility
43
- if (!(0, metadataUtil_1.validCustomSettingType)(describeObj)) {
44
- const errMsg = messages.getMessage('customSettingTypeError', [objname]);
45
- throw new core_1.SfError(errMsg, 'customSettingTypeError');
46
- }
47
- }
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;
53
- try {
54
- this.ux.startSpinner('creating the CMDT object');
55
- // create custom metadata type
56
- const templates = new templates_1.Templates();
57
- const objectXML = templates.createObjectXML({ label, pluralLabel }, visibility);
58
- const fileWriter = new fileWriter_1.FileWriter();
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) =>
66
- // check for Geo Location fields before hand and create two different fields for longitude and latitude.
67
- f.type !== 'Location' ? [f] : convertLocationFieldToText(f));
68
- // create custom metdata fields
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');
71
- const createUtil = new createUtil_1.CreateUtil();
72
- // if customMetadata folder does not exist, create it
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);
76
- const fileData = await createUtil.getFileData(fieldDirPath, fileNames);
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);
81
- const lblName = rec['Name'];
82
- const recordName = (0, validationUtil_1.isValidMetadataRecordName)(lblName) ? lblName : lblName.replace(/ +/g, '_');
83
- return createUtil.createRecord({
84
- typename: devName,
85
- recordname: recordName,
86
- label: lblName,
87
- inputdir: outputDir,
88
- outputdir: recordsOutputDir,
89
- protected: visibility !== 'Public',
90
- varargs: record,
91
- fileData,
92
- ignorefields: ignoreFields,
93
- });
94
- }));
95
- this.ux.stopSpinner('custom metadata type and records creation in completed');
96
- this.ux.log(`Congrats! Created a ${devName} custom metadata type with ${sObjectRecords.records.length} records!`);
97
- }
98
- catch (e) {
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 });
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))));
107
- this.ux.stopSpinner('generate command failed to run');
108
- const errMsg = messages.getMessage('generateError', [e instanceof Error ? e.message : 'unknown error']);
109
- throw new core_1.SfError(errMsg, 'generateError');
110
- }
111
- return { outputDir, recordsOutputDir };
112
- }
113
- }
114
- exports.default = Generate;
115
- _a = Generate;
116
- Generate.description = messages.getMessage('commandDescription');
117
- Generate.longDescription = messages.getMessage('commandLongDescription');
118
- Generate.examples = [
119
- messages.getMessage('exampleCaption1'),
120
- ' $ sfdx force:cmdt:generate --devname MyCMDT --sobjectname MySourceObject__c',
121
- messages.getMessage('exampleCaption2'),
122
- " $ sfdx force:cmdt:generate --devname MyCMDT --sobjectname MySourceObject__c --ignoreunsupported --targetusername '" +
123
- messages.getMessage('targetusernameFlagExample') +
124
- "'",
125
- messages.getMessage('exampleCaption3'),
126
- ' $ sfdx force:cmdt:generate --devname MyCMDT --sobjectname SourceCustomObject__c --visibility Protected',
127
- messages.getMessage('exampleCaption4'),
128
- ' $ sfdx force:cmdt:generate --devname MyCMDT --label "' +
129
- messages.getMessage('labelFlagExample') +
130
- '" ' +
131
- '--plurallabel "' +
132
- messages.getMessage('plurallabelFlagExample') +
133
- '" --sobjectname SourceCustomSetting__c --visibility Protected',
134
- messages.getMessage('exampleCaption5'),
135
- " $ sfdx force:cmdt:generate --devname MyCMDT --sobjectname SourceCustomSetting__c --typeoutputdir '" +
136
- messages.getMessage('typeoutputdirFlagExample') +
137
- "'",
138
- messages.getMessage('exampleCaption6'),
139
- " $ sfdx force:cmdt:generate --devname MyCMDT --sobjectname SourceCustomSetting__c --recordsoutputdir '" +
140
- messages.getMessage('recordsoutputdirFlagExample') +
141
- "'",
142
- ];
143
- Generate.args = [{ name: 'file' }];
144
- Generate.flagsConfig = {
145
- // flag with a value (-n, --name=VALUE)
146
- devname: command_1.flags.string({
147
- char: 'n',
148
- required: true,
149
- description: messages.getMessage('devnameFlagDescription'),
150
- longDescription: messages.getMessage('devnameFlagLongDescription'),
151
- parse: async (input) => Promise.resolve((0, validationUtil_1.validateMetadataTypeName)(input)),
152
- }),
153
- label: command_1.flags.string({
154
- char: 'l',
155
- description: messages.getMessage('labelFlagDescription'),
156
- longDescription: messages.getMessage('labelFlagLongDescription'),
157
- }),
158
- plurallabel: command_1.flags.string({
159
- char: 'p',
160
- description: messages.getMessage('plurallabelFlagDescription'),
161
- longDescription: messages.getMessage('plurallabelFlagLongDescription'),
162
- }),
163
- visibility: command_1.flags.enum({
164
- char: 'v',
165
- description: messages.getMessage('visibilityFlagDescription'),
166
- longDescription: messages.getMessage('visibilityFlagLongDescription'),
167
- options: ['PackageProtected', 'Protected', 'Public'],
168
- default: 'Public',
169
- }),
170
- sobjectname: command_1.flags.string({
171
- char: 's',
172
- required: true,
173
- description: messages.getMessage('sobjectnameFlagDescription'),
174
- longDescription: messages.getMessage('sobjectnameFlagLongDescription'),
175
- parse: async (sobjectname) => Promise.resolve((0, validationUtil_1.validateAPIName)(sobjectname)),
176
- }),
177
- ignoreunsupported: command_1.flags.boolean({
178
- char: 'i',
179
- description: messages.getMessage('ignoreUnsupportedFlagDescription'),
180
- longDescription: messages.getMessage('ignoreUnsupportedFlagLongDescription'),
181
- }),
182
- typeoutputdir: command_1.flags.directory({
183
- char: 'd',
184
- description: messages.getMessage('typeoutputdirFlagDescription'),
185
- longDescription: messages.getMessage('typeoutputdirFlagLongDescription'),
186
- default: path.join('force-app', 'main', 'default', 'objects'),
187
- }),
188
- recordsoutputdir: command_1.flags.directory({
189
- char: 'r',
190
- description: messages.getMessage('recordsoutputdirFlagDescription'),
191
- longDescription: messages.getMessage('recordsoutputdirFlagLongDescription'),
192
- default: path.join('force-app', 'main', 'default', 'customMetadata'),
193
- }),
194
- };
195
- Generate.requiresUsername = true;
196
- Generate.requiresProject = true;
197
- const getSoqlQuery = (describeResult) => {
198
- const fieldNames = describeResult.fields
199
- .map((field) => field.fullName)
200
- .join(',');
201
- // Added Name hardcoded as Name field is not retrieved as part of object describe.
202
- return `SELECT Name, ${fieldNames} FROM ${describeResult.fullName}`;
203
- };
204
- const convertLocationFieldToText = (field) => {
205
- const baseTextField = {
206
- required: field['required'],
207
- trackHistory: field['trackHistory'],
208
- trackTrending: field['trackTrending'],
209
- type: 'Text',
210
- length: 40,
211
- summaryFilterItems: [],
212
- };
213
- return ['Lat_', 'Long_'].map((prefix) => ({
214
- ...baseTextField,
215
- fullName: `${prefix}${field.fullName}`,
216
- label: `${prefix}${field.label}`,
217
- }));
218
- };
219
- //# sourceMappingURL=generate.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"generate.js","sourceRoot":"","sources":["../../../../src/commands/force/cmdt/generate.ts"],"names":[],"mappings":";;;AAAA;;;;;GAKG;AACH,yBAAyB;AACzB,6BAA6B;AAC7B,iDAAyD;AACzD,2CAAqD;AACrD,yCAA0C;AAE1C,gEAA6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AAC;AAEF,MAAM,0BAA0B,GAAG,CAAC,KAAkB,EAAiB,EAAE;IACvE,MAAM,aAAa,GAAG;QACpB,QAAQ,EAAE,KAAK,CAAC,UAAU,CAAC;QAC3B,YAAY,EAAE,KAAK,CAAC,cAAc,CAAC;QACnC,aAAa,EAAE,KAAK,CAAC,eAAe,CAAC;QACrC,IAAI,EAAE,MAAM;QACZ,MAAM,EAAE,EAAE;QACV,kBAAkB,EAAE,EAAE;KACvB,CAAC;IACF,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;QACxC,GAAG,aAAa;QAChB,QAAQ,EAAE,GAAG,MAAM,GAAG,KAAK,CAAC,QAAQ,EAAE;QACtC,KAAK,EAAE,GAAG,MAAM,GAAG,KAAK,CAAC,KAAK,EAAE;KACjC,CAAC,CAAC,CAAC;AACN,CAAC,CAAC"}
@@ -1,32 +0,0 @@
1
- import { flags, SfdxCommand } from '@salesforce/command';
2
- import { CustomField } from 'jsforce/api/metadata';
3
- interface CmdtRecordCreateResponse {
4
- typename: string;
5
- recordname: string;
6
- label: string;
7
- inputdir: string;
8
- outputdir: string;
9
- protectedFlag: boolean;
10
- varargs: Record<string, unknown>;
11
- fileData: CustomField[];
12
- }
13
- export default class Create extends SfdxCommand {
14
- static description: string;
15
- static longDescription: string;
16
- static examples: string[];
17
- protected static flagsConfig: {
18
- typename: flags.Discriminated<flags.String>;
19
- recordname: flags.Discriminated<flags.String>;
20
- label: flags.Discriminated<flags.String>;
21
- protected: flags.Discriminated<flags.String>;
22
- inputdir: flags.Discriminated<flags.String>;
23
- outputdir: flags.Discriminated<flags.String>;
24
- };
25
- protected static varargs: {
26
- required: boolean;
27
- validator: (name: string) => void;
28
- };
29
- protected static requiresProject: boolean;
30
- run(): Promise<CmdtRecordCreateResponse>;
31
- }
32
- export {};
@@ -1,140 +0,0 @@
1
- "use strict";
2
- var _a;
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- /*
5
- * Copyright (c) 2020, salesforce.com, inc.
6
- * All rights reserved.
7
- * Licensed under the BSD 3-Clause license.
8
- * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
9
- */
10
- const fs = require("fs");
11
- const path = require("path");
12
- const command_1 = require("@salesforce/command");
13
- const core_1 = require("@salesforce/core");
14
- const createUtil_1 = require("../../../../lib/helpers/createUtil");
15
- const validationUtil_1 = require("../../../../lib/helpers/validationUtil");
16
- // Initialize Messages with the current plugin directory
17
- core_1.Messages.importMessagesDirectory(__dirname);
18
- // Load the specific messages for this file. Messages from @salesforce/command, @salesforce/core,
19
- // or any library that is using the messages framework can also be loaded this way.
20
- const messages = core_1.Messages.loadMessages('@salesforce/plugin-custom-metadata', 'createRecord');
21
- class Create extends command_1.SfdxCommand {
22
- // eslint-disable-next-line @typescript-eslint/member-ordering
23
- async run() {
24
- var _b;
25
- try {
26
- const createUtil = new createUtil_1.CreateUtil();
27
- let typename = this.flags.typename;
28
- const recordname = this.flags.recordname;
29
- const label = (_b = this.flags.label) !== null && _b !== void 0 ? _b : recordname;
30
- const protectedFlag = this.flags.protected === 'true';
31
- const inputdir = this.flags.inputdir;
32
- const outputdir = this.flags.outputdir;
33
- const dirName = createUtil.appendDirectorySuffix(typename);
34
- const fieldDirPath = path.join(inputdir, dirName, 'fields');
35
- const fileNames = await fs.promises.readdir(fieldDirPath);
36
- // forgive them if they passed in type__mdt, and cut off the __mdt
37
- if (typename.endsWith('__mdt')) {
38
- typename = typename.substring(0, typename.indexOf('__mdt'));
39
- }
40
- // if customMetadata folder does not exist, create it
41
- await fs.promises.mkdir(outputdir, { recursive: true });
42
- const fileData = await createUtil.getFileData(fieldDirPath, fileNames);
43
- await createUtil.createRecord({
44
- typename,
45
- recordname,
46
- label,
47
- inputdir,
48
- outputdir,
49
- protected: protectedFlag,
50
- varargs: this.varargs,
51
- fileData,
52
- });
53
- this.ux.log(messages.getMessage('successResponse', [typename, recordname, label, protectedFlag, outputdir]));
54
- // Return an object to be displayed with --json
55
- return {
56
- typename,
57
- recordname,
58
- label,
59
- inputdir,
60
- outputdir,
61
- protectedFlag,
62
- varargs: this.varargs,
63
- fileData,
64
- };
65
- }
66
- catch (err) {
67
- if (err instanceof Error) {
68
- this.ux.log(err.message);
69
- }
70
- }
71
- }
72
- }
73
- exports.default = Create;
74
- _a = Create;
75
- Create.description = messages.getMessage('commandDescription');
76
- Create.longDescription = messages.getMessage('commandLongDescription');
77
- Create.examples = [
78
- messages.getMessage('exampleCaption1'),
79
- ' $ sfdx force:cmdt:record:create --typename MyCMT__mdt --recordname MyRecord My_Custom_Field_1=Foo My_Custom_Field_2=Bar',
80
- messages.getMessage('exampleCaption2'),
81
- ' $ sfdx force:cmdt:record:create --typename MyCMT__mdt --recordname MyRecord --label "' +
82
- messages.getMessage('labelFlagExample') +
83
- '" ' +
84
- '--protected true My_Custom_Field_1=Foo My_Custom_Field_2=Bar',
85
- ];
86
- Create.flagsConfig = {
87
- typename: command_1.flags.string({
88
- char: 't',
89
- description: messages.getMessage('typenameFlagDescription'),
90
- longDescription: messages.getMessage('typenameFlagLongDescription'),
91
- required: true,
92
- parse: async (input) => Promise.resolve((0, validationUtil_1.validateMetadataTypeName)(input)),
93
- }),
94
- recordname: command_1.flags.string({
95
- char: 'n',
96
- description: messages.getMessage('recordNameFlagDescription'),
97
- longDescription: messages.getMessage('recordNameFlagLongDescription'),
98
- required: true,
99
- parse: async (input) => Promise.resolve((0, validationUtil_1.validateMetadataRecordName)(input)),
100
- }),
101
- label: command_1.flags.string({
102
- char: 'l',
103
- description: messages.getMessage('labelFlagDescription'),
104
- longDescription: messages.getMessage('labelFlagLongDescription'),
105
- parse: async (input) => Promise.resolve((0, validationUtil_1.validateLessThanForty)(input, messages.getMessage('notAValidLabelNameError', [input]))),
106
- }),
107
- protected: command_1.flags.string({
108
- char: 'p',
109
- description: messages.getMessage('protectedFlagDescription'),
110
- longDescription: messages.getMessage('protectedFlagLongDescription'),
111
- options: ['true', 'false'],
112
- default: 'false',
113
- }),
114
- inputdir: command_1.flags.directory({
115
- char: 'i',
116
- description: messages.getMessage('inputDirectoryFlagDescription'),
117
- longDescription: messages.getMessage('inputDirectoryFlagLongDescription'),
118
- default: path.join('force-app', 'main', 'default', 'objects'),
119
- }),
120
- outputdir: command_1.flags.directory({
121
- char: 'd',
122
- description: messages.getMessage('outputDirectoryFlagDescription'),
123
- longDescription: messages.getMessage('outputDirectoryFlagLongDescription'),
124
- default: path.join('force-app', 'main', 'default', 'customMetadata'),
125
- }),
126
- };
127
- Create.varargs = {
128
- required: false,
129
- validator: (name) => {
130
- // only custom fields allowed
131
- if (!name.endsWith('__c')) {
132
- const errMsg = `Invalid parameter [${name}] found`;
133
- const errName = 'InvalidVarargName';
134
- const errAction = messages.getMessage('errorInvalidCustomField');
135
- throw new core_1.SfError(errMsg, errName, [errAction]);
136
- }
137
- },
138
- };
139
- Create.requiresProject = true;
140
- //# sourceMappingURL=create.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"create.js","sourceRoot":"","sources":["../../../../../src/commands/force/cmdt/record/create.ts"],"names":[],"mappings":";;;AAAA;;;;;GAKG;AACH,yBAAyB;AACzB,6BAA6B;AAC7B,iDAAyD;AACzD,2CAAqD;AAErD,mEAAgE;AAChE,2EAIgD;AAEhD,wDAAwD;AACxD,eAAQ,CAAC,uBAAuB,CAAC,SAAS,CAAC,CAAC;AAE5C,iGAAiG;AACjG,mFAAmF;AACnF,MAAM,QAAQ,GAAG,eAAQ,CAAC,YAAY,CAAC,oCAAoC,EAAE,cAAc,CAAC,CAAC;AAY7F,MAAqB,MAAO,SAAQ,qBAAW;IAwE7C,8DAA8D;IACvD,KAAK,CAAC,GAAG;;QACd,IAAI;YACF,MAAM,UAAU,GAAG,IAAI,uBAAU,EAAE,CAAC;YACpC,IAAI,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,QAAkB,CAAC;YAC7C,MAAM,UAAU,GAAG,IAAI,CAAC,KA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W,EAAE,QAAQ,CAAC,UAAU,CAAC,gCAAgC,CAAC;QAClE,eAAe,EAAE,QAAQ,CAAC,UAAU,CAAC,oCAAoC,CAAC;QAC1E,OAAO,EAAE,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,MAAM,EAAE,SAAS,EAAE,gBAAgB,CAAC;KACrE,CAAC;CACH,CAAC;AAEe,cAAO,GAAG;IACzB,QAAQ,EAAE,KAAK;IACf,SAAS,EAAE,CAAC,IAAY,EAAQ,EAAE;QAChC,6BAA6B;QAC7B,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE;YACzB,MAAM,MAAM,GAAG,sBAAsB,IAAI,SAAS,CAAC;YACnD,MAAM,OAAO,GAAG,mBAAmB,CAAC;YACpC,MAAM,SAAS,GAAG,QAAQ,CAAC,UAAU,CAAC,yBAAyB,CAAC,CAAC;YACjE,MAAM,IAAI,cAAO,CAAC,MAAM,EAAE,OAAO,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC;SACjD;IACH,CAAC;CACF,CAAC;AAEe,sBAAe,GAAG,IAAI,CAAC"}
@@ -1,16 +0,0 @@
1
- import { flags, SfdxCommand } from '@salesforce/command';
2
- import { CreateConfig } from '../../../../lib/interfaces/createConfig';
3
- export default class Insert extends SfdxCommand {
4
- static description: string;
5
- static longDescription: string;
6
- static examples: string[];
7
- protected static flagsConfig: {
8
- filepath: flags.Discriminated<flags.String>;
9
- typename: flags.Discriminated<flags.String>;
10
- inputdir: flags.Discriminated<flags.String>;
11
- outputdir: flags.Discriminated<flags.String>;
12
- namecolumn: flags.Discriminated<flags.String>;
13
- };
14
- protected static requiresProject: boolean;
15
- run(): Promise<CreateConfig[]>;
16
- }
@@ -1,110 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- /*
4
- * Copyright (c) 2020, salesforce.com, inc.
5
- * All rights reserved.
6
- * Licensed under the BSD 3-Clause license.
7
- * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
8
- */
9
- const fs = require("fs");
10
- const path = require("path");
11
- const command_1 = require("@salesforce/command");
12
- const core_1 = require("@salesforce/core");
13
- const csv = require("../../../../../csvtojson");
14
- const createUtil_1 = require("../../../../lib/helpers/createUtil");
15
- core_1.Messages.importMessagesDirectory(__dirname);
16
- const messages = core_1.Messages.loadMessages('@salesforce/plugin-custom-metadata', 'insertRecord');
17
- class Insert extends command_1.SfdxCommand {
18
- // eslint-disable-next-line @typescript-eslint/member-ordering
19
- async run() {
20
- const createUtil = new createUtil_1.CreateUtil();
21
- const filepath = this.flags.filepath;
22
- let typename = this.flags.typename;
23
- const inputdir = this.flags.inputdir;
24
- const outputdir = this.flags.outputdir;
25
- const dirName = createUtil.appendDirectorySuffix(typename);
26
- const fieldDirPath = path.join(inputdir, dirName, 'fields');
27
- const fileNames = await fs.promises.readdir(fieldDirPath);
28
- const nameField = this.flags.namecolumn;
29
- // forgive them if they passed in type__mdt, and cut off the __mdt
30
- if (typename.endsWith('__mdt')) {
31
- typename = typename.substring(0, typename.indexOf('__mdt'));
32
- }
33
- // if customMetadata folder does not exist, create it
34
- await fs.promises.mkdir(outputdir, { recursive: true });
35
- const fileData = await createUtil.getFileData(fieldDirPath, fileNames);
36
- const csvDataAry = (await csv().fromFile(filepath));
37
- const metadataTypeFields = createUtil.getFieldNames(fileData, nameField);
38
- if (csvDataAry.length > 0) {
39
- const record = csvDataAry[0];
40
- for (const key in record) {
41
- if (!metadataTypeFields.includes(key)) {
42
- throw new core_1.SfError(messages.getMessage('fieldNotFoundError', [key, typename]));
43
- }
44
- }
45
- }
46
- // find the cmdt in the inputdir.
47
- // loop through files and create records that match fields
48
- const recordConfigs = csvDataAry.map((record) => ({
49
- typename,
50
- recordname: record[nameField].replace(' ', '_'),
51
- label: record[nameField],
52
- inputdir,
53
- outputdir,
54
- protected: false,
55
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
56
- varargs: Object.fromEntries(
57
- // TODO: throw an error if any of the fields in the csvDataAry do not exist in the fileData
58
- fileData.map((file) => (record[file.fullName] ? [file.fullName, record[file.fullName]] : []))),
59
- fileData,
60
- }));
61
- await Promise.all(recordConfigs.map((r) => createUtil.createRecord(r)));
62
- this.ux.log(messages.getMessage('successResponse', [filepath, outputdir]));
63
- return recordConfigs;
64
- }
65
- }
66
- exports.default = Insert;
67
- Insert.description = messages.getMessage('commandDescription');
68
- Insert.longDescription = messages.getMessage('commandLongDescription');
69
- Insert.examples = [
70
- messages.getMessage('exampleCaption1'),
71
- ' $ sfdx force:cmdt:record:insert --filepath path/to/my.csv --typename My_CMDT_Name',
72
- messages.getMessage('exampleCaption2'),
73
- ' $ sfdx force:cmdt:record:insert --filepath path/to/my.csv --typename My_CMDT_Name --inputdir "' +
74
- messages.getMessage('inputDirectoryFlagExample') +
75
- '" --namecolumn "PrimaryKey"',
76
- ];
77
- Insert.flagsConfig = {
78
- filepath: command_1.flags.string({
79
- char: 'f',
80
- description: messages.getMessage('filepathFlagDescription'),
81
- longDescription: messages.getMessage('filepathFlagLongDescription'),
82
- required: true,
83
- }),
84
- typename: command_1.flags.string({
85
- char: 't',
86
- description: messages.getMessage('typenameFlagDescription'),
87
- longDescription: messages.getMessage('typenameFlagLongDescription'),
88
- required: true,
89
- }),
90
- inputdir: command_1.flags.directory({
91
- char: 'i',
92
- description: messages.getMessage('inputDirectoryFlagDescription'),
93
- longDescription: messages.getMessage('inputDirectoryFlagLongDescription'),
94
- default: path.join('force-app', 'main', 'default', 'objects'),
95
- }),
96
- outputdir: command_1.flags.directory({
97
- char: 'd',
98
- description: messages.getMessage('outputDirectoryFlagDescription'),
99
- longDescription: messages.getMessage('outputDirectoryFlagLongDescription'),
100
- default: path.join('force-app', 'main', 'default', 'customMetadata'),
101
- }),
102
- namecolumn: command_1.flags.string({
103
- char: 'n',
104
- description: messages.getMessage('namecolumnFlagDescription'),
105
- longDescription: messages.getMessage('namecolumnFlagLongDescription'),
106
- default: 'Name',
107
- }),
108
- };
109
- Insert.requiresProject = true;
110
- //# sourceMappingURL=insert.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"insert.js","sourceRoot":"","sources":["../../../../../src/commands/force/cmdt/record/insert.ts"],"names":[],"mappings":";;AAAA;;;;;GAKG;AACH,yBAAyB;AACzB,6BAA6B;AAC7B,iDAAyD;AACzD,2CAAqD;AAErD,gDAAgD;AAChD,mEAAgE;AAGhE,eAAQ,CAAC,uBAAuB,CAAC,SAAS,CAAC,CAAC;AAC5C,MAAM,QAAQ,GAAG,eAAQ,CAAC,YAAY,CAAC,oCAAoC,EAAE,cAAc,CAAC,CAAC;AAE7F,MAAqB,MAAO,SAAQ,qBAAW;IAgD7C,8DAA8D;IACvD,KAAK,CAAC,GAAG;QACd,MAAM,UAAU,GAAG,IAAI,uBAAU,EAAE,CAAC;QACpC,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,QAAkB,CAAC;QAC/C,IAAI,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,QAAkB,CAAC;QAC7C,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,QAAkB,CAAC;QAC/C,MAAM,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,SAAmB,CAAC;QACjD,MAAM,OAAO,GAAG,UAAU,CAAC,qBAAqB,CAAC,QAAQ,CAAC,CAAC;QAC3D,MAAM,YAAY,GAAG,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC;QAC5D,MAAM,SAAS,GAAG,MAAM,EAAE,CAAC,QAAQ,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;QAC1D,MAAM,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,UAAoB,CAAC;QAElD,kEAAkE;QAClE,IAAI,QAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE;YAC9B,QAAQ,GAAG,QAAQ,CAAC,SAAS,CAAC,CAAC,EAAE,QAAQ,CAAC,OAAO,CAAC,OA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UAAU,CAAC,6BAA6B,CAAC;QACnE,QAAQ,EAAE,IAAI;KACf,CAAC;IACF,QAAQ,EAAE,eAAK,CAAC,SAAS,CAAC;QACxB,IAAI,EAAE,GAAG;QACT,WAAW,EAAE,QAAQ,CAAC,UAAU,CAAC,+BAA+B,CAAC;QACjE,eAAe,EAAE,QAAQ,CAAC,UAAU,CAAC,mCAAmC,CAAC;QACzE,OAAO,EAAE,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,CAAC;KAC9D,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,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,MAAM,EAAE,SAAS,EAAE,gBAAgB,CAAC;KACrE,CAAC;IACF,UAAU,EAAE,eAAK,CAAC,MAAM,CAAC;QACvB,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,MAAM;KAChB,CAAC;CACH,CAAC;AAEe,sBAAe,GAAG,IAAI,CAAC"}
@@ -1,62 +0,0 @@
1
- import { CustomField } from 'jsforce/api/metadata';
2
- import { CreateConfig } from '../interfaces/createConfig';
3
- export declare class CreateUtil {
4
- /**
5
- * Number and Percent types will be int or double depending on their respective scale values.
6
- * If the scale === 0, it is an int, otherwise it is a double
7
- */
8
- /**
9
- * Creates the Custom Metadata Record
10
- *
11
- * @param createConfig Properties include typename, recname, label, protection, varargs, and fileData
12
- * @return void
13
- */
14
- createRecord(createConfig: CreateConfig): Promise<void>;
15
- /**
16
- *
17
- * @param fieldDirPath path to a /fields folder that contains all the fields to read
18
- * @param fileNames filenames in that folder that should be read
19
- * @returns CustomField[]
20
- */
21
- getFileData(fieldDirPath: string, fileNames: string[]): Promise<CustomField[]>;
22
- /**
23
- * Filenames should have the suffix of '__mdt'. This will append that suffix if it does not exist.
24
- *
25
- * @param typename Name of file
26
- */
27
- appendDirectorySuffix(typename: string): string;
28
- /**
29
- * Get the field primitive type from the custom metadata type that has a matching field name.
30
- *
31
- * @param fileData Array of objects based on metadata type xml
32
- * @param fieldName Name of the field
33
- * @return {string} Type used by a custom metadata record
34
- */
35
- getFieldPrimitiveType(fileData?: CustomField[], fieldName?: string): string;
36
- /**
37
- * Get the field type from the custom metadata type that has a matching field name.
38
- *
39
- * @param fileData Array of objects based on metadata type xml
40
- * @param fieldName Name of the field
41
- * @return {string} Data Type of the field.
42
- */
43
- getFieldDataType(fileData?: CustomField[], fieldName?: string): CustomField['type'];
44
- /**
45
- * Goes through the file data that has been genreated and gets all of the field names and adds the
46
- * name of the field that is used as the label for metadata record
47
- *
48
- * @param fileData Array of objects based on metadata type xml
49
- * @param nameField name of the column that is going to be used for the name of the metadata record
50
- * @return [] Array of field names
51
- */
52
- getFieldNames(fileData: CustomField[], nameField: string): string[];
53
- /**
54
- * Takes JSON representation of CLI varargs and converts them to xml with help
55
- * from helper.getFieldTemplate
56
- *
57
- * @param cliParams Object that holds key:value pairs from CLI input
58
- * @param fileData Array of objects that contain field data
59
- * @return {string} String representation of XML
60
- */
61
- private buildCustomFieldXml;
62
- }