diff options
author | Samy Pessé <samypesse@gmail.com> | 2015-10-13 15:50:54 +0200 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2015-10-13 15:50:54 +0200 |
commit | 269d08a35fb1e5a235b4db078293d0bd3f8565ff (patch) | |
tree | 4080be0ef4fdd384d19182d38a2b8ccd7956367d | |
parent | f626e83e48fbe3039aa21f5df610d9004f5f75c4 (diff) | |
download | gitbook-269d08a35fb1e5a235b4db078293d0bd3f8565ff.zip gitbook-269d08a35fb1e5a235b4db078293d0bd3f8565ff.tar.gz gitbook-269d08a35fb1e5a235b4db078293d0bd3f8565ff.tar.bz2 |
Correctly handle pre-version for plugins checks
-rw-r--r-- | lib/configuration.js | 3 | ||||
-rw-r--r-- | lib/plugin.js | 5 | ||||
-rw-r--r-- | lib/version.js | 19 |
3 files changed, 23 insertions, 4 deletions
diff --git a/lib/configuration.js b/lib/configuration.js index d514720..5c5f9af 100644 --- a/lib/configuration.js +++ b/lib/configuration.js @@ -5,6 +5,7 @@ var semver = require('semver'); var pkg = require('../package.json'); var i18n = require('./utils/i18n'); +var version = require('./version'); var DEFAULT_CONFIG = require('./config_default'); @@ -139,7 +140,7 @@ Configuration.prototype.load = function() { }) .then(function() { if (!that.book.isSubBook()) { - if (!semver.satisfies(pkg.version, that.options.gitbook)) { + if (!version.satisfies(that.options.gitbook)) { throw new Error('GitBook version doesn\'t satisfy version required by the book: '+that.options.gitbook); } if (that.options.gitbook != '*' && !semver.satisfies(semver.inc(pkg.version, 'patch'), that.options.gitbook)) { diff --git a/lib/plugin.js b/lib/plugin.js index b4d4aa1..b7e8260 100644 --- a/lib/plugin.js +++ b/lib/plugin.js @@ -1,6 +1,5 @@ var _ = require('lodash'); var Q = require('q'); -var semver = require('semver'); var path = require('path'); var url = require('url'); var fs = require('./utils/fs'); @@ -9,7 +8,7 @@ var mergeDefaults = require('merge-defaults'); var jsonschema = require('jsonschema'); var jsonSchemaDefaults = require('json-schema-defaults'); -var pkg = require('../package.json'); +var version = require('./version'); var PLUGIN_PREFIX = 'gitbook-plugin-'; @@ -145,7 +144,7 @@ Plugin.prototype.isValid = function() { this.packageInfos.name && this.packageInfos.engines && this.packageInfos.engines.gitbook && - semver.satisfies(pkg.version, this.packageInfos.engines.gitbook) + version.satisfies(this.packageInfos.engines.gitbook) ); // Valid hooks diff --git a/lib/version.js b/lib/version.js new file mode 100644 index 0000000..f0ae187 --- /dev/null +++ b/lib/version.js @@ -0,0 +1,19 @@ +var semver = require('semver'); +var pkg = require('../package.json'); + +var VERSION = pkg.version; +var VERSION_STABLE = VERSION.replace(/\-(\S+)/g, ''); + +// Test if current current gitbook version satisfies a condition +// We can't directly use samver.satisfies since it will break all plugins when gitbook version is a prerelease (beta, alpha) +function satisfies(condition) { + // Test with real version + if (semver.satisfies(VERSION, condition)) return true; + + // Test with future stable release + return semver.satisfies(VERSION_STABLE, condition); +} + +module.exports = { + satisfies: satisfies +}; |