From bbdcd5d460263698a65eae8efd9c16d9f1758b9e Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Thu, 13 Feb 2014 22:38:24 -0500 Subject: [PATCH] resolved #997 --- nodebb | 6 +++--- src/plugins.js | 25 ++++++++++++++++++++++++- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/nodebb b/nodebb index 25bb31f1c5..9e313a7f4f 100755 --- a/nodebb +++ b/nodebb @@ -6,7 +6,7 @@ case "$1" in start) - node app + node app "$@" ;; upgrade) @@ -26,14 +26,14 @@ case "$1" in echo "Launching NodeBB in \"development\" mode." echo "To run the production build of NodeBB, please use \"forever\"." echo "More Information: https://github.com/designcreateplay/NodeBB/wiki/How-to-run-NodeBB" - NODE_ENV=development node app + NODE_ENV=development node app "$@" ;; watch) echo "Launching NodeBB in \"development\" mode." echo "To run the production build of NodeBB, please use \"forever\"." echo "More Information: https://github.com/designcreateplay/NodeBB/wiki/How-to-run-NodeBB" - NODE_ENV=development supervisor -q --extensions 'node|js|tpl' -- app $1 + NODE_ENV=development supervisor -q --extensions 'node|js|tpl' -- app "$@" ;; # language) diff --git a/src/plugins.js b/src/plugins.js index f2346dfc71..d2b7a6cc98 100644 --- a/src/plugins.js +++ b/src/plugins.js @@ -4,8 +4,11 @@ var fs = require('fs'), winston = require('winston'), nconf = require('nconf'), eventEmitter = require('events').EventEmitter, + semver = require('semver'), + db = require('./database'), - meta = require('./meta'); + meta = require('./meta'), + pkg = require('../package.json'); (function(Plugins) { @@ -107,6 +110,26 @@ var fs = require('fs'), var pluginData = JSON.parse(data), libraryPath, staticDir; + if (pluginData.minver && semver.validRange(pluginData.minver)) { + if (!semver.satisfies(pkg.version, pluginData.minver)) { + // If NodeBB is not new enough to run this plugin + if (process.env.NODE_ENV === 'development') { + // Throw a warning in development, but do nothing else + winston.warn('[plugins/' + pluginData.id + '] This plugin may not be compatible with your version of NodeBB. This may cause unintended behaviour or crashing.'); + } else { + if (nconf.get('check-plugins') !== false) { + // Refuse to load this plugin... + winston.error('[plugins/' + pluginData.id + '] This plugin is reportedly incompatible with your version of NodeBB, so it has been disabled.'); + winston.error('[plugins/' + pluginData.id + '] Use `--no-check-plugins` if you wish to live dangerously.'); + + // ... and disable it, too + Plugins.toggleActive(pluginData.id); + return callback(); + } + } + } + } + async.parallel([ function(next) { if (pluginData.library) {