diff options
author | Samy Pessé <samypesse@gmail.com> | 2016-06-08 15:02:34 +0200 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2016-06-08 15:02:34 +0200 |
commit | 004f91f02c7b98005f8f7cc032ad24d8800651da (patch) | |
tree | d175bb7e4e9b8e2004f0ddde5f8d1e22797c501a /lib/plugins/sortPlugins.js | |
parent | e6c6ec4293fdf0bd225f1c6613ea484469fa98fd (diff) | |
download | gitbook-004f91f02c7b98005f8f7cc032ad24d8800651da.zip gitbook-004f91f02c7b98005f8f7cc032ad24d8800651da.tar.gz gitbook-004f91f02c7b98005f8f7cc032ad24d8800651da.tar.bz2 |
sortPlugins should not be async
Diffstat (limited to 'lib/plugins/sortPlugins.js')
-rw-r--r-- | lib/plugins/sortPlugins.js | 47 |
1 files changed, 19 insertions, 28 deletions
diff --git a/lib/plugins/sortPlugins.js b/lib/plugins/sortPlugins.js index 6626936..e96b02c 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 {<OrderedMap<String:Plugin>>} plugins - @param {<List<String>>} requirementsKeys - @return {Promise<OrderedMap<String:Plugin>>} -*/ - + * Sort the list of installed plugins to match list in book.json + * The themes should always be loaded after the plugins + * + * @param {<OrderedMap<String:Plugin>>} plugins + * @param {<List<String>>} requirementsKeys + * @return {OrderedMap<String:Plugin>} + */ 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()); - - // 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); + // 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()); - return loadingOrder || definitionOrder ? -1 : 1; - }); + // 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 plugins; + return loadingOrder || definitionOrder ? -1 : 1; }); } |