mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-07 11:30:55 +03:00
Merge pull request #1462 from hswolff/plugin-init-cleanup
Move plugin init code into plugin.js and have it called from server.js
This commit is contained in:
commit
1f29029deb
@ -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;
|
||||
|
@ -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()) {
|
||||
|
@ -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'
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user