@ds-sfdc/sfparty 1.2.3 → 1.2.4

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ds-sfdc/sfparty",
3
- "version": "1.2.3",
3
+ "version": "1.2.4",
4
4
  "description": "Salesforce metadata XML splitter for CI/CD",
5
5
  "type": "module",
6
6
  "repository": {
package/src/index.js CHANGED
@@ -17,6 +17,7 @@ import * as profileDefinition from './meta/Profiles.js'
17
17
  import * as permsetDefinition from './meta/PermissionSets.js'
18
18
  import * as workflowDefinition from './meta/Workflows.js'
19
19
  import * as git from './lib/gitUtils.js'
20
+ import logUpdate from 'log-update'
20
21
 
21
22
  const processStartTime = process.hrtime.bigint()
22
23
 
@@ -35,6 +36,7 @@ global.icons = {
35
36
  "fail": '❗',
36
37
  "working": '⏳',
37
38
  "party": '🎉',
39
+ "delete": '❌💀❌',
38
40
  }
39
41
 
40
42
  global.displayError = (error, quit = false) => {
@@ -243,8 +245,9 @@ yargs(hideBin(process.argv))
243
245
  reject(error)
244
246
  })
245
247
  }
248
+ } else {
249
+ resolve(false)
246
250
  }
247
- resolve(false)
248
251
  })
249
252
  startProm.then((result) => {
250
253
  global.git.enabled = result
@@ -484,7 +487,7 @@ function processCombine(typeItem, argv) {
484
487
 
485
488
 
486
489
  if (type == global.metaTypes.label.type) {
487
- if (!global.git.enabled || [...new Set([...global.metaTypes.label.add.directories, ...global.metaTypes.label.remove.directories])].includes(global.metaTypes.label.definition.root)) {
490
+ if (!global.git.enabled || [...new Set([...global.metaTypes[typeItem].add.directories, ...global.metaTypes[typeItem].remove.directories])].includes(global.metaTypes[typeItem].definition.root)) {
488
491
  processList.push(global.metaTypes.label.definition.root)
489
492
  }
490
493
  } else if (!all) {
@@ -496,26 +499,25 @@ function processCombine(typeItem, argv) {
496
499
  processList.push(name)
497
500
  } else {
498
501
  if (global.git.enabled) {
499
- processList = [...new Set([...global.metaTypes.label.add.directories, ...global.metaTypes.label.remove.directories])]
502
+ processList = [...new Set([...global.metaTypes[typeItem].add.directories, ...global.metaTypes[typeItem].remove.directories])]
500
503
  } else {
501
504
  processList = fileUtils.getDirectories(sourceDir)
502
505
  }
503
506
  }
504
507
 
505
508
  processed.total = processList.length
509
+ console.log(`${ chalk.bgBlackBright(processed.total) } ${ typeItem } file(s) to process`)
506
510
 
507
511
  // Abort if there are no files to process
508
512
  if (processed.total == 0) {
509
- console.log(`${ chalk.bgBlackBright('0') } ${ typeItem } files to process`)
510
513
  resolve(true)
511
514
  return
512
515
  }
513
516
 
517
+ console.log()
514
518
  console.log(`${ chalk.bgBlackBright('Source path:') } ${ sourceDir }`)
515
519
  console.log(`${ chalk.bgBlackBright('Target path:') } ${ targetDir }`)
516
520
  console.log()
517
- console.log(`Combining a total of ${ processed.total } file(s)`)
518
- console.log()
519
521
 
520
522
  const promList = []
521
523
  processList.forEach(metaDir => {
@@ -536,7 +538,7 @@ function processCombine(typeItem, argv) {
536
538
 
537
539
  Promise.allSettled(promList).then((results) => {
538
540
  let successes = 0
539
- let errors = 0
541
+ let errors = processed.errors++
540
542
  results.forEach(result => {
541
543
  if (result.value == true) {
542
544
  successes++
@@ -574,9 +576,5 @@ function gitFiles(data) {
574
576
  }
575
577
  }
576
578
  }
577
- const found = typeArray.some(r => item.path.split(path.sep).includes(r))
578
- if (found.length > 0) {
579
- let data1 = item.path
580
- }
581
579
  })
582
580
  }
@@ -68,7 +68,7 @@ export function deleteFile(filePath) {
68
68
  if (!fileExists(filePath)) {
69
69
  return false
70
70
  } else {
71
- return unlinkSync(filePath, { recursive: false, force: true });
71
+ return fs.unlinkSync(filePath, { recursive: false, force: true });
72
72
  }
73
73
  }
74
74
 
@@ -47,8 +47,11 @@ export function diff(dir, gitRef) {
47
47
  const gitData = gitString.split(os.EOL)
48
48
  let leftOver = ''
49
49
  gitData.forEach((gitRow, index) => {
50
- if (index < count || lastIndex + 1 == gitString) {
50
+ if (gitRow.indexOf('\t') !== -1 &&(index < count || lastIndex + 1 == gitString)) {
51
51
  const file = gitRow.split('\t')
52
+ if (file.slice(-1)[0] == 'uthorizationFormConsent.yaml') {
53
+ let test = true
54
+ }
52
55
  if (file.slice(-1) !== '') {
53
56
  files.push({
54
57
  type: status[(file[0] === file.slice(-1)) ? 'A' : Array.from(file[0])[0]],
@@ -76,16 +79,18 @@ export function diff(dir, gitRef) {
76
79
  reject(error)
77
80
  })
78
81
  gitDiff.on("close", code => {
79
- const gitData = data.toString().split(os.EOL)
80
- gitData.forEach(gitRow => {
81
- const file = gitRow.split('\t')
82
- if (file.slice(-1) !== '') {
83
- files.push({
84
- type: status[(file[0] === file.slice(-1)) ? 'A' : Array.from(file[0])[0]],
85
- path: file.slice(-1)[0],
86
- })
87
- }
88
- })
82
+ if (data !== '') {
83
+ const gitData = data.toString().split(os.EOL)
84
+ gitData.forEach(gitRow => {
85
+ const file = gitRow.split('\t')
86
+ if (file.slice(-1) !== '') {
87
+ files.push({
88
+ type: status[(file[0] === file.slice(-1)) ? 'A' : Array.from(file[0])[0]],
89
+ path: file.slice(-1)[0],
90
+ })
91
+ }
92
+ })
93
+ }
89
94
 
90
95
  resolve(files)
91
96
  })
@@ -102,9 +102,21 @@ export class Combine {
102
102
  that.#json[key] = undefined
103
103
  })
104
104
 
105
- getXML(that)
106
-
107
- saveXML(that)
105
+ let success = getXML(that)
106
+ if (success) {
107
+ saveXML(that)
108
+ } else {
109
+ logUpdate(that.#spinnerMessage
110
+ .replace('[%1]', that.sequence.toString().padStart(that.total.toString().length, ' '))
111
+ .replace('[%2]', `. ${chalk.redBright('source not found - removing XML file')}`)
112
+ .replace('[%3]', ``)
113
+ .replace('[%4]', `${global.icons.delete} `)
114
+ .replace('[%5]', that.#fileName.shortName)
115
+ )
116
+ logUpdate.done()
117
+ deleteFile(that.#fileName.fullName)
118
+ resolve('deleted')
119
+ }
108
120
  resolve(true)
109
121
  })
110
122
 
@@ -118,35 +130,47 @@ export class Combine {
118
130
  that.#startTime = process.hrtime.bigint()
119
131
  that.#spinnerMessage = `[%1] of ${that.total} - ${that.#root}: [%4]${chalk.yellowBright('[%5]')}[%2][%3]`
120
132
 
121
- that.#types.forEach(key => {
122
- // display message
123
- logUpdate(that.#spinnerMessage
124
- .replace('[%1]', that.sequence.toString().padStart(that.total.toString().length, ' '))
125
- .replace('[%2]', `\n${chalk.magentaBright(nextFrame(that))} ${key}`)
126
- .replace('[%3]', `${that.#errorMessage}`)
127
- .replace('[%4]', `${global.icons.working} `)
128
- .replace('[%5]', `${that.#fileName.shortName} `)
129
- )
133
+ try {
134
+ that.#types.forEach(key => {
135
+ // display message
136
+ logUpdate(that.#spinnerMessage
137
+ .replace('[%1]', that.sequence.toString().padStart(that.total.toString().length, ' '))
138
+ .replace('[%2]', `\n${chalk.magentaBright(nextFrame(that))} ${key}`)
139
+ .replace('[%3]', `${that.#errorMessage}`)
140
+ .replace('[%4]', `${global.icons.working} `)
141
+ .replace('[%5]', `${that.#fileName.shortName} `)
142
+ )
130
143
 
131
144
 
132
- if (that.metadataDefinition.main.includes(key)) {
133
- // TODO process main
134
- const fileObj = {
135
- shortName: 'Main',
136
- fullName: path.join(that.sourceDir, that.metaDir, `main.${global.format}`),
137
- }
138
- processFile(that, key, fileObj, 'main')
139
- if (that.#json.$ === undefined) {
140
- that.#json.$ = { xmlns: 'https://soap.sforce.com/2006/04/metadata' }
145
+ if (that.metadataDefinition.main.includes(key)) {
146
+ // TODO process main
147
+ const fileObj = {
148
+ shortName: 'Main',
149
+ fullName: path.join(that.sourceDir, that.metaDir, `main.${global.format}`),
150
+ }
151
+ let success = processFile(that, key, fileObj, 'main')
152
+ if (!success) {
153
+ throw new Error('delete XML')
154
+ }
155
+ if (that.#json.$ === undefined) {
156
+ that.#json.$ = { xmlns: 'https://soap.sforce.com/2006/04/metadata' }
157
+ }
158
+ } else if (that.metadataDefinition.singleFiles.includes(key)) {
159
+ processSingleFile(that, key)
160
+ } else if (that.metadataDefinition.directories.includes(key)) {
161
+ processDirectory(that, key)
162
+ } else {
163
+ global.logger.warn(`Unexpected metadata type: ${chalk.redBright(key)}`)
141
164
  }
142
- } else if (that.metadataDefinition.singleFiles.includes(key)) {
143
- processSingleFile(that, key)
144
- } else if (that.metadataDefinition.directories.includes(key)) {
145
- processDirectory(that, key)
165
+ })
166
+ return true
167
+ } catch (error) {
168
+ if (error.message == 'delete XML') {
169
+ return false
146
170
  } else {
147
- global.logger.warn(`Unexpected metadata type: ${chalk.redBright(key)}`)
171
+ return true
148
172
  }
149
- })
173
+ }
150
174
  }
151
175
 
152
176
  function processSingleFile(that, key) {
@@ -188,6 +212,10 @@ export class Combine {
188
212
  return true
189
213
  }
190
214
 
215
+ function deleteFile(fileName) {
216
+ fileUtils.deleteFile(fileName)
217
+ }
218
+
191
219
  function processFile(that, key, fileObj = undefined, rootKey = undefined) {
192
220
  if (
193
221
  fileObj === undefined ||
@@ -200,7 +228,12 @@ export class Combine {
200
228
  }
201
229
 
202
230
  if (!fileUtils.fileExists(fileObj.fullName)) {
203
- return
231
+ // File does not exist
232
+ // If file is main.yaml, then return false to indicate that the XML file should be deleted
233
+ if (fileObj.fullName == path.join(that.sourceDir, that.metaDir, `main.${global.format}`)) {
234
+ return false
235
+ }
236
+ return true
204
237
  }
205
238
 
206
239
  let result = fileUtils.readFile(fileObj.fullName)
@@ -216,7 +249,7 @@ export class Combine {
216
249
  if (Array.isArray(result[key])) {
217
250
  result[key].forEach(arrItem => {
218
251
  that.#json[key].push(arrItem)
219
- })
252
+ })
220
253
  } else {
221
254
  that.#json[key].push(result[key])
222
255
  }
@@ -233,7 +266,7 @@ export class Combine {
233
266
  }
234
267
 
235
268
  updateFileStats(that, fileObj.fullName, fileUtils.fileInfo(fileObj.fullName).stats)
236
- // genericXML(that, key, fileObj.fullName)
269
+ return true
237
270
  }
238
271
 
239
272
  function hydrateObject(that, json, key, fileObj) {