@ds-sfdc/sfparty 1.3.1 → 1.3.3

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/README.md CHANGED
@@ -46,6 +46,7 @@ sfparty combine
46
46
  -f, --format format to use yaml (default) or json
47
47
  -s, --source package directory path specified in sfdx-project.json
48
48
  -t, --target target path to directory to create yaml/json files
49
+ -g, --git combine files based on git commits
49
50
  -h, --help Show help
50
51
  ```
51
52
 
@@ -138,6 +139,9 @@ sfparty combine --git
138
139
  ## CI/CD
139
140
  sfparty is meant to be a supplemental addition to your CI/CD process. Your pipeline should already build out a `package.xml` and `destructiveChanges.xml`. When sfparty runs it will do a `git diff` and append changes to the files. You can use a utility like [sfdx-git-delta](https://www.npmjs.com/package/sfdx-git-delta) to build out the package.
140
141
  ```
142
+ Command:
143
+ sfparty combine --git
144
+
141
145
  Required:
142
146
  -g, --git process files based on git commits. This option does not require a value.
143
147
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ds-sfdc/sfparty",
3
- "version": "1.3.1",
3
+ "version": "1.3.3",
4
4
  "description": "Salesforce metadata XML splitter for CI/CD",
5
5
  "type": "module",
6
6
  "repository": {
package/src/index.js CHANGED
@@ -11,7 +11,7 @@ import convertHrtime from 'convert-hrtime'
11
11
  import axios from 'axios'
12
12
  import { marked } from 'marked'
13
13
  import markedTerminal from 'marked-terminal'
14
-
14
+ import * as pkgObj from '../package.json' assert { type: "json" }
15
15
  import * as fileUtils from './lib/fileUtils.js'
16
16
  import * as yargOptions from './meta/yargs.js'
17
17
  import * as metadataSplit from './party/split.js'
@@ -23,7 +23,6 @@ import * as workflowDefinition from './meta/Workflows.js'
23
23
  import { checkVersion } from './lib/checkVersion.js'
24
24
  import * as git from './lib/gitUtils.js'
25
25
 
26
- const pkgObj = fileUtils.readFile('package.json')
27
26
  const processStartTime = process.hrtime.bigint()
28
27
 
29
28
  marked.setOptions({
@@ -140,7 +139,7 @@ yargs(hideBin(process.argv))
140
139
  .check(yargCheck)
141
140
  },
142
141
  handler: (argv) => {
143
- checkVersion(axios, exec, pkgObj.version, true)
142
+ checkVersion(axios, exec, pkgObj.default.version, true)
144
143
  }
145
144
  })
146
145
  .command({
@@ -155,7 +154,7 @@ yargs(hideBin(process.argv))
155
154
  .check(yargCheck)
156
155
  },
157
156
  handler: (argv) => {
158
- checkVersion(axios, exec, pkgObj.version)
157
+ checkVersion(axios, exec, pkgObj.default.version)
159
158
  global.format = argv.format
160
159
  splitHandler(argv, processStartTime)
161
160
  }
@@ -172,7 +171,7 @@ yargs(hideBin(process.argv))
172
171
  .check(yargCheck)
173
172
  },
174
173
  handler: (argv) => {
175
- checkVersion(axios, exec, pkgObj.version)
174
+ checkVersion(axios, exec, pkgObj.default.version)
176
175
  global.format = argv.format
177
176
  const startProm = new Promise((resolve, reject) => {
178
177
  if (argv.git !== undefined) {
@@ -603,7 +602,7 @@ function displayHeader() {
603
602
  horizontal: '─',
604
603
  vertical: '│',
605
604
  }
606
- let versionString = `sfparty v${pkgObj.version}${(process.stdout.columns > pkgObj.description.length + 15) ? ' - ' + pkgObj.description : ''}`
605
+ let versionString = `sfparty v${pkgObj.default.version}${(process.stdout.columns > pkgObj.default.description.length + 15) ? ' - ' + pkgObj.default.description : ''}`
607
606
  let titleMessage = `${global.icons.party} ${chalk.yellowBright(versionString)} ${global.icons.party}`
608
607
  titleMessage = titleMessage.padEnd((process.stdout.columns / 2) + versionString.length / 1.65)
609
608
  titleMessage = titleMessage.padStart(process.stdout.columns)
@@ -619,7 +618,16 @@ function getRootPath(packageDir) {
619
618
  let defaultDir
620
619
  if (rootPath) {
621
620
  global.__basedir = fileUtils.fileInfo(rootPath).dirname
622
- let packageJSON = JSON.parse(readFileSync(rootPath))
621
+ let packageJSON
622
+ try {
623
+ packageJSON = JSON.parse(readFileSync(rootPath))
624
+ } catch (error) {
625
+ if (error.message.indexOf('JSON at position') > 0) {
626
+ global.displayError('sfdx-project.json has invalid JSON', true)
627
+ } else {
628
+ global.displayError(error, true)
629
+ }
630
+ }
623
631
  if (Array.isArray(packageJSON.packageDirectories)) {
624
632
  packageJSON.packageDirectories.every(directory => {
625
633
  if (directory.default || packageJSON.packageDirectories.length == 1) defaultDir = directory.path
@@ -5,10 +5,11 @@ import * as fileUtils from './fileUtils.js'
5
5
  import * as packageDefinition from '../meta/Package.js'
6
6
 
7
7
  export class Package {
8
- #packageJSON = undefined
8
+
9
9
 
10
10
  constructor(xmlPath) {
11
11
  this.xmlPath = xmlPath
12
+ this.packageJSON = undefined
12
13
  }
13
14
 
14
15
  getPackageXML() {
@@ -16,7 +17,7 @@ export class Package {
16
17
  return new Promise((resolve, reject) => {
17
18
  if (that.xmlPath === undefined) throw new Error('Package not initialized')
18
19
 
19
- let fileName = path.join(global.__basedir, that.xmlPath)
20
+ let fileName = path.resolve(that.xmlPath)
20
21
  if (fileUtils.fileExists(fileName) && global.git.append) {
21
22
  let data = fileUtils.readFile(fileName)
22
23
  data
@@ -40,18 +41,18 @@ export class Package {
40
41
  } catch (error) {
41
42
  json.Package.version = packageDefinition.metadataDefinition.fallbackVersion
42
43
  }
43
- that.#packageJSON = json
44
+ that.packageJSON = json
44
45
  if (json.Package.types !== undefined) transformJSON(json.Package.types)
45
46
  }
46
47
  }
47
48
 
48
49
  addMember(type, member) {
49
50
  const that = this
50
- if (that.#packageJSON === undefined) throw new Error('getPackageXML must be called before adding members')
51
+ if (that.packageJSON === undefined) throw new Error('getPackageXML must be called before adding members')
51
52
  if (type === undefined) throw new Error('An undefined type was received when attempting to add a member')
52
53
  if (member === undefined) throw new Error('An undefined member was received when attempting to add a member')
53
54
 
54
- const packageJSON = that.#packageJSON
55
+ const packageJSON = that.packageJSON
55
56
  let foundMember = false
56
57
  let foundAsterisk = false
57
58
  let typeJSON = undefined
@@ -83,7 +84,7 @@ export class Package {
83
84
  // exit if member already exists
84
85
  if (foundMember) return
85
86
  if (foundAsterisk) {
86
- global.logger.warn(`Found ${chalk.bgBlackBright('*')} in type: ${type}.`)
87
+ // global.logger.warn(`Found ${chalk.bgBlackBright('*')} in type: ${type}.`)
87
88
  return
88
89
  }
89
90
 
@@ -107,7 +108,7 @@ export class Package {
107
108
 
108
109
  savePackage() {
109
110
  let that = this
110
- let json = that.#packageJSON.Package
111
+ let json = that.packageJSON.Package
111
112
  json.$.xmlns = json.$.xmlns.replace('http:', 'https:')
112
113
 
113
114
  const builder = new xml2js.Builder(
@@ -153,3 +154,5 @@ function xml2json(currentValue) {
153
154
  if (currentValue == 'false') currentValue = false
154
155
  return currentValue
155
156
  }
157
+
158
+ // Create JEST tests that cover 100% of the code