summaryrefslogtreecommitdiffstats
path: root/lib/generate/plugin.js
blob: bc131c6de1d3a74f386f2b8a298bc3696d6ae2ee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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;