diff options
Diffstat (limited to 'lib/plugins/validatePlugin.js')
-rw-r--r-- | lib/plugins/validatePlugin.js | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/lib/plugins/validatePlugin.js b/lib/plugins/validatePlugin.js new file mode 100644 index 0000000..37f6900 --- /dev/null +++ b/lib/plugins/validatePlugin.js @@ -0,0 +1,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; |