@ds-sfdc/sfparty 1.3.7 → 1.3.8
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 +1 -1
- package/src/index.js +27 -11
- package/src/lib/checkVersion.js +3 -7
- package/src/lib/packageUtil.js +2 -1
- package/src/lib/pkgObj.cjs +1 -0
- package/src/meta/Workflows.js +9 -0
- package/test/lib/package/getPackageXML.spec.js +69 -66
package/package.json
CHANGED
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
|
-
import
|
|
14
|
+
import pkgObj from './lib/pkgObj.cjs'
|
|
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'
|
|
@@ -139,7 +139,7 @@ yargs(hideBin(process.argv))
|
|
|
139
139
|
.check(yargCheck)
|
|
140
140
|
},
|
|
141
141
|
handler: (argv) => {
|
|
142
|
-
checkVersion({axios, spawnSync, currentVersion: pkgObj.
|
|
142
|
+
checkVersion({axios, spawnSync, currentVersion: pkgObj.version, update: true})
|
|
143
143
|
}
|
|
144
144
|
})
|
|
145
145
|
.command({
|
|
@@ -162,7 +162,6 @@ yargs(hideBin(process.argv))
|
|
|
162
162
|
.check(yargCheck)
|
|
163
163
|
},
|
|
164
164
|
handler: (argv) => {
|
|
165
|
-
checkVersion({axios, spawnSync, currentVersion: pkgObj.default.version})
|
|
166
165
|
global.format = argv.format
|
|
167
166
|
splitHandler(argv, processStartTime)
|
|
168
167
|
}
|
|
@@ -179,7 +178,6 @@ yargs(hideBin(process.argv))
|
|
|
179
178
|
.check(yargCheck)
|
|
180
179
|
},
|
|
181
180
|
handler: (argv) => {
|
|
182
|
-
checkVersion({axios, spawnSync, currentVersion: pkgObj.default.version})
|
|
183
181
|
global.format = argv.format
|
|
184
182
|
const startProm = new Promise((resolve, reject) => {
|
|
185
183
|
if (argv.git !== undefined) {
|
|
@@ -193,11 +191,10 @@ yargs(hideBin(process.argv))
|
|
|
193
191
|
global.git.latest = data.latestCommit
|
|
194
192
|
global.git.last = data.lastCommit
|
|
195
193
|
if (data.last === undefined) {
|
|
196
|
-
|
|
194
|
+
gitMode({status: 'not active'})
|
|
197
195
|
resolve(false)
|
|
198
196
|
} else {
|
|
199
|
-
|
|
200
|
-
console.log()
|
|
197
|
+
gitMode({status: 'active', lastCommit: data.lastCommit, latestCommit: data.latestCommit})
|
|
201
198
|
const diff = git.diff(global.__basedir, `${data.lastCommit}..${data.latestCommit}`)
|
|
202
199
|
diff
|
|
203
200
|
.then((data, error) => {
|
|
@@ -215,8 +212,7 @@ yargs(hideBin(process.argv))
|
|
|
215
212
|
throw error
|
|
216
213
|
})
|
|
217
214
|
} else {
|
|
218
|
-
|
|
219
|
-
console.log()
|
|
215
|
+
gitMode({status: 'active', gitRef})
|
|
220
216
|
const diff = git.diff(global.__basedir, gitRef)
|
|
221
217
|
diff
|
|
222
218
|
.then((data, error) => {
|
|
@@ -252,6 +248,26 @@ yargs(hideBin(process.argv))
|
|
|
252
248
|
.argv
|
|
253
249
|
.parse
|
|
254
250
|
|
|
251
|
+
function gitMode({ status, gitRef, lastCommit, latestCommit }) {
|
|
252
|
+
let statusMessage
|
|
253
|
+
let displayMessage
|
|
254
|
+
if (status == 'not active') {
|
|
255
|
+
statusMessage = clc.bgMagentaBright('not active:')
|
|
256
|
+
displayMessage = `no prior commit - processing all`
|
|
257
|
+
} else {
|
|
258
|
+
statusMessage = clc.magentaBright('active:')
|
|
259
|
+
if (gitRef === undefined) {
|
|
260
|
+
displayMessage = `${clc.bgBlackBright(data.lastCommit) + '..' + clc.bgBlackBright(data.latestCommit)}`
|
|
261
|
+
console.log(`${clc.yellowBright('git mode')} ${clc.magentaBright('active:')} ${clc.bgBlackBright(data.lastCommit) + '..' + clc.bgBlackBright(data.latestCommit)}`)
|
|
262
|
+
} else {
|
|
263
|
+
displayMessage = `${clc.magentaBright('active:')} ${clc.bgBlackBright(gitRef)}`
|
|
264
|
+
console.log(`${clc.yellowBright('git mode')} ${clc.magentaBright('active:')} ${clc.bgBlackBright(gitRef)}`)
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
console.log(`${clc.yellowBright('git mode')} ${status}:)} ${displayMessage}`)
|
|
268
|
+
console.log()
|
|
269
|
+
}
|
|
270
|
+
|
|
255
271
|
function yargCheck(argv, options) {
|
|
256
272
|
const argvKeys = Object.keys(argv)
|
|
257
273
|
const invalidKeys = argvKeys.filter(key =>
|
|
@@ -262,7 +278,7 @@ function yargCheck(argv, options) {
|
|
|
262
278
|
)
|
|
263
279
|
|
|
264
280
|
if (!argv._.includes('update')) {
|
|
265
|
-
checkVersion({axios, spawnSync, currentVersion: pkgObj.
|
|
281
|
+
checkVersion({axios, spawnSync, currentVersion: pkgObj.version, update: false})
|
|
266
282
|
}
|
|
267
283
|
|
|
268
284
|
if (invalidKeys.length > 0) {
|
|
@@ -614,7 +630,7 @@ function displayHeader() {
|
|
|
614
630
|
horizontal: '─',
|
|
615
631
|
vertical: '│',
|
|
616
632
|
}
|
|
617
|
-
let versionString = `sfparty v${pkgObj.
|
|
633
|
+
let versionString = `sfparty v${pkgObj.version}${(process.stdout.columns > pkgObj.description.length + 15) ? ' - ' + pkgObj.description : ''}`
|
|
618
634
|
let titleMessage = `${global.icons.party} ${clc.yellowBright(versionString)} ${global.icons.party}`
|
|
619
635
|
titleMessage = titleMessage.padEnd((process.stdout.columns / 2) + versionString.length / 1.65)
|
|
620
636
|
titleMessage = titleMessage.padStart(process.stdout.columns)
|
package/src/lib/checkVersion.js
CHANGED
|
@@ -22,7 +22,7 @@ class UpdateError extends Error {
|
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
export async function checkVersion({axios, spawnSync, currentVersion, update = false}) {
|
|
25
|
+
export async function checkVersion({ axios, spawnSync, currentVersion, update = false }) {
|
|
26
26
|
try {
|
|
27
27
|
const { data } = await axios.get('https://registry.npmjs.org/@ds-sfdc/sfparty', {
|
|
28
28
|
params: {
|
|
@@ -31,13 +31,9 @@ export async function checkVersion({axios, spawnSync, currentVersion, update = f
|
|
|
31
31
|
})
|
|
32
32
|
const latestVersion = data['dist-tags'].latest
|
|
33
33
|
if (semver.gt(latestVersion, currentVersion)) {
|
|
34
|
-
let icon
|
|
35
34
|
const version = clc.bgCyanBright(data['dist-tags'].latest)
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
} else {
|
|
39
|
-
icon = global.icons.fail
|
|
40
|
-
}
|
|
35
|
+
const icon = (update) ? global.icons.working : global.icons.fail
|
|
36
|
+
console.log()
|
|
41
37
|
console.log(`${icon} A newer version ${version} is available.`)
|
|
42
38
|
if (!update) {
|
|
43
39
|
console.log(`Please upgrade by running ${clc.cyanBright('sfparty update')}`)
|
package/src/lib/packageUtil.js
CHANGED
|
@@ -48,7 +48,8 @@ export class Package {
|
|
|
48
48
|
|
|
49
49
|
function processJSON(that, json, fileUtils) {
|
|
50
50
|
try {
|
|
51
|
-
|
|
51
|
+
let data = fileUtils.readFile(path.join(global.__basedir, 'sfdx-project.json'))
|
|
52
|
+
json.Package.version = data.sourceApiVersion
|
|
52
53
|
} catch (error) {
|
|
53
54
|
json.Package.version = packageDefinition.metadataDefinition.fallbackVersion
|
|
54
55
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = pkgObj = require('../../package.json')
|
package/src/meta/Workflows.js
CHANGED
|
@@ -53,5 +53,14 @@ export const metadataDefinition = {
|
|
|
53
53
|
'rules': ['fullName'],
|
|
54
54
|
'outboundMessages': ['fullName'],
|
|
55
55
|
'tasks': ['fullName'],
|
|
56
|
+
},
|
|
57
|
+
package: {
|
|
58
|
+
'alerts': 'WorkflowAlert',
|
|
59
|
+
'fieldUpdates': 'WorkflowFieldUpdate',
|
|
60
|
+
'flowActions': 'WorkflowFlowAction',
|
|
61
|
+
'knowledgePublishes': 'WorkflowKnowledgePublish',
|
|
62
|
+
'outboundMessages': 'WorkflowOutboundMessage',
|
|
63
|
+
'rules': 'WorkflowRule',
|
|
64
|
+
'tasks': ' WorkflowTask',
|
|
56
65
|
}
|
|
57
66
|
}
|
|
@@ -7,7 +7,7 @@ import * as permsetDefinition from '../../../src/meta/PermissionSets.js'
|
|
|
7
7
|
import * as workflowDefinition from '../../../src/meta/Workflows.js'
|
|
8
8
|
|
|
9
9
|
global.__basedir = '.'
|
|
10
|
-
|
|
10
|
+
global.format = 'yaml'
|
|
11
11
|
global.metaTypes = {
|
|
12
12
|
label: {
|
|
13
13
|
type: labelDefinition.metadataDefinition.filetype,
|
|
@@ -35,96 +35,96 @@ global.metaTypes = {
|
|
|
35
35
|
},
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
let pkg
|
|
38
|
+
let pkg
|
|
39
39
|
const fileUtils = {
|
|
40
40
|
fileExists: jest.fn(),
|
|
41
41
|
readFile: jest.fn(),
|
|
42
42
|
}
|
|
43
43
|
beforeEach(() => {
|
|
44
|
-
pkg = new Package('xmlPath')
|
|
45
|
-
})
|
|
44
|
+
pkg = new Package('xmlPath')
|
|
45
|
+
})
|
|
46
46
|
|
|
47
47
|
|
|
48
48
|
afterEach(() => {
|
|
49
|
-
jest.clearAllMocks()
|
|
50
|
-
})
|
|
49
|
+
jest.clearAllMocks()
|
|
50
|
+
})
|
|
51
51
|
|
|
52
52
|
it('should default the package if the json is empty', async () => {
|
|
53
|
-
fileUtils.fileExists.mockReturnValue(true)
|
|
54
|
-
fileUtils.readFile.mockResolvedValue({})
|
|
53
|
+
fileUtils.fileExists.mockReturnValue(true)
|
|
54
|
+
fileUtils.readFile.mockResolvedValue({})
|
|
55
55
|
global.git = { append: true }
|
|
56
|
-
const result = await pkg.getPackageXML(fileUtils)
|
|
57
|
-
expect(result).toBe('existing')
|
|
58
|
-
expect(fileUtils.fileExists).toHaveBeenCalled()
|
|
59
|
-
expect(fileUtils.readFile).toHaveBeenCalled()
|
|
60
|
-
expect(pkg.packageJSON).toEqual(packageDefinition.metadataDefinition.emptyPackage)
|
|
61
|
-
})
|
|
56
|
+
const result = await pkg.getPackageXML(fileUtils)
|
|
57
|
+
expect(result).toBe('existing')
|
|
58
|
+
expect(fileUtils.fileExists).toHaveBeenCalled()
|
|
59
|
+
expect(fileUtils.readFile).toHaveBeenCalled()
|
|
60
|
+
expect(pkg.packageJSON).toEqual(packageDefinition.metadataDefinition.emptyPackage)
|
|
61
|
+
})
|
|
62
62
|
|
|
63
63
|
it('should read an existing file and call processJSON', async () => {
|
|
64
|
-
fileUtils.fileExists.mockReturnValue(true)
|
|
65
|
-
fileUtils.readFile.mockResolvedValue(packageDefinition.metadataDefinition.emptyPackage)
|
|
64
|
+
fileUtils.fileExists.mockReturnValue(true)
|
|
65
|
+
fileUtils.readFile.mockResolvedValue(packageDefinition.metadataDefinition.emptyPackage)
|
|
66
66
|
global.git = { append: true }
|
|
67
|
-
const result = await pkg.getPackageXML(fileUtils)
|
|
68
|
-
expect(result).toBe('existing')
|
|
69
|
-
expect(fileUtils.fileExists).toHaveBeenCalled()
|
|
70
|
-
expect(fileUtils.readFile).toHaveBeenCalled()
|
|
71
|
-
})
|
|
67
|
+
const result = await pkg.getPackageXML(fileUtils)
|
|
68
|
+
expect(result).toBe('existing')
|
|
69
|
+
expect(fileUtils.fileExists).toHaveBeenCalled()
|
|
70
|
+
expect(fileUtils.readFile).toHaveBeenCalled()
|
|
71
|
+
})
|
|
72
72
|
|
|
73
73
|
it('should create an empty pkg JSON and call processJSON', async () => {
|
|
74
|
-
fileUtils.fileExists.mockReturnValue(false)
|
|
74
|
+
fileUtils.fileExists.mockReturnValue(false)
|
|
75
75
|
const finalJSON = JSON.parse(JSON.stringify(packageDefinition.metadataDefinition.emptyPackage))
|
|
76
76
|
finalJSON.Package.version = packageDefinition.metadataDefinition.fallbackVersion
|
|
77
|
-
const result = await pkg.getPackageXML(fileUtils)
|
|
78
|
-
expect(result).toBe('not found')
|
|
79
|
-
expect(fileUtils.fileExists).toHaveBeenCalled()
|
|
80
|
-
expect(pkg.packageJSON).toEqual(finalJSON)
|
|
81
|
-
})
|
|
77
|
+
const result = await pkg.getPackageXML(fileUtils)
|
|
78
|
+
expect(result).toBe('not found')
|
|
79
|
+
expect(fileUtils.fileExists).toHaveBeenCalled()
|
|
80
|
+
expect(pkg.packageJSON).toEqual(finalJSON)
|
|
81
|
+
})
|
|
82
82
|
|
|
83
83
|
it('should throw an error if xmlPath is undefined', async () => {
|
|
84
|
-
pkg.xmlPath = undefined
|
|
85
|
-
await expect(pkg.getPackageXML(fileUtils)).rejects.toThrowError('Package not initialized')
|
|
86
|
-
})
|
|
84
|
+
pkg.xmlPath = undefined
|
|
85
|
+
await expect(pkg.getPackageXML(fileUtils)).rejects.toThrowError('Package not initialized')
|
|
86
|
+
})
|
|
87
87
|
|
|
88
88
|
it('should throw an error if error occurs during processing', async () => {
|
|
89
|
-
fileUtils.fileExists.mockReturnValue(true)
|
|
90
|
-
fileUtils.readFile.mockRejectedValue(new Error('Error'))
|
|
91
|
-
await expect(pkg.getPackageXML(fileUtils)).rejects.toThrowError('Error')
|
|
92
|
-
})
|
|
89
|
+
fileUtils.fileExists.mockReturnValue(true)
|
|
90
|
+
fileUtils.readFile.mockRejectedValue(new Error('Error'))
|
|
91
|
+
await expect(pkg.getPackageXML(fileUtils)).rejects.toThrowError('Error')
|
|
92
|
+
})
|
|
93
93
|
|
|
94
94
|
it('should catch errors and reject the promise', async () => {
|
|
95
|
-
fileUtils.fileExists.mockReturnValue(true)
|
|
96
|
-
fileUtils.readFile.mockRejectedValue(new Error('Test Error'))
|
|
95
|
+
fileUtils.fileExists.mockReturnValue(true)
|
|
96
|
+
fileUtils.readFile.mockRejectedValue(new Error('Test Error'))
|
|
97
97
|
global.git = { append: true }
|
|
98
98
|
try {
|
|
99
|
-
await pkg.getPackageXML(fileUtils)
|
|
99
|
+
await pkg.getPackageXML(fileUtils)
|
|
100
100
|
} catch (error) {
|
|
101
|
-
expect(error.message).toEqual('Test Error')
|
|
101
|
+
expect(error.message).toEqual('Test Error')
|
|
102
102
|
}
|
|
103
|
-
})
|
|
103
|
+
})
|
|
104
104
|
|
|
105
105
|
it('should default to an empty package if the read file is empty', async () => {
|
|
106
|
-
fileUtils.fileExists.mockReturnValue(true)
|
|
107
|
-
fileUtils.readFile.mockResolvedValue('')
|
|
106
|
+
fileUtils.fileExists.mockReturnValue(true)
|
|
107
|
+
fileUtils.readFile.mockResolvedValue('')
|
|
108
108
|
global.git = { append: true }
|
|
109
|
-
const result = await pkg.getPackageXML(fileUtils)
|
|
110
|
-
expect(result).toBe('existing')
|
|
111
|
-
expect(pkg.packageJSON).toEqual(packageDefinition.metadataDefinition.emptyPackage)
|
|
112
|
-
expect(fileUtils.fileExists).toHaveBeenCalled()
|
|
113
|
-
expect(fileUtils.readFile).toHaveBeenCalled()
|
|
114
|
-
})
|
|
109
|
+
const result = await pkg.getPackageXML(fileUtils)
|
|
110
|
+
expect(result).toBe('existing')
|
|
111
|
+
expect(pkg.packageJSON).toEqual(packageDefinition.metadataDefinition.emptyPackage)
|
|
112
|
+
expect(fileUtils.fileExists).toHaveBeenCalled()
|
|
113
|
+
expect(fileUtils.readFile).toHaveBeenCalled()
|
|
114
|
+
})
|
|
115
115
|
|
|
116
116
|
it('should throw an error if fileUtils.readFile() returns a rejected promise', async () => {
|
|
117
|
-
fileUtils.fileExists.mockReturnValue(true)
|
|
118
|
-
fileUtils.readFile.mockRejectedValue(new Error('Test Error'))
|
|
117
|
+
fileUtils.fileExists.mockReturnValue(true)
|
|
118
|
+
fileUtils.readFile.mockRejectedValue(new Error('Test Error'))
|
|
119
119
|
global.git = { append: true }
|
|
120
|
-
await expect(pkg.getPackageXML(fileUtils)).rejects.toThrowError('Test Error')
|
|
121
|
-
expect(fileUtils.fileExists).toHaveBeenCalled()
|
|
122
|
-
expect(fileUtils.readFile).toHaveBeenCalled()
|
|
123
|
-
})
|
|
120
|
+
await expect(pkg.getPackageXML(fileUtils)).rejects.toThrowError('Test Error')
|
|
121
|
+
expect(fileUtils.fileExists).toHaveBeenCalled()
|
|
122
|
+
expect(fileUtils.readFile).toHaveBeenCalled()
|
|
123
|
+
})
|
|
124
124
|
|
|
125
125
|
it('should correctly process the json object returned from the XML file', async () => {
|
|
126
|
-
fileUtils.fileExists.mockReturnValue(true)
|
|
127
|
-
fileUtils.readFile.
|
|
126
|
+
fileUtils.fileExists.mockReturnValue(true)
|
|
127
|
+
fileUtils.readFile.mockResolvedValueOnce({
|
|
128
128
|
"Package": {
|
|
129
129
|
"types": [{
|
|
130
130
|
"members": ["Test", "Test.yaml"],
|
|
@@ -141,28 +141,31 @@ it('should correctly process the json object returned from the XML file', async
|
|
|
141
141
|
}],
|
|
142
142
|
"version": "56.0"
|
|
143
143
|
}
|
|
144
|
-
})
|
|
144
|
+
})
|
|
145
|
+
fileUtils.readFile.mockImplementationOnce(() => {
|
|
146
|
+
return { sourceApiVersion: '56.0' }
|
|
147
|
+
})
|
|
145
148
|
global.git = { append: true }
|
|
146
|
-
const result = await pkg.getPackageXML(fileUtils)
|
|
147
|
-
expect(result).toBe('existing')
|
|
148
|
-
expect(fileUtils.fileExists).toHaveBeenCalled()
|
|
149
|
-
expect(fileUtils.readFile).toHaveBeenCalled()
|
|
149
|
+
const result = await pkg.getPackageXML(fileUtils)
|
|
150
|
+
expect(result).toBe('existing')
|
|
151
|
+
expect(fileUtils.fileExists).toHaveBeenCalled()
|
|
152
|
+
expect(fileUtils.readFile).toHaveBeenCalled()
|
|
150
153
|
expect(pkg.packageJSON).toEqual({
|
|
151
154
|
"Package": {
|
|
152
155
|
"types": [{
|
|
153
|
-
"members": ["Test"
|
|
156
|
+
"members": ["Test"],
|
|
154
157
|
"name": "CustomLabels"
|
|
155
158
|
}, {
|
|
156
|
-
"members": ["Test"
|
|
159
|
+
"members": ["Test"],
|
|
157
160
|
"name": "Profile"
|
|
158
161
|
}, {
|
|
159
|
-
"members": ["Test"
|
|
162
|
+
"members": ["Test"],
|
|
160
163
|
"name": "PermissionSet"
|
|
161
164
|
}, {
|
|
162
|
-
"members": ["Test"
|
|
165
|
+
"members": ["Test"],
|
|
163
166
|
"name": "Workflow"
|
|
164
167
|
}],
|
|
165
168
|
"version": "56.0"
|
|
166
169
|
}
|
|
167
|
-
})
|
|
168
|
-
})
|
|
170
|
+
})
|
|
171
|
+
})
|