diff --git a/core/ghost.js b/core/ghost.js index b86e75eb31..b298b7a696 100644 --- a/core/ghost.js +++ b/core/ghost.js @@ -14,7 +14,6 @@ var config = require('../config'), Polyglot = require('node-polyglot'), Mailer = require('./server/mail'), models = require('./server/models'), - plugins = require('./server/plugins'), requireTree = require('./server/require-tree'), permissions = require('./server/permissions'), uuid = require('node-uuid'), @@ -352,35 +351,4 @@ Ghost.prototype.doFilter = function (name, args) { return when.pipeline(priorityCallbacks, args); }; -// Initialise plugins. Will load from config.activePlugins by default -Ghost.prototype.initPlugins = function (pluginsToLoad) { - var self = this; - - if (!_.isArray(pluginsToLoad)) { - - try { - // We have to parse the value because it's a string - pluginsToLoad = JSON.parse(this.settings('activePlugins')) || []; - } catch (e) { - errors.logError( - 'Failed to parse activePlugins setting value: ' + e.message, - 'Your plugins will not be loaded.', - 'Check your settings table for typos in the activePlugins value. It should look like: ["plugin-1", "plugin2"] (double quotes required).' - ); - return when.resolve(); - } - } - - return plugins.init(self, pluginsToLoad).then(function (loadedPlugins) { - // Extend the loadedPlugins onto the available plugins - _.extend(self.availablePlugins, loadedPlugins); - }).otherwise(function (err) { - errors.logError( - err.message || err, - 'The plugin will not be loaded', - 'Check with the plugin creator, or read the plugin documentation for more details on plugin requirements' - ); - }); -}; - module.exports = Ghost; diff --git a/core/server.js b/core/server.js index 3ae4146c6b..d9d153adfd 100644 --- a/core/server.js +++ b/core/server.js @@ -10,6 +10,7 @@ var express = require('express'), admin = require('./server/controllers/admin'), frontend = require('./server/controllers/frontend'), api = require('./server/api'), + plugins = require('./server/plugins'), path = require('path'), hbs = require('express-hbs'), Ghost = require('./ghost'), @@ -373,7 +374,7 @@ when(ghost.init()).then(function () { ghost.server = server; // Initialize plugins then start the server - ghost.initPlugins().then(function () { + plugins.init(ghost).then(function () { // ## Start Ghost App if (getSocket()) { diff --git a/core/server/plugins/index.js b/core/server/plugins/index.js index 468d0b9184..57c6cdbac5 100644 --- a/core/server/plugins/index.js +++ b/core/server/plugins/index.js @@ -1,6 +1,7 @@ var _ = require('underscore'), when = require('when'), + errors = require('../errorHandling'), ghostApi, loader = require('./loader'), GhostPlugin = require('./GhostPlugin'); @@ -34,7 +35,21 @@ function saveInstalledPlugins(installedPlugins) { module.exports = { GhostPlugin: GhostPlugin, - init: function (ghost, pluginsToLoad) { + init: function (ghost) { + var pluginsToLoad; + + try { + // We have to parse the value because it's a string + pluginsToLoad = JSON.parse(ghost.settings('activePlugins')) || []; + } catch (e) { + errors.logError( + 'Failed to parse activePlugins setting value: ' + e.message, + 'Your plugins will not be loaded.', + 'Check your settings table for typos in the activePlugins value. It should look like: ["plugin-1", "plugin2"] (double quotes required).' + ); + return when.resolve(); + } + // Grab all installed plugins, install any not already installed that are in pluginsToLoad. return getInstalledPlugins().then(function (installedPlugins) { var loadedPlugins = {}, @@ -64,8 +79,14 @@ module.exports = { // Save our installed plugins to settings return saveInstalledPlugins(_.keys(loadedPlugins)); }).then(function () { - // Return the hash of all loaded plugins - return when.resolve(loadedPlugins); + // Extend the loadedPlugins onto the available plugins + _.extend(ghost.availablePlugins, loadedPlugins); + }).otherwise(function (err) { + errors.logError( + err.message || err, + 'The plugin will not be loaded', + 'Check with the plugin creator, or read the plugin documentation for more details on plugin requirements' + ); }); }); }