@ds-sfdc/sfparty 1.3.15 → 1.4.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/package.json +2 -5
- package/src/index.js +39 -9
- package/src/party/combine.js +78 -53
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ds-sfdc/sfparty",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"description": "Salesforce metadata XML splitter for CI/CD",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
@@ -24,7 +24,6 @@
|
|
|
24
24
|
"license": "BSD-3-Clause",
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"axios": "^1.2.2",
|
|
27
|
-
"chai-as-promised": "^7.1.1",
|
|
28
27
|
"cli-color": "^2.0.3",
|
|
29
28
|
"cli-spinners": "^2.7.0",
|
|
30
29
|
"convert-hrtime": "^5.0.0",
|
|
@@ -48,10 +47,8 @@
|
|
|
48
47
|
"babel-jest": "^29.3.1",
|
|
49
48
|
"husky": "^8.0.3",
|
|
50
49
|
"jest": "^29.3.1",
|
|
51
|
-
"mocha": "^10.2.0",
|
|
52
50
|
"nodemon": "^2.0.20",
|
|
53
|
-
"prettier": "^2.8.3"
|
|
54
|
-
"should": "^7.1.0"
|
|
51
|
+
"prettier": "^2.8.3"
|
|
55
52
|
},
|
|
56
53
|
"engines": {
|
|
57
54
|
"node": ">=0.11"
|
package/src/index.js
CHANGED
|
@@ -4,6 +4,7 @@ import { spawnSync, spawn, execSync } from 'child_process'
|
|
|
4
4
|
import fs from 'fs'
|
|
5
5
|
import path from 'path'
|
|
6
6
|
import yargs from 'yargs'
|
|
7
|
+
import xml2js from 'xml2js'
|
|
7
8
|
import { hideBin } from 'yargs/helpers'
|
|
8
9
|
import winston from 'winston'
|
|
9
10
|
import clc from 'cli-color'
|
|
@@ -22,6 +23,7 @@ import * as permsetDefinition from './meta/PermissionSets.js'
|
|
|
22
23
|
import * as workflowDefinition from './meta/Workflows.js'
|
|
23
24
|
import { checkVersion } from './lib/checkVersion.js'
|
|
24
25
|
import * as git from './lib/gitUtils.js'
|
|
26
|
+
import * as packageUtil from './lib/packageUtil.js'
|
|
25
27
|
|
|
26
28
|
const processStartTime = process.hrtime.bigint()
|
|
27
29
|
|
|
@@ -109,7 +111,8 @@ let errorMessage = clc.red(
|
|
|
109
111
|
clc.whiteBright.bgRedBright('combine') +
|
|
110
112
|
'.',
|
|
111
113
|
)
|
|
112
|
-
|
|
114
|
+
let addPkg
|
|
115
|
+
let desPkg
|
|
113
116
|
displayHeader() // display header mast
|
|
114
117
|
|
|
115
118
|
let checkYargs = false
|
|
@@ -254,7 +257,32 @@ yargs(hideBin(process.argv))
|
|
|
254
257
|
})
|
|
255
258
|
startProm.then((result) => {
|
|
256
259
|
global.git.enabled = result
|
|
257
|
-
|
|
260
|
+
|
|
261
|
+
if (global.git.enabled) {
|
|
262
|
+
let addManifest =
|
|
263
|
+
argv.package || 'manifest/package-party.xml'
|
|
264
|
+
let desManifest =
|
|
265
|
+
argv.destructive ||
|
|
266
|
+
'manifest/destructiveChanges-party.xml'
|
|
267
|
+
|
|
268
|
+
addPkg = new packageUtil.Package(addManifest)
|
|
269
|
+
desPkg = new packageUtil.Package(desManifest)
|
|
270
|
+
const prom1 = addPkg.getPackageXML(fileUtils)
|
|
271
|
+
const prom2 = desPkg.getPackageXML(fileUtils)
|
|
272
|
+
|
|
273
|
+
Promise.allSettled([prom1, prom2]).then((results) => {
|
|
274
|
+
const rejected = results.filter(
|
|
275
|
+
(p) => p.status === 'rejected',
|
|
276
|
+
)
|
|
277
|
+
if (rejected.length > 0) {
|
|
278
|
+
throw new Error(rejected[0].value)
|
|
279
|
+
} else {
|
|
280
|
+
combineHandler(argv, processStartTime)
|
|
281
|
+
}
|
|
282
|
+
})
|
|
283
|
+
} else {
|
|
284
|
+
combineHandler(argv, processStartTime)
|
|
285
|
+
}
|
|
258
286
|
})
|
|
259
287
|
startProm.catch((error) => {
|
|
260
288
|
global.displayError(error, true)
|
|
@@ -565,6 +593,10 @@ function combineHandler(argv, startTime) {
|
|
|
565
593
|
fs,
|
|
566
594
|
})
|
|
567
595
|
}
|
|
596
|
+
if (global.git.enabled) {
|
|
597
|
+
addPkg.savePackage(xml2js, fileUtils)
|
|
598
|
+
desPkg.savePackage(xml2js, fileUtils)
|
|
599
|
+
}
|
|
568
600
|
if (argv.type === undefined || argv.type.split(',').length > 1) {
|
|
569
601
|
let message = `Split completed in `
|
|
570
602
|
displayMessageAndDuration(startTime, message)
|
|
@@ -599,8 +631,6 @@ function processCombine(typeItem, argv) {
|
|
|
599
631
|
let name = argv.name
|
|
600
632
|
let all =
|
|
601
633
|
argv.type === undefined || name === undefined ? true : argv.all
|
|
602
|
-
let addManifest = argv.package
|
|
603
|
-
let desManifest = argv.destructive
|
|
604
634
|
|
|
605
635
|
sourceDir = path.join(
|
|
606
636
|
global.__basedir,
|
|
@@ -680,13 +710,13 @@ function processCombine(typeItem, argv) {
|
|
|
680
710
|
processList.forEach((metaDir) => {
|
|
681
711
|
const metadataItem = new metadataCombine.Combine({
|
|
682
712
|
metadataDefinition: typeObj.definition,
|
|
683
|
-
sourceDir
|
|
684
|
-
targetDir
|
|
685
|
-
metaDir
|
|
713
|
+
sourceDir,
|
|
714
|
+
targetDir,
|
|
715
|
+
metaDir,
|
|
686
716
|
sequence: promList.length + 1,
|
|
687
717
|
total: processed.total,
|
|
688
|
-
|
|
689
|
-
|
|
718
|
+
addPkg,
|
|
719
|
+
desPkg,
|
|
690
720
|
})
|
|
691
721
|
const metadataItemProm = metadataItem.combine()
|
|
692
722
|
promList.push(metadataItemProm)
|
package/src/party/combine.js
CHANGED
|
@@ -15,7 +15,6 @@ const processed = {
|
|
|
15
15
|
current: 0,
|
|
16
16
|
type: undefined,
|
|
17
17
|
}
|
|
18
|
-
|
|
19
18
|
export class Combine {
|
|
20
19
|
#type = undefined
|
|
21
20
|
#root = undefined
|
|
@@ -33,8 +32,7 @@ export class Combine {
|
|
|
33
32
|
mtime: undefined,
|
|
34
33
|
}
|
|
35
34
|
#json = {}
|
|
36
|
-
#
|
|
37
|
-
#desPkg = undefined
|
|
35
|
+
#diffOnly = false
|
|
38
36
|
|
|
39
37
|
constructor(config) {
|
|
40
38
|
this.metadataDefinition = config.metadataDefinition
|
|
@@ -43,9 +41,8 @@ export class Combine {
|
|
|
43
41
|
this.metaDir = config.metaDir
|
|
44
42
|
this.sequence = config.sequence
|
|
45
43
|
this.total = config.total
|
|
46
|
-
this.
|
|
47
|
-
this.
|
|
48
|
-
config.desManifest || 'manifest/destructiveChanges-party.xml'
|
|
44
|
+
this.addPkg = config.addPkg
|
|
45
|
+
this.desPkg = config.desPkg
|
|
49
46
|
}
|
|
50
47
|
|
|
51
48
|
get metadataDefinition() {
|
|
@@ -86,6 +83,12 @@ export class Combine {
|
|
|
86
83
|
combine() {
|
|
87
84
|
return new Promise((resolve, reject) => {
|
|
88
85
|
const that = this
|
|
86
|
+
that.#diffOnly =
|
|
87
|
+
global.metaTypes[that.metadataDefinition.alias].add.files
|
|
88
|
+
.length > 0 ||
|
|
89
|
+
global.metaTypes[that.metadataDefinition.alias].remove.files
|
|
90
|
+
.length > 0
|
|
91
|
+
|
|
89
92
|
if (!fileUtils.directoryExists({ dirPath: that.sourceDir, fs }))
|
|
90
93
|
reject(`Path does not exist: ${that.sourceDir}`)
|
|
91
94
|
let types = ['directories', 'singleFiles', 'main']
|
|
@@ -111,38 +114,39 @@ export class Combine {
|
|
|
111
114
|
that.#json[key] = undefined
|
|
112
115
|
})
|
|
113
116
|
|
|
114
|
-
|
|
115
|
-
that.#addPkg = new packageUtil.Package(that.addManifest)
|
|
116
|
-
that.#desPkg = new packageUtil.Package(that.desManifest)
|
|
117
|
-
const prom1 = that.#addPkg.getPackageXML(fileUtils)
|
|
118
|
-
const prom2 = that.#desPkg.getPackageXML(fileUtils)
|
|
119
|
-
|
|
120
|
-
Promise.allSettled([prom1, prom2]).then((results) => {
|
|
121
|
-
const rejected = results.filter(
|
|
122
|
-
(p) => p.status === 'rejected',
|
|
123
|
-
)
|
|
124
|
-
if (rejected.length > 0) {
|
|
125
|
-
reject(rejected[0].value)
|
|
126
|
-
} else {
|
|
127
|
-
resolve(processStart(that))
|
|
128
|
-
}
|
|
129
|
-
})
|
|
130
|
-
} else {
|
|
131
|
-
resolve(processStart(that))
|
|
132
|
-
}
|
|
117
|
+
resolve(processStart(that))
|
|
133
118
|
})
|
|
134
119
|
|
|
135
120
|
function processStart(that) {
|
|
136
|
-
let success =
|
|
121
|
+
let success = processParts(that)
|
|
137
122
|
if (success) {
|
|
138
123
|
if (
|
|
139
124
|
!that.metadataDefinition.packageTypeIsDirectory &&
|
|
140
125
|
global.git.enabled
|
|
141
126
|
) {
|
|
142
|
-
|
|
127
|
+
if (
|
|
128
|
+
!that.#diffOnly ||
|
|
129
|
+
global.metaTypes[that.metadataDefinition.alias].add
|
|
130
|
+
.files.length > 0
|
|
131
|
+
) {
|
|
132
|
+
that.addPkg.addMember(
|
|
133
|
+
that.#root,
|
|
134
|
+
that.#fileName.shortName,
|
|
135
|
+
)
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
if (
|
|
139
|
+
that.#diffOnly &&
|
|
140
|
+
global.metaTypes[that.metadataDefinition.alias].remove
|
|
141
|
+
.files.length > 0
|
|
142
|
+
) {
|
|
143
|
+
that.desPkg.addMember(
|
|
144
|
+
that.#root,
|
|
145
|
+
that.#fileName.shortName,
|
|
146
|
+
)
|
|
147
|
+
}
|
|
143
148
|
}
|
|
144
149
|
saveXML(that)
|
|
145
|
-
if (global.git.enabled) savePackageXML(that)
|
|
146
150
|
return true
|
|
147
151
|
} else {
|
|
148
152
|
logUpdate(
|
|
@@ -168,20 +172,14 @@ export class Combine {
|
|
|
168
172
|
!that.metadataDefinition.packageTypeIsDirectory &&
|
|
169
173
|
global.git.enabled
|
|
170
174
|
) {
|
|
171
|
-
that
|
|
175
|
+
that.desPkg.addMember(that.#root, that.#fileName.shortName)
|
|
172
176
|
}
|
|
173
|
-
deleteFile(that.#fileName.fullName)
|
|
174
|
-
if (global.git.enabled) savePackageXML(that)
|
|
177
|
+
deleteFile(that, that.#fileName.fullName)
|
|
175
178
|
return 'deleted'
|
|
176
179
|
}
|
|
177
180
|
}
|
|
178
181
|
|
|
179
|
-
function
|
|
180
|
-
that.#addPkg.savePackage(xml2js, fileUtils)
|
|
181
|
-
that.#desPkg.savePackage(xml2js, fileUtils)
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
function getXML(that) {
|
|
182
|
+
function processParts(that) {
|
|
185
183
|
if (processed.type != that.#root) {
|
|
186
184
|
processed.current = 0
|
|
187
185
|
processed.type = that.#root
|
|
@@ -320,11 +318,28 @@ export class Combine {
|
|
|
320
318
|
processFile(that, key, fileObj)
|
|
321
319
|
})
|
|
322
320
|
}
|
|
321
|
+
|
|
322
|
+
const filteredArray = global.metaTypes[
|
|
323
|
+
that.metadataDefinition.alias
|
|
324
|
+
].remove.files.filter((filePath) =>
|
|
325
|
+
filePath.startsWith(
|
|
326
|
+
path.join(that.sourceDir, that.metaDir, key),
|
|
327
|
+
),
|
|
328
|
+
)
|
|
329
|
+
filteredArray.forEach((file) => {
|
|
330
|
+
const fileObj = {
|
|
331
|
+
shortName: path.basename(file),
|
|
332
|
+
fullName: file,
|
|
333
|
+
}
|
|
334
|
+
processFile(that, key, fileObj)
|
|
335
|
+
})
|
|
336
|
+
|
|
323
337
|
return true
|
|
324
338
|
}
|
|
325
339
|
|
|
326
|
-
function deleteFile(fileName) {
|
|
340
|
+
function deleteFile(that, fileName) {
|
|
327
341
|
fileUtils.deleteFile(fileName)
|
|
342
|
+
fileUtils.deleteDirectory(path.join(that.sourceDir, that.metaDir))
|
|
328
343
|
}
|
|
329
344
|
|
|
330
345
|
function processFile(
|
|
@@ -349,6 +364,16 @@ export class Combine {
|
|
|
349
364
|
)
|
|
350
365
|
}
|
|
351
366
|
|
|
367
|
+
const diffFiles = global.metaTypes[
|
|
368
|
+
that.metadataDefinition.alias
|
|
369
|
+
].add.files.concat(
|
|
370
|
+
global.metaTypes[that.metadataDefinition.alias].remove.files,
|
|
371
|
+
)
|
|
372
|
+
|
|
373
|
+
if (that.#diffOnly) {
|
|
374
|
+
if (!diffFiles.includes(fileObj.fullName)) return true
|
|
375
|
+
}
|
|
376
|
+
|
|
352
377
|
if (!fileUtils.fileExists({ filePath: fileObj.fullName, fs })) {
|
|
353
378
|
// File does not exist
|
|
354
379
|
// If file is main.yaml, then return false to indicate that the XML file should be deleted
|
|
@@ -375,19 +400,19 @@ export class Combine {
|
|
|
375
400
|
path.dirname(fileObj.fullName).split('/').pop() in
|
|
376
401
|
that.metadataDefinition.package
|
|
377
402
|
) {
|
|
378
|
-
that
|
|
403
|
+
that.desPkg.addMember(
|
|
379
404
|
that.metadataDefinition.package[
|
|
380
|
-
|
|
381
|
-
'.' +
|
|
382
|
-
path
|
|
383
|
-
.dirname(fileObj.fullName)
|
|
384
|
-
.split('/')
|
|
385
|
-
.pop()
|
|
405
|
+
path.dirname(fileObj.fullName).split('/').pop()
|
|
386
406
|
],
|
|
387
|
-
|
|
407
|
+
that.#fileName.shortName +
|
|
408
|
+
'.' +
|
|
409
|
+
fileObj.shortName.replace(
|
|
410
|
+
`.${global.format}`,
|
|
411
|
+
'',
|
|
412
|
+
),
|
|
388
413
|
)
|
|
389
414
|
} else if (that.metadataDefinition.packageTypeIsDirectory) {
|
|
390
|
-
that
|
|
415
|
+
that.desPkg.addMember(
|
|
391
416
|
that.#root,
|
|
392
417
|
fileObj.shortName.replace(`.${global.format}`, ''),
|
|
393
418
|
)
|
|
@@ -459,16 +484,16 @@ export class Combine {
|
|
|
459
484
|
path.dirname(fileObj.fullName).split('/').pop() in
|
|
460
485
|
that.metadataDefinition.package
|
|
461
486
|
) {
|
|
462
|
-
that
|
|
487
|
+
that.addPkg.addMember(
|
|
463
488
|
that.metadataDefinition.package[
|
|
464
|
-
|
|
465
|
-
'.' +
|
|
466
|
-
path.dirname(fileObj.fullName).split('/').pop()
|
|
489
|
+
path.dirname(fileObj.fullName).split('/').pop()
|
|
467
490
|
],
|
|
468
|
-
|
|
491
|
+
that.#fileName.shortName +
|
|
492
|
+
'.' +
|
|
493
|
+
fileObj.shortName.replace(`.${global.format}`, ''),
|
|
469
494
|
)
|
|
470
495
|
} else if (that.metadataDefinition.packageTypeIsDirectory) {
|
|
471
|
-
that
|
|
496
|
+
that.addPkg.addMember(
|
|
472
497
|
that.#root,
|
|
473
498
|
fileObj.shortName.replace(`.${global.format}`, ''),
|
|
474
499
|
)
|