sfdx-easy-sources 0.8.3 → 0.9.1-develop.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/lib/commands/easysources/allmeta/minify.d.ts +1 -0
- package/lib/commands/easysources/allmeta/minify.js +17 -2
- package/lib/commands/easysources/allmeta/minify.js.map +1 -1
- package/lib/commands/easysources/objecttranslations/merge.d.ts +1 -3
- package/lib/commands/easysources/objecttranslations/merge.js +46 -17
- package/lib/commands/easysources/objecttranslations/merge.js.map +1 -1
- package/lib/commands/easysources/objecttranslations/minify.d.ts +1 -3
- package/lib/commands/easysources/objecttranslations/minify.js +52 -32
- package/lib/commands/easysources/objecttranslations/minify.js.map +1 -1
- package/lib/commands/easysources/objecttranslations/split.js +79 -55
- package/lib/commands/easysources/objecttranslations/split.js.map +1 -1
- package/lib/commands/easysources/objecttranslations/upsert.d.ts +1 -3
- package/lib/commands/easysources/objecttranslations/upsert.js +109 -75
- package/lib/commands/easysources/objecttranslations/upsert.js.map +1 -1
- package/lib/commands/easysources/permissionsets/clean.js +4 -5
- package/lib/commands/easysources/permissionsets/clean.js.map +1 -1
- package/lib/commands/easysources/permissionsets/delete.js +4 -5
- package/lib/commands/easysources/permissionsets/delete.js.map +1 -1
- package/lib/commands/easysources/permissionsets/minify.js +52 -32
- package/lib/commands/easysources/permissionsets/minify.js.map +1 -1
- package/lib/commands/easysources/profiles/clean.js +4 -5
- package/lib/commands/easysources/profiles/clean.js.map +1 -1
- package/lib/commands/easysources/profiles/delete.js +4 -5
- package/lib/commands/easysources/profiles/delete.js.map +1 -1
- package/lib/commands/easysources/profiles/minify.js +52 -32
- package/lib/commands/easysources/profiles/minify.js.map +1 -1
- package/lib/commands/easysources/profiles/split.js +1 -1
- package/lib/commands/easysources/recordtypes/clean.js +5 -5
- package/lib/commands/easysources/recordtypes/clean.js.map +1 -1
- package/lib/commands/easysources/recordtypes/delete.js +5 -5
- package/lib/commands/easysources/recordtypes/delete.js.map +1 -1
- package/lib/commands/easysources/recordtypes/merge.js +24 -9
- package/lib/commands/easysources/recordtypes/merge.js.map +1 -1
- package/lib/commands/easysources/recordtypes/split.js +58 -40
- package/lib/commands/easysources/recordtypes/split.js.map +1 -1
- package/lib/commands/easysources/recordtypes/updatekey.js +38 -22
- package/lib/commands/easysources/recordtypes/updatekey.js.map +1 -1
- package/lib/commands/easysources/recordtypes/upsert.js +90 -64
- package/lib/commands/easysources/recordtypes/upsert.js.map +1 -1
- package/lib/commands/easysources/translations/minify.js +53 -31
- package/lib/commands/easysources/translations/minify.js.map +1 -1
- package/lib/utils/commands/keyupdater.d.ts +5 -1
- package/lib/utils/commands/keyupdater.js +37 -23
- package/lib/utils/commands/keyupdater.js.map +1 -1
- package/lib/utils/commands/merger.d.ts +4 -0
- package/lib/utils/commands/merger.js +11 -5
- package/lib/utils/commands/merger.js.map +1 -1
- package/lib/utils/commands/splitter.d.ts +5 -1
- package/lib/utils/commands/splitter.js +62 -48
- package/lib/utils/commands/splitter.js.map +1 -1
- package/lib/utils/commands/upserter.d.ts +3 -3
- package/lib/utils/commands/upserter.js +128 -102
- package/lib/utils/commands/upserter.js.map +1 -1
- package/lib/utils/commands/utils.d.ts +11 -0
- package/lib/utils/commands/utils.js +35 -1
- package/lib/utils/commands/utils.js.map +1 -1
- package/lib/utils/constants/constants_applications.d.ts +2 -8
- package/lib/utils/constants/constants_globalvaluesets.d.ts +2 -8
- package/lib/utils/constants/constants_globalvaluesettranslations.d.ts +2 -8
- package/lib/utils/constants/constants_labels.d.ts +2 -8
- package/lib/utils/constants/constants_objecttranslations.d.ts +14 -56
- package/lib/utils/constants/constants_permissionsets.d.ts +2 -8
- package/lib/utils/constants/constants_profiles.d.ts +4 -16
- package/lib/utils/constants/constants_translations.d.ts +12 -48
- package/lib/utils/csvWriter.d.ts +9 -0
- package/lib/utils/csvWriter.js +53 -0
- package/lib/utils/csvWriter.js.map +1 -0
- package/lib/utils/utils.d.ts +1 -4
- package/lib/utils/utils.js +8 -1
- package/lib/utils/utils.js.map +1 -1
- package/oclif.manifest.json +1 -1
- package/package.json +3 -2
|
@@ -13,12 +13,13 @@ const core_1 = require("@salesforce/core");
|
|
|
13
13
|
const fs = require('fs-extra');
|
|
14
14
|
const path_1 = require("path");
|
|
15
15
|
const performance_1 = require("../../../utils/performance");
|
|
16
|
-
const { Parser, transforms: { unwind } } = require('json2csv');
|
|
17
16
|
const constants_translations_1 = require("../../../utils/constants/constants_translations");
|
|
18
17
|
const filesUtils_1 = require("../../../utils/filesUtils");
|
|
19
18
|
const utils_1 = require("../../../utils/utils");
|
|
20
19
|
const constants_1 = require("../../../utils/constants/constants");
|
|
21
20
|
const localSettings_1 = require("../../../utils/localSettings");
|
|
21
|
+
const utils_2 = require("../../../utils/commands/utils");
|
|
22
|
+
const csvWriter_1 = require("../../../utils/csvWriter");
|
|
22
23
|
const settings = (0, localSettings_1.loadSettings)();
|
|
23
24
|
// Initialize Messages with the current plugin directory
|
|
24
25
|
core_1.Messages.importMessagesDirectory(__dirname);
|
|
@@ -61,11 +62,20 @@ Clean.flagsConfig = {
|
|
|
61
62
|
// Export function for programmatic API
|
|
62
63
|
async function translationMinify(options = {}) {
|
|
63
64
|
performance_1.default.getInstance().start();
|
|
65
|
+
const csvWriter = new csvWriter_1.default();
|
|
64
66
|
const csvDir = (0, path_1.join)((options["es-csv"] || settings['easysources-csv-path'] || constants_1.DEFAULT_ESCSV_PATH), constants_translations_1.TRANSLATIONS_SUBPATH);
|
|
65
67
|
const xmlDir = (0, path_1.join)((options["sf-xml"] || settings['salesforce-xml-path'] || constants_1.DEFAULT_SFXML_PATH));
|
|
66
68
|
const inputTranslation = (options.input);
|
|
67
|
-
|
|
68
|
-
|
|
69
|
+
// Initialize result object
|
|
70
|
+
const result = { result: 'OK', items: {} };
|
|
71
|
+
try {
|
|
72
|
+
(0, filesUtils_1.checkDirOrErrorSync)(csvDir);
|
|
73
|
+
(0, filesUtils_1.checkDirOrErrorSync)(xmlDir);
|
|
74
|
+
}
|
|
75
|
+
catch (error) {
|
|
76
|
+
performance_1.default.getInstance().end();
|
|
77
|
+
return (0, utils_2.jsonAndPrintError)(error.message);
|
|
78
|
+
}
|
|
69
79
|
var transationList = [];
|
|
70
80
|
if (inputTranslation) {
|
|
71
81
|
transationList = inputTranslation.split(',');
|
|
@@ -78,41 +88,53 @@ async function translationMinify(options = {}) {
|
|
|
78
88
|
// translationName is the profile name without the extension
|
|
79
89
|
for (const translationName of transationList) {
|
|
80
90
|
console.log('Minifying on: ' + translationName);
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
for (const boolName of (0, utils_1.toArray)(constants_translations_1.TRANSLAT_TAG_BOOL[tag_section])) {
|
|
92
|
-
if (!(0, utils_1.isBlank)(res[boolName]))
|
|
91
|
+
try {
|
|
92
|
+
for (const tag_section in constants_translations_1.TRANSLATION_ITEMS) {
|
|
93
|
+
// tag_section is a profile section (applicationVisibilities, classAccess ecc)
|
|
94
|
+
const csvFilePath = (0, path_1.join)(csvDir, translationName, (0, filesUtils_1.calcCsvFilename)(translationName, tag_section));
|
|
95
|
+
if (fs.existsSync(csvFilePath)) {
|
|
96
|
+
// get the list of resources on the csv. eg. the list of apex classes
|
|
97
|
+
var resListCsv = await (0, filesUtils_1.readCsvToJsonArray)(csvFilePath);
|
|
98
|
+
resListCsv = resListCsv.filter(function (res) {
|
|
99
|
+
// return true to persist, false to delete
|
|
100
|
+
if (constants_translations_1.TRANSLAT_TAG_BOOL[tag_section] == null)
|
|
93
101
|
return true;
|
|
102
|
+
for (const boolName of (0, utils_1.toArray)(constants_translations_1.TRANSLAT_TAG_BOOL[tag_section])) {
|
|
103
|
+
if (!(0, utils_1.isBlank)(res[boolName]))
|
|
104
|
+
return true;
|
|
105
|
+
}
|
|
106
|
+
return false;
|
|
107
|
+
});
|
|
108
|
+
// write the cleaned csv
|
|
109
|
+
const headers = constants_translations_1.TRANSLATION_ITEMS[tag_section].headers;
|
|
110
|
+
if (options.sort === 'true') {
|
|
111
|
+
resListCsv = (0, utils_1.sortByKey)(resListCsv);
|
|
112
|
+
}
|
|
113
|
+
try {
|
|
114
|
+
const csvContent = await csvWriter.toCsv(resListCsv, headers);
|
|
115
|
+
fs.writeFileSync(csvFilePath, csvContent, { flag: 'w+' });
|
|
116
|
+
// file written successfully
|
|
117
|
+
}
|
|
118
|
+
catch (err) {
|
|
119
|
+
console.error(err);
|
|
120
|
+
throw new Error(`Failed to write CSV file ${csvFilePath}: ${err.message}`);
|
|
94
121
|
}
|
|
95
|
-
return false;
|
|
96
|
-
});
|
|
97
|
-
// write the cleaned csv
|
|
98
|
-
const headers = constants_translations_1.TRANSLATION_ITEMS[tag_section].headers;
|
|
99
|
-
const transforms = [unwind({ paths: headers })];
|
|
100
|
-
const parser = new Parser({ fields: [...headers, '_tagid'], transforms });
|
|
101
|
-
if (options.sort === 'true') {
|
|
102
|
-
resListCsv = (0, utils_1.sortByKey)(resListCsv);
|
|
103
|
-
}
|
|
104
|
-
const csv = parser.parse(resListCsv);
|
|
105
|
-
try {
|
|
106
|
-
fs.writeFileSync(csvFilePath, csv, { flag: 'w+' });
|
|
107
|
-
}
|
|
108
|
-
catch (err) {
|
|
109
|
-
console.error(err);
|
|
110
122
|
}
|
|
123
|
+
// Translation processed successfully
|
|
124
|
+
result.items[translationName] = { result: 'OK' };
|
|
111
125
|
}
|
|
112
126
|
}
|
|
127
|
+
catch (error) {
|
|
128
|
+
// Translation processing failed
|
|
129
|
+
console.error(`Error minifying translation ${translationName}:`, error);
|
|
130
|
+
result.items[translationName] = {
|
|
131
|
+
result: 'KO',
|
|
132
|
+
error: error.message || 'Unknown error occurred'
|
|
133
|
+
};
|
|
134
|
+
}
|
|
113
135
|
}
|
|
114
136
|
performance_1.default.getInstance().end();
|
|
115
|
-
return
|
|
137
|
+
return result;
|
|
116
138
|
}
|
|
117
139
|
exports.translationMinify = translationMinify;
|
|
118
140
|
//# sourceMappingURL=minify.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"minify.js","sourceRoot":"","sources":["../../../../src/commands/easysources/translations/minify.ts"],"names":[],"mappings":";;;AAAA;;;;;GAKG;AACH,yBAAyB;AACzB,iDAAyD;AACzD,2CAA4C;AAE5C,MAAM,EAAE,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;AAC/B,+BAA4B;AAC5B,4DAAqD;AACrD,
|
|
1
|
+
{"version":3,"file":"minify.js","sourceRoot":"","sources":["../../../../src/commands/easysources/translations/minify.ts"],"names":[],"mappings":";;;AAAA;;;;;GAKG;AACH,yBAAyB;AACzB,iDAAyD;AACzD,2CAA4C;AAE5C,MAAM,EAAE,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;AAC/B,+BAA4B;AAC5B,4DAAqD;AACrD,4FAA6H;AAC7H,0DAAoG;AACpG,gDAAkE;AAClE,kEAA4F;AAC5F,gEAA4D;AAC5D,yDAAkE;AAClE,wDAAiD;AAEjD,MAAM,QAAQ,GAAG,IAAA,4BAAY,GAAE,CAAC;AAEhC,wDAAwD;AACxD,eAAQ,CAAC,uBAAuB,CAAC,SAAS,CAAC,CAAC;AAE5C,iGAAiG;AACjG,mFAAmF;AACnF,MAAM,QAAQ,GAAG,eAAQ,CAAC,YAAY,CAAC,mBAAmB,EAAE,qBAAqB,CAAC,CAAC;AAEnF,MAAqB,KAAM,SAAQ,qBAAW;IA6BnC,KAAK,CAAC,GAAG;QACZ,qBAAW,CAAC,WAAW,EAAE,CAAC,KAAK,EAAE,CAAC;QAElC,MAAM,MAAM,GAAG,MAAM,iBAAiB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAEnD,qBAAW,CAAC,WAAW,EAAE,CAAC,GAAG,EAAE,CAAC;QAEhC,OAAO,MAAM,CAAC;IAClB,CAAC;;AArCL,wBAuCC;AAtCiB,iBAAW,GAAG,QAAQ,CAAC,UA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AAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;aACpD;SAEJ;QAAC,OAAO,KAAK,EAAE;YACZ,gCAAgC;YAChC,OAAO,CAAC,KAAK,CAAC,+BAA+B,eAAe,GAAG,EAAE,KAAK,CAAC,CAAC;YACxE,MAAM,CAAC,KAAK,CAAC,eAAe,CAAC,GAAG;gBAC5B,MAAM,EAAE,IAAI;gBACZ,KAAK,EAAE,KAAK,CAAC,OAAO,IAAI,wBAAwB;aACnD,CAAC;SACL;KACJ;IAED,qBAAW,CAAC,WAAW,EAAE,CAAC,GAAG,EAAE,CAAC;IAGhC,OAAO,MAAM,CAAC;AAClB,CAAC;AAvFD,8CAuFC"}
|
|
@@ -4,19 +4,22 @@ exports.updatekey = void 0;
|
|
|
4
4
|
const filesUtils_1 = require("../filesUtils");
|
|
5
5
|
const utils_1 = require("../utils");
|
|
6
6
|
const utils_2 = require("../utils");
|
|
7
|
-
const { Parser, transforms: { unwind } } = require('json2csv');
|
|
8
7
|
const path_1 = require("path");
|
|
9
8
|
const constants_1 = require("../constants/constants");
|
|
10
9
|
const localSettings_1 = require("../localSettings");
|
|
10
|
+
const utils_3 = require("./utils");
|
|
11
|
+
const csvWriter_1 = require("../csvWriter");
|
|
11
12
|
const fs = require('fs-extra');
|
|
12
13
|
const settings = (0, localSettings_1.loadSettings)();
|
|
13
14
|
async function updatekey(flags, file_subpath, file_items) {
|
|
15
|
+
const csvWriter = new csvWriter_1.default();
|
|
14
16
|
const baseInputDir = (0, path_1.join)((flags["es-csv"] || settings['easysources-csv-path'] || constants_1.DEFAULT_ESCSV_PATH), file_subpath);
|
|
15
17
|
const inputFiles = (flags.input);
|
|
16
18
|
if (!fs.existsSync(baseInputDir)) {
|
|
17
|
-
|
|
18
|
-
return;
|
|
19
|
+
return (0, utils_3.jsonAndPrintError)(`Input folder ${baseInputDir} does not exist`);
|
|
19
20
|
}
|
|
21
|
+
// Initialize result object
|
|
22
|
+
const result = { result: 'OK', items: {} };
|
|
20
23
|
var dirList = [];
|
|
21
24
|
if (inputFiles) {
|
|
22
25
|
dirList = inputFiles.split(',');
|
|
@@ -29,30 +32,41 @@ async function updatekey(flags, file_subpath, file_items) {
|
|
|
29
32
|
// dir is the file name without the extension
|
|
30
33
|
for (const dir of dirList) {
|
|
31
34
|
console.log('UpdateKey: ' + dir);
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
35
|
+
try {
|
|
36
|
+
// tag_Section is each file section (applicationVisibilities, classAccess ecc)
|
|
37
|
+
for (const tag_section in file_items) {
|
|
38
|
+
const csvFilePath = (0, path_1.join)(baseInputDir, dir, (0, filesUtils_1.calcCsvFilename)(dir, tag_section));
|
|
39
|
+
if (fs.existsSync(csvFilePath)) {
|
|
40
|
+
var jsonArray = await (0, filesUtils_1.readCsvToJsonArray)(csvFilePath);
|
|
41
|
+
(0, utils_2.generateTagId)(jsonArray, file_items[tag_section].key, file_items[tag_section].headers);
|
|
42
|
+
if (flags.sort === 'true') {
|
|
43
|
+
jsonArray = (0, utils_1.sortByKey)(jsonArray);
|
|
44
|
+
}
|
|
45
|
+
const headers = file_items[tag_section].headers;
|
|
46
|
+
try {
|
|
47
|
+
const csvContent = await csvWriter.toCsv(jsonArray, headers);
|
|
48
|
+
fs.writeFileSync(csvFilePath, csvContent, { flag: 'w+' });
|
|
49
|
+
// file written successfully
|
|
50
|
+
}
|
|
51
|
+
catch (err) {
|
|
52
|
+
console.error(err);
|
|
53
|
+
throw new Error(`Failed to write CSV file ${csvFilePath}: ${err.message}`);
|
|
54
|
+
}
|
|
51
55
|
}
|
|
52
56
|
}
|
|
57
|
+
// Directory processed successfully
|
|
58
|
+
result.items[dir] = { result: 'OK' };
|
|
59
|
+
}
|
|
60
|
+
catch (error) {
|
|
61
|
+
// Directory processing failed
|
|
62
|
+
console.error(`Error processing directory ${dir}:`, error);
|
|
63
|
+
result.items[dir] = {
|
|
64
|
+
result: 'KO',
|
|
65
|
+
error: error.message || 'Unknown error occurred'
|
|
66
|
+
};
|
|
53
67
|
}
|
|
54
68
|
}
|
|
55
|
-
return
|
|
69
|
+
return result;
|
|
56
70
|
}
|
|
57
71
|
exports.updatekey = updatekey;
|
|
58
72
|
//# sourceMappingURL=keyupdater.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keyupdater.js","sourceRoot":"","sources":["../../../src/utils/commands/keyupdater.ts"],"names":[],"mappings":";;;AAAA,8CAAmE;AACnE,oCAAoC;AACpC,oCAAwC;AACxC
|
|
1
|
+
{"version":3,"file":"keyupdater.js","sourceRoot":"","sources":["../../../src/utils/commands/keyupdater.ts"],"names":[],"mappings":";;;AAAA,8CAAmE;AACnE,oCAAoC;AACpC,oCAAwC;AACxC,+BAA4B;AAC5B,sDAA4D;AAC5D,oDAAgD;AAChD,mCAA4C;AAC5C,4CAAqC;AACrC,MAAM,EAAE,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;AAE/B,MAAM,QAAQ,GAAG,IAAA,4BAAY,GAAE,CAAC;AAEzB,KAAK,UAAU,SAAS,CAAC,KAAK,EAAE,YAAY,EAAE,UAAU;IAC3D,MAAM,SAAS,GAAG,IAAI,mBAAS,EAAE,CAAC;IAElC,MAAM,YAAY,GAAG,IAAA,WAAI,EAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,QAAQ,CAAC,sBAAsB,CAAC,IAAI,8BAAkB,CAAC,EAAE,YAAY,CAAW,CAAC;IAC/H,MAAM,UAAU,GAAG,CAAC,KAAK,CAAC,KAAK,CAAW,CAAC;IAE3C,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,YAAY,CAAC,EAAE;QAC9B,OAAO,IAAA,yBAAiB,EAA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C,WAAW,CAAC,CAAC,OAAO,CAAC;oBAEhD,IAAI;wBACA,MAAM,UAAU,GAAG,MAAM,SAAS,CAAC,KAAK,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;wBAC7D,EAAE,CAAC,aAAa,CAAC,WAAW,EAAE,UAAU,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;wBAC1D,4BAA4B;qBAC/B;oBAAC,OAAO,GAAG,EAAE;wBACV,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;wBACnB,MAAM,IAAI,KAAK,CAAC,4BAA4B,WAAW,KAAK,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC;qBAE9E;iBACJ;aACJ;YAED,mCAAmC;YACnC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;SAExC;QAAC,OAAO,KAAK,EAAE;YACZ,8BAA8B;YAC9B,OAAO,CAAC,KAAK,CAAC,8BAA8B,GAAG,GAAG,EAAE,KAAK,CAAC,CAAC;YAC3D,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG;gBAChB,MAAM,EAAE,IAAI;gBACZ,KAAK,EAAE,KAAK,CAAC,OAAO,IAAI,wBAAwB;aACnD,CAAC;SACL;KACJ;IAED,OAAO,MAAM,CAAC;AAClB,CAAC;AApED,8BAoEC"}
|
|
@@ -9,5 +9,9 @@
|
|
|
9
9
|
*/
|
|
10
10
|
export declare function mergeItemFromCsv(itemName: string, csvDirPath: string, file_root_tag: string, file_items: any, flags: any): Promise<any>;
|
|
11
11
|
export declare function merge(flags: any, file_subpath: any, file_extension: any, file_root_tag: any, file_items: any): Promise<{
|
|
12
|
+
error: string;
|
|
12
13
|
result: string;
|
|
14
|
+
} | {
|
|
15
|
+
result: string;
|
|
16
|
+
items: {};
|
|
13
17
|
}>;
|
|
@@ -8,6 +8,7 @@ const filesUtils_1 = require("../filesUtils");
|
|
|
8
8
|
const utils_1 = require("../utils");
|
|
9
9
|
const localSettings_1 = require("../localSettings");
|
|
10
10
|
const flatArrayUtils_1 = require("../flatArrayUtils");
|
|
11
|
+
const utils_2 = require("./utils");
|
|
11
12
|
const settings = (0, localSettings_1.loadSettings)();
|
|
12
13
|
/**
|
|
13
14
|
* Core merge logic that creates merged XML from CSV files in memory
|
|
@@ -54,9 +55,10 @@ async function merge(flags, file_subpath, file_extension, file_root_tag, file_it
|
|
|
54
55
|
const baseOutputDir = (0, path_1.join)((flags["sf-xml"] || settings['salesforce-xml-path'] || constants_1.DEFAULT_SFXML_PATH), file_subpath);
|
|
55
56
|
const inputProfile = (flags.input);
|
|
56
57
|
if (!fs.existsSync(baseInputDir)) {
|
|
57
|
-
|
|
58
|
-
return;
|
|
58
|
+
return (0, utils_2.jsonAndPrintError)(`Input folder ${baseInputDir} does not exist`);
|
|
59
59
|
}
|
|
60
|
+
// Initialize result object
|
|
61
|
+
const result = { result: 'OK', items: {} };
|
|
60
62
|
var dirList = [];
|
|
61
63
|
if (inputProfile) {
|
|
62
64
|
dirList = inputProfile.split(',');
|
|
@@ -77,14 +79,18 @@ async function merge(flags, file_subpath, file_extension, file_root_tag, file_it
|
|
|
77
79
|
const mergedXml = await mergeItemFromCsv(dir, csvDirPath, file_root_tag, file_items, flags);
|
|
78
80
|
const outputFile = (0, path_1.join)(baseOutputDir, dir + file_extension);
|
|
79
81
|
(0, filesUtils_1.writeXmlToFile)(outputFile, mergedXml);
|
|
82
|
+
// Directory processed successfully
|
|
83
|
+
result.items[dir] = { result: 'OK' };
|
|
80
84
|
}
|
|
81
85
|
catch (error) {
|
|
82
86
|
console.log(`Error merging ${dir}: ${error.message}. Skipping...`);
|
|
83
|
-
|
|
87
|
+
result.items[dir] = {
|
|
88
|
+
result: 'KO',
|
|
89
|
+
error: error.message || 'Unknown error occurred'
|
|
90
|
+
};
|
|
84
91
|
}
|
|
85
92
|
}
|
|
86
|
-
|
|
87
|
-
return { result };
|
|
93
|
+
return result;
|
|
88
94
|
}
|
|
89
95
|
exports.merge = merge;
|
|
90
96
|
//# sourceMappingURL=merger.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"merger.js","sourceRoot":"","sources":["../../../src/utils/commands/merger.ts"],"names":[],"mappings":";;;AAAA,MAAM,EAAE,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;AAC/B,+BAA4B;AAC5B,sDAAmG;AACnG,8CAAoG;AACpG,oCAAoC;AACpC,oDAAgD;AAChD,sDAAgD;
|
|
1
|
+
{"version":3,"file":"merger.js","sourceRoot":"","sources":["../../../src/utils/commands/merger.ts"],"names":[],"mappings":";;;AAAA,MAAM,EAAE,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;AAC/B,+BAA4B;AAC5B,sDAAmG;AACnG,8CAAoG;AACpG,oCAAoC;AACpC,oDAAgD;AAChD,sDAAgD;AAChD,mCAA4C;AAE5C,MAAM,QAAQ,GAAG,IAAA,4BAAY,GAAE,CAAC;AAEhC;;;;;;;;GAQG;AACI,KAAK,UAAU,gBAAgB,CAAC,QAAgB,EAAE,UAAkB,EAAE,aAAqB,EAAE,UAAe,EAAE,KAAU;IAC3H,MAAM,QAAQ,GAAG,IAAA,WAAI,EAAC,UAAU,EAAE,QAAQ,CAAC,GAAG,8BAAkB,CAAC;IAEjE,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE;QAC1B,MAAM,IAAI,KAAK,CAAC,GAAG,QAAQ,YAAY,CAAC,CAAC;KAC5C;IAED,MAAM,SAAS,GAAG,CAAC,MAAM,IAAA,4BAAe,EAAC,QAAQ,CAAC,CAAC,IAAI,EAAE,CAAC;IAE1D,8EAA8E;IAC9E,KAAK,MAAM,WAAW,IAAI,UAAU,EAAE;QAClC,MAAM,WAAW,GAAG,IAAA,WAAI,EAAC,UAAU,EAAE,IAAA,4BAAe,EAAC,QAAQ,EAAE,WAAW,CAAC,CAAC,CAAC;QAC7E,IAAI,EAAE,CAAC,UAAU,CAAC,W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QAAC,OAAO,KAAK,EAAE;YACZ,OAAO,CAAC,GAAG,CAAC,iBAAiB,GAAG,KAAK,KAAK,CAAC,OAAO,eAAe,CAAC,CAAC;YACnE,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG;gBAChB,MAAM,EAAE,IAAI;gBACZ,KAAK,EAAE,KAAK,CAAC,OAAO,IAAI,wBAAwB;aACnD,CAAC;SACL;KACJ;IAED,OAAO,MAAM,CAAC;AAClB,CAAC;AA9CD,sBA8CC"}
|
|
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.split = void 0;
|
|
4
4
|
const filesUtils_1 = require("../filesUtils");
|
|
5
5
|
const utils_1 = require("../utils");
|
|
6
|
-
const { Parser, transforms: { unwind } } = require('json2csv');
|
|
7
6
|
const path_1 = require("path");
|
|
8
7
|
const fs = require('fs-extra');
|
|
9
8
|
const utils_2 = require("../utils");
|
|
@@ -11,16 +10,21 @@ const constants_1 = require("../constants/constants");
|
|
|
11
10
|
const constants_profiles_1 = require("../constants/constants_profiles");
|
|
12
11
|
const localSettings_1 = require("../localSettings");
|
|
13
12
|
const flatArrayUtils_1 = require("../flatArrayUtils");
|
|
13
|
+
const utils_3 = require("./utils");
|
|
14
|
+
const csvWriter_1 = require("../csvWriter");
|
|
15
|
+
const utils_4 = require("./utils");
|
|
14
16
|
const settings = (0, localSettings_1.loadSettings)();
|
|
15
17
|
async function split(flags, file_subpath, file_extension, file_root_tag, file_items) {
|
|
18
|
+
const csvWriter = new csvWriter_1.default();
|
|
16
19
|
const baseInputDir = (0, path_1.join)((flags["sf-xml"] || settings['salesforce-xml-path'] || constants_1.DEFAULT_SFXML_PATH), file_subpath);
|
|
17
20
|
const baseOutputDir = (0, path_1.join)((flags["es-csv"] || settings['easysources-csv-path'] || constants_1.DEFAULT_ESCSV_PATH), file_subpath);
|
|
18
21
|
const ignoreUserPerm = (file_subpath === constants_profiles_1.PROFILES_SUBPATH && (flags.ignoreuserperm === 'true' || settings['ignore-user-permissions']) || false);
|
|
19
22
|
const inputFiles = (flags.input);
|
|
20
23
|
if (!fs.existsSync(baseInputDir)) {
|
|
21
|
-
|
|
22
|
-
return;
|
|
24
|
+
return (0, utils_3.jsonAndPrintError)(`Input folder ${baseInputDir} does not exist`);
|
|
23
25
|
}
|
|
26
|
+
// Initialize result object
|
|
27
|
+
const result = { result: 'OK', items: {} };
|
|
24
28
|
var fileList = [];
|
|
25
29
|
if (inputFiles) {
|
|
26
30
|
fileList = inputFiles.split(',');
|
|
@@ -33,58 +37,68 @@ async function split(flags, file_subpath, file_extension, file_root_tag, file_it
|
|
|
33
37
|
for (const filename of fileList) {
|
|
34
38
|
const fullFilename = filename.endsWith(file_extension) ? filename : filename + file_extension;
|
|
35
39
|
console.log('Splitting: ' + fullFilename);
|
|
36
|
-
const inputFile = (0, path_1.join)(baseInputDir, fullFilename);
|
|
37
|
-
const xmlFileContent = (await (0, filesUtils_1.readXmlFromFile)(inputFile)) ?? {};
|
|
38
|
-
const fileProperties = xmlFileContent[file_root_tag] ?? {};
|
|
39
40
|
const fileName = (0, filesUtils_1.removeExtension)(fullFilename);
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
if (
|
|
47
|
-
|
|
48
|
-
continue;
|
|
49
|
-
}
|
|
50
|
-
var myjson = fileProperties[tag_section];
|
|
51
|
-
// skip when tag is not found in the xml
|
|
52
|
-
if (myjson == undefined)
|
|
53
|
-
continue;
|
|
54
|
-
// fixes scenarios when the tag is one, since it would be read as object and not array
|
|
55
|
-
if (!Array.isArray(myjson))
|
|
56
|
-
myjson = [myjson];
|
|
57
|
-
myjson = (0, flatArrayUtils_1.arrayToFlat)(myjson);
|
|
58
|
-
// generate _tagId column
|
|
59
|
-
(0, utils_1.generateTagId)(myjson, file_items[tag_section].key, file_items[tag_section].headers);
|
|
60
|
-
// sorts array by _tagid. sorting is made as string
|
|
61
|
-
if (flags.sort === 'true') {
|
|
62
|
-
myjson = (0, utils_2.sortByKey)(myjson);
|
|
41
|
+
try {
|
|
42
|
+
const inputFile = (0, path_1.join)(baseInputDir, fullFilename);
|
|
43
|
+
const xmlFileContent = (await (0, filesUtils_1.readXmlFromFile)(inputFile)) ?? {};
|
|
44
|
+
const fileProperties = xmlFileContent[file_root_tag] ?? {};
|
|
45
|
+
const outputDir = (0, path_1.join)(baseOutputDir, fileName);
|
|
46
|
+
// Delete outputDir if it exists to ensure a clean split
|
|
47
|
+
if (fs.existsSync(outputDir)) {
|
|
48
|
+
fs.removeSync(outputDir);
|
|
63
49
|
}
|
|
64
|
-
const
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
50
|
+
for (const tag_section in file_items) {
|
|
51
|
+
if (ignoreUserPerm && tag_section == constants_profiles_1.PROFILE_USERPERM_ROOT) {
|
|
52
|
+
xmlFileContent[file_root_tag][tag_section] = null;
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
var myjson = fileProperties[tag_section];
|
|
56
|
+
// skip when tag is not found in the xml
|
|
57
|
+
if (myjson == undefined)
|
|
58
|
+
continue;
|
|
59
|
+
// fixes scenarios when the tag is one, since it would be read as object and not array
|
|
60
|
+
if (!Array.isArray(myjson))
|
|
61
|
+
myjson = [myjson];
|
|
62
|
+
myjson = (0, flatArrayUtils_1.arrayToFlat)(myjson);
|
|
63
|
+
// generate _tagId column
|
|
64
|
+
(0, utils_1.generateTagId)(myjson, file_items[tag_section].key, file_items[tag_section].headers);
|
|
65
|
+
// sorts array by _tagid. sorting is made as string
|
|
66
|
+
if (flags.sort === 'true') {
|
|
67
|
+
myjson = (0, utils_2.sortByKey)(myjson);
|
|
68
|
+
}
|
|
69
|
+
const headers = file_items[tag_section].headers;
|
|
70
|
+
const outputFileCSV = (0, path_1.join)(outputDir, (0, filesUtils_1.calcCsvFilename)(fileName, tag_section));
|
|
71
|
+
if (!fs.existsSync(outputDir)) {
|
|
72
|
+
fs.mkdirSync(outputDir, { recursive: true });
|
|
73
|
+
}
|
|
74
|
+
try {
|
|
75
|
+
const csvContent = await csvWriter.toCsv(myjson, headers);
|
|
76
|
+
fs.writeFileSync(outputFileCSV, csvContent, { flag: 'w+' });
|
|
77
|
+
// file written successfully
|
|
78
|
+
}
|
|
79
|
+
catch (err) {
|
|
80
|
+
console.error(err);
|
|
81
|
+
}
|
|
82
|
+
xmlFileContent[file_root_tag][tag_section] = null;
|
|
76
83
|
}
|
|
77
|
-
|
|
78
|
-
|
|
84
|
+
if (fs.existsSync(outputDir)) {
|
|
85
|
+
const outputFileXML = (0, path_1.join)(outputDir, fileName + constants_1.XML_PART_EXTENSION);
|
|
86
|
+
xmlFileContent[file_root_tag] = (0, utils_4.sortObjectKeys)(xmlFileContent[file_root_tag]);
|
|
87
|
+
(0, filesUtils_1.writeXmlToFile)(outputFileXML, xmlFileContent);
|
|
79
88
|
}
|
|
80
|
-
|
|
89
|
+
// File processed successfully
|
|
90
|
+
result.items[fileName] = { result: 'OK' };
|
|
81
91
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
92
|
+
catch (error) {
|
|
93
|
+
// File processing failed
|
|
94
|
+
console.error(`Error processing file ${fullFilename}:`, error);
|
|
95
|
+
result.items[fileName] = {
|
|
96
|
+
result: 'KO',
|
|
97
|
+
error: error.message || 'Unknown error occurred'
|
|
98
|
+
};
|
|
85
99
|
}
|
|
86
100
|
}
|
|
87
|
-
return
|
|
101
|
+
return result;
|
|
88
102
|
}
|
|
89
103
|
exports.split = split;
|
|
90
104
|
//# sourceMappingURL=splitter.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"splitter.js","sourceRoot":"","sources":["../../../src/utils/commands/splitter.ts"],"names":[],"mappings":";;;AAAA,8CAAiG;AACjG,oCAAwC;AACxC
|
|
1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AC;oBAC5D,4BAA4B;iBAC/B;gBAAC,OAAO,GAAG,EAAE;oBACV,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;iBACtB;gBACD,cAAc,CAAC,aAAa,CAAC,CAAC,WAAW,CAAC,GAAG,IAAI,CAAC;aACrD;YAED,IAAI,EAAE,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE;gBAC1B,MAAM,aAAa,GAAG,IAAA,WAAI,EAAC,SAAS,EAAE,QAAQ,GAAG,8BAAkB,CAAC,CAAC;gBACrE,cAAc,CAAC,aAAa,CAAC,GAAG,IAAA,sBAAc,EAAC,cAAc,CAAC,aAAa,CAAC,CAAC,CAAC;gBAC9E,IAAA,2BAAc,EAAC,aAAa,EAAE,cAAc,CAAC,CAAC;aACjD;YAED,8BAA8B;YAC9B,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;SAC7C;QAAC,OAAO,KAAK,EAAE;YACZ,yBAAyB;YACzB,OAAO,CAAC,KAAK,CAAC,yBAAyB,YAAY,GAAG,EAAE,KAAK,CAAC,CAAC;YAC/D,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAG;gBACrB,MAAM,EAAE,IAAI;gBACZ,KAAK,EAAE,KAAK,CAAC,OAAO,IAAI,wBAAwB;aACnD,CAAC;SACL;KACJ;IAED,OAAO,MAAM,CAAC;AAClB,CAAC;AAnGD,sBAmGC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export declare function upsert(flags: any, file_subpath: any, file_extension: any, file_root_tag: any, file_items: any): Promise<{
|
|
2
2
|
error: string;
|
|
3
|
-
|
|
3
|
+
result: string;
|
|
4
4
|
} | {
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
result: string;
|
|
6
|
+
items: {};
|
|
7
7
|
}>;
|