mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-17 16:15:22 +00:00
34 lines
835 B
JavaScript
34 lines
835 B
JavaScript
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;
|