mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 18:55:26 +00:00
40 lines
833 B
JavaScript
40 lines
833 B
JavaScript
(function() {
|
|
'use strict';
|
|
|
|
module.exports = function tryRequire(name, options) {
|
|
var result,
|
|
o = options || {},
|
|
|
|
error = tryCatch(function() {
|
|
result = require(name);
|
|
});
|
|
|
|
if (error) {
|
|
if (o.log)
|
|
console.error(error.message);
|
|
else if (o.callback)
|
|
result = exec.bind(null, error);
|
|
|
|
if (o.exit)
|
|
process.exit(1);
|
|
}
|
|
|
|
return result;
|
|
};
|
|
|
|
function exec(error, callback) {
|
|
callback(error);
|
|
}
|
|
|
|
function tryCatch(fn) {
|
|
var error;
|
|
|
|
try {
|
|
fn();
|
|
} catch(err) {
|
|
error = err;
|
|
}
|
|
|
|
return error;
|
|
}
|
|
})();
|