mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-28 05:37:34 +03:00
37b2fd93d8
Move helper functions registerThemeHelper and registerAsyncThemeHelper to the helpers module. Also update the app proxy object to reflect this new code location, and the tests to reflect that as well Create ./sore/server/filters which houses all filter related behavior. Was previously on the ghost singleton. Also create the filters_spec file for testing and update all code and tests to use new code location. Create ./sore/server/helpers/template which houses all template related behavior. Was previously on the ghost singleton. Also create the helpers_template_spec file for testing and update all code and tests to use new code location. Move ghost.mail instance onto the mail module directly and update related code and tests to use new location Move Polyglot instance onto require module directly Move ghost.availablePlugins to plugins module directly
95 lines
3.6 KiB
JavaScript
95 lines
3.6 KiB
JavaScript
|
|
var _ = require('underscore'),
|
|
when = require('when'),
|
|
errors = require('../errorHandling'),
|
|
ghostApi,
|
|
loader = require('./loader'),
|
|
availablePlugins;
|
|
|
|
// Holds the available plugins
|
|
availablePlugins = {};
|
|
|
|
function getInstalledPlugins() {
|
|
if (!ghostApi) {
|
|
ghostApi = require('../api');
|
|
}
|
|
|
|
return ghostApi.settings.read('installedPlugins').then(function (installed) {
|
|
installed.value = installed.value || '[]';
|
|
|
|
try {
|
|
installed = JSON.parse(installed.value);
|
|
} catch (e) {
|
|
return when.reject(e);
|
|
}
|
|
|
|
return installed;
|
|
});
|
|
}
|
|
|
|
function saveInstalledPlugins(installedPlugins) {
|
|
return getInstalledPlugins().then(function (currentInstalledPlugins) {
|
|
var updatedPluginsInstalled = _.uniq(installedPlugins.concat(currentInstalledPlugins));
|
|
|
|
return ghostApi.settings.edit('installedPlugins', updatedPluginsInstalled);
|
|
});
|
|
}
|
|
|
|
module.exports = {
|
|
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 = {},
|
|
recordLoadedPlugin = function (name, loadedPlugin) {
|
|
// After loading the plugin, add it to our hash of loaded plugins
|
|
loadedPlugins[name] = loadedPlugin;
|
|
|
|
return when.resolve(loadedPlugin);
|
|
},
|
|
loadPromises = _.map(pluginsToLoad, function (plugin) {
|
|
// If already installed, just activate the plugin
|
|
if (_.contains(installedPlugins, plugin)) {
|
|
return loader.activatePluginByName(plugin, ghost).then(function (loadedPlugin) {
|
|
return recordLoadedPlugin(plugin, loadedPlugin);
|
|
});
|
|
}
|
|
|
|
// Install, then activate the plugin
|
|
return loader.installPluginByName(plugin, ghost).then(function () {
|
|
return loader.activatePluginByName(plugin, ghost);
|
|
}).then(function (loadedPlugin) {
|
|
return recordLoadedPlugin(plugin, loadedPlugin);
|
|
});
|
|
});
|
|
|
|
return when.all(loadPromises).then(function () {
|
|
// Save our installed plugins to settings
|
|
return saveInstalledPlugins(_.keys(loadedPlugins));
|
|
}).then(function () {
|
|
// Extend the loadedPlugins onto the available plugins
|
|
_.extend(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'
|
|
);
|
|
});
|
|
});
|
|
},
|
|
availablePlugins: availablePlugins
|
|
}; |