@salesforce/plugin-custom-metadata 1.0.12 → 1.1.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.
- package/CHANGELOG.md +7 -0
- package/README.md +37 -37
- package/lib/commands/force/cmdt/create.d.ts +4 -4
- package/lib/commands/force/cmdt/create.js +84 -80
- package/lib/commands/force/cmdt/create.js.map +1 -1
- package/lib/commands/force/cmdt/field/create.d.ts +3 -3
- package/lib/commands/force/cmdt/field/create.js +102 -89
- package/lib/commands/force/cmdt/field/create.js.map +1 -1
- package/lib/commands/force/cmdt/generate.d.ts +6 -6
- package/lib/commands/force/cmdt/generate.js +256 -243
- package/lib/commands/force/cmdt/generate.js.map +1 -1
- package/lib/commands/force/cmdt/record/create.d.ts +6 -6
- package/lib/commands/force/cmdt/record/create.js +130 -124
- package/lib/commands/force/cmdt/record/create.js.map +1 -1
- package/lib/commands/force/cmdt/record/insert.d.ts +5 -5
- package/lib/commands/force/cmdt/record/insert.js +105 -105
- package/lib/commands/force/cmdt/record/insert.js.map +1 -1
- package/lib/index.js +3 -3
- package/lib/lib/helpers/createUtil.js +14 -10
- package/lib/lib/helpers/createUtil.js.map +1 -1
- package/lib/lib/helpers/fileWriter.d.ts +2 -0
- package/lib/lib/helpers/fileWriter.js +5 -3
- package/lib/lib/helpers/fileWriter.js.map +1 -1
- package/lib/lib/helpers/metadataUtil.d.ts +2 -2
- package/lib/lib/helpers/metadataUtil.js +22 -15
- package/lib/lib/helpers/metadataUtil.js.map +1 -1
- package/lib/lib/helpers/validationUtil.js +9 -6
- package/lib/lib/helpers/validationUtil.js.map +1 -1
- package/lib/lib/interfaces/createConfig.js +3 -3
- package/lib/lib/interfaces/customField.js +3 -3
- package/lib/lib/interfaces/errorMessage.js +3 -3
- package/lib/lib/interfaces/record.js +3 -3
- package/lib/lib/interfaces/saveResults.js +3 -3
- package/lib/lib/templates/templates.d.ts +2 -0
- package/lib/lib/templates/templates.js +64 -23
- package/lib/lib/templates/templates.js.map +1 -1
- package/oclif.manifest.json +1 -1
- package/package.json +19 -19
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create.js","sourceRoot":"","sources":["../../../../../src/commands/force/cmdt/field/create.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AAEH,
|
|
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,IAAI,+BAAc,EAAE,CAAC;QACvC,IAAI,CAAC,SAAS,CAAC,eAAe,CAAC,SAAS,CAAC,EAAE;YACzC,MAAM,IAAI,gBAAS,CACjB,QAAQ,CA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Q,CAAC,UAAU,CAAC,8BAA8B,CAAC;QAChE,eAAe,EAAE,QAAQ,CAAC,UAAU,CAAC,kCAAkC,CAAC;QACxE,OAAO,EAAE,CAAC;KACX,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,CAClC,oCAAoC,CACrC;KACF,CAAC;CACH,CAAC;AAEF,uGAAuG;AACtF,sBAAe,GAAG,IAAI,CAAC"}
|
|
@@ -8,14 +8,14 @@ export default class Generate extends SfdxCommand {
|
|
|
8
8
|
name: string;
|
|
9
9
|
}[];
|
|
10
10
|
protected static flagsConfig: {
|
|
11
|
-
devname: flags.Discriminated<flags.
|
|
12
|
-
label: flags.Discriminated<flags.
|
|
13
|
-
plurallabel: flags.Discriminated<flags.
|
|
11
|
+
devname: flags.Discriminated<flags.String>;
|
|
12
|
+
label: flags.Discriminated<flags.String>;
|
|
13
|
+
plurallabel: flags.Discriminated<flags.String>;
|
|
14
14
|
visibility: flags.Discriminated<flags.Enum<string>>;
|
|
15
|
-
sobjectname: flags.Discriminated<flags.
|
|
15
|
+
sobjectname: flags.Discriminated<flags.String>;
|
|
16
16
|
ignoreunsupported: flags.Discriminated<flags.Boolean<boolean>>;
|
|
17
|
-
typeoutputdir: flags.Discriminated<flags.
|
|
18
|
-
recordsoutputdir: flags.Discriminated<flags.
|
|
17
|
+
typeoutputdir: flags.Discriminated<flags.String>;
|
|
18
|
+
recordsoutputdir: flags.Discriminated<flags.String>;
|
|
19
19
|
};
|
|
20
20
|
protected static requiresUsername: boolean;
|
|
21
21
|
protected static requiresProject: boolean;
|
|
@@ -1,279 +1,292 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/*
|
|
3
|
-
* Copyright (c)
|
|
3
|
+
* Copyright (c) 2020, salesforce.com, inc.
|
|
4
4
|
* All rights reserved.
|
|
5
|
-
*
|
|
6
|
-
* For full license text, see
|
|
5
|
+
* Licensed under the BSD 3-Clause license.
|
|
6
|
+
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
const command_1 = require("@salesforce/command");
|
|
10
10
|
const core_1 = require("@salesforce/core");
|
|
11
11
|
const kit_1 = require("@salesforce/kit");
|
|
12
12
|
const ts_types_1 = require("@salesforce/ts-types");
|
|
13
|
-
const util_1 = require("util");
|
|
14
13
|
const createUtil_1 = require("../../../lib/helpers/createUtil");
|
|
15
14
|
const fileWriter_1 = require("../../../lib/helpers/fileWriter");
|
|
16
15
|
const metadataUtil_1 = require("../../../lib/helpers/metadataUtil");
|
|
17
16
|
const validationUtil_1 = require("../../../lib/helpers/validationUtil");
|
|
18
17
|
const templates_1 = require("../../../lib/templates/templates");
|
|
19
18
|
// Initialize Messages with the current plugin directory
|
|
20
|
-
|
|
19
|
+
core_1.Messages.importMessagesDirectory(__dirname);
|
|
21
20
|
// Load the specific messages for this file. Messages from @salesforce/command, @salesforce/core,
|
|
22
21
|
// or any library that is using the messages framework can also be loaded this way.
|
|
23
|
-
const messages =
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
if (
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
throw core_1.SfdxError.create('@salesforce/plugin-custom-metadata', 'generate', 'sourceusernameError', [sourceuser]);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
else {
|
|
47
|
-
username = sourceuser;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
if (!util_1.isNullOrUndefined(username)) {
|
|
51
|
-
try {
|
|
52
|
-
// connect to source org if source user name provided
|
|
53
|
-
sourceOrgConn = await command_1.core.Connection.create({
|
|
54
|
-
authInfo: await command_1.core.AuthInfo.create({ username })
|
|
55
|
-
});
|
|
22
|
+
const messages = core_1.Messages.loadMessages('@salesforce/plugin-custom-metadata', 'generate');
|
|
23
|
+
class Generate extends command_1.SfdxCommand {
|
|
24
|
+
async run() {
|
|
25
|
+
// this.org is guaranteed because requiresUsername=true, as opposed to supportsUsername
|
|
26
|
+
const conn = this.org.getConnection();
|
|
27
|
+
// to validate different flags provided by the user
|
|
28
|
+
const validator = new validationUtil_1.ValidationUtil();
|
|
29
|
+
const objname = this.flags.sobjectname;
|
|
30
|
+
const cmdttype = this.flags.devname;
|
|
31
|
+
const sourceuser = this.flags.targetusername;
|
|
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]);
|
|
56
42
|
}
|
|
57
|
-
catch (err) {
|
|
58
|
-
const errMsg = messages.getMessage('sourceuserAuthenticationError', [sourceuser, err.message]);
|
|
59
|
-
throw new core_1.SfdxError(errMsg, 'sourceuserAuthenticationError');
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
if (!validator.validateAPIName(objname)) {
|
|
63
|
-
throw core_1.SfdxError.create('@salesforce/plugin-custom-metadata', 'generate', 'sobjectnameFlagError', [objname]);
|
|
64
|
-
}
|
|
65
|
-
let devName;
|
|
66
|
-
if (!validator.validateMetadataTypeName(cmdttype)) {
|
|
67
|
-
throw core_1.SfdxError.create('@salesforce/plugin-custom-metadata', 'generate', 'typenameFlagError', [cmdttype]);
|
|
68
|
-
}
|
|
69
|
-
if (cmdttype.endsWith('__mdt') || cmdttype.endsWith('__MDT')) {
|
|
70
|
-
devName = cmdttype.substring(0, cmdttype.indexOf('__mdt'));
|
|
71
43
|
}
|
|
72
44
|
else {
|
|
73
|
-
|
|
45
|
+
username = sourceuser;
|
|
74
46
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
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
|
+
});
|
|
79
54
|
}
|
|
80
|
-
|
|
81
|
-
|
|
55
|
+
catch (err) {
|
|
56
|
+
const errMsg = messages.getMessage('sourceuserAuthenticationError', [
|
|
57
|
+
sourceuser,
|
|
58
|
+
err.message,
|
|
59
|
+
]);
|
|
60
|
+
throw new core_1.SfdxError(errMsg, 'sourceuserAuthenticationError');
|
|
82
61
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
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
|
+
// use default target org connection to get object describe if no source is provided.
|
|
85
|
+
describeObj = await metadataUtil.describeObj(objname);
|
|
86
|
+
// throw error if the object doesnot exist(empty json as response from the describe call.)
|
|
87
|
+
if ((0, kit_1.isEmpty)(describeObj)) {
|
|
88
|
+
const errMsg = messages.getMessage('sobjectnameNoResultError', [objname]);
|
|
89
|
+
throw new core_1.SfdxError(errMsg, 'sobjectnameNoResultError');
|
|
90
|
+
}
|
|
91
|
+
// check for custom setting
|
|
92
|
+
if (describeObj['customSettingsType'] !== undefined) {
|
|
93
|
+
// if custom setting check for type and visbility
|
|
94
|
+
if (!metadataUtil.validCustomSettingType(describeObj)) {
|
|
95
|
+
const errMsg = messages.getMessage('customSettingTypeError', [objname]);
|
|
96
|
+
throw new core_1.SfdxError(errMsg, 'customSettingTypeError');
|
|
89
97
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
98
|
+
}
|
|
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';
|
|
104
|
+
try {
|
|
105
|
+
this.ux.startSpinner('custom metadata generation in progress');
|
|
106
|
+
// create custom metadata type
|
|
107
|
+
const templates = new templates_1.Templates();
|
|
108
|
+
const objectXML = templates.createObjectXML({ label, pluralLabel }, visibility);
|
|
109
|
+
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');
|
|
97
122
|
}
|
|
98
|
-
|
|
99
|
-
const
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
123
|
+
// 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);
|
|
118
147
|
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
type: 'Text',
|
|
130
|
-
length: '40'
|
|
131
|
-
};
|
|
132
|
-
fields.push(lat);
|
|
133
|
-
const long = {
|
|
134
|
-
fullName: 'Long_' + field['fullName'],
|
|
135
|
-
label: 'Long_' + field['label'],
|
|
136
|
-
required: field['required'],
|
|
137
|
-
trackHistory: field['trackHistory'],
|
|
138
|
-
trackTrending: field['trackTrending'],
|
|
139
|
-
type: 'Text',
|
|
140
|
-
length: '40'
|
|
141
|
-
};
|
|
142
|
-
fields.push(long);
|
|
143
|
-
}
|
|
144
|
-
});
|
|
145
|
-
// create custom metdata fields
|
|
146
|
-
for (const field of fields) {
|
|
147
|
-
// 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.
|
|
148
|
-
if ((templates.canConvert(field['type']) || !ignoreFields) && field['type'] !== 'Location') {
|
|
149
|
-
const recordname = field['fullName'];
|
|
150
|
-
const fieldXML = templates.createFieldXML(field, !ignoreFields);
|
|
151
|
-
const targetDir = `${outputDir}${devName}__mdt`;
|
|
152
|
-
await fileWriter.writeFieldFile(command_1.core.fs, targetDir, recordname, fieldXML);
|
|
153
|
-
}
|
|
148
|
+
});
|
|
149
|
+
// 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);
|
|
154
158
|
}
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
await createUtil.createRecord({
|
|
171
|
-
typename,
|
|
172
|
-
recordname: recordName,
|
|
173
|
-
label: lblName,
|
|
174
|
-
inputdir: outputDir,
|
|
175
|
-
outputdir: recordsOutputDir,
|
|
176
|
-
protected: security,
|
|
177
|
-
varargs: record,
|
|
178
|
-
fileData,
|
|
179
|
-
ignorefields: ignoreFields
|
|
180
|
-
});
|
|
159
|
+
}
|
|
160
|
+
const createUtil = new createUtil_1.CreateUtil();
|
|
161
|
+
// 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);
|
|
167
|
+
const fileData = await createUtil.getFileData(fieldDirPath, fileNames);
|
|
168
|
+
for (const rec of sObjectRecords.records) {
|
|
169
|
+
const record = metadataUtil.cleanQueryResponse(rec, describeObj);
|
|
170
|
+
const lblName = rec['Name'];
|
|
171
|
+
let recordName = rec['Name'];
|
|
172
|
+
if (!validator.validateMetadataRecordName(rec['Name'])) {
|
|
173
|
+
recordName = recordName.replace(/ +/g, '_');
|
|
181
174
|
}
|
|
182
|
-
|
|
183
|
-
|
|
175
|
+
await createUtil.createRecord({
|
|
176
|
+
typename,
|
|
177
|
+
recordname: recordName,
|
|
178
|
+
label: lblName,
|
|
179
|
+
inputdir: outputDir,
|
|
180
|
+
outputdir: recordsOutputDir,
|
|
181
|
+
protected: security,
|
|
182
|
+
varargs: record,
|
|
183
|
+
fileData,
|
|
184
|
+
ignorefields: ignoreFields,
|
|
185
|
+
});
|
|
184
186
|
}
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
187
|
+
this.ux.stopSpinner('custom metadata type and records creation in completed');
|
|
188
|
+
this.ux.log(`Congrats! Created a ${devName} custom metadata type with ${sObjectRecords.records.length} records!`);
|
|
189
|
+
}
|
|
190
|
+
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);
|
|
196
200
|
}
|
|
197
201
|
}
|
|
198
|
-
this.ux.stopSpinner('generate command failed to run');
|
|
199
|
-
const errMsg = messages.getMessage('generateError', [e.message]);
|
|
200
|
-
throw new core_1.SfdxError(errMsg, 'generateError');
|
|
201
202
|
}
|
|
202
|
-
|
|
203
|
+
this.ux.stopSpinner('generate command failed to run');
|
|
204
|
+
const errMsg = messages.getMessage('generateError', [e.message]);
|
|
205
|
+
throw new core_1.SfdxError(errMsg, 'generateError');
|
|
203
206
|
}
|
|
207
|
+
return { outputDir, recordsOutputDir };
|
|
204
208
|
}
|
|
205
|
-
|
|
206
|
-
Generate.longDescription = messages.getMessage('commandLongDescription');
|
|
207
|
-
Generate.examples = [
|
|
208
|
-
messages.getMessage('exampleCaption1'),
|
|
209
|
-
' $ sfdx force:cmdt:generate --devname MyCMDT --sobjectname MySourceObject__c',
|
|
210
|
-
messages.getMessage('exampleCaption2'),
|
|
211
|
-
' $ sfdx force:cmdt:generate --devname MyCMDT --sobjectname MySourceObject__c --ignoreunsupported --targetusername \'' + messages.getMessage('targetusernameFlagExample') + '\'',
|
|
212
|
-
messages.getMessage('exampleCaption3'),
|
|
213
|
-
' $ sfdx force:cmdt:generate --devname MyCMDT --sobjectname SourceCustomObject__c --visibility Protected',
|
|
214
|
-
messages.getMessage('exampleCaption4'),
|
|
215
|
-
' $ sfdx force:cmdt:generate --devname MyCMDT --label "' + messages.getMessage('labelFlagExample') + '" ' +
|
|
216
|
-
'--plurallabel "' + messages.getMessage('plurallabelFlagExample') + '" --sobjectname SourceCustomSetting__c --visibility Protected',
|
|
217
|
-
messages.getMessage('exampleCaption5'),
|
|
218
|
-
' $ sfdx force:cmdt:generate --devname MyCMDT --sobjectname SourceCustomSetting__c --typeoutputdir \'' + messages.getMessage('typeoutputdirFlagExample') + '\'',
|
|
219
|
-
messages.getMessage('exampleCaption6'),
|
|
220
|
-
' $ sfdx force:cmdt:generate --devname MyCMDT --sobjectname SourceCustomSetting__c --recordsoutputdir \'' + messages.getMessage('recordsoutputdirFlagExample') + '\''
|
|
221
|
-
];
|
|
222
|
-
Generate.args = [{ name: 'file' }];
|
|
223
|
-
Generate.flagsConfig = {
|
|
224
|
-
// flag with a value (-n, --name=VALUE)
|
|
225
|
-
devname: command_1.flags.string({
|
|
226
|
-
char: 'n',
|
|
227
|
-
required: true,
|
|
228
|
-
description: messages.getMessage('devnameFlagDescription'),
|
|
229
|
-
longDescription: messages.getMessage('devnameFlagLongDescription')
|
|
230
|
-
}),
|
|
231
|
-
label: command_1.flags.string({
|
|
232
|
-
char: 'l',
|
|
233
|
-
description: messages.getMessage('labelFlagDescription'),
|
|
234
|
-
longDescription: messages.getMessage('labelFlagLongDescription')
|
|
235
|
-
}),
|
|
236
|
-
plurallabel: command_1.flags.string({
|
|
237
|
-
char: 'p',
|
|
238
|
-
description: messages.getMessage('plurallabelFlagDescription'),
|
|
239
|
-
longDescription: messages.getMessage('plurallabelFlagLongDescription')
|
|
240
|
-
}),
|
|
241
|
-
visibility: command_1.flags.enum({
|
|
242
|
-
char: 'v',
|
|
243
|
-
description: messages.getMessage('visibilityFlagDescription'),
|
|
244
|
-
longDescription: messages.getMessage('visibilityFlagLongDescription'),
|
|
245
|
-
options: ['PackageProtected', 'Protected', 'Public'],
|
|
246
|
-
default: 'Public'
|
|
247
|
-
}),
|
|
248
|
-
sobjectname: command_1.flags.string({
|
|
249
|
-
char: 's',
|
|
250
|
-
required: true,
|
|
251
|
-
description: messages.getMessage('sobjectnameFlagDescription'),
|
|
252
|
-
longDescription: messages.getMessage('sobjectnameFlagLongDescription')
|
|
253
|
-
}),
|
|
254
|
-
ignoreunsupported: command_1.flags.boolean({
|
|
255
|
-
char: 'i',
|
|
256
|
-
description: messages.getMessage('ignoreUnsupportedFlagDescription'),
|
|
257
|
-
longDescription: messages.getMessage('ignoreUnsupportedFlagLongDescription')
|
|
258
|
-
}),
|
|
259
|
-
typeoutputdir: command_1.flags.directory({
|
|
260
|
-
char: 'd',
|
|
261
|
-
description: messages.getMessage('typeoutputdirFlagDescription'),
|
|
262
|
-
longDescription: messages.getMessage('typeoutputdirFlagLongDescription'),
|
|
263
|
-
default: 'force-app/main/default/objects/'
|
|
264
|
-
}),
|
|
265
|
-
recordsoutputdir: command_1.flags.directory({
|
|
266
|
-
char: 'r',
|
|
267
|
-
description: messages.getMessage('recordsoutputdirFlagDescription'),
|
|
268
|
-
longDescription: messages.getMessage('recordsoutputdirFlagLongDescription'),
|
|
269
|
-
default: 'force-app/main/default/customMetadata/'
|
|
270
|
-
})
|
|
271
|
-
};
|
|
272
|
-
// Comment this out if your command does not require an org username
|
|
273
|
-
Generate.requiresUsername = true;
|
|
274
|
-
// Set this to true if your command requires a project workspace; 'requiresProject' is false by default
|
|
275
|
-
Generate.requiresProject = true;
|
|
276
|
-
return Generate;
|
|
277
|
-
})();
|
|
209
|
+
}
|
|
278
210
|
exports.default = Generate;
|
|
211
|
+
Generate.description = messages.getMessage('commandDescription');
|
|
212
|
+
Generate.longDescription = messages.getMessage('commandLongDescription');
|
|
213
|
+
Generate.examples = [
|
|
214
|
+
messages.getMessage('exampleCaption1'),
|
|
215
|
+
' $ sfdx force:cmdt:generate --devname MyCMDT --sobjectname MySourceObject__c',
|
|
216
|
+
messages.getMessage('exampleCaption2'),
|
|
217
|
+
" $ sfdx force:cmdt:generate --devname MyCMDT --sobjectname MySourceObject__c --ignoreunsupported --targetusername '" +
|
|
218
|
+
messages.getMessage('targetusernameFlagExample') +
|
|
219
|
+
"'",
|
|
220
|
+
messages.getMessage('exampleCaption3'),
|
|
221
|
+
' $ sfdx force:cmdt:generate --devname MyCMDT --sobjectname SourceCustomObject__c --visibility Protected',
|
|
222
|
+
messages.getMessage('exampleCaption4'),
|
|
223
|
+
' $ sfdx force:cmdt:generate --devname MyCMDT --label "' +
|
|
224
|
+
messages.getMessage('labelFlagExample') +
|
|
225
|
+
'" ' +
|
|
226
|
+
'--plurallabel "' +
|
|
227
|
+
messages.getMessage('plurallabelFlagExample') +
|
|
228
|
+
'" --sobjectname SourceCustomSetting__c --visibility Protected',
|
|
229
|
+
messages.getMessage('exampleCaption5'),
|
|
230
|
+
" $ sfdx force:cmdt:generate --devname MyCMDT --sobjectname SourceCustomSetting__c --typeoutputdir '" +
|
|
231
|
+
messages.getMessage('typeoutputdirFlagExample') +
|
|
232
|
+
"'",
|
|
233
|
+
messages.getMessage('exampleCaption6'),
|
|
234
|
+
" $ sfdx force:cmdt:generate --devname MyCMDT --sobjectname SourceCustomSetting__c --recordsoutputdir '" +
|
|
235
|
+
messages.getMessage('recordsoutputdirFlagExample') +
|
|
236
|
+
"'",
|
|
237
|
+
];
|
|
238
|
+
Generate.args = [{ name: 'file' }];
|
|
239
|
+
Generate.flagsConfig = {
|
|
240
|
+
// flag with a value (-n, --name=VALUE)
|
|
241
|
+
devname: command_1.flags.string({
|
|
242
|
+
char: 'n',
|
|
243
|
+
required: true,
|
|
244
|
+
description: messages.getMessage('devnameFlagDescription'),
|
|
245
|
+
longDescription: messages.getMessage('devnameFlagLongDescription'),
|
|
246
|
+
}),
|
|
247
|
+
label: command_1.flags.string({
|
|
248
|
+
char: 'l',
|
|
249
|
+
description: messages.getMessage('labelFlagDescription'),
|
|
250
|
+
longDescription: messages.getMessage('labelFlagLongDescription'),
|
|
251
|
+
}),
|
|
252
|
+
plurallabel: command_1.flags.string({
|
|
253
|
+
char: 'p',
|
|
254
|
+
description: messages.getMessage('plurallabelFlagDescription'),
|
|
255
|
+
longDescription: messages.getMessage('plurallabelFlagLongDescription'),
|
|
256
|
+
}),
|
|
257
|
+
visibility: command_1.flags.enum({
|
|
258
|
+
char: 'v',
|
|
259
|
+
description: messages.getMessage('visibilityFlagDescription'),
|
|
260
|
+
longDescription: messages.getMessage('visibilityFlagLongDescription'),
|
|
261
|
+
options: ['PackageProtected', 'Protected', 'Public'],
|
|
262
|
+
default: 'Public',
|
|
263
|
+
}),
|
|
264
|
+
sobjectname: command_1.flags.string({
|
|
265
|
+
char: 's',
|
|
266
|
+
required: true,
|
|
267
|
+
description: messages.getMessage('sobjectnameFlagDescription'),
|
|
268
|
+
longDescription: messages.getMessage('sobjectnameFlagLongDescription'),
|
|
269
|
+
}),
|
|
270
|
+
ignoreunsupported: command_1.flags.boolean({
|
|
271
|
+
char: 'i',
|
|
272
|
+
description: messages.getMessage('ignoreUnsupportedFlagDescription'),
|
|
273
|
+
longDescription: messages.getMessage('ignoreUnsupportedFlagLongDescription'),
|
|
274
|
+
}),
|
|
275
|
+
typeoutputdir: command_1.flags.directory({
|
|
276
|
+
char: 'd',
|
|
277
|
+
description: messages.getMessage('typeoutputdirFlagDescription'),
|
|
278
|
+
longDescription: messages.getMessage('typeoutputdirFlagLongDescription'),
|
|
279
|
+
default: 'force-app/main/default/objects/',
|
|
280
|
+
}),
|
|
281
|
+
recordsoutputdir: command_1.flags.directory({
|
|
282
|
+
char: 'r',
|
|
283
|
+
description: messages.getMessage('recordsoutputdirFlagDescription'),
|
|
284
|
+
longDescription: messages.getMessage('recordsoutputdirFlagLongDescription'),
|
|
285
|
+
default: 'force-app/main/default/customMetadata/',
|
|
286
|
+
}),
|
|
287
|
+
};
|
|
288
|
+
// Comment this out if your command does not require an org username
|
|
289
|
+
Generate.requiresUsername = true;
|
|
290
|
+
// Set this to true if your command requires a project workspace; 'requiresProject' is false by default
|
|
291
|
+
Generate.requiresProject = true;
|
|
279
292
|
//# sourceMappingURL=generate.js.map
|