summaryrefslogtreecommitdiffstats
path: root/lib/modifiers/config/removePlugin.js
blob: 123be0b6ce1d83594a9de287f118147bcc3d1d19 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
var DEFAULT_PLUGINS = require('../../constants/defaultPlugins');
var togglePlugin = require('./togglePlugin');

/**
 * Remove a plugin from a book's configuration
 * @param {Config} config
 * @param {String} plugin
 * @return {Config}
 */
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) {
        return togglePlugin(config, pluginName, false);
    }

    // Remove the dependency from the list
    deps = deps.filter(function(dep) {
        return dep.getName() === pluginName;
    });
    return config.setPluginDependencies(deps);
}

module.exports = removePlugin;