diff --git a/app.js b/app.js index bb81d91698..0a963230b0 100644 --- a/app.js +++ b/app.js @@ -183,7 +183,7 @@ function start() { require('./src/meta').configs.init(next); }, function(next) { - return next(new Error('dependencies-out-of-date')); + require('./src/meta').dependencies.check(next); }, function(next) { require('./src/upgrade').check(next); diff --git a/src/meta.js b/src/meta.js index 7226de3c60..2def8dedff 100644 --- a/src/meta.js +++ b/src/meta.js @@ -24,6 +24,7 @@ var async = require('async'), require('./meta/settings')(Meta); require('./meta/logs')(Meta); require('./meta/tags')(Meta); + require('./meta/dependencies')(Meta); Meta.templates = require('./meta/templates'); /* Assorted */ diff --git a/src/meta/dependencies.js b/src/meta/dependencies.js new file mode 100644 index 0000000000..61f750bb15 --- /dev/null +++ b/src/meta/dependencies.js @@ -0,0 +1,41 @@ +'use strict'; + +var path = require('path'), + fs = require('fs'), + async = require('async'), + semver = require('semver'), + winston = require('winston'), + + pkg = require.main.require('./package.json'); + +module.exports = function(Meta) { + Meta.dependencies = {}; + + Meta.dependencies.check = function(callback) { + var modules = Object.keys(pkg.dependencies); + winston.verbose('Checking dependencies for outdated modules'); + + async.every(modules, function(module, next) { + fs.readFile(path.join(__dirname, '../../node_modules/', module, 'package.json'), { + encoding: 'utf-8' + }, function(err, pkgData) { + try { + var pkgData = JSON.parse(pkgData), + ok = semver.satisfies(pkgData.version, pkg.dependencies[module]); + + if (ok) { + next(true); + } else { + process.stdout.write('[' + 'outdated'.yellow + '] ' + module.bold + ' v' + pkgData.version + ', requires ' + pkg.dependencies[module] + '\n') + next(false); + } + } catch(e) { + winston.error('[meta.dependencies] Could not read: ' + module); + process.exit(); + } + }) + }, function(ok) { + callback(!ok ? new Error('dependencies-out-of-date') : null); + }); + }; +}; \ No newline at end of file