summaryrefslogtreecommitdiffstats
path: root/lib/plugins/listAll.js
blob: 70bf9cd58c18ea59b442be9d7deea36f35d46265 (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
43
44
var Immutable = require('immutable');
var Plugin = require('../models/plugin');

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

/**
    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 = deps.concat(DEFAULT_PLUGINS);

    // 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);
    });

    // Sort plugins
    return sortPlugins(plugins);
}

module.exports = listAll;