blob: 4baa911390228aa189c99ce388845df01952dc0f (
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
|
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.get('name') &&
packageInfos.get('engines') &&
packageInfos.get('engines').get('gitbook')
);
if (!isValid) {
return Promise.reject(new Error('Error loading plugin "' + plugin.getName() + '" at "' + plugin.getPath() + '"'));
}
var engine = packageInfos.get('engines').get('gitbook');
if (!gitbook.satisfies(engine)) {
return Promise.reject(new Error('GitBook doesn\'t satisfy the requirements of this plugin: ' + engine));
}
return Promise(plugin);
}
module.exports = validatePlugin;
|