2016-01-29 20:23:57 +00:00
|
|
|
(function() {
|
2018-02-12 05:05:29 +00:00
|
|
|
/**
|
|
|
|
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 */
|
2016-02-01 14:25:22 +00:00
|
|
|
module.exports = function(cmd, args, isSync, callback, param) {
|
2018-02-12 05:05:29 +00:00
|
|
|
var ex, info, spawn;
|
2016-01-29 20:23:57 +00:00
|
|
|
try {
|
2018-02-12 05:05:29 +00:00
|
|
|
// .spawnSync not available on earlier Node.js, so default to .spawn
|
2016-01-29 20:23:57 +00:00
|
|
|
spawn = require('child_process')[isSync ? 'spawnSync' : 'spawn'];
|
|
|
|
info = spawn(cmd, args);
|
|
|
|
if (!isSync) {
|
|
|
|
info.on('error', function(err) {
|
2016-02-01 14:25:22 +00:00
|
|
|
if (typeof callback === "function") {
|
|
|
|
callback(err, param);
|
2016-01-29 20:23:57 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
if (info.error) {
|
2016-02-01 14:25:22 +00:00
|
|
|
if (typeof callback === "function") {
|
|
|
|
callback(info.error, param);
|
2016-01-29 20:23:57 +00:00
|
|
|
}
|
2016-02-01 14:25:22 +00:00
|
|
|
return {
|
|
|
|
cmd: cmd,
|
|
|
|
inner: info.error
|
|
|
|
};
|
2016-01-29 20:23:57 +00:00
|
|
|
}
|
|
|
|
}
|
2018-02-12 05:05:29 +00:00
|
|
|
} catch (error) {
|
|
|
|
ex = error;
|
2016-02-01 14:25:22 +00:00
|
|
|
if (typeof callback === "function") {
|
2018-02-12 05:05:29 +00:00
|
|
|
callback(ex, param);
|
2016-01-29 20:23:57 +00:00
|
|
|
}
|
2018-02-12 05:05:29 +00:00
|
|
|
return ex;
|
2016-01-29 20:23:57 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
}).call(this);
|
2016-02-02 02:14:36 +00:00
|
|
|
|
|
|
|
//# sourceMappingURL=safe-spawn.js.map
|