diff options
author | Ryan Swanson <ryan.swanson@theice.com> | 2016-05-26 14:30:29 -0400 |
---|---|---|
committer | Ryan Swanson <ryan.swanson@theice.com> | 2016-05-26 14:30:29 -0400 |
commit | 465e8d6c0adfe69f696fafa7486541aac55298fe (patch) | |
tree | 9d74bf28ccc1dfdcc38f2666f4459b44452a00bf /lib/plugins/installPlugins.js | |
parent | 7b915428f7b780e49b641639c6ba7166132ac87c (diff) | |
download | gitbook-465e8d6c0adfe69f696fafa7486541aac55298fe.zip gitbook-465e8d6c0adfe69f696fafa7486541aac55298fe.tar.gz gitbook-465e8d6c0adfe69f696fafa7486541aac55298fe.tar.bz2 |
Fixed two issues for handling git URLs for plugins that are published to git repositories rather than on npmjs.org.
Fixed issue in pluginDependency to dereference 'name' and 'version' using Immutable Map.get(...) accessors since config values are now wrapped by Immutable.fromJS(...) in config.js > setValue(...). Added associated unit test.
Fixed issue in resolveVersion where a plugin may be using a git URL rather than a semver for the version portion of the plugin config definition. In addition, refactored the resolveVersion function into a new module to allow for unit testing. Added associated unit test.
Diffstat (limited to 'lib/plugins/installPlugins.js')
-rw-r--r-- | lib/plugins/installPlugins.js | 67 |
1 files changed, 1 insertions, 66 deletions
diff --git a/lib/plugins/installPlugins.js b/lib/plugins/installPlugins.js index 5adae04..ed9316c 100644 --- a/lib/plugins/installPlugins.js +++ b/lib/plugins/installPlugins.js @@ -1,75 +1,10 @@ -var npm = require('npm'); var npmi = require('npmi'); -var semver = require('semver'); -var Immutable = require('immutable'); var pkg = require('../../package.json'); var DEFAULT_PLUGINS = require('../constants/defaultPlugins'); var Promise = require('../utils/promise'); -var Plugin = require('../models/plugin'); -var gitbook = require('../gitbook'); var listForBook = require('./listForBook'); - -var npmIsReady; - -/** - Initialize and prepare NPM - - @return {Promise} -*/ -function initNPM() { - if (npmIsReady) return npmIsReady; - - npmIsReady = Promise.nfcall(npm.load, { - silent: true, - loglevel: 'silent' - }); - - return npmIsReady; -} - - - -/** - Resolve a plugin to a version - - @param {Plugin} - @return {Promise<String>} -*/ -function resolveVersion(plugin) { - var npmId = Plugin.nameToNpmID(plugin.getName()); - var requiredVersion = plugin.getVersion(); - - return initNPM() - .then(function() { - return Promise.nfcall(npm.commands.view, [npmId + '@' + requiredVersion, 'engines'], true); - }) - .then(function(versions) { - versions = Immutable.Map(versions).entrySeq(); - - var result = versions - .map(function(entry) { - return { - version: entry[0], - gitbook: (entry[1].engines || {}).gitbook - }; - }) - .filter(function(v) { - return v.gitbook && gitbook.satisfies(v.gitbook); - }) - .sort(function(v1, v2) { - return semver.lt(v1.version, v2.version)? 1 : -1; - }) - .get(0); - - if (!result) { - return undefined; - } else { - return result.version; - } - }); -} - +var resolveVersion = require('./resolveVersion'); /** Install a plugin for a book |