@salesforce/plugin-custom-metadata 2.0.8 → 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.
- package/LICENSE.txt +1 -1
- package/README.md +0 -1
- package/lib/commands/generate/cmdt/field.d.ts +23 -0
- package/lib/commands/generate/cmdt/field.js +100 -0
- package/lib/commands/generate/cmdt/field.js.map +1 -0
- package/lib/commands/generate/cmdt/fromorg.d.ts +26 -0
- package/lib/commands/generate/cmdt/fromorg.js +184 -0
- package/lib/commands/generate/cmdt/fromorg.js.map +1 -0
- package/lib/commands/generate/cmdt/object.d.ts +23 -0
- package/lib/commands/generate/cmdt/object.js +79 -0
- package/lib/commands/generate/cmdt/object.js.map +1 -0
- package/lib/commands/generate/cmdt/record.d.ts +29 -0
- package/lib/commands/generate/cmdt/record.js +111 -0
- package/lib/commands/generate/cmdt/record.js.map +1 -0
- package/lib/commands/generate/cmdt/records.d.ts +18 -0
- package/lib/commands/generate/cmdt/records.js +105 -0
- package/lib/commands/generate/cmdt/records.js.map +1 -0
- package/lib/shared/helpers/createUtil.d.ts +51 -0
- package/lib/shared/helpers/createUtil.js +168 -0
- package/lib/shared/helpers/createUtil.js.map +1 -0
- package/lib/shared/helpers/fileWriter.d.ts +24 -0
- package/lib/shared/helpers/fileWriter.js +59 -0
- package/lib/shared/helpers/fileWriter.js.map +1 -0
- package/lib/{lib → shared}/helpers/metadataUtil.d.ts +1 -1
- package/lib/{lib → shared}/helpers/metadataUtil.js +1 -1
- package/lib/shared/helpers/metadataUtil.js.map +1 -0
- package/lib/{lib → shared}/helpers/validationUtil.d.ts +0 -0
- package/lib/{lib → shared}/helpers/validationUtil.js +0 -0
- package/lib/shared/helpers/validationUtil.js.map +1 -0
- package/lib/{lib → shared}/interfaces/createConfig.d.ts +3 -2
- package/lib/{lib → shared}/interfaces/createConfig.js +0 -0
- package/lib/shared/interfaces/createConfig.js.map +1 -0
- package/lib/shared/templates/templates.d.ts +20 -0
- package/lib/shared/templates/templates.js +208 -0
- package/lib/shared/templates/templates.js.map +1 -0
- package/messages/field.md +79 -0
- package/messages/fromorg.md +87 -0
- package/messages/object.md +73 -0
- package/messages/record.md +53 -0
- package/messages/records.md +49 -0
- package/messages/template.md +3 -0
- package/messages/validation.md +11 -0
- package/oclif.manifest.json +1 -1
- package/package.json +21 -20
- package/lib/commands/force/cmdt/create.d.ts +0 -25
- package/lib/commands/force/cmdt/create.js +0 -94
- package/lib/commands/force/cmdt/create.js.map +0 -1
- package/lib/commands/force/cmdt/field/create.d.ts +0 -25
- package/lib/commands/force/cmdt/field/create.js +0 -113
- package/lib/commands/force/cmdt/field/create.js.map +0 -1
- package/lib/commands/force/cmdt/generate.d.ts +0 -27
- package/lib/commands/force/cmdt/generate.js +0 -219
- package/lib/commands/force/cmdt/generate.js.map +0 -1
- package/lib/commands/force/cmdt/record/create.d.ts +0 -32
- package/lib/commands/force/cmdt/record/create.js +0 -140
- package/lib/commands/force/cmdt/record/create.js.map +0 -1
- package/lib/commands/force/cmdt/record/insert.d.ts +0 -16
- package/lib/commands/force/cmdt/record/insert.js +0 -110
- package/lib/commands/force/cmdt/record/insert.js.map +0 -1
- package/lib/lib/helpers/createUtil.d.ts +0 -62
- package/lib/lib/helpers/createUtil.js +0 -170
- package/lib/lib/helpers/createUtil.js.map +0 -1
- package/lib/lib/helpers/fileWriter.d.ts +0 -27
- package/lib/lib/helpers/fileWriter.js +0 -63
- package/lib/lib/helpers/fileWriter.js.map +0 -1
- package/lib/lib/helpers/metadataUtil.js.map +0 -1
- package/lib/lib/helpers/validationUtil.js.map +0 -1
- package/lib/lib/interfaces/createConfig.js.map +0 -1
- package/lib/lib/templates/templates.d.ts +0 -37
- package/lib/lib/templates/templates.js +0 -221
- package/lib/lib/templates/templates.js.map +0 -1
- package/messages/createField.json +0 -24
- package/messages/createRecord.json +0 -32
- package/messages/createType.json +0 -33
- package/messages/generate.json +0 -40
- package/messages/insertRecord.json +0 -26
- package/messages/template.json +0 -3
- package/messages/validation.json +0 -5
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { SfCommand } from '@salesforce/sf-plugins-core';
|
|
2
|
+
import { CreateConfigs } from '../../../shared/interfaces/createConfig';
|
|
3
|
+
export default class Insert extends SfCommand<CreateConfigs> {
|
|
4
|
+
static readonly summary: string;
|
|
5
|
+
static readonly description: string;
|
|
6
|
+
static readonly requiresProject = true;
|
|
7
|
+
static readonly aliases: string[];
|
|
8
|
+
static readonly examples: string[];
|
|
9
|
+
static readonly flags: {
|
|
10
|
+
loglevel: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined>;
|
|
11
|
+
csv: import("@oclif/core/lib/interfaces").OptionFlag<string>;
|
|
12
|
+
'type-name': import("@oclif/core/lib/interfaces").OptionFlag<string>;
|
|
13
|
+
'input-directory': import("@oclif/core/lib/interfaces").OptionFlag<string>;
|
|
14
|
+
'output-directory': import("@oclif/core/lib/interfaces").OptionFlag<string>;
|
|
15
|
+
'name-column': import("@oclif/core/lib/interfaces").OptionFlag<string>;
|
|
16
|
+
};
|
|
17
|
+
run(): Promise<CreateConfigs>;
|
|
18
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
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 sf_plugins_core_1 = require("@salesforce/sf-plugins-core");
|
|
12
|
+
const core_1 = require("@salesforce/core");
|
|
13
|
+
const csv = require("../../../../csvtojson");
|
|
14
|
+
const createUtil_1 = require("../../../shared/helpers/createUtil");
|
|
15
|
+
core_1.Messages.importMessagesDirectory(__dirname);
|
|
16
|
+
const messages = core_1.Messages.loadMessages('@salesforce/plugin-custom-metadata', 'records');
|
|
17
|
+
class Insert extends sf_plugins_core_1.SfCommand {
|
|
18
|
+
async run() {
|
|
19
|
+
const { flags } = await this.parse(Insert);
|
|
20
|
+
const dirName = (0, createUtil_1.appendDirectorySuffix)(flags['type-name']);
|
|
21
|
+
const fieldDirPath = path.join(flags['input-directory'], dirName, 'fields');
|
|
22
|
+
const fileNames = await fs.promises.readdir(fieldDirPath);
|
|
23
|
+
// if customMetadata folder does not exist, create it
|
|
24
|
+
await fs.promises.mkdir(flags['output-directory'], { recursive: true });
|
|
25
|
+
const fileData = await (0, createUtil_1.getFileData)(fieldDirPath, fileNames);
|
|
26
|
+
const csvDataAry = (await csv().fromFile(flags.csv));
|
|
27
|
+
const metadataTypeFields = (0, createUtil_1.getFieldNames)(fileData, flags['name-column']);
|
|
28
|
+
if (csvDataAry.length > 0) {
|
|
29
|
+
const record = csvDataAry[0];
|
|
30
|
+
for (const key in record) {
|
|
31
|
+
if (!metadataTypeFields.includes(key)) {
|
|
32
|
+
throw new core_1.SfError(messages.getMessage('fieldNotFoundError', [key, flags['type-name']]));
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
// find the cmdt in the inputdir.
|
|
37
|
+
// loop through files and create records that match fields
|
|
38
|
+
const recordConfigs = csvDataAry.map((record) => ({
|
|
39
|
+
typename: flags['type-name'],
|
|
40
|
+
recordname: record[flags['name-column']].replace(' ', '_'),
|
|
41
|
+
label: record[flags['name-column']],
|
|
42
|
+
inputdir: flags['input-directory'],
|
|
43
|
+
outputdir: flags['output-directory'],
|
|
44
|
+
protected: false,
|
|
45
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
46
|
+
varargs: Object.fromEntries(
|
|
47
|
+
// TODO: throw an error if any of the fields in the csvDataAry do not exist in the fileData
|
|
48
|
+
fileData.map((file) => {
|
|
49
|
+
if (file.fullName) {
|
|
50
|
+
return record[file.fullName] ? [file.fullName, record[file.fullName]] : [];
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
throw new core_1.SfError('No fullName found in fileData');
|
|
54
|
+
}
|
|
55
|
+
})),
|
|
56
|
+
fileData,
|
|
57
|
+
}));
|
|
58
|
+
await Promise.all(recordConfigs.map((r) => (0, createUtil_1.createRecord)(r)));
|
|
59
|
+
this.log(messages.getMessage('successResponse', [flags.csv, flags['output-directory']]));
|
|
60
|
+
return recordConfigs;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
exports.default = Insert;
|
|
64
|
+
Insert.summary = messages.getMessage('summary');
|
|
65
|
+
Insert.description = messages.getMessage('description');
|
|
66
|
+
Insert.requiresProject = true;
|
|
67
|
+
Insert.aliases = ['force:cmdt:record:insert', 'cmdt:record:insert'];
|
|
68
|
+
Insert.examples = messages.getMessages('examples');
|
|
69
|
+
Insert.flags = {
|
|
70
|
+
loglevel: sf_plugins_core_1.loglevel,
|
|
71
|
+
csv: sf_plugins_core_1.Flags.string({
|
|
72
|
+
char: 'f',
|
|
73
|
+
summary: messages.getMessage('flags.csv.summary'),
|
|
74
|
+
required: true,
|
|
75
|
+
aliases: ['filepath'],
|
|
76
|
+
}),
|
|
77
|
+
'type-name': sf_plugins_core_1.Flags.string({
|
|
78
|
+
char: 't',
|
|
79
|
+
summary: messages.getMessage('flags.type-name.summary'),
|
|
80
|
+
description: messages.getMessage('flags.type-name.description'),
|
|
81
|
+
required: true,
|
|
82
|
+
parse: (input) => Promise.resolve(input.endsWith('__mdt') ? input.replace('__mdt', '') : input),
|
|
83
|
+
aliases: ['typename'],
|
|
84
|
+
}),
|
|
85
|
+
'input-directory': sf_plugins_core_1.Flags.directory({
|
|
86
|
+
char: 'i',
|
|
87
|
+
summary: messages.getMessage('flags.input-directory.summary'),
|
|
88
|
+
default: path.join('force-app', 'main', 'default', 'objects'),
|
|
89
|
+
aliases: ['inputdir', 'inputdirectory'],
|
|
90
|
+
exists: true,
|
|
91
|
+
}),
|
|
92
|
+
'output-directory': sf_plugins_core_1.Flags.directory({
|
|
93
|
+
char: 'd',
|
|
94
|
+
summary: messages.getMessage('flags.output-directory.summary'),
|
|
95
|
+
default: path.join('force-app', 'main', 'default', 'customMetadata'),
|
|
96
|
+
aliases: ['outputdir', 'outputdirectory'],
|
|
97
|
+
}),
|
|
98
|
+
'name-column': sf_plugins_core_1.Flags.string({
|
|
99
|
+
char: 'n',
|
|
100
|
+
summary: messages.getMessage('flags.name-column.summary'),
|
|
101
|
+
default: 'Name',
|
|
102
|
+
aliases: ['namecolumn'],
|
|
103
|
+
}),
|
|
104
|
+
};
|
|
105
|
+
//# sourceMappingURL=records.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"records.js","sourceRoot":"","sources":["../../../../src/commands/generate/cmdt/records.ts"],"names":[],"mappings":";;AAAA;;;;;GAKG;AACH,yBAAyB;AACzB,6BAA6B;AAC7B,iEAAyE;AACzE,2CAAqD;AAErD,6CAA6C;AAC7C,mEAAqH;AAGrH,eAAQ,CAAC,uBAAuB,CAAC,SAAS,CAAC,CAAC;AAC5C,MAAM,QAAQ,GAAG,eAAQ,CAAC,YAAY,CAAC,oCAAoC,EAAE,SAAS,CAAC,CAAC;AAExF,MAAqB,MAAO,SAAQ,2BAAwB;IA2CnD,KAAK,CAAC,GAAG;QACd,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QAC3C,MAAM,OAAO,GAAG,IAAA,kCAAqB,EAAC,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC;QAC1D,MAAM,YAAY,GAAG,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,iBAAiB,CAAC,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC;QAC5E,MAAM,SAAS,GAAG,MAAM,EAAE,CAAC,QAAQ,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;QAE1D,qDAAqD;QACrD,MAAM,EAAE,C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AO,EAAE,MAAM;QACf,OAAO,EAAE,CAAC,YAAY,CAAC;KACxB,CAAC;CACH,CAAC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { CustomField } from 'jsforce/api/metadata';
|
|
2
|
+
import { CreateConfig } from '../interfaces/createConfig';
|
|
3
|
+
/**
|
|
4
|
+
* Number and Percent types will be int or double depending on their respective scale values.
|
|
5
|
+
* If the scale === 0, it is an int, otherwise it is a double
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
*
|
|
9
|
+
* @param fieldDirPath path to a /fields folder that contains all the fields to read
|
|
10
|
+
* @param fileNames filenames in that folder that should be read
|
|
11
|
+
* @returns CustomField[]
|
|
12
|
+
*/
|
|
13
|
+
export declare const getFileData: (fieldDirPath: string, fileNames: string[]) => Promise<CustomField[]>;
|
|
14
|
+
/**
|
|
15
|
+
* Get the field type from the custom metadata type that has a matching field name.
|
|
16
|
+
*
|
|
17
|
+
* @param fileData Array of objects based on metadata type xml
|
|
18
|
+
* @param fieldName Name of the field
|
|
19
|
+
* @return {string} Data Type of the field.
|
|
20
|
+
*/
|
|
21
|
+
export declare const getFieldDataType: (fileData?: CustomField[], fieldName?: string) => CustomField['type'];
|
|
22
|
+
/**
|
|
23
|
+
* Creates the Custom Metadata Record
|
|
24
|
+
*
|
|
25
|
+
* @param createConfig Properties include typename, recname, label, protection, varargs, and fileData
|
|
26
|
+
* @return void
|
|
27
|
+
*/
|
|
28
|
+
export declare const createRecord: (createConfig: CreateConfig) => Promise<void>;
|
|
29
|
+
/**
|
|
30
|
+
* Get the field primitive type from the custom metadata type that has a matching field name.
|
|
31
|
+
*
|
|
32
|
+
* @param fileData Array of objects based on metadata type xml
|
|
33
|
+
* @param fieldName Name of the field
|
|
34
|
+
* @return {string} Type used by a custom metadata record
|
|
35
|
+
*/
|
|
36
|
+
export declare const getFieldPrimitiveType: (fileData?: CustomField[], fieldName?: string) => string;
|
|
37
|
+
/**
|
|
38
|
+
* Filenames should have the suffix of '__mdt'. This will append that suffix if it does not exist.
|
|
39
|
+
*
|
|
40
|
+
* @param typename Name of file
|
|
41
|
+
*/
|
|
42
|
+
export declare const appendDirectorySuffix: (typename: string) => string;
|
|
43
|
+
/**
|
|
44
|
+
* Goes through the file data that has been genreated and gets all of the field names and adds the
|
|
45
|
+
* name of the field that is used as the label for metadata record
|
|
46
|
+
*
|
|
47
|
+
* @param fileData Array of objects based on metadata type xml
|
|
48
|
+
* @param nameField name of the column that is going to be used for the name of the metadata record
|
|
49
|
+
* @return [] Array of field names
|
|
50
|
+
*/
|
|
51
|
+
export declare const getFieldNames: (fileData: CustomField[], nameField: string) => string[];
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getFieldNames = exports.appendDirectorySuffix = exports.getFieldPrimitiveType = exports.createRecord = exports.getFieldDataType = exports.getFileData = void 0;
|
|
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 fast_xml_parser_1 = require("fast-xml-parser");
|
|
13
|
+
const ts_types_1 = require("@salesforce/ts-types");
|
|
14
|
+
const templates_1 = require("../templates/templates");
|
|
15
|
+
const fieldTypeMap = new Map([
|
|
16
|
+
['Checkbox', 'boolean'],
|
|
17
|
+
['Date', 'date'],
|
|
18
|
+
['DateTime', 'dateTime'],
|
|
19
|
+
['Email', 'string'],
|
|
20
|
+
['Phone', 'string'],
|
|
21
|
+
['Picklist', 'string'],
|
|
22
|
+
['Text', 'string'],
|
|
23
|
+
['TextArea', 'string'],
|
|
24
|
+
['LongTextArea', 'string'],
|
|
25
|
+
['Url', 'string'],
|
|
26
|
+
]);
|
|
27
|
+
// NOTE: the template string indentation is important to output well-formatted XML. Altering that whitespace will change the whitespace of the output.
|
|
28
|
+
/**
|
|
29
|
+
* Number and Percent types will be int or double depending on their respective scale values.
|
|
30
|
+
* If the scale === 0, it is an int, otherwise it is a double
|
|
31
|
+
*/
|
|
32
|
+
/**
|
|
33
|
+
*
|
|
34
|
+
* @param fieldDirPath path to a /fields folder that contains all the fields to read
|
|
35
|
+
* @param fileNames filenames in that folder that should be read
|
|
36
|
+
* @returns CustomField[]
|
|
37
|
+
*/
|
|
38
|
+
const getFileData = async (fieldDirPath, fileNames) => {
|
|
39
|
+
const parser = new fast_xml_parser_1.XMLParser();
|
|
40
|
+
return Promise.all(fileNames
|
|
41
|
+
.map((file) => path.join(fieldDirPath, file))
|
|
42
|
+
.map(async (filePath) => {
|
|
43
|
+
const fileData = await fs.promises.readFile(filePath, 'utf8');
|
|
44
|
+
return parser.parse(fileData).CustomField;
|
|
45
|
+
}));
|
|
46
|
+
};
|
|
47
|
+
exports.getFileData = getFileData;
|
|
48
|
+
/**
|
|
49
|
+
* Get the field type from the custom metadata type that has a matching field name.
|
|
50
|
+
*
|
|
51
|
+
* @param fileData Array of objects based on metadata type xml
|
|
52
|
+
* @param fieldName Name of the field
|
|
53
|
+
* @return {string} Data Type of the field.
|
|
54
|
+
*/
|
|
55
|
+
const getFieldDataType = (fileData = [], fieldName = '') => { var _a; return (_a = fileData.find((file) => file.fullName === fieldName)) === null || _a === void 0 ? void 0 : _a.type; };
|
|
56
|
+
exports.getFieldDataType = getFieldDataType;
|
|
57
|
+
/**
|
|
58
|
+
* Creates the Custom Metadata Record
|
|
59
|
+
*
|
|
60
|
+
* @param createConfig Properties include typename, recname, label, protection, varargs, and fileData
|
|
61
|
+
* @return void
|
|
62
|
+
*/
|
|
63
|
+
const createRecord = async (createConfig) => {
|
|
64
|
+
const outputFilePath = path.join(createConfig.outputdir, `${createConfig.typename}.${createConfig.recordname}.md-meta.xml`);
|
|
65
|
+
const newRecordContent = getRecordTemplate(createConfig.label, createConfig.protected, buildCustomFieldXml(createConfig.fileData, createConfig.varargs, createConfig.ignorefields));
|
|
66
|
+
return fs.promises.writeFile(outputFilePath, newRecordContent);
|
|
67
|
+
};
|
|
68
|
+
exports.createRecord = createRecord;
|
|
69
|
+
/**
|
|
70
|
+
* Get the field primitive type from the custom metadata type that has a matching field name.
|
|
71
|
+
*
|
|
72
|
+
* @param fileData Array of objects based on metadata type xml
|
|
73
|
+
* @param fieldName Name of the field
|
|
74
|
+
* @return {string} Type used by a custom metadata record
|
|
75
|
+
*/
|
|
76
|
+
const getFieldPrimitiveType = (fileData = [], fieldName) => {
|
|
77
|
+
var _a;
|
|
78
|
+
const matchingFile = fileData.find((file) => file.fullName === fieldName);
|
|
79
|
+
if (matchingFile && typeof matchingFile.type === 'string' && ['Number', 'Percent'].includes(matchingFile.type)) {
|
|
80
|
+
return getNumberType(matchingFile.type, matchingFile.scale);
|
|
81
|
+
}
|
|
82
|
+
if (matchingFile && typeof matchingFile.type === 'string') {
|
|
83
|
+
return (_a = fieldTypeMap.get(matchingFile.type)) !== null && _a !== void 0 ? _a : 'string';
|
|
84
|
+
}
|
|
85
|
+
return 'string';
|
|
86
|
+
};
|
|
87
|
+
exports.getFieldPrimitiveType = getFieldPrimitiveType;
|
|
88
|
+
/**
|
|
89
|
+
* Filenames should have the suffix of '__mdt'. This will append that suffix if it does not exist.
|
|
90
|
+
*
|
|
91
|
+
* @param typename Name of file
|
|
92
|
+
*/
|
|
93
|
+
const appendDirectorySuffix = (typename) => typename.endsWith('__mdt') ? typename : `${typename}__mdt`;
|
|
94
|
+
exports.appendDirectorySuffix = appendDirectorySuffix;
|
|
95
|
+
/**
|
|
96
|
+
* Goes through the file data that has been genreated and gets all of the field names and adds the
|
|
97
|
+
* name of the field that is used as the label for metadata record
|
|
98
|
+
*
|
|
99
|
+
* @param fileData Array of objects based on metadata type xml
|
|
100
|
+
* @param nameField name of the column that is going to be used for the name of the metadata record
|
|
101
|
+
* @return [] Array of field names
|
|
102
|
+
*/
|
|
103
|
+
const getFieldNames = (fileData, nameField) => [
|
|
104
|
+
...fileData.map((file) => file.fullName).filter(ts_types_1.isString),
|
|
105
|
+
nameField,
|
|
106
|
+
];
|
|
107
|
+
exports.getFieldNames = getFieldNames;
|
|
108
|
+
/**
|
|
109
|
+
* Takes JSON representation of CLI varargs and converts them to xml with help
|
|
110
|
+
* from helper.getFieldTemplate
|
|
111
|
+
*
|
|
112
|
+
* @param cliParams Object that holds key:value pairs from CLI input
|
|
113
|
+
* @param fileData Array of objects that contain field data
|
|
114
|
+
* @return {string} String representation of XML
|
|
115
|
+
*/
|
|
116
|
+
const buildCustomFieldXml = (fileData = [], cliParams = {}, ignoreFields = false) => {
|
|
117
|
+
let ret = '';
|
|
118
|
+
for (const fieldName of Object.keys(cliParams)) {
|
|
119
|
+
const type = (0, exports.getFieldPrimitiveType)(fileData, fieldName);
|
|
120
|
+
const dataType = (0, exports.getFieldDataType)(fileData, fieldName);
|
|
121
|
+
// Added functionality to handle the igonre fields scenario.
|
|
122
|
+
if ((0, templates_1.canConvert)(dataType) || !ignoreFields) {
|
|
123
|
+
ret += getFieldTemplate(fieldName, cliParams[fieldName], type);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return ret;
|
|
127
|
+
};
|
|
128
|
+
/**
|
|
129
|
+
* Get the number type based on the scale.
|
|
130
|
+
* If the scale === 0, it is an int, otherwise it is a double.
|
|
131
|
+
*
|
|
132
|
+
* @param type Number or Percent
|
|
133
|
+
* @param scale 0 or another number
|
|
134
|
+
* @return {string} int or double
|
|
135
|
+
*/
|
|
136
|
+
const getNumberType = (type, scale) => ['Number', 'Percent'].includes(type) && scale === 0 ? 'int' : 'double';
|
|
137
|
+
/**
|
|
138
|
+
* Template for a single customMetadata record value. This is used by helper.getRecordTemplate.
|
|
139
|
+
*
|
|
140
|
+
* @param fieldName Field API Name (i.e, Foo__c)
|
|
141
|
+
* @param val Value of the field
|
|
142
|
+
* @param type Field type (i.e. boolean, dateTime, date, string, double)
|
|
143
|
+
* @return {string} String representation of XML
|
|
144
|
+
*/
|
|
145
|
+
const getFieldTemplate = (fieldName, val, type) => {
|
|
146
|
+
const cleanValue = String(val).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
|
|
147
|
+
const value = val === null || val === '' ? '<value xsi:nil="true"/>' : `<value xsi:type="xsd:${type}">${cleanValue}</value>`;
|
|
148
|
+
return `
|
|
149
|
+
<values>
|
|
150
|
+
<field>${fieldName}</field>
|
|
151
|
+
${value}
|
|
152
|
+
</values>`;
|
|
153
|
+
};
|
|
154
|
+
/**
|
|
155
|
+
* Template to compile entire customMetadata record
|
|
156
|
+
*
|
|
157
|
+
* @param label Name of the record
|
|
158
|
+
* @param protection Is the record protected?
|
|
159
|
+
* @param values Template string representation of values
|
|
160
|
+
* @return {string} String representation of XML
|
|
161
|
+
*/
|
|
162
|
+
const getRecordTemplate = (label, protection = false, values) => `
|
|
163
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
164
|
+
<CustomMetadata xmlns="http://soap.sforce.com/2006/04/metadata" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
|
|
165
|
+
<label>${label}</label>
|
|
166
|
+
<protected>${protection}</protected>${values}
|
|
167
|
+
</CustomMetadata>`.trim();
|
|
168
|
+
//# sourceMappingURL=createUtil.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createUtil.js","sourceRoot":"","sources":["../../../src/shared/helpers/createUtil.ts"],"names":[],"mappings":";;;AAAA;;;;;GAKG;AACH,yBAAyB;AACzB,6BAA6B;AAE7B,qDAA4C;AAC5C,mDAAgD;AAEhD,sDAAoD;AAMpD,MAAM,YAAY,GAAG,IAAI,GAAG,CAAiB;IAC3C,CAAC,UAAU,EAAE,SAAS,CAAC;IACvB,CAAC,MAAM,EAAE,MAAM,CAAC;IAChB,CAAC,UAAU,EA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;;;GAOG;AACH,MAAM,gBAAgB,GAAG,CAAC,SAAiB,EAAE,GAAW,EAAE,IAAY,EAAU,EAAE;IAChF,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;IAClG,MAAM,KAAK,GACT,GAAG,KAAK,IAAI,IAAI,GAAG,KAAK,EAAE,CAAC,CAAC,CAAC,yBAAyB,CAAC,CAAC,CAAC,wBAAwB,IAAI,KAAK,UAAU,UAAU,CAAC;IAEjH,OAAO;;iBAEQ,SAAS;UAChB,KAAK;cACD,CAAC;AACf,CAAC,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,iBAAiB,GAAG,CAAC,KAAa,EAAE,UAAU,GAAG,KAAK,EAAE,MAAc,EAAU,EAAE,CACtF;;;aAGW,KAAK;iBACD,UAAU,eAAe,MAAM;kBAC9B,CAAC,IAAI,EAAE,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import * as fs from 'fs';
|
|
3
|
+
interface FileWriterResult {
|
|
4
|
+
dir: string;
|
|
5
|
+
fileName: string;
|
|
6
|
+
updated: boolean;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Using the given file system, creates a file representing a new custom metadata type.
|
|
10
|
+
*
|
|
11
|
+
* @param fs
|
|
12
|
+
* @param devname
|
|
13
|
+
* @param objectXML
|
|
14
|
+
*/
|
|
15
|
+
export declare const writeTypeFile: (corefs: typeof fs | undefined, dir: string, devName: string, objectXML: string) => Promise<FileWriterResult>;
|
|
16
|
+
/**
|
|
17
|
+
* Using the given file system, creates a file representing a new field for the given custom metadata type
|
|
18
|
+
*
|
|
19
|
+
* @param fs
|
|
20
|
+
* @param fieldname
|
|
21
|
+
* @param fieldXML
|
|
22
|
+
*/
|
|
23
|
+
export declare const writeFieldFile: (corefs: typeof fs | undefined, dir: string, fieldName: string | undefined | null, fieldXML: string) => Promise<FileWriterResult>;
|
|
24
|
+
export {};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2020, salesforce.com, inc.
|
|
4
|
+
* All rights reserved.
|
|
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
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.writeFieldFile = exports.writeTypeFile = void 0;
|
|
10
|
+
const fs = require("fs");
|
|
11
|
+
const path = require("path");
|
|
12
|
+
/**
|
|
13
|
+
* Using the given file system, creates a file representing a new custom metadata type.
|
|
14
|
+
*
|
|
15
|
+
* @param fs
|
|
16
|
+
* @param devname
|
|
17
|
+
* @param objectXML
|
|
18
|
+
*/
|
|
19
|
+
const writeTypeFile = async (corefs = fs, dir, devName, objectXML) => {
|
|
20
|
+
let apiName = devName;
|
|
21
|
+
// replace __c with __mdt
|
|
22
|
+
if (apiName.endsWith('__c')) {
|
|
23
|
+
apiName = apiName.replace('__c', '__mdt');
|
|
24
|
+
}
|
|
25
|
+
// appending __mdt if they did not pass it in.
|
|
26
|
+
if (!apiName.endsWith('__mdt')) {
|
|
27
|
+
apiName += '__mdt';
|
|
28
|
+
}
|
|
29
|
+
const outputFilePath = path.join(removeTrailingSlash(dir), apiName);
|
|
30
|
+
const fileName = `${apiName}.object-meta.xml`;
|
|
31
|
+
const updated = fs.existsSync(path.join(outputFilePath, fileName));
|
|
32
|
+
await corefs.promises.mkdir(outputFilePath, { recursive: true });
|
|
33
|
+
await corefs.promises.writeFile(path.join(outputFilePath, fileName), objectXML);
|
|
34
|
+
return { dir: outputFilePath, fileName, updated };
|
|
35
|
+
};
|
|
36
|
+
exports.writeTypeFile = writeTypeFile;
|
|
37
|
+
/**
|
|
38
|
+
* Using the given file system, creates a file representing a new field for the given custom metadata type
|
|
39
|
+
*
|
|
40
|
+
* @param fs
|
|
41
|
+
* @param fieldname
|
|
42
|
+
* @param fieldXML
|
|
43
|
+
*/
|
|
44
|
+
// /fields/{fieldAPI}.field-meta.xml
|
|
45
|
+
const writeFieldFile = async (corefs = fs, dir, fieldName, fieldXML) => {
|
|
46
|
+
// appending __c if its not already there
|
|
47
|
+
if ((fieldName === null || fieldName === void 0 ? void 0 : fieldName.endsWith('__c')) === false) {
|
|
48
|
+
fieldName += '__c';
|
|
49
|
+
}
|
|
50
|
+
const outputFilePath = path.join(removeTrailingSlash(dir), 'fields');
|
|
51
|
+
const fileName = `${fieldName}.field-meta.xml`;
|
|
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);
|
|
55
|
+
return { dir: outputFilePath, fileName, updated };
|
|
56
|
+
};
|
|
57
|
+
exports.writeFieldFile = writeFieldFile;
|
|
58
|
+
const removeTrailingSlash = (dir) => dir.replace(/\/+$/, '');
|
|
59
|
+
//# sourceMappingURL=fileWriter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fileWriter.js","sourceRoot":"","sources":["../../../src/shared/helpers/fileWriter.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,yBAAyB;AACzB,6BAA6B;AAQ7B;;;;;;GAMG;AACI,MAAM,aAAa,GAAG,KAAK,EAChC,MAAM,GAAG,EAAE,EACX,GAAW,EACX,OAAe,EACf,SAAiB,EACU,EAAE;IAC7B,IAAI,OAAO,GAAG,OAAO,CAAC;IAEtB,yBAAyB;IACzB,IAAI,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE;QAC3B,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,KAAK,EAAE,OA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I,CAAC,IAAI,CAAC,cAAc,EAAE,QAAQ,CAAC,CAAC,CAAC;IACnE,MAAM,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,cAAc,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IACjE,MAAM,MAAM,CAAC,QAAQ,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,QAAQ,CAAC,EAAE,QAAQ,CAAC,CAAC;IAE/E,OAAO,EAAE,GAAG,EAAE,cAAc,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC;AACpD,CAAC,CAAC;AAjBW,QAAA,cAAc,kBAiBzB;AAEF,MAAM,mBAAmB,GAAG,CAAC,GAAW,EAAU,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC"}
|
|
@@ -7,7 +7,7 @@ import { Record } from 'jsforce';
|
|
|
7
7
|
* @param fieldName API name of the field to query
|
|
8
8
|
* @returns Promise - Promise - record in JSON format
|
|
9
9
|
*/
|
|
10
|
-
export declare const describeField: (objDescribe: CustomObject, fieldName: string) => CustomField;
|
|
10
|
+
export declare const describeField: (objDescribe: CustomObject, fieldName: string) => CustomField | undefined;
|
|
11
11
|
/**
|
|
12
12
|
* Returns true if the object name you specify is a list type custom setting
|
|
13
13
|
*
|
|
@@ -37,7 +37,7 @@ const cleanQueryResponse = (sObjectRecord, objectDescribe) => Object.fromEntries
|
|
|
37
37
|
.flatMap(([fieldName, value]) => {
|
|
38
38
|
const fieldDescribe = (0, exports.describeField)(objectDescribe, fieldName);
|
|
39
39
|
// everything but location returns as is
|
|
40
|
-
if (fieldDescribe.type !== 'Location') {
|
|
40
|
+
if ((fieldDescribe === null || fieldDescribe === void 0 ? void 0 : fieldDescribe.type) !== 'Location') {
|
|
41
41
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
42
42
|
return [[fieldName, value]];
|
|
43
43
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1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,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IACzC,IAAI,UAAU,CAAC,QAAQ,CAAC,UAAU,CAAC,IAAI,UAAU,CAAC,QAAQ,CAAC,WAAW,CAAC,EAAE;QACvE,OAAO;YACL,CAAC,OAAO,SAAS,EAAE,EAAE,UAAU,CAAC,KAAK,CAAC,UAAU,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,UAAU,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC;YAC5F,CAAC,QAAQ,SAAS,EAAE,EAAE,UAAU,CAAC,KAAK,CAAC,UAAU,CAAC,WAAW,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,UAAU,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC;SAClG,CAAC;KACH;SAAM;QACL,OAAO;YACL,CAAC,OAAO,SAAS,EAAE,EAAE,EAAE,CAAC;YACxB,CAAC,QAAQ,SAAS,EAAE,EAAE,EAAE,CAAC;SAC1B,CAAC;KACH;AACH,CAAC,CAAC,CACL,CAAC;AAxBS,QAAA,kBAAkB,sBAwB3B"}
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validationUtil.js","sourceRoot":"","sources":["../../../src/shared/helpers/validationUtil.ts"],"names":[],"mappings":";;;AAAA;;;;;GAKG;AACH,2CAAqD;AACrD,eAAQ,CAAC,uBAAuB,CAAC,SAAS,CAAC,CAAC;AAC5C,MAAM,QAAQ,GAAG,eAAQ,CAAC,IAAI,CAAC,oCAAoC,EAAE,YAAY,EAAE;IACjF,sBAAsB;IACtB,oBAAoB;IACpB,0BAA0B;CAC3B,CAAC,CAAC;AAEH;;;;GAIG;AACI,MAAM,eAAe,GAAG,CAAC,IAAY,EAAE,OAAgB,EAAU,EAAE;IACxE,mGAAmG;IACnG,sFAAsF;IACtF,mCAAmC;IACnC,MAAM,YAAY,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,EAA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CAAC,CAAC,CAAC;KAChF;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC,CAAC;AANW,QAAA,0BAA0B,8BAMrC;AAEF;;;;GAIG;AACI,MAAM,qBAAqB,GAAG,CAAC,IAAY,EAAE,OAAe,EAAU,EAAE;IAC7E,IAAI,IAAI,CAAC,MAAM,GAAG,EAAE,EAAE;QACpB,MAAM,IAAI,cAAO,CAAC,OAAO,CAAC,CAAC;KAC5B;IACD,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AALW,QAAA,qBAAqB,yBAKhC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Record } from 'jsforce';
|
|
2
2
|
import { CustomField } from 'jsforce/api/metadata';
|
|
3
|
-
export
|
|
3
|
+
export type CreateConfig = {
|
|
4
4
|
typename: string;
|
|
5
5
|
recordname: string;
|
|
6
6
|
label: string;
|
|
@@ -10,4 +10,5 @@ export interface CreateConfig {
|
|
|
10
10
|
varargs?: Record;
|
|
11
11
|
fileData?: CustomField[];
|
|
12
12
|
ignorefields?: boolean;
|
|
13
|
-
}
|
|
13
|
+
};
|
|
14
|
+
export type CreateConfigs = CreateConfig[];
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createConfig.js","sourceRoot":"","sources":["../../../src/shared/interfaces/createConfig.ts"],"names":[],"mappings":";AAAA;;;;;GAKG"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { CustomField } from 'jsforce/api/metadata';
|
|
2
|
+
/**
|
|
3
|
+
* Using the given data and visibility, creates the body of a type metadata file
|
|
4
|
+
*
|
|
5
|
+
* @param data
|
|
6
|
+
* @param visibility
|
|
7
|
+
*/
|
|
8
|
+
export declare const createObjectXML: ({ label, pluralLabel }: {
|
|
9
|
+
label: string;
|
|
10
|
+
pluralLabel: string;
|
|
11
|
+
}, visibility: string) => string;
|
|
12
|
+
/**
|
|
13
|
+
* Using the given data and defaultToString, creates the body for a field file.
|
|
14
|
+
*
|
|
15
|
+
* @param data Record details
|
|
16
|
+
* @param defaultToString If the defaultToString set type to Text for unsupported field types
|
|
17
|
+
*/
|
|
18
|
+
export declare const createFieldXML: (data: CustomField, defaultToString: boolean) => string;
|
|
19
|
+
export declare const createDefaultTypeStructure: (fullName: string, type: string, label: string, picklistValues?: string[], decimalplaces?: number) => CustomField;
|
|
20
|
+
export declare const canConvert: (type: string | undefined | null) => boolean;
|