diff options
author | Samy Pessé <samypesse@gmail.com> | 2014-04-19 15:41:29 +0200 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2014-04-19 15:41:29 +0200 |
commit | 56eb4a2897ae78be35db33172376f9901e23546e (patch) | |
tree | 5d768d6e4ff6dc0705aee5a2255c0df0e42f165e /lib/generate/plugin.js | |
parent | 7a461eaa613312430712212bc2247a1961c762f8 (diff) | |
download | gitbook-56eb4a2897ae78be35db33172376f9901e23546e.zip gitbook-56eb4a2897ae78be35db33172376f9901e23546e.tar.gz gitbook-56eb4a2897ae78be35db33172376f9901e23546e.tar.bz2 |
Add base plugin object and test validation of plugin
Diffstat (limited to 'lib/generate/plugin.js')
-rw-r--r-- | lib/generate/plugin.js | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/lib/generate/plugin.js b/lib/generate/plugin.js new file mode 100644 index 0000000..bc131c6 --- /dev/null +++ b/lib/generate/plugin.js @@ -0,0 +1,28 @@ +var semver = require("semver"); +var fs = require("./fs"); + +var pkg = require("../../package.json"); + +var Plugin = function(name) { + this.name = name; + this.packageInfos = {}; + + try { + this.packageInfos = require(name+"/package.json"); + } catch (e) { + this.packageInfos = {}; + } +}; + +// Test if it's a valid plugin +Plugin.prototype.isValid = function() { + return ( + this.packageInfos + && this.packageInfos.name + && this.packageInfos.engines + && this.packageInfos.engines.gitbook + && semver.satisfies(pkg.version, this.packageInfos.engines.gitbook) + ); +}; + +module.exports = Plugin;
\ No newline at end of file |