1
0
mirror of https://github.com/JuanCanham/HackMyResume.git synced 2024-11-05 09:56:22 +00:00
HackMyResume/dist/utils/safe-spawn.js
hacksalot 0f65e4c9f3 Finish HackMyCore reshaping.
Reintroduce HackMyCore, dropping the interim submodule, and reorganize
and improve tests.
2016-01-29 15:23:57 -05:00

47 lines
982 B
JavaScript

/**
Safe spawn utility for HackMyResume / FluentCV.
@module utils/safe-spawn
@license MIT. See LICENSE.md for details.
*/
(function() {
module.exports = function(cmd, args, isSync, callback) {
var info, spawn;
try {
spawn = require('child_process')[isSync ? 'spawnSync' : 'spawn'];
info = spawn(cmd, args);
if (!isSync) {
info.on('error', function(err) {
if (callback != null) {
callback(err);
} else {
throw {
cmd: cmd,
inner: err
};
}
});
} else {
if (info.error) {
if (callback != null) {
callback(err);
} else {
throw {
cmd: cmd,
inner: info.error
};
}
}
}
} catch (_error) {
if (callback != null) {
return callback(_error);
} else {
throw _error;
}
}
};
}).call(this);