1
0
mirror of https://github.com/JuanCanham/HackMyResume.git synced 2024-11-16 22:00:09 +00:00
HackMyResume/dist/utils/safe-spawn.js

47 lines
1.0 KiB
JavaScript
Raw Normal View History

/**
Safe spawn utility for HackMyResume / FluentCV.
@module utils/safe-spawn
@license MIT. See LICENSE.md for details.
*/
/** Safely spawn a process synchronously or asynchronously without throwing an
exception
*/
(function() {
module.exports = function(cmd, args, isSync, callback, param) {
var info, spawn;
try {
spawn = require('child_process')[isSync ? 'spawnSync' : 'spawn'];
info = spawn(cmd, args);
if (!isSync) {
info.on('error', function(err) {
if (typeof callback === "function") {
callback(err, param);
}
});
} else {
if (info.error) {
if (typeof callback === "function") {
callback(info.error, param);
}
return {
cmd: cmd,
inner: info.error
};
}
}
} catch (_error) {
if (typeof callback === "function") {
callback(_error, param);
}
return _error;
}
};
}).call(this);
2016-02-02 02:14:36 +00:00
//# sourceMappingURL=safe-spawn.js.map