summaryrefslogtreecommitdiffstats
path: root/lib/plugins
diff options
context:
space:
mode:
authorSamy Pesse <samypesse@gmail.com>2016-02-16 15:42:24 +0100
committerSamy Pesse <samypesse@gmail.com>2016-02-16 15:42:24 +0100
commit327d0bf5c52982a5a20967c8435aff9b60ed509d (patch)
tree61c840cc330f3b552ab7c37640f668bd8d331684 /lib/plugins
parent2375296e67cf813db2076877ba64c0d3dfae2b3f (diff)
downloadgitbook-327d0bf5c52982a5a20967c8435aff9b60ed509d.zip
gitbook-327d0bf5c52982a5a20967c8435aff9b60ed509d.tar.gz
gitbook-327d0bf5c52982a5a20967c8435aff9b60ed509d.tar.bz2
Validate plugin after loading
Diffstat (limited to 'lib/plugins')
-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;