MCPcopy
hub / github.com/tschaub/gh-pages / spawn

Function spawn

lib/git.js:28–48  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

26 * @return {Promise} A promise.
27 */
28function 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.

Callers 1

git.jsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…