summaryrefslogtreecommitdiffstats
path: root/lib/plugins/validatePlugin.js
blob: 37f69007acf8f09afcee558804819178d484003e (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
var gitbook = require('../gitbook');

var Promise = require('../utils/promise');

/**
    Validate a plugin

    @param {Plugin}
    @return {Promise<Plugin>}
*/
function validatePlugin(plugin) {
    var packageInfos = plugin.getPackage();

    var isValid = (
        plugin.isLoaded() &&
        packageInfos &&
        packageInfos.name &&
        packageInfos.engines &&
        packageInfos.engines.gitbook
    );

    if (!isValid) {
        return Promise.reject(new Error('Error loading plugin "' + plugin.getName() + '" at "' + plugin.getPath() + '"'));
    }

    if (!gitbook.satisfies(this.packageInfos.engines.gitbook)) {
        return Promise.reject(new Error('GitBook doesn\'t satisfy the requirements of this plugin: ' + packageInfos.engines.gitbook));
    }

    return Promise();
}

module.exports = validatePlugin;