feature(tryrequire) add from npm

This commit is contained in:
coderaiser 2015-01-01 13:47:21 -05:00
parent 102ec0731a
commit 7fe855edfe
9 changed files with 13 additions and 56 deletions

View file

@ -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});

View file

@ -5,7 +5,7 @@
crypto = require('crypto'),
tryRequire = require(DIR + 'tryRequire'),
tryRequire = require('tryrequire'),
config = require(DIR + 'config'),
oldPass,

View file

@ -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'),

View file

@ -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();

View file

@ -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. ' +

View file

@ -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,

View file

@ -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'),

View file

@ -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;
}
})();

View file

@ -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",