diff options
Diffstat (limited to 'lib/plugins')
-rw-r--r-- | lib/plugins/__tests__/findForBook.js | 19 | ||||
-rw-r--r-- | lib/plugins/__tests__/locateRootFolder.js | 10 | ||||
-rw-r--r-- | lib/plugins/findForBook.js | 14 | ||||
-rw-r--r-- | lib/plugins/locateRootFolder.js | 22 |
4 files changed, 58 insertions, 7 deletions
diff --git a/lib/plugins/__tests__/findForBook.js b/lib/plugins/__tests__/findForBook.js new file mode 100644 index 0000000..d8af2e9 --- /dev/null +++ b/lib/plugins/__tests__/findForBook.js @@ -0,0 +1,19 @@ +var path = require('path'); + +var Book = require('../../models/book'); +var createNodeFS = require('../../fs/node'); +var findForBook = require('../findForBook'); + +describe('findForBook', function() { + var fs = createNodeFS( + path.resolve(__dirname, '../../..') + ); + var book = Book.createForFS(fs); + + it('should list default plugins', function() { + return findForBook(book) + .then(function(plugins) { + expect(plugins.has('fontsettings')).toBeTruthy(); + }); + }); +}); diff --git a/lib/plugins/__tests__/locateRootFolder.js b/lib/plugins/__tests__/locateRootFolder.js new file mode 100644 index 0000000..bb414a3 --- /dev/null +++ b/lib/plugins/__tests__/locateRootFolder.js @@ -0,0 +1,10 @@ +var path = require('path'); +var locateRootFolder = require('../locateRootFolder'); + +describe('locateRootFolder', function() { + it('should correctly resolve the node_modules for gitbook', function() { + expect(locateRootFolder()).toBe( + path.resolve(__dirname, '../../../') + ); + }); +}); diff --git a/lib/plugins/findForBook.js b/lib/plugins/findForBook.js index 14ccc05..be2ad9f 100644 --- a/lib/plugins/findForBook.js +++ b/lib/plugins/findForBook.js @@ -1,22 +1,22 @@ -var path = require('path'); var Immutable = require('immutable'); var Promise = require('../utils/promise'); var timing = require('../utils/timing'); var findInstalled = require('./findInstalled'); +var locateRootFolder = require('./locateRootFolder'); /** - List all plugins installed in a book - - @param {Book} - @return {Promise<OrderedMap<String:Plugin>>} -*/ + * List all plugins installed in a book + * + * @param {Book} + * @return {Promise<OrderedMap<String:Plugin>>} + */ function findForBook(book) { return timing.measure( 'plugins.findForBook', Promise.all([ - findInstalled(path.resolve(__dirname, '../..')), + findInstalled(locateRootFolder()), findInstalled(book.getRoot()) ]) diff --git a/lib/plugins/locateRootFolder.js b/lib/plugins/locateRootFolder.js new file mode 100644 index 0000000..1139510 --- /dev/null +++ b/lib/plugins/locateRootFolder.js @@ -0,0 +1,22 @@ +var path = require('path'); +var resolve = require('resolve'); + +var DEFAULT_PLUGINS = require('../constants/defaultPlugins'); + +/** + * Resolve the root folder containing for node_modules + * since gitbook can be used as a library and dependency can be flattened. + * + * @return {String} folderPath + */ +function locateRootFolder() { + var firstDefaultPlugin = DEFAULT_PLUGINS.first(); + var pluginPath = resolve.sync(firstDefaultPlugin.getNpmID() + '/package.json', { + basedir: __dirname + }); + var nodeModules = path.resolve(pluginPath, '../../..'); + + return nodeModules; +} + +module.exports = locateRootFolder; |