summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/plugins/plugin.js33
1 files changed, 28 insertions, 5 deletions
diff --git a/lib/plugins/plugin.js b/lib/plugins/plugin.js
index d4d2b23..05fa8ca 100644
--- a/lib/plugins/plugin.js
+++ b/lib/plugins/plugin.js
@@ -1,7 +1,9 @@
+var _ = require('lodash');
var path = require('path');
var resolve = require('resolve');
var Promise = require('../utils/promise');
+var gitbook = require('../gitbook');
var PLUGIN_PREFIX = 'gitbook-plugin-';
@@ -62,14 +64,35 @@ BookPlugin.prototype.load = function() {
return true;
})
- .then(function() {
- if (!that.isLoaded()) {
- throw new Error('Couldn\'t locate plugin "' + that.id + '", Run \'gitbook install\' to install plugins from registry.');
- }
- });
+ .then(that.validate);
this.log.info.log('Loading plugin "' + this.id + '" ...');
return this.log.info.promise('', promise);
};
+
+// Verify the definition of a plugin
+// Also verify that the plugin accepts the current gitbook version
+// This method throws erros if plugin is invalid
+BookPlugin.prototype.validate = function() {
+ var isValid = (
+ this.packageInfos &&
+ this.packageInfos.name &&
+ this.packageInfos.engines &&
+ this.packageInfos.engines.gitbook
+ );
+
+ if (!this.isLoaded()) {
+ throw new Error('Couldn\'t locate plugin "' + this.id + '", Run \'gitbook install\' to install plugins from registry.');
+ }
+
+ if (!isValid) {
+ throw new Error('Invalid plugin "' + this.id + '"');
+ }
+
+ if (!gitbook.satisfies(this.packageInfos.engines.gitbook)) {
+ throw new Error('GitBook doesn\'t satisfy the requirements of this plugin: '+this.packageInfos.engines.gitbook);
+ }
+};
+
module.exports = BookPlugin;