-
Notifications
You must be signed in to change notification settings - Fork 55
Expand file tree
/
Copy path_sfOrgStatus.js
More file actions
92 lines (77 loc) · 3.15 KB
/
_sfOrgStatus.js
File metadata and controls
92 lines (77 loc) · 3.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
'use strict';
// Initialize required modules
const sfdx = require('sfdx-node/parallel');
const config = require('config');
/**
* @function getFilePathOrFullName
* @description Skinny helper-function designed to shorthand filepath retrieval
*
* @param {Object} statusObject Represents the statusObject containing the base filePath
* @param {String} baseForcePath Represents the path of the base deployment directory for the SFDC codebase
* @returns {String} Returns either the filePath or the basePath -- depending on the statusObject
**/
function getFilePathOrFullName(statusObject, baseForcePath) {
// Evaluate that the property exists AND it's not null
if (Object.prototype.hasOwnProperty.call(statusObject, 'filePath') && statusObject.filePath !== null) {
return statusObject.filePath.replace(baseForcePath, '');
}
// Default the return property
return statusObject.fullName;
}
/**
* @function _sfOrgStatus
* @description Attempts to retrieve the remote deploy status of a scratchOrg
*
* @param {Object} environmentDef Represents the already-validated environment details to use when performing the actions
* @returns {Promise} Returns the result of the scratchOrg status request
*/
module.exports = environmentDef => {
// Initialize the status argument
const statusArguments = {
local: false,
remote: false,
_rejectOnError: true
};
// Evaluate if we should show local status
if (Object.prototype.hasOwnProperty.call(environmentDef, 'statusLocal')
&& environmentDef.statusLocal !== undefined) {
statusArguments.local = environmentDef.statusLocal;
}
// Evaluate if we should show remote status
if (Object.prototype.hasOwnProperty.call(environmentDef, 'statusRemote')
&& environmentDef.statusRemote !== undefined) {
statusArguments.remote = environmentDef.statusRemote;
}
// Set the username to deploy to if it's defined
if (Object.prototype.hasOwnProperty.call(environmentDef, 'sfScratchOrgUsername')) {
statusArguments.targetusername = environmentDef.sfScratchOrgUsername;
}
let baseForcePath = config.get('paths.source.dx.base').toString();
baseForcePath = baseForcePath.replace('./', '');
// Get source status for first scratch org
return sfdx.force.source.status(statusArguments)
.then(statuses => {
if (!statuses) {
return {
outputDisplay: []
};
}
return {
outputDisplay: statuses.map(status => [
status.state,
status.type,
getFilePathOrFullName(status, baseForcePath)
])
};
}).catch((err) => {
// if the error is related to a non source tracked org, this is fine, exit gracefully
if (err.length > 0
&& Object.prototype.hasOwnProperty.call(err[0], 'name')
&& err[0].name === 'NonSourceTrackedOrgError') {
return {
outputDisplay: []
};
}
throw new Error(JSON.stringify(err));
});
};