exec.js 846 B

1234567891011121314151617181920212223242526272829
  1. 'use strict';
  2. var log = require('fancy-log');
  3. var exec = require('child_process').exec;
  4. module.exports = function (opt, cb) {
  5. if (!cb && typeof opt === 'function') {
  6. // optional options
  7. cb = opt;
  8. opt = {};
  9. }
  10. if (!cb || typeof cb !== 'function') cb = function () {};
  11. if (!opt) opt = { };
  12. if (!opt.log) opt.log = !cb;
  13. if (!opt.cwd) opt.cwd = process.cwd();
  14. if (!opt.maxBuffer) opt.maxBuffer = 200 * 1024; // Default buffer value for child_process.exec
  15. if (!opt.args) opt.args = ' ';
  16. var cmd = 'git ' + opt.args;
  17. return exec(cmd, {cwd : opt.cwd, maxBuffer: opt.maxBuffer}, function(err, stdout, stderr) {
  18. if (err) return cb(err, stderr);
  19. if (opt.log && !opt.quiet) log(cmd + '\n' + stdout, stderr);
  20. else {
  21. if (!opt.quiet) log(cmd + ' (log : false)', stderr);
  22. }
  23. cb(err, stdout);
  24. });
  25. };