diff options
author | Samy Pessé <samypesse@gmail.com> | 2016-01-29 12:28:51 +0100 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2016-01-29 12:28:51 +0100 |
commit | 633de85180b1c968edc3e884821c3de668d23506 (patch) | |
tree | 462d2201da36e4b9c9a9eda3d521d885a7ac5ec0 /lib/plugins | |
parent | f32d03eb88d66b37874c461c6327b4576327b4db (diff) | |
download | gitbook-633de85180b1c968edc3e884821c3de668d23506.zip gitbook-633de85180b1c968edc3e884821c3de668d23506.tar.gz gitbook-633de85180b1c968edc3e884821c3de668d23506.tar.bz2 |
Improve plugin loading to elimate false-negative
Diffstat (limited to 'lib/plugins')
-rw-r--r-- | lib/plugins/plugin.js | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/lib/plugins/plugin.js b/lib/plugins/plugin.js index e9af9d4..d4d2b23 100644 --- a/lib/plugins/plugin.js +++ b/lib/plugins/plugin.js @@ -14,12 +14,14 @@ function npmId(name) { function BookPlugin(book, pluginId) { this.book = book; + this.log = this.book.log; + this.id = pluginId; this.npmId = npmId(pluginId); + this.baseDir; this.packageInfos = undefined; this.content = undefined; - } // Return true if plugin has been loaded correctly @@ -36,26 +38,28 @@ BookPlugin.prototype.load = function() { } // Try loading plugins from different location - return Promise.some([ + var promise = Promise.some([ this.book.resolve('node_modules'), __dirname ], function(baseDir) { + // Locate plugin and load pacjage.json try { - var res = resolve.sync(name+'/package.json', { basedir: baseDir }); + var res = resolve.sync(name + '/package.json', { basedir: baseDir }); that.baseDir = path.dirname(res); that.packageInfos = require(res); - that.content = require(resolve.sync(name, { basedir: baseDir })); - - return true; } catch (err) { - if (err.code != 'MODULE_NOT_FOUND') throw(err); + if (err.code != 'MODULE_NOT_FOUND') throw err; that.packageInfos = undefined; that.content = undefined; return false; } + + // Load plugin JS content + that.content = require(resolve.sync(name, { basedir: baseDir })); + return true; }) .then(function() { @@ -63,6 +67,9 @@ BookPlugin.prototype.load = function() { throw new Error('Couldn\'t locate plugin "' + that.id + '", Run \'gitbook install\' to install plugins from registry.'); } }); + + this.log.info.log('Loading plugin "' + this.id + '" ...'); + return this.log.info.promise('', promise); }; module.exports = BookPlugin; |