diff --git a/lib/plugins/__tests__/sortPlugins.js b/lib/plugins/__tests__/sortPlugins.js index 0f5464651..2d7a66d98 100644 --- a/lib/plugins/__tests__/sortPlugins.js +++ b/lib/plugins/__tests__/sortPlugins.js @@ -7,56 +7,54 @@ describe('sortPlugins', function() { var deps = PluginDependency.listFromString('theme-faq'), allPlugins = listAll(deps); - return sortPlugins(allPlugins, []) - .then(function(sorted) { - var plugins = sorted.slice(0, -2), - themes = sorted.slice(-2); + var sorted = sortPlugins(allPlugins, []); - var pluginsOk = plugins.every(function(plugin) { - return !plugin.isTheme(); - }); + var plugins = sorted.slice(0, -2), + themes = sorted.slice(-2); - var themesOk = themes.every(function(theme) { - return theme.isTheme(); - }); - - expect(pluginsOk).toBe(true); - expect(plugins.has('search')).toBe(true); - - expect(themesOk).toBe(true); - expect(themes.size).toBe(2); - expect(themes.has('theme-faq')).toBe(true); - expect(themes.has('theme-default')).toBe(true); - - // theme-default should be last - expect(themes.last().getName()).toBe('theme-default'); + var pluginsOk = plugins.every(function(plugin) { + return !plugin.isTheme(); }); + + var themesOk = themes.every(function(theme) { + return theme.isTheme(); + }); + + expect(pluginsOk).toBe(true); + expect(plugins.has('search')).toBe(true); + + expect(themesOk).toBe(true); + expect(themes.size).toBe(2); + expect(themes.has('theme-faq')).toBe(true); + expect(themes.has('theme-default')).toBe(true); + + // theme-default should be last + expect(themes.last().getName()).toBe('theme-default'); }); it('must load themes after plugins with a complex dependencies list', function() { var deps = PluginDependency.listFromString('comment,theme-faq,-search,ga'), allPlugins = listAll(deps); - return sortPlugins(allPlugins, []) - .then(function(sorted) { - var plugins = sorted.slice(0, -2), - themes = sorted.slice(-2); + var sorted = sortPlugins(allPlugins, []); - var pluginsOk = plugins.every(function(plugin) { - return !plugin.isTheme(); - }); + var plugins = sorted.slice(0, -2), + themes = sorted.slice(-2); - var themesOk = themes.every(function(theme) { - return theme.isTheme(); - }); - - expect(pluginsOk).toBe(true); - expect(plugins.has('search')).toBe(false); - - expect(themesOk).toBe(true); - expect(themes.size).toBe(2); - expect(themes.has('theme-faq')).toBe(true); - expect(themes.has('theme-default')).toBe(true); + var pluginsOk = plugins.every(function(plugin) { + return !plugin.isTheme(); }); + + var themesOk = themes.every(function(theme) { + return theme.isTheme(); + }); + + expect(pluginsOk).toBe(true); + expect(plugins.has('search')).toBe(false); + + expect(themesOk).toBe(true); + expect(themes.size).toBe(2); + expect(themes.has('theme-faq')).toBe(true); + expect(themes.has('theme-default')).toBe(true); }); }); \ No newline at end of file diff --git a/lib/plugins/loadForBook.js b/lib/plugins/loadForBook.js index fd45a77eb..296cb0117 100644 --- a/lib/plugins/loadForBook.js +++ b/lib/plugins/loadForBook.js @@ -7,11 +7,10 @@ var sortPlugins = require('./sortPlugins'); /** - Load a list of plugins in a book - - @param {Book} - @return {Promise} -*/ + * Load a list of plugins in a book + * @param {Book} + * @return {Promise} + */ function loadForBook(book) { var logger = book.getLogger(); var requirements = listForBook(book); @@ -28,9 +27,9 @@ function loadForBook(book) { ); }); - return sortPlugins(installed, requirementsKeys); - }) - .then(function(installed) { + // Sort plugins + installed = sortPlugins(installed, requirementsKeys); + // Log state logger.info.ln(installed.size + ' plugins are installed'); if (requirements.size != installed.size) { diff --git a/lib/plugins/sortPlugins.js b/lib/plugins/sortPlugins.js index 662693612..e96b02ceb 100644 --- a/lib/plugins/sortPlugins.js +++ b/lib/plugins/sortPlugins.js @@ -1,44 +1,35 @@ -var Promise = require('../utils/promise'); - var THEME_PREFIX = require('../constants/themePrefix'); var LOADING_ORDER = ['plugin', 'theme']; /** - Returns the type of a plugin given its name - - @return {String} -*/ + * Returns the type of a plugin given its name + * @return {String} + */ function pluginType(name) { return (name && name.indexOf(THEME_PREFIX) === 0) ? 'theme' : 'plugin'; } /** - Sort the list of installed plugins to match list in book.json - The themes should always be loaded after the plugins - - @param {>} plugins - @param {>} requirementsKeys - @return {Promise>} -*/ - + * Sort the list of installed plugins to match list in book.json + * The themes should always be loaded after the plugins + * + * @param {>} plugins + * @param {>} requirementsKeys + * @return {OrderedMap} + */ function sortPlugins(plugins, requirementsKeys) { - return Promise() - .then(function() { - // Sort plugins to match list in book.json - plugins = plugins.sort(function(a, b) { - // Get order from book.json - var definitionOrder = requirementsKeys.indexOf(a.getName()) < requirementsKeys.indexOf(b.getName()); + // Sort plugins to match list in book.json + return plugins.sort(function(a, b) { + // Get order from book.json + var definitionOrder = requirementsKeys.indexOf(a.getName()) < requirementsKeys.indexOf(b.getName()); - // Get order from plugins a and b type - var aType = pluginType(a.getName()), - bType = pluginType(b.getName()), - loadingOrder = LOADING_ORDER.indexOf(aType) < LOADING_ORDER.indexOf(bType); + // Get order from plugins a and b type + var aType = pluginType(a.getName()), + bType = pluginType(b.getName()), + loadingOrder = LOADING_ORDER.indexOf(aType) < LOADING_ORDER.indexOf(bType); - return loadingOrder || definitionOrder ? -1 : 1; - }); - - return plugins; + return loadingOrder || definitionOrder ? -1 : 1; }); }