git-repository
Version:
A Promise-based wrapper library for Git CLI
45 lines (37 loc) • 1.29 kB
JavaScript
/**
* Copyright © 2015 Konstantin Tarkus. All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE.txt file in the root directory of this source tree.
*/
;
Object.defineProperty(exports, '__esModule', {
value: true
});
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
var _child_process = require('child_process');
var _child_process2 = _interopRequireDefault(_child_process);
var exec = function exec(command, args, options) {
return new Promise(function (resolve, reject) {
var out = '';
var err = '';
var p = _child_process2['default'].spawn(command, args, options);
p.stdout.on('data', function (data) {
return out += data;
});
p.stderr.on('data', function (data) {
return err += data;
});
p.on('error', reject);
p.on('close', function (code) {
return resolve([code, out.trim(), err.trim()]);
});
});
};
var spawn = function spawn(command, args, options) {
return new Promise(function (resolve, reject) {
_child_process2['default'].spawn(command, args, options).on('error', reject).on('close', resolve);
});
};
exports['default'] = { exec: exec, spawn: spawn };
module.exports = exports['default'];