@tangelo/tangelo-configuration-toolkit
Version:
Tangelo Configuration Toolkit is a command-line toolkit which offers support for developing a Tangelo configuration.
27 lines (21 loc) • 801 B
JavaScript
const {spawnSync} = require('child_process');
module.exports = function execGitCommand(args, path, returnProperties, expectedStatus) {
const cmd = spawnSync('git', [args], {cwd: path, shell: true});
if (cmd.status !== 0) return {error: `${cmd.stderr}`};
if (expectedStatus!=undefined) return cmd.status == expectedStatus;
let retObj = (cmd.stdout||'').toString().trim().split(';');
if (returnProperties?.[0]) {
const o = {};
retObj = (
retObj.forEach((v, i) => {
o[returnProperties[i]] =
returnProperties[i] == 'date' ? new Date(v) :
returnProperties[i] == 'branch' ? v.replace(/HEAD -> ([^,]+).*/, '$1') :
v
;
}),
o
);
}
return retObj.length === 1 ? retObj[0] : retObj;
};