mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 10:45:47 +00:00
feature(tryRequire) name, callback -> name, options
This commit is contained in:
parent
4d8adf3ed9
commit
30ea708d09
6 changed files with 11 additions and 14 deletions
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
tryRequire = require(DIR_SERVER + 'tryRequire'),
|
||||
|
||||
io = tryRequire('socket.io');
|
||||
io = tryRequire('socket.io', {log: true});
|
||||
|
||||
/**
|
||||
* start server function
|
||||
|
|
|
|||
|
|
@ -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'),
|
||||
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@
|
|||
|
||||
ConfigPath = DIR + 'json/config.json',
|
||||
|
||||
config = tryRequire(ConfigPath) || {};
|
||||
config = tryRequire(ConfigPath, {log: true}) || {};
|
||||
|
||||
module.exports = function(key, value) {
|
||||
var result;
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue