summaryrefslogtreecommitdiffstats
path: root/lib/plugins/listAll.js
blob: cbeb06b894071f84632360b884b43cd9d7a8d756 (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
30
31
32
33
34
35
36
37
38
39
40
41
42
var Immutable = require('immutable');
var Plugin = require('../models/plugin');

var DEFAULT_PLUGINS = require('../constants/defaultPlugins');

/**
    List all plugins for a book

    @param {List<PluginDependency>} deps
    @return {OrderedMap<Plugin>}
*/
function listAll(deps) {
    // Extract list of plugins to disable (starting with -)
    var toRemove = deps
        .filter(function(plugin) {
            return !plugin.isEnabled();
        })
        .map(function(plugin) {
            return plugin.getName();
        });

    // Concat with default plugins
    deps = DEFAULT_PLUGINS.concat(deps);

    // Convert to an ordered map of Plugin
    var plugins = deps
        .map(function(dep) {
            var plugin = Plugin.createFromDep(dep);

            return [dep.getName(), plugin];
        });
    plugins = Immutable.OrderedMap(plugins);

    // Remove plugins
    plugins = plugins.filterNot(function(plugin, name) {
        return toRemove.includes(name);
    });

    return plugins;
}

module.exports = listAll;