@salesforce/plugin-custom-metadata 1.1.0 → 2.0.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/LICENSE.txt +2 -2
- package/README.md +137 -133
- package/lib/commands/force/cmdt/create.d.ts +8 -2
- package/lib/commands/force/cmdt/create.js +15 -21
- package/lib/commands/force/cmdt/create.js.map +1 -1
- package/lib/commands/force/cmdt/field/create.d.ts +7 -2
- package/lib/commands/force/cmdt/field/create.js +15 -20
- package/lib/commands/force/cmdt/field/create.js.map +1 -1
- package/lib/commands/force/cmdt/generate.d.ts +6 -2
- package/lib/commands/force/cmdt/generate.js +79 -150
- package/lib/commands/force/cmdt/generate.js.map +1 -1
- package/lib/commands/force/cmdt/record/create.d.ts +14 -3
- package/lib/commands/force/cmdt/record/create.js +25 -33
- package/lib/commands/force/cmdt/record/create.js.map +1 -1
- package/lib/commands/force/cmdt/record/insert.d.ts +2 -2
- package/lib/commands/force/cmdt/record/insert.js +28 -40
- package/lib/commands/force/cmdt/record/insert.js.map +1 -1
- package/lib/lib/helpers/createUtil.d.ts +10 -6
- package/lib/lib/helpers/createUtil.js +48 -100
- package/lib/lib/helpers/createUtil.js.map +1 -1
- package/lib/lib/helpers/fileWriter.d.ts +11 -11
- package/lib/lib/helpers/fileWriter.js +14 -24
- package/lib/lib/helpers/fileWriter.js.map +1 -1
- package/lib/lib/helpers/metadataUtil.d.ts +25 -51
- package/lib/lib/helpers/metadataUtil.js +55 -131
- package/lib/lib/helpers/metadataUtil.js.map +1 -1
- package/lib/lib/helpers/validationUtil.d.ts +25 -26
- package/lib/lib/helpers/validationUtil.js +66 -43
- package/lib/lib/helpers/validationUtil.js.map +1 -1
- package/lib/lib/interfaces/createConfig.d.ts +3 -2
- package/lib/lib/templates/templates.d.ts +8 -99
- package/lib/lib/templates/templates.js +38 -67
- package/lib/lib/templates/templates.js.map +1 -1
- package/messages/createField.json +22 -31
- package/messages/generate.json +38 -51
- package/messages/template.json +2 -2
- package/messages/validation.json +5 -0
- package/oclif.manifest.json +1 -1
- package/package.json +53 -42
- package/CHANGELOG.md +0 -39
- package/lib/lib/interfaces/customField.d.ts +0 -7
- package/lib/lib/interfaces/customField.js +0 -9
- package/lib/lib/interfaces/customField.js.map +0 -1
- package/lib/lib/interfaces/errorMessage.d.ts +0 -4
- package/lib/lib/interfaces/errorMessage.js +0 -9
- package/lib/lib/interfaces/errorMessage.js.map +0 -1
- package/lib/lib/interfaces/record.d.ts +0 -3
- package/lib/lib/interfaces/record.js +0 -9
- package/lib/lib/interfaces/record.js.map +0 -1
- package/lib/lib/interfaces/saveResults.d.ts +0 -5
- package/lib/lib/interfaces/saveResults.js +0 -9
- package/lib/lib/interfaces/saveResults.js.map +0 -1
|
@@ -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
|
-
|
|
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 createUtil_1 = require("../../../../lib/helpers/createUtil");
|
|
12
|
-
const fileWriter_1 = require("../../../../lib/helpers/fileWriter");
|
|
13
15
|
const validationUtil_1 = require("../../../../lib/helpers/validationUtil");
|
|
14
16
|
// Initialize Messages with the current plugin directory
|
|
15
17
|
core_1.Messages.importMessagesDirectory(__dirname);
|
|
@@ -17,35 +19,26 @@ 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', 'createRecord');
|
|
19
21
|
class Create extends command_1.SfdxCommand {
|
|
22
|
+
// eslint-disable-next-line @typescript-eslint/member-ordering
|
|
20
23
|
async run() {
|
|
24
|
+
var _b;
|
|
21
25
|
try {
|
|
22
|
-
const validator = new validationUtil_1.ValidationUtil();
|
|
23
26
|
const createUtil = new createUtil_1.CreateUtil();
|
|
24
|
-
const fileWriter = new fileWriter_1.FileWriter();
|
|
25
27
|
let typename = this.flags.typename;
|
|
26
28
|
const recordname = this.flags.recordname;
|
|
27
|
-
const label = this.flags.label
|
|
28
|
-
const protectedFlag = this.flags.protected
|
|
29
|
-
const inputdir = this.flags.inputdir
|
|
30
|
-
const outputdir = this.flags.outputdir
|
|
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;
|
|
31
33
|
const dirName = createUtil.appendDirectorySuffix(typename);
|
|
32
|
-
const fieldDirPath =
|
|
33
|
-
|
|
34
|
-
throw new core_1.SfdxError(messages.getMessage('notValidAPINameError', [typename]));
|
|
35
|
-
}
|
|
36
|
-
if (!validator.validateMetadataRecordName(recordname)) {
|
|
37
|
-
throw new core_1.SfdxError(messages.getMessage('notAValidRecordNameError', [recordname]));
|
|
38
|
-
}
|
|
39
|
-
if (!validator.validateLessThanForty(label)) {
|
|
40
|
-
throw new core_1.SfdxError(messages.getMessage('notAValidLabelNameError', [label]));
|
|
41
|
-
}
|
|
42
|
-
const fileNames = await core_1.fs.readdir(fieldDirPath);
|
|
34
|
+
const fieldDirPath = path.join(inputdir, dirName, 'fields');
|
|
35
|
+
const fileNames = await fs.promises.readdir(fieldDirPath);
|
|
43
36
|
// forgive them if they passed in type__mdt, and cut off the __mdt
|
|
44
37
|
if (typename.endsWith('__mdt')) {
|
|
45
38
|
typename = typename.substring(0, typename.indexOf('__mdt'));
|
|
46
39
|
}
|
|
47
40
|
// if customMetadata folder does not exist, create it
|
|
48
|
-
await
|
|
41
|
+
await fs.promises.mkdir(outputdir, { recursive: true });
|
|
49
42
|
const fileData = await createUtil.getFileData(fieldDirPath, fileNames);
|
|
50
43
|
await createUtil.createRecord({
|
|
51
44
|
typename,
|
|
@@ -57,13 +50,7 @@ class Create extends command_1.SfdxCommand {
|
|
|
57
50
|
varargs: this.varargs,
|
|
58
51
|
fileData,
|
|
59
52
|
});
|
|
60
|
-
this.ux.log(messages.getMessage('successResponse', [
|
|
61
|
-
typename,
|
|
62
|
-
recordname,
|
|
63
|
-
label,
|
|
64
|
-
protectedFlag,
|
|
65
|
-
outputdir,
|
|
66
|
-
]));
|
|
53
|
+
this.ux.log(messages.getMessage('successResponse', [typename, recordname, label, protectedFlag, outputdir]));
|
|
67
54
|
// Return an object to be displayed with --json
|
|
68
55
|
return {
|
|
69
56
|
typename,
|
|
@@ -77,11 +64,14 @@ class Create extends command_1.SfdxCommand {
|
|
|
77
64
|
};
|
|
78
65
|
}
|
|
79
66
|
catch (err) {
|
|
80
|
-
|
|
67
|
+
if (err instanceof Error) {
|
|
68
|
+
this.ux.log(err.message);
|
|
69
|
+
}
|
|
81
70
|
}
|
|
82
71
|
}
|
|
83
72
|
}
|
|
84
73
|
exports.default = Create;
|
|
74
|
+
_a = Create;
|
|
85
75
|
Create.description = messages.getMessage('commandDescription');
|
|
86
76
|
Create.longDescription = messages.getMessage('commandLongDescription');
|
|
87
77
|
Create.examples = [
|
|
@@ -99,17 +89,20 @@ Create.flagsConfig = {
|
|
|
99
89
|
description: messages.getMessage('typenameFlagDescription'),
|
|
100
90
|
longDescription: messages.getMessage('typenameFlagLongDescription'),
|
|
101
91
|
required: true,
|
|
92
|
+
parse: async (input) => Promise.resolve((0, validationUtil_1.validateMetadataTypeName)(input)),
|
|
102
93
|
}),
|
|
103
94
|
recordname: command_1.flags.string({
|
|
104
95
|
char: 'n',
|
|
105
96
|
description: messages.getMessage('recordNameFlagDescription'),
|
|
106
97
|
longDescription: messages.getMessage('recordNameFlagLongDescription'),
|
|
107
98
|
required: true,
|
|
99
|
+
parse: async (input) => Promise.resolve((0, validationUtil_1.validateMetadataRecordName)(input)),
|
|
108
100
|
}),
|
|
109
101
|
label: command_1.flags.string({
|
|
110
102
|
char: 'l',
|
|
111
103
|
description: messages.getMessage('labelFlagDescription'),
|
|
112
104
|
longDescription: messages.getMessage('labelFlagLongDescription'),
|
|
105
|
+
parse: async (input) => Promise.resolve((0, validationUtil_1.validateLessThanForty)(input, messages.getMessage('notAValidLabelNameError', [input]))),
|
|
113
106
|
}),
|
|
114
107
|
protected: command_1.flags.string({
|
|
115
108
|
char: 'p',
|
|
@@ -122,27 +115,26 @@ Create.flagsConfig = {
|
|
|
122
115
|
char: 'i',
|
|
123
116
|
description: messages.getMessage('inputDirectoryFlagDescription'),
|
|
124
117
|
longDescription: messages.getMessage('inputDirectoryFlagLongDescription'),
|
|
125
|
-
default: 'force-app
|
|
118
|
+
default: path.join('force-app', 'main', 'default', 'objects'),
|
|
126
119
|
}),
|
|
127
120
|
outputdir: command_1.flags.directory({
|
|
128
121
|
char: 'd',
|
|
129
122
|
description: messages.getMessage('outputDirectoryFlagDescription'),
|
|
130
123
|
longDescription: messages.getMessage('outputDirectoryFlagLongDescription'),
|
|
131
|
-
default: 'force-app
|
|
124
|
+
default: path.join('force-app', 'main', 'default', 'customMetadata'),
|
|
132
125
|
}),
|
|
133
126
|
};
|
|
134
127
|
Create.varargs = {
|
|
135
128
|
required: false,
|
|
136
|
-
validator: (name
|
|
129
|
+
validator: (name) => {
|
|
137
130
|
// only custom fields allowed
|
|
138
131
|
if (!name.endsWith('__c')) {
|
|
139
132
|
const errMsg = `Invalid parameter [${name}] found`;
|
|
140
133
|
const errName = 'InvalidVarargName';
|
|
141
134
|
const errAction = messages.getMessage('errorInvalidCustomField');
|
|
142
|
-
throw new core_1.
|
|
135
|
+
throw new core_1.SfError(errMsg, errName, [errAction]);
|
|
143
136
|
}
|
|
144
137
|
},
|
|
145
138
|
};
|
|
146
|
-
// Set this to true if your command requires a project workspace; 'requiresProject' is false by default
|
|
147
139
|
Create.requiresProject = true;
|
|
148
140
|
//# sourceMappingURL=create.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create.js","sourceRoot":"","sources":["../../../../../src/commands/force/cmdt/record/create.ts"],"names":[],"mappings":"
|
|
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,KAAK,CAAC,UAAoB,CAAC;YACnD,MAAM,KAAK,GAAG,MAAC,IAAI,CAAC,KAAK,CAAC,KAAgB,mCAAI,UAAU,CAAC;YACzD,MAAM,aAAa,GAAI,IAAI,CAAC,KAAK,CAAC,SAAoB,KAAK,MAAM,CAAC;YAClE,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,QAAkB,CAAC;YAC/C,MAAM,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,SAAmB,CAAC;YACjD,MAAM,OAAO,GAAG,UAAU,CAAC,qBAAqB,CAAC,QAAQ,CAA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AC,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;CACD,CAAA;AAEe,sBAAe,GAAG,IAAK,CAAA"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { flags, SfdxCommand } from '@salesforce/command';
|
|
2
|
-
import {
|
|
2
|
+
import { CreateConfig } from '../../../../lib/interfaces/createConfig';
|
|
3
3
|
export default class Insert extends SfdxCommand {
|
|
4
4
|
static description: string;
|
|
5
5
|
static longDescription: string;
|
|
@@ -12,5 +12,5 @@ export default class Insert extends SfdxCommand {
|
|
|
12
12
|
namecolumn: flags.Discriminated<flags.String>;
|
|
13
13
|
};
|
|
14
14
|
protected static requiresProject: boolean;
|
|
15
|
-
run(): Promise<
|
|
15
|
+
run(): Promise<CreateConfig[]>;
|
|
16
16
|
}
|
|
@@ -1,78 +1,66 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2
3
|
/*
|
|
3
4
|
* Copyright (c) 2020, salesforce.com, inc.
|
|
4
5
|
* All rights reserved.
|
|
5
6
|
* Licensed under the BSD 3-Clause license.
|
|
6
7
|
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
|
|
7
8
|
*/
|
|
8
|
-
|
|
9
|
+
const fs = require("fs");
|
|
10
|
+
const path = require("path");
|
|
9
11
|
const command_1 = require("@salesforce/command");
|
|
10
12
|
const core_1 = require("@salesforce/core");
|
|
11
13
|
const csv = require("../../../../../csvtojson");
|
|
12
14
|
const createUtil_1 = require("../../../../lib/helpers/createUtil");
|
|
13
|
-
const fileWriter_1 = require("../../../../lib/helpers/fileWriter");
|
|
14
15
|
core_1.Messages.importMessagesDirectory(__dirname);
|
|
15
16
|
const messages = core_1.Messages.loadMessages('@salesforce/plugin-custom-metadata', 'insertRecord');
|
|
16
17
|
class Insert extends command_1.SfdxCommand {
|
|
18
|
+
// eslint-disable-next-line @typescript-eslint/member-ordering
|
|
17
19
|
async run() {
|
|
18
20
|
const createUtil = new createUtil_1.CreateUtil();
|
|
19
|
-
const fileWriter = new fileWriter_1.FileWriter();
|
|
20
21
|
const filepath = this.flags.filepath;
|
|
21
22
|
let typename = this.flags.typename;
|
|
22
|
-
const inputdir = this.flags.inputdir
|
|
23
|
-
const outputdir = this.flags.outputdir
|
|
23
|
+
const inputdir = this.flags.inputdir;
|
|
24
|
+
const outputdir = this.flags.outputdir;
|
|
24
25
|
const dirName = createUtil.appendDirectorySuffix(typename);
|
|
25
|
-
const fieldDirPath =
|
|
26
|
-
const fileNames = await
|
|
27
|
-
const nameField = this.flags.namecolumn
|
|
26
|
+
const fieldDirPath = path.join(inputdir, dirName, 'fields');
|
|
27
|
+
const fileNames = await fs.promises.readdir(fieldDirPath);
|
|
28
|
+
const nameField = this.flags.namecolumn;
|
|
28
29
|
// forgive them if they passed in type__mdt, and cut off the __mdt
|
|
29
30
|
if (typename.endsWith('__mdt')) {
|
|
30
31
|
typename = typename.substring(0, typename.indexOf('__mdt'));
|
|
31
32
|
}
|
|
32
33
|
// if customMetadata folder does not exist, create it
|
|
33
|
-
await
|
|
34
|
+
await fs.promises.mkdir(outputdir, { recursive: true });
|
|
34
35
|
const fileData = await createUtil.getFileData(fieldDirPath, fileNames);
|
|
35
|
-
const csvDataAry = await csv().fromFile(filepath);
|
|
36
|
-
let recordConfig;
|
|
37
|
-
const ret = [];
|
|
36
|
+
const csvDataAry = (await csv().fromFile(filepath));
|
|
38
37
|
const metadataTypeFields = createUtil.getFieldNames(fileData, nameField);
|
|
39
38
|
if (csvDataAry.length > 0) {
|
|
40
39
|
const record = csvDataAry[0];
|
|
41
40
|
for (const key in record) {
|
|
42
41
|
if (!metadataTypeFields.includes(key)) {
|
|
43
|
-
throw new core_1.
|
|
42
|
+
throw new core_1.SfError(messages.getMessage('fieldNotFoundError', [key, typename]));
|
|
44
43
|
}
|
|
45
44
|
}
|
|
46
45
|
}
|
|
47
46
|
// find the cmdt in the inputdir.
|
|
48
47
|
// loop through files and create records that match fields
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
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(
|
|
52
57
|
// TODO: throw an error if any of the fields in the csvDataAry do not exist in the fileData
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
if (record.hasOwnProperty(fullName)) {
|
|
58
|
-
varargs[fullName] = record[fullName];
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
recordConfig = {
|
|
62
|
-
typename,
|
|
63
|
-
recordname,
|
|
64
|
-
label: record[nameField],
|
|
65
|
-
inputdir,
|
|
66
|
-
outputdir,
|
|
67
|
-
protected: false,
|
|
68
|
-
varargs,
|
|
69
|
-
fileData,
|
|
70
|
-
};
|
|
71
|
-
ret.push(recordConfig);
|
|
72
|
-
await createUtil.createRecord(recordConfig);
|
|
73
|
-
}
|
|
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)));
|
|
74
62
|
this.ux.log(messages.getMessage('successResponse', [filepath, outputdir]));
|
|
75
|
-
return
|
|
63
|
+
return recordConfigs;
|
|
76
64
|
}
|
|
77
65
|
}
|
|
78
66
|
exports.default = Insert;
|
|
@@ -103,13 +91,13 @@ Insert.flagsConfig = {
|
|
|
103
91
|
char: 'i',
|
|
104
92
|
description: messages.getMessage('inputDirectoryFlagDescription'),
|
|
105
93
|
longDescription: messages.getMessage('inputDirectoryFlagLongDescription'),
|
|
106
|
-
default: 'force-app
|
|
94
|
+
default: path.join('force-app', 'main', 'default', 'objects'),
|
|
107
95
|
}),
|
|
108
96
|
outputdir: command_1.flags.directory({
|
|
109
97
|
char: 'd',
|
|
110
98
|
description: messages.getMessage('outputDirectoryFlagDescription'),
|
|
111
99
|
longDescription: messages.getMessage('outputDirectoryFlagLongDescription'),
|
|
112
|
-
default: 'force-app
|
|
100
|
+
default: path.join('force-app', 'main', 'default', 'customMetadata'),
|
|
113
101
|
}),
|
|
114
102
|
namecolumn: command_1.flags.string({
|
|
115
103
|
char: 'n',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"insert.js","sourceRoot":"","sources":["../../../../../src/commands/force/cmdt/record/insert.ts"],"names":[],"mappings":"
|
|
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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AC;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,12 +1,10 @@
|
|
|
1
|
+
import { CustomField } from 'jsforce/api/metadata';
|
|
1
2
|
import { CreateConfig } from '../interfaces/createConfig';
|
|
2
|
-
import { CustomField } from '../interfaces/customField';
|
|
3
3
|
export declare class CreateUtil {
|
|
4
|
-
private fieldTypeMap;
|
|
5
4
|
/**
|
|
6
5
|
* Number and Percent types will be int or double depending on their respective scale values.
|
|
7
6
|
* If the scale === 0, it is an int, otherwise it is a double
|
|
8
7
|
*/
|
|
9
|
-
constructor();
|
|
10
8
|
/**
|
|
11
9
|
* Creates the Custom Metadata Record
|
|
12
10
|
*
|
|
@@ -14,7 +12,13 @@ export declare class CreateUtil {
|
|
|
14
12
|
* @return void
|
|
15
13
|
*/
|
|
16
14
|
createRecord(createConfig: CreateConfig): Promise<void>;
|
|
17
|
-
|
|
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[]>;
|
|
18
22
|
/**
|
|
19
23
|
* Filenames should have the suffix of '__mdt'. This will append that suffix if it does not exist.
|
|
20
24
|
*
|
|
@@ -36,7 +40,7 @@ export declare class CreateUtil {
|
|
|
36
40
|
* @param fieldName Name of the field
|
|
37
41
|
* @return {string} Data Type of the field.
|
|
38
42
|
*/
|
|
39
|
-
getFieldDataType(fileData?: CustomField[], fieldName?: string):
|
|
43
|
+
getFieldDataType(fileData?: CustomField[], fieldName?: string): CustomField['type'];
|
|
40
44
|
/**
|
|
41
45
|
* Goes through the file data that has been genreated and gets all of the field names and adds the
|
|
42
46
|
* name of the field that is used as the label for metadata record
|
|
@@ -45,7 +49,7 @@ export declare class CreateUtil {
|
|
|
45
49
|
* @param nameField name of the column that is going to be used for the name of the metadata record
|
|
46
50
|
* @return [] Array of field names
|
|
47
51
|
*/
|
|
48
|
-
getFieldNames(fileData:
|
|
52
|
+
getFieldNames(fileData: CustomField[], nameField: string): string[];
|
|
49
53
|
/**
|
|
50
54
|
* Takes JSON representation of CLI varargs and converts them to xml with help
|
|
51
55
|
* from helper.getFieldTemplate
|
|
@@ -1,35 +1,34 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CreateUtil = void 0;
|
|
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
|
-
|
|
9
|
-
|
|
10
|
-
const
|
|
11
|
-
const xml2js_1 = require("xml2js");
|
|
10
|
+
const fs = require("fs");
|
|
11
|
+
const path = require("path");
|
|
12
|
+
const fast_xml_parser_1 = require("fast-xml-parser");
|
|
12
13
|
const templates_1 = require("../templates/templates");
|
|
14
|
+
const fieldTypeMap = {
|
|
15
|
+
Checkbox: 'boolean',
|
|
16
|
+
Date: 'date',
|
|
17
|
+
DateTime: 'dateTime',
|
|
18
|
+
Email: 'string',
|
|
19
|
+
Phone: 'string',
|
|
20
|
+
Picklist: 'string',
|
|
21
|
+
Text: 'string',
|
|
22
|
+
TextArea: 'string',
|
|
23
|
+
LongTextArea: 'string',
|
|
24
|
+
Url: 'string',
|
|
25
|
+
};
|
|
13
26
|
// NOTE: the template string indentation is important to output well-formatted XML. Altering that whitespace will change the whitespace of the output.
|
|
14
27
|
class CreateUtil {
|
|
15
28
|
/**
|
|
16
29
|
* Number and Percent types will be int or double depending on their respective scale values.
|
|
17
30
|
* If the scale === 0, it is an int, otherwise it is a double
|
|
18
31
|
*/
|
|
19
|
-
constructor() {
|
|
20
|
-
this.fieldTypeMap = {
|
|
21
|
-
Checkbox: 'boolean',
|
|
22
|
-
Date: 'date',
|
|
23
|
-
DateTime: 'dateTime',
|
|
24
|
-
Email: 'string',
|
|
25
|
-
Phone: 'string',
|
|
26
|
-
Picklist: 'string',
|
|
27
|
-
Text: 'string',
|
|
28
|
-
TextArea: 'string',
|
|
29
|
-
LongTextArea: 'string',
|
|
30
|
-
Url: 'string',
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
32
|
/**
|
|
34
33
|
* Creates the Custom Metadata Record
|
|
35
34
|
*
|
|
@@ -37,24 +36,24 @@ class CreateUtil {
|
|
|
37
36
|
* @return void
|
|
38
37
|
*/
|
|
39
38
|
async createRecord(createConfig) {
|
|
40
|
-
const outputFilePath =
|
|
39
|
+
const outputFilePath = path.join(createConfig.outputdir, `${createConfig.typename}.${createConfig.recordname}.md-meta.xml`);
|
|
41
40
|
const newRecordContent = this.getRecordTemplate(createConfig.label, createConfig.protected, this.buildCustomFieldXml(createConfig.fileData, createConfig.varargs, createConfig.ignorefields));
|
|
42
|
-
return
|
|
41
|
+
return fs.promises.writeFile(outputFilePath, newRecordContent);
|
|
43
42
|
}
|
|
43
|
+
/**
|
|
44
|
+
*
|
|
45
|
+
* @param fieldDirPath path to a /fields folder that contains all the fields to read
|
|
46
|
+
* @param fileNames filenames in that folder that should be read
|
|
47
|
+
* @returns CustomField[]
|
|
48
|
+
*/
|
|
44
49
|
async getFileData(fieldDirPath, fileNames) {
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
str = fileData.toString('utf8');
|
|
53
|
-
(0, xml2js_1.parseString)(str, (err, res) => {
|
|
54
|
-
ret.push(res);
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
return ret;
|
|
50
|
+
const parser = new fast_xml_parser_1.XMLParser();
|
|
51
|
+
return Promise.all(fileNames
|
|
52
|
+
.map((file) => path.join(fieldDirPath, file))
|
|
53
|
+
.map(async (filePath) => {
|
|
54
|
+
const fileData = await fs.promises.readFile(filePath, 'utf8');
|
|
55
|
+
return parser.parse(fileData).CustomField;
|
|
56
|
+
}));
|
|
58
57
|
}
|
|
59
58
|
/**
|
|
60
59
|
* Filenames should have the suffix of '__mdt'. This will append that suffix if it does not exist.
|
|
@@ -62,12 +61,7 @@ class CreateUtil {
|
|
|
62
61
|
* @param typename Name of file
|
|
63
62
|
*/
|
|
64
63
|
appendDirectorySuffix(typename) {
|
|
65
|
-
|
|
66
|
-
return typename;
|
|
67
|
-
}
|
|
68
|
-
else {
|
|
69
|
-
return typename + '__mdt';
|
|
70
|
-
}
|
|
64
|
+
return typename.endsWith('__mdt') ? typename : `${typename}__mdt`;
|
|
71
65
|
}
|
|
72
66
|
/**
|
|
73
67
|
* Get the field primitive type from the custom metadata type that has a matching field name.
|
|
@@ -76,24 +70,12 @@ class CreateUtil {
|
|
|
76
70
|
* @param fieldName Name of the field
|
|
77
71
|
* @return {string} Type used by a custom metadata record
|
|
78
72
|
*/
|
|
79
|
-
getFieldPrimitiveType(fileData = [], fieldName
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
type = file.CustomField.type[0];
|
|
86
|
-
if (type === 'Number' || type === 'Percent') {
|
|
87
|
-
ret = this.getNumberType(type, file.CustomField.scale[0]);
|
|
88
|
-
}
|
|
89
|
-
else {
|
|
90
|
-
ret = this.fieldTypeMap[type];
|
|
91
|
-
}
|
|
92
|
-
if (thisFieldName === fieldName) {
|
|
93
|
-
return ret;
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
return ret;
|
|
73
|
+
getFieldPrimitiveType(fileData = [], fieldName) {
|
|
74
|
+
var _a;
|
|
75
|
+
const matchingFile = fileData.find((file) => file.fullName === fieldName);
|
|
76
|
+
return matchingFile && ['Number', 'Percent'].includes(matchingFile.type)
|
|
77
|
+
? this.getNumberType(matchingFile.type, matchingFile.scale)
|
|
78
|
+
: (_a = fieldTypeMap[matchingFile === null || matchingFile === void 0 ? void 0 : matchingFile.type]) !== null && _a !== void 0 ? _a : 'string';
|
|
97
79
|
}
|
|
98
80
|
/**
|
|
99
81
|
* Get the field type from the custom metadata type that has a matching field name.
|
|
@@ -103,15 +85,8 @@ class CreateUtil {
|
|
|
103
85
|
* @return {string} Data Type of the field.
|
|
104
86
|
*/
|
|
105
87
|
getFieldDataType(fileData = [], fieldName = '') {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
for (const file of fileData) {
|
|
109
|
-
thisFieldName = file.CustomField.fullName[0];
|
|
110
|
-
type = file.CustomField.type[0];
|
|
111
|
-
if (thisFieldName === fieldName) {
|
|
112
|
-
return type;
|
|
113
|
-
}
|
|
114
|
-
}
|
|
88
|
+
var _a;
|
|
89
|
+
return (_a = fileData.find((file) => file.fullName === fieldName)) === null || _a === void 0 ? void 0 : _a.type;
|
|
115
90
|
}
|
|
116
91
|
/**
|
|
117
92
|
* Goes through the file data that has been genreated and gets all of the field names and adds the
|
|
@@ -122,13 +97,7 @@ class CreateUtil {
|
|
|
122
97
|
* @return [] Array of field names
|
|
123
98
|
*/
|
|
124
99
|
getFieldNames(fileData, nameField) {
|
|
125
|
-
|
|
126
|
-
for (const file of fileData) {
|
|
127
|
-
const fullName = file.CustomField.fullName[0];
|
|
128
|
-
metadataTypeFields.push(fullName);
|
|
129
|
-
}
|
|
130
|
-
metadataTypeFields.push(nameField);
|
|
131
|
-
return metadataTypeFields;
|
|
100
|
+
return [...fileData.map((file) => file.fullName), nameField];
|
|
132
101
|
}
|
|
133
102
|
/**
|
|
134
103
|
* Takes JSON representation of CLI varargs and converts them to xml with help
|
|
@@ -140,21 +109,14 @@ class CreateUtil {
|
|
|
140
109
|
*/
|
|
141
110
|
buildCustomFieldXml(fileData, cliParams, ignoreFields) {
|
|
142
111
|
let ret = '';
|
|
143
|
-
let type = '';
|
|
144
|
-
let dataType = '';
|
|
145
112
|
const templates = new templates_1.Templates();
|
|
146
113
|
for (const fieldName of Object.keys(cliParams)) {
|
|
147
|
-
type = this.getFieldPrimitiveType(fileData, fieldName);
|
|
148
|
-
dataType = this.getFieldDataType(fileData, fieldName);
|
|
114
|
+
const type = this.getFieldPrimitiveType(fileData, fieldName);
|
|
115
|
+
const dataType = this.getFieldDataType(fileData, fieldName);
|
|
149
116
|
// Added functionality to handle the igonre fields scenario.
|
|
150
|
-
if (templates.canConvert(dataType)) {
|
|
117
|
+
if (templates.canConvert(dataType) || !ignoreFields) {
|
|
151
118
|
ret += this.getFieldTemplate(fieldName, cliParams[fieldName], type);
|
|
152
119
|
}
|
|
153
|
-
else {
|
|
154
|
-
if (!ignoreFields) {
|
|
155
|
-
ret += this.getFieldTemplate(fieldName, cliParams[fieldName], type);
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
120
|
}
|
|
159
121
|
return ret;
|
|
160
122
|
}
|
|
@@ -167,11 +129,7 @@ class CreateUtil {
|
|
|
167
129
|
* @return {string} int or double
|
|
168
130
|
*/
|
|
169
131
|
getNumberType(type, scale) {
|
|
170
|
-
|
|
171
|
-
(type === 'Percent' && parseFloat(scale) === 0)) {
|
|
172
|
-
return 'int';
|
|
173
|
-
}
|
|
174
|
-
return 'double';
|
|
132
|
+
return ['Number', 'Percent'].includes(type) && scale === 0 ? 'int' : 'double';
|
|
175
133
|
}
|
|
176
134
|
/**
|
|
177
135
|
* Template for a single customMetadata record value. This is used by helper.getRecordTemplate.
|
|
@@ -182,18 +140,8 @@ class CreateUtil {
|
|
|
182
140
|
* @return {string} String representation of XML
|
|
183
141
|
*/
|
|
184
142
|
getFieldTemplate(fieldName, val, type) {
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
const cleanValue = String(val)
|
|
188
|
-
.replace(/&/g, '&')
|
|
189
|
-
.replace(/</g, '<')
|
|
190
|
-
.replace(/>/g, '>');
|
|
191
|
-
if (val === null || val === '') {
|
|
192
|
-
value = '<value xsi:nil="true"/>';
|
|
193
|
-
}
|
|
194
|
-
else {
|
|
195
|
-
value = `<value xsi:type="xsd:${type}">${cleanValue}</value>`;
|
|
196
|
-
}
|
|
143
|
+
const cleanValue = String(val).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
|
|
144
|
+
const value = val === null || val === '' ? '<value xsi:nil="true"/>' : `<value xsi:type="xsd:${type}">${cleanValue}</value>`;
|
|
197
145
|
return `
|
|
198
146
|
<values>
|
|
199
147
|
<field>${fieldName}</field>
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createUtil.js","sourceRoot":"","sources":["../../../src/lib/helpers/createUtil.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"createUtil.js","sourceRoot":"","sources":["../../../src/lib/helpers/createUtil.ts"],"names":[],"mappings":";;;AAAA;;;;;GAKG;AACH,yBAAyB;AACzB,6BAA6B;AAE7B,qDAA4C;AAE5C,sDAAmD;AAMnD,MAAM,YAAY,GAAG;IACnB,QAAQ,EAAE,SAAS;IACnB,IAAI,EAAE,MAAM;IACZ,QAAQ,EAAE,UAAU;IACpB,KAAK,EAAE,QAAQ;IACf,KAAK,EAAE,QAAQ;IACf,QAAQ,EAAE,QAAQ;IAClB,IAAI,EAAE,QAAQ;IACd,QAAQ,EAAE,QAAQ;IAClB,YAAY,EAAE,QAAQ;IACtB,GAAG,EAAE,QAAQ;CACd,CAAC;AACF,sJAAsJ;AACtJ,MAAa,UAAU;IACrB;;;OAGG;IAEH;;;;;OAKG;IACI,KAAK,CAAC,YAAY,CAAC,YAA0B;QAClD,MAAM,cAAc,GAAG,IAAI,CAAC,IAAI,CAC9B,YAAY,CAAC,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