diff options
Diffstat (limited to 'lib/plugins/registry.js')
-rw-r--r-- | lib/plugins/registry.js | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/lib/plugins/registry.js b/lib/plugins/registry.js index bc17a8c..ea172c4 100644 --- a/lib/plugins/registry.js +++ b/lib/plugins/registry.js @@ -23,7 +23,7 @@ function pluginId(name) { // Validate an NPM plugin ID function validateId(name) { - return name.indexOf(PLUGIN_PREFIX) === 0; + return name && name.indexOf(PLUGIN_PREFIX) === 0; } // Initialize NPM for operations @@ -107,24 +107,25 @@ function installPlugin(book, plugin, version) { } // List all packages installed inside a folder -// Returns a map { pluginName -> folder } +// Returns an ordered list of plugins function listInstalled(folder) { var options = { dev: false, log: function() {}, depth: 4 }; - var result = {}; + var results = []; function onPackage(pkg, isRoot) { if (!validateId(pkg.name)){ if (!isRoot) return; } else { - result[pluginId(pkg.name)] = { + results.push({ + name: pluginId(pkg.name), version: pkg.version, path: pkg.realPath, depth: pkg.depth - }; + }); } _.each(pkg.dependencies, function(dep) { @@ -135,18 +136,19 @@ function listInstalled(folder) { return Promise.nfcall(readInstalled, folder, options) .then(function(data) { onPackage(data, true); - return result; + return _.uniq(results, 'name'); }); } // List installed plugins for a book (defaults and installed) function listPlugins(book) { - return Promise.nfcall([ + return Promise.all([ listInstalled(path.resolve(__dirname, '../..')), listInstalled(book.root) ]) .spread(function(defaultPlugins, plugins) { - return _.extend(defaultPlugins, plugins); + var results = plugins.concat(defaultPlugins); + return _.uniq(results, 'name'); }); } |