feature(tryRequire) name, callback -> name, options

This commit is contained in:
coderaiser 2014-09-22 07:33:06 -04:00
parent 4d8adf3ed9
commit 30ea708d09
6 changed files with 11 additions and 14 deletions

View file

@ -29,10 +29,7 @@
return emptyFunc;
};
webconsole = tryRequire('console-io', function(error) {
if (error)
Util.log(error.message);
}) || emptyFunc;
webconsole = tryRequire('console-io', {log: true}) || emptyFunc;
module.exports = function(params) {
var keys,

View file

@ -14,7 +14,7 @@
tryRequire = require(DIR_SERVER + 'tryRequire'),
io = tryRequire('socket.io');
io = tryRequire('socket.io', {log: true});
/**
* start server function

View file

@ -5,7 +5,7 @@
DIR_LIB = DIR + '../',
crypto = require('crypto'),
tryRequire = require(DIR + 'tryRequire'),
tryRequire = require(DIR + 'tryRequire', {log: true}),
config = require(DIR + 'config'),
Util = require(DIR_LIB + 'util'),

View file

@ -12,7 +12,7 @@
ConfigPath = DIR + 'json/config.json',
config = tryRequire(ConfigPath) || {};
config = tryRequire(ConfigPath, {log: true}) || {};
module.exports = function(key, value) {
var result;

View file

@ -9,10 +9,10 @@
tryRequire = require('./tryRequire.js'),
pty = tryRequire('pty.js', function(error) {
if (error)
Util.log(error.message);
pty = tryRequire('pty.js', {
log: true
}),
Clients = [],
CHANNEL = CloudFunc.CHANNEL_TERMINAL,

View file

@ -3,16 +3,16 @@
var Util = require('../util');
module.exports = function(name, callback) {
module.exports = function tryRequire(name, options) {
var module,
isFunc = typeof callback === 'function',
o = options || {},
error = Util.exec.try(function() {
module = require(name);
});
if (error && isFunc)
callback(error);
if (error && o.log)
Util.log(error.message);
return module;
};