@salesforce/plugin-custom-metadata 1.0.11 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +23 -7
- package/LICENSE.txt +2 -2
- package/README.md +153 -149
- package/lib/commands/force/cmdt/create.d.ts +12 -6
- package/lib/commands/force/cmdt/create.js +80 -82
- package/lib/commands/force/cmdt/create.js.map +1 -1
- package/lib/commands/force/cmdt/field/create.d.ts +10 -5
- package/lib/commands/force/cmdt/field/create.js +98 -90
- package/lib/commands/force/cmdt/field/create.js.map +1 -1
- package/lib/commands/force/cmdt/generate.d.ts +12 -8
- package/lib/commands/force/cmdt/generate.js +199 -257
- package/lib/commands/force/cmdt/generate.js.map +1 -1
- package/lib/commands/force/cmdt/record/create.d.ts +20 -9
- package/lib/commands/force/cmdt/record/create.js +123 -125
- package/lib/commands/force/cmdt/record/create.js.map +1 -1
- package/lib/commands/force/cmdt/record/insert.d.ts +7 -7
- package/lib/commands/force/cmdt/record/insert.js +97 -109
- package/lib/commands/force/cmdt/record/insert.js.map +1 -1
- package/lib/index.js +3 -3
- package/lib/lib/helpers/createUtil.d.ts +10 -6
- package/lib/lib/helpers/createUtil.js +50 -98
- package/lib/lib/helpers/createUtil.js.map +1 -1
- package/lib/lib/helpers/fileWriter.d.ts +13 -11
- package/lib/lib/helpers/fileWriter.js +19 -27
- package/lib/lib/helpers/fileWriter.js.map +1 -1
- package/lib/lib/helpers/metadataUtil.d.ts +25 -51
- package/lib/lib/helpers/metadataUtil.js +58 -127
- package/lib/lib/helpers/metadataUtil.js.map +1 -1
- package/lib/lib/helpers/validationUtil.d.ts +25 -26
- package/lib/lib/helpers/validationUtil.js +69 -43
- package/lib/lib/helpers/validationUtil.js.map +1 -1
- package/lib/lib/interfaces/createConfig.d.ts +3 -2
- package/lib/lib/interfaces/createConfig.js +3 -3
- package/lib/lib/templates/templates.d.ts +10 -99
- package/lib/lib/templates/templates.js +52 -40
- 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 +57 -46
- 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,35 +1,34 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CreateUtil = void 0;
|
|
2
4
|
/*
|
|
3
|
-
* Copyright (c)
|
|
5
|
+
* Copyright (c) 2020, salesforce.com, inc.
|
|
4
6
|
* All rights reserved.
|
|
5
|
-
*
|
|
6
|
-
* For full license text, see
|
|
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
|
|
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
|
-
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,10 +129,7 @@ class CreateUtil {
|
|
|
167
129
|
* @return {string} int or double
|
|
168
130
|
*/
|
|
169
131
|
getNumberType(type, scale) {
|
|
170
|
-
|
|
171
|
-
return 'int';
|
|
172
|
-
}
|
|
173
|
-
return 'double';
|
|
132
|
+
return ['Number', 'Percent'].includes(type) && scale === 0 ? 'int' : 'double';
|
|
174
133
|
}
|
|
175
134
|
/**
|
|
176
135
|
* Template for a single customMetadata record value. This is used by helper.getRecordTemplate.
|
|
@@ -181,15 +140,8 @@ class CreateUtil {
|
|
|
181
140
|
* @return {string} String representation of XML
|
|
182
141
|
*/
|
|
183
142
|
getFieldTemplate(fieldName, val, type) {
|
|
184
|
-
// update to handle the null situation
|
|
185
|
-
let value = '';
|
|
186
143
|
const cleanValue = String(val).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
|
|
187
|
-
|
|
188
|
-
value = '<value xsi:nil="true"/>';
|
|
189
|
-
}
|
|
190
|
-
else {
|
|
191
|
-
value = `<value xsi:type="xsd:${type}">${cleanValue}</value>`;
|
|
192
|
-
}
|
|
144
|
+
const value = val === null || val === '' ? '<value xsi:nil="true"/>' : `<value xsi:type="xsd:${type}">${cleanValue}</value>`;
|
|
193
145
|
return `
|
|
194
146
|
<values>
|
|
195
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,SAAS,EACtB,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EAAE;gBACnD,GAAG,IAAI,IAAI,CAAC,gBAAgB,CAAC,SAAS,EAAE,SAAS,CAAC,SAAS,CAAC,EAAE,IAAI,CAAC,CAAC;aACrE;SACF;QAED,OAAO,GAAG,CAAC;IACb,CAAC;IAED;;;;;;;OAOG;IACK,aAAa,CAAC,IAAY,EAAE,KAAa;QAC/C,OAAO,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,QAAQ,CAAC;IAChF,CAAC;IAED;;;;;;;OAOG;IACK,gBAAgB,CAAC,SAAiB,EAAE,GAAW,EAAE,IAAY;QACnE,MAAM,UAAU,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QAClG,MAAM,KAAK,GACT,GAAG,KAAK,IAAI,IAAI,GAAG,KAAK,EAAE,CAAC,CAAC,CAAC,yBAAyB,CAAC,CAAC,CAAC,wBAAwB,IAAI,KAAK,UAAU,UAAU,CAAC;QAEjH,OAAO;;iBAEM,SAAS;UAChB,KAAK;cACD,CAAC;IACb,CAAC;IAED;;;;;;;OAOG;IACK,iBAAiB,CAAC,KAAa,EAAE,UAAmB,EAAE,MAAc;QAC1E,OAAO;;;aAGE,KAAK;iBACD,UAAU,eAAe,MAAM;kBAC9B,CAAC,IAAI,EAAE,CAAC;IACxB,CAAC;CACF;AArKD,gCAqKC"}
|
|
@@ -1,25 +1,27 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import * as fs from 'fs';
|
|
3
|
+
interface FileWriterResult {
|
|
4
|
+
dir: string;
|
|
5
|
+
fileName: string;
|
|
6
|
+
updated: boolean;
|
|
7
|
+
}
|
|
1
8
|
export declare class FileWriter {
|
|
2
9
|
/**
|
|
3
10
|
* Using the given file system, creates a file representing a new custom metadata type.
|
|
11
|
+
*
|
|
4
12
|
* @param fs
|
|
5
13
|
* @param devname
|
|
6
14
|
* @param objectXML
|
|
7
15
|
*/
|
|
8
|
-
writeTypeFile(corefs:
|
|
9
|
-
dir: string;
|
|
10
|
-
fileName: string;
|
|
11
|
-
updated: boolean;
|
|
12
|
-
}>;
|
|
16
|
+
writeTypeFile(corefs: typeof fs, dir: string, devName: string, objectXML: string): Promise<FileWriterResult>;
|
|
13
17
|
/**
|
|
14
18
|
* Using the given file system, creates a file representing a new field for the given custom metadata type
|
|
19
|
+
*
|
|
15
20
|
* @param fs
|
|
16
21
|
* @param fieldname
|
|
17
22
|
* @param fieldXML
|
|
18
23
|
*/
|
|
19
|
-
writeFieldFile(corefs:
|
|
20
|
-
dir: string;
|
|
21
|
-
fileName: string;
|
|
22
|
-
updated: boolean;
|
|
23
|
-
}>;
|
|
24
|
-
createDir(dir: any): any;
|
|
24
|
+
writeFieldFile(corefs: typeof fs, dir: string, fieldName: string, fieldXML: string): Promise<FileWriterResult>;
|
|
25
25
|
}
|
|
26
|
+
export declare const removeTrailingSlash: (dir: string) => string;
|
|
27
|
+
export {};
|
|
@@ -1,23 +1,24 @@
|
|
|
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
|
-
exports.FileWriter = void 0;
|
|
9
|
+
exports.removeTrailingSlash = exports.FileWriter = void 0;
|
|
10
10
|
const fs = require("fs");
|
|
11
|
+
const path = require("path");
|
|
11
12
|
class FileWriter {
|
|
12
13
|
/**
|
|
13
14
|
* Using the given file system, creates a file representing a new custom metadata type.
|
|
15
|
+
*
|
|
14
16
|
* @param fs
|
|
15
17
|
* @param devname
|
|
16
18
|
* @param objectXML
|
|
17
19
|
*/
|
|
18
|
-
async writeTypeFile(corefs, dir, devName, objectXML) {
|
|
20
|
+
async writeTypeFile(corefs = fs, dir, devName, objectXML) {
|
|
19
21
|
let apiName = devName;
|
|
20
|
-
const dirName = this.createDir(dir);
|
|
21
22
|
// replace __c with __mdt
|
|
22
23
|
if (apiName.endsWith('__c')) {
|
|
23
24
|
apiName = apiName.replace('__c', '__mdt');
|
|
@@ -26,44 +27,35 @@ class FileWriter {
|
|
|
26
27
|
if (!apiName.endsWith('__mdt')) {
|
|
27
28
|
apiName += '__mdt';
|
|
28
29
|
}
|
|
29
|
-
const outputFilePath =
|
|
30
|
+
const outputFilePath = path.join((0, exports.removeTrailingSlash)(dir), apiName);
|
|
30
31
|
const fileName = `${apiName}.object-meta.xml`;
|
|
31
|
-
const updated = fs.existsSync(outputFilePath
|
|
32
|
-
await corefs.
|
|
33
|
-
await corefs.writeFile(outputFilePath
|
|
32
|
+
const updated = fs.existsSync(path.join(outputFilePath, fileName));
|
|
33
|
+
await corefs.promises.mkdir(outputFilePath, { recursive: true });
|
|
34
|
+
await corefs.promises.writeFile(path.join(outputFilePath, fileName), objectXML);
|
|
34
35
|
return { dir: outputFilePath, fileName, updated };
|
|
35
36
|
}
|
|
36
37
|
/**
|
|
37
38
|
* Using the given file system, creates a file representing a new field for the given custom metadata type
|
|
39
|
+
*
|
|
38
40
|
* @param fs
|
|
39
41
|
* @param fieldname
|
|
40
42
|
* @param fieldXML
|
|
41
43
|
*/
|
|
42
44
|
// /fields/{fieldAPI}.field-meta.xml
|
|
43
|
-
async writeFieldFile(corefs, dir, fieldName, fieldXML) {
|
|
44
|
-
const dirName = this.createDir(dir);
|
|
45
|
+
async writeFieldFile(corefs = fs, dir, fieldName, fieldXML) {
|
|
45
46
|
// appending __c if its not already there
|
|
46
47
|
if (fieldName.endsWith('__c') === false) {
|
|
47
48
|
fieldName += '__c';
|
|
48
49
|
}
|
|
49
|
-
const outputFilePath =
|
|
50
|
+
const outputFilePath = path.join((0, exports.removeTrailingSlash)(dir), 'fields');
|
|
50
51
|
const fileName = `${fieldName}.field-meta.xml`;
|
|
51
|
-
const updated = fs.existsSync(outputFilePath
|
|
52
|
-
await corefs.
|
|
53
|
-
await corefs.writeFile(outputFilePath
|
|
52
|
+
const updated = fs.existsSync(path.join(outputFilePath, fileName));
|
|
53
|
+
await corefs.promises.mkdir(outputFilePath, { recursive: true });
|
|
54
|
+
await corefs.promises.writeFile(path.join(outputFilePath, fileName), fieldXML);
|
|
54
55
|
return { dir: outputFilePath, fileName, updated };
|
|
55
56
|
}
|
|
56
|
-
createDir(dir) {
|
|
57
|
-
if (dir) {
|
|
58
|
-
if (dir.endsWith('/')) {
|
|
59
|
-
return dir;
|
|
60
|
-
}
|
|
61
|
-
else {
|
|
62
|
-
return dir + '/';
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
return '';
|
|
66
|
-
}
|
|
67
57
|
}
|
|
68
58
|
exports.FileWriter = FileWriter;
|
|
59
|
+
const removeTrailingSlash = (dir) => dir.replace(/\/+$/, '');
|
|
60
|
+
exports.removeTrailingSlash = removeTrailingSlash;
|
|
69
61
|
//# sourceMappingURL=fileWriter.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fileWriter.js","sourceRoot":"","sources":["../../../src/lib/helpers/fileWriter.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,yBAAyB;
|
|
1
|
+
{"version":3,"file":"fileWriter.js","sourceRoot":"","sources":["../../../src/lib/helpers/fileWriter.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,yBAAyB;AACzB,6BAA6B;AAQ7B,MAAa,UAAU;IACrB;;;;;;OAMG;IACI,KAAK,CAAC,aAAa,CAAC,MAAM,GAAG,EAAE,EA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AE,QAAQ,CAAC,CAAC;QACrE,MAAM,QAAQ,GAAG,GAAG,SAAS,iBAAiB,CAAC;QAC/C,MAAM,OAAO,GAAG,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,QAAQ,CAAC,CAAC,CAAC;QACnE,MAAM,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,cAAc,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QACjE,MAAM,MAAM,CAAC,QAAQ,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,QAAQ,CAAC,EAAE,QAAQ,CAAC,CAAC;QAE/E,OAAO,EAAE,GAAG,EAAE,cAAc,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC;IACpD,CAAC;CACF;AAzDD,gCAyDC;AAEM,MAAM,mBAAmB,GAAG,CAAC,GAAW,EAAU,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;AAAvE,QAAA,mBAAmB,uBAAoD"}
|
|
@@ -1,51 +1,25 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
queryRecords(describeResult: AnyJson): Promise<AnyJson>;
|
|
27
|
-
/**
|
|
28
|
-
* Returns describe object for the field API name from the Object API name you specify
|
|
29
|
-
*
|
|
30
|
-
* @param objDescribe describe object JSON
|
|
31
|
-
* @param fieldName API name of the field to query
|
|
32
|
-
* @returns Promise - Promise - record in JSON format
|
|
33
|
-
*/
|
|
34
|
-
describeField(objDescribe: AnyJson, fieldName: string): AnyJson;
|
|
35
|
-
/**
|
|
36
|
-
* Returns describe object for all fields from the object API name you specify
|
|
37
|
-
*
|
|
38
|
-
* @param objDescribe object describe JSON
|
|
39
|
-
* @returns Promise - Promise - record in JSON format
|
|
40
|
-
*/
|
|
41
|
-
describeObjFields(objDescribe: AnyJson): AnyJson;
|
|
42
|
-
/**
|
|
43
|
-
* Returns true if the object name you specify is a list type custom setting
|
|
44
|
-
*
|
|
45
|
-
* @param objName API name of the object to query
|
|
46
|
-
* @returns boolean
|
|
47
|
-
*/
|
|
48
|
-
validCustomSettingType(objDescribe: AnyJson): boolean;
|
|
49
|
-
cleanQueryResponse(sObjecRecord: AnyJson, objectDescribe: AnyJson): import("@salesforce/ts-types").JsonMap;
|
|
50
|
-
private _getSoqlQuery;
|
|
51
|
-
}
|
|
1
|
+
import { CustomObject, CustomField } from 'jsforce/api/metadata';
|
|
2
|
+
import { Record } from 'jsforce';
|
|
3
|
+
/**
|
|
4
|
+
* Returns describe object for the field API name from the Object API name you specify
|
|
5
|
+
*
|
|
6
|
+
* @param objDescribe describe object JSON
|
|
7
|
+
* @param fieldName API name of the field to query
|
|
8
|
+
* @returns Promise - Promise - record in JSON format
|
|
9
|
+
*/
|
|
10
|
+
export declare const describeField: (objDescribe: CustomObject, fieldName: string) => CustomField;
|
|
11
|
+
/**
|
|
12
|
+
* Returns true if the object name you specify is a list type custom setting
|
|
13
|
+
*
|
|
14
|
+
* @param objName object describe JSON
|
|
15
|
+
* @returns boolean
|
|
16
|
+
*/
|
|
17
|
+
export declare const validCustomSettingType: (objDescribe: CustomObject) => boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Returns describe object for all fields from the object API name you specify
|
|
20
|
+
*
|
|
21
|
+
* @param objDescribe object describe JSON
|
|
22
|
+
* @returns Promise - Promise - record in JSON format
|
|
23
|
+
*/
|
|
24
|
+
export declare const describeObjFields: (objDescribe: CustomObject) => CustomField[];
|
|
25
|
+
export declare const cleanQueryResponse: (sObjectRecord: Record, objectDescribe: CustomObject) => Record;
|