1'use strict' 2 3const BB = require('bluebird') 4 5module.exports = function (child, hasExitCode = false) { 6 return BB.fromNode(function (cb) { 7 child.on('error', cb) 8 child.on(hasExitCode ? 'close' : 'end', function (exitCode) { 9 if (exitCode === undefined || exitCode === 0) { 10 cb() 11 } else { 12 let err = new Error('exited with error code: ' + exitCode) 13 cb(err) 14 } 15 }) 16 }) 17} 18