mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 10:45:47 +00:00
feature(tryrequire) add from npm
This commit is contained in:
parent
102ec0731a
commit
7fe855edfe
9 changed files with 13 additions and 56 deletions
|
|
@ -12,7 +12,7 @@
|
|||
config = require(DIR_SERVER + 'config'),
|
||||
express = require(DIR_SERVER + 'express'),
|
||||
|
||||
tryRequire = require(DIR_SERVER + 'tryRequire'),
|
||||
tryRequire = require('tryrequire'),
|
||||
|
||||
io = tryRequire('socket.io', {log: true});
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
crypto = require('crypto'),
|
||||
|
||||
tryRequire = require(DIR + 'tryRequire'),
|
||||
tryRequire = require('tryrequire'),
|
||||
config = require(DIR + 'config'),
|
||||
|
||||
oldPass,
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@
|
|||
CloudFunc = require(DIR_LIB + 'cloudfunc'),
|
||||
check = Util.check,
|
||||
|
||||
tryRequire = require(DIR_SERVER + 'tryRequire'),
|
||||
tryRequire = require('tryrequire'),
|
||||
|
||||
pipe = require('pipe-io'),
|
||||
ponse = require('ponse'),
|
||||
|
|
|
|||
|
|
@ -5,10 +5,10 @@
|
|||
DIR_LIB = DIR + 'lib/',
|
||||
|
||||
Util = require(DIR_LIB + 'util'),
|
||||
tryRequire = require('./tryRequire'),
|
||||
|
||||
tryRequire = require('tryrequire'),
|
||||
|
||||
express = tryRequire('express'),
|
||||
|
||||
logger = tryRequire('morgan'),
|
||||
|
||||
app = express && express();
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@
|
|||
'use strict';
|
||||
|
||||
var DIR = '../',
|
||||
DIR_SERVER = './',
|
||||
|
||||
fs = require('fs'),
|
||||
|
||||
|
|
@ -11,7 +10,7 @@
|
|||
diffPatch = require(DIR + 'diff/diff-match-patch').diff_match_patch,
|
||||
diff = new (require(DIR + 'diff').DiffProto)(diffPatch),
|
||||
|
||||
tryRequire = require(DIR_SERVER + 'tryRequire'),
|
||||
tryRequire = require('tryrequire'),
|
||||
flop = tryRequire('flop', {log: true, exit: true}),
|
||||
|
||||
ERROR_MSG = 'File is to big. ' +
|
||||
|
|
|
|||
|
|
@ -9,14 +9,11 @@
|
|||
|
||||
Util = require(DIR_LIB + 'util'),
|
||||
|
||||
tryRequire = require(DIR + 'tryRequire'),
|
||||
tryOptions = {log: true, exit: true},
|
||||
mellow = require('mellow'),
|
||||
pipe = require('pipe-io'),
|
||||
ponse = require('ponse'),
|
||||
|
||||
mellow = tryRequire('mellow', tryOptions),
|
||||
pipe = tryRequire('pipe-io', tryOptions),
|
||||
ponse = tryRequire('ponse', tryOptions),
|
||||
|
||||
marked = tryRequire('marked');
|
||||
marked = require('marked');
|
||||
|
||||
module.exports = function(name, request, callback) {
|
||||
var query,
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
Util = require(DIR_LIB + 'util'),
|
||||
CloudFunc = require(DIR_LIB + 'cloudfunc'),
|
||||
|
||||
tryRequire = require('./tryRequire.js'),
|
||||
tryRequire = require('tryrequire'),
|
||||
|
||||
pty = tryRequire('pty.js'),
|
||||
|
||||
|
|
|
|||
|
|
@ -1,40 +0,0 @@
|
|||
(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;
|
||||
}
|
||||
})();
|
||||
|
|
@ -44,7 +44,8 @@
|
|||
"pipe-io": "~1.1.1",
|
||||
"ponse": "~1.3.0",
|
||||
"restafary": "~1.0.0",
|
||||
"socket.io": "~1.2.0"
|
||||
"socket.io": "~1.2.0",
|
||||
"tryrequire": "~1.1.5"
|
||||
},
|
||||
"devDependencies": {
|
||||
"changelog-io": "~1.3.4",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue