mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-21 10:03:31 +00:00
Improve addPlugin to not append default plugins to the list
This commit is contained in:
@@ -1,16 +1,22 @@
|
||||
var PluginDependency = require('../../models/pluginDependency');
|
||||
var togglePlugin = require('./togglePlugin');
|
||||
var isDefaultPlugin = require('./isDefaultPlugin');
|
||||
|
||||
/**
|
||||
* Add a plugin to a book's configuration
|
||||
* @param {Config} config
|
||||
* @param {String} plugin
|
||||
* @param {String} pluginName
|
||||
* @param {String} version (optional)
|
||||
* @return {Config}
|
||||
*/
|
||||
function addPlugin(config, plugin, version) {
|
||||
var deps = config.getPluginDependencies();
|
||||
function addPlugin(config, pluginName, version) {
|
||||
// For default plugin, we only ensure it is enabled
|
||||
if (isDefaultPlugin(pluginName, version)) {
|
||||
return togglePlugin(config, pluginName, true);
|
||||
}
|
||||
|
||||
var dep = PluginDependency.create(plugin, version);
|
||||
var deps = config.getPluginDependencies();
|
||||
var dep = PluginDependency.create(pluginName, version);
|
||||
|
||||
deps = deps.push(dep);
|
||||
return config.setPluginDependencies(deps);
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
var DEFAULT_PLUGINS = require('../../constants/defaultPlugins');
|
||||
|
||||
/**
|
||||
* Test if a plugin is a default one
|
||||
* @param {String} plugin
|
||||
* @param {String} version
|
||||
* @return {Boolean}
|
||||
*/
|
||||
function isDefaultPlugin(pluginName, version) {
|
||||
return !!DEFAULT_PLUGINS.find(function(dep) {
|
||||
return dep.getName() === pluginName && (!version || dep.getVersion() === version);
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = isDefaultPlugin;
|
||||
@@ -1,5 +1,5 @@
|
||||
var DEFAULT_PLUGINS = require('../../constants/defaultPlugins');
|
||||
var togglePlugin = require('./togglePlugin');
|
||||
var isDefaultPlugin = require('./isDefaultPlugin');
|
||||
|
||||
/**
|
||||
* Remove a plugin from a book's configuration
|
||||
@@ -10,12 +10,8 @@ var togglePlugin = require('./togglePlugin');
|
||||
function removePlugin(config, pluginName) {
|
||||
var deps = config.getPluginDependencies();
|
||||
|
||||
var isDefault = DEFAULT_PLUGINS.find(function(dep) {
|
||||
return dep.getName() === pluginName;
|
||||
});
|
||||
|
||||
// For default plugin, we have to disable it instead of removing from the list
|
||||
if (isDefault) {
|
||||
if (isDefaultPlugin(pluginName)) {
|
||||
return togglePlugin(config, pluginName, false);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user