-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathutils.js
72 lines (64 loc) · 2.39 KB
/
utils.js
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
let childProcess = require('child_process');
const path = require('path');
function execShellCommand(command) {
return new Promise((resolve) => {
childProcess.exec(command, { encoding: 'utf8', maxBuffer: 1024 * 1024 }, (error, stdout, stderr) => {
if (error) {
console.warn(error);
}
resolve(stdout ? stdout : stderr);
});
});
}
function execShellCommandCWD(command, workingdirectory) {
return new Promise((resolve) => {
childProcess.exec(command, {
encoding: 'utf8',
maxBuffer: 1024 * 1024,
cwd: workingdirectory
},
(error, stdout, stderr) => {
if (error) {
console.warn(error);
}
resolve(stdout ? stdout : stderr);
});
});
}
async function runSFDXCommand(command) {
console.log(command);
var commandOutput = await execShellCommand(command);
//console.log(commandOutput);
return JSON.parse(commandOutput);
}
async function runSFDXCommandCWD(command, workingdirectory) {
console.log('runSFDXCommandCWD->COMMAND->', command);
console.log('runSFDXCommandCWD->CWD->', workingdirectory);
var commandOutput = await execShellCommandCWD(command, workingdirectory);
console.log(commandOutput);
return JSON.parse(commandOutput);
}
module.exports = {
sleep: (ms) => {
return new Promise(resolve => setTimeout(resolve, ms));
},
runSFDXCommand: runSFDXCommand,
runSFDXCommandCWD: runSFDXCommandCWD,
deploySFDXMetadata: async(username, folder) => {
//
return await runSFDXCommand(`sfdx force:mdapi:deploy -u ${username} -d ${folder} -w -1 --json`);
},
deploySFDXForceSourceDeployCWD: async(username, metadata, workingdirectory) => {
//
return await runSFDXCommandCWD(`sfdx force:source:deploy -u ${username} -m ${metadata} --json`, workingdirectory);
},
retrieveSFDXMetadata: async(username, metadata, targetfolder) => {
//
return await runSFDXCommand(`sfdx force:mdapi:retrieve -u ${username} -m "${metadata}" -r ${targetfolder} -w -1 --json`);
},
runShellCommand: async(targetShell, username) => {
//Make sure we can execute
await runSFDXCommand(`chmod 777 ${targetShell}`);
return await runSFDXCommand(`./${targetShell} ${username}`);
}
}