* Util function for handling spawned processes as promises. * @param {string} exe Executable. * @param {Array } args Arguments. * @param {string} cwd Working directory. * @return {Promise} A promise.
(exe, args, cwd)
| 26 | * @return {Promise} A promise. |
| 27 | */ |
| 28 | function spawn(exe, args, cwd) { |
| 29 | return new Promise((resolve, reject) => { |
| 30 | const child = cp.spawn(exe, args, {cwd: cwd || process.cwd()}); |
| 31 | const buffer = []; |
| 32 | child.stderr.on('data', (chunk) => { |
| 33 | buffer.push(chunk.toString()); |
| 34 | }); |
| 35 | child.stdout.on('data', (chunk) => { |
| 36 | buffer.push(chunk.toString()); |
| 37 | }); |
| 38 | child.on('close', (code) => { |
| 39 | const output = buffer.join(''); |
| 40 | if (code) { |
| 41 | const msg = output || 'Process failed: ' + code; |
| 42 | reject(new ProcessError(code, msg)); |
| 43 | } else { |
| 44 | resolve(output); |
| 45 | } |
| 46 | }); |
| 47 | }); |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * Create an object for executing git commands. |
no outgoing calls
no test coverage detected
searching dependent graphs…