-
Notifications
You must be signed in to change notification settings - Fork 48.3k
/
Copy pathutils.js
41 lines (35 loc) · 1020 Bytes
/
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
const cp = require('child_process');
const util = require('util');
function execHelper(command, options, streamStdout = false) {
return new Promise((resolve, reject) => {
const proc = cp.exec(command, options, (error, stdout) =>
error ? reject(error) : resolve(stdout.trim())
);
if (streamStdout) {
proc.stdout.pipe(process.stdout);
}
});
}
function _spawn(command, args, options, cb) {
const child = cp.spawn(command, args, options);
child.on('close', exitCode => {
cb(null, exitCode);
});
return child;
}
const spawnHelper = util.promisify(_spawn);
async function getDateStringForCommit(commit) {
let dateString = await execHelper(
`git show -s --no-show-signature --format=%cd --date=format:%Y%m%d ${commit}`
);
// On CI environment, this string is wrapped with quotes '...'s
if (dateString.startsWith("'")) {
dateString = dateString.slice(1, 9);
}
return dateString;
}
module.exports = {
execHelper,
spawnHelper,
getDateStringForCommit,
};