diff --git a/lib/commands/index.js b/lib/commands/index.js index 7d197c90..95082b14 100644 --- a/lib/commands/index.js +++ b/lib/commands/index.js @@ -4,6 +4,7 @@ module.exports = { 'install': require('./install'), 'help': require('./help'), 'list': require('./list'), + 'lookup': require('./lookup'), 'search': require('./search'), 'update': require('./update'), 'uninstall': require('./uninstall') diff --git a/lib/commands/info.js b/lib/commands/info.js index 9351f7b6..1e8f04b5 100644 --- a/lib/commands/info.js +++ b/lib/commands/info.js @@ -24,7 +24,7 @@ function info(pkg, property, options, config) { repository.versions(pkg.name) .then(function (versions) { emitter.emit('end', { - package: pkg.name, + name: pkg.name, versions: versions }); }); diff --git a/lib/commands/lookup.js b/lib/commands/lookup.js new file mode 100644 index 00000000..012c974a --- /dev/null +++ b/lib/commands/lookup.js @@ -0,0 +1,53 @@ +var EventEmitter = require('events').EventEmitter; +var mout = require('mout'); +var RegistryClient = require('bower-registry-client'); +var cli = require('../util/cli'); +var defaultConfig = require('../config'); + +function lookup(name, options, config) { + var registryClient; + var emitter = new EventEmitter(); + + options = options || {}; + config = mout.object.deepMixIn(config || {}, defaultConfig); + config.cache = config.storage.registry; + + registryClient = new RegistryClient(config); + registryClient.lookup(name, function (err, entry) { + if (err) { + return emitter.emit('error', err); + } + + // TODO: Handle entry.type.. for now it's only 'alias' + // When we got published packages, this needs to be adjusted + emitter.emit('end', !entry ? null : { + name: name, + url: entry && entry.url + }); + }); + + return emitter; +} + +// ------------------- + +lookup.line = function (argv) { + var options = lookup.options(argv); + var name = options.argv.remain[1]; + + if (!name) { + return null; + } + + return lookup(name, options); +}; + +lookup.options = function (argv) { + return cli.readOptions(argv); +}; + +lookup.completion = function () { + // TODO: +}; + +module.exports = lookup; diff --git a/lib/core/Manager.js b/lib/core/Manager.js index 56f8ea8e..aa913feb 100644 --- a/lib/core/Manager.js +++ b/lib/core/Manager.js @@ -423,7 +423,7 @@ Manager.prototype._dissect = function () { // Sort semver ones DESC semvers.sort(function (first, second) { - return semver.rcompare(first, second); + return semver.rcompare(first.pkgMeta.version, second.pkgMeta.version); }); // Filter non-semver ones diff --git a/lib/core/Project.js b/lib/core/Project.js index ac4a540b..b1e08d60 100644 --- a/lib/core/Project.js +++ b/lib/core/Project.js @@ -217,6 +217,7 @@ Project.prototype.uninstall = function (names, options) { .then(function () { var message; var data; + var dependantsNames; var dependants = []; // Walk the down the tree, gathering dependants of the package @@ -226,6 +227,9 @@ Project.prototype.uninstall = function (names, options) { } }, true); + // Remove duplicates + dependants = mout.array.unique(dependants); + // Note that the root is filtered from the dependants // as well as other dependants marked to be uninstalled dependants = dependants.filter(function (dependant) { @@ -241,12 +245,20 @@ Project.prototype.uninstall = function (names, options) { // Otherwise we need to figure it out if the user really wants to remove it, // even with dependants - message = dependants.map(function (dep) { return dep.name; }).join(', ') + ' depends on ' + decEndpoint.name; + // As such we need to prompt the user with a meaningful message + dependantsNames = dependants + .map(function (dep) { + return dep.name; + }) + .sort(function (name1, name2) { + return name1.localeCompare(name2); + }); + + dependantsNames = mout.array.unique(dependantsNames); + message = dependantsNames.join(', ') + ' depends on ' + decEndpoint.name; data = { name: decEndpoint.name, - dependants: dependants.map(function (decEndpoint) { - return decEndpoint.name; - }) + dependants: dependants }; // If interactive is disabled, error out diff --git a/lib/renderers/StandardRenderer.js b/lib/renderers/StandardRenderer.js index 173865df..a9f66bf2 100644 --- a/lib/renderers/StandardRenderer.js +++ b/lib/renderers/StandardRenderer.js @@ -137,7 +137,7 @@ StandardRenderer.prototype._list = function (tree) { StandardRenderer.prototype._search = function (results) { var str = template.render('std/search-results.std', results); - this._write(process.stderr, str); + this._write(process.stdout, str); }; StandardRenderer.prototype._info = function (data) { @@ -145,7 +145,7 @@ StandardRenderer.prototype._info = function (data) { // If the response is the whole package info // render the appropriate template - if (typeof data === 'object' && data.package && data.versions) { + if (typeof data === 'object' && data.name && data.versions) { str = template.render('std/info.std', data); } else { // TODO: colorize/highlight json @@ -160,6 +160,12 @@ StandardRenderer.prototype._info = function (data) { this._write(process.stdout, str); }; +StandardRenderer.prototype._lookup = function (data) { + var str = template.render('std/lookup.std', data); + + this._write(process.stdout, str); +}; + StandardRenderer.prototype._cacheList = function (entries) { entries.forEach(function (entry) { var pkgMeta = entry.pkgMeta; diff --git a/templates/json/help-lookup.json b/templates/json/help-lookup.json new file mode 100644 index 00000000..089fcbde --- /dev/null +++ b/templates/json/help-lookup.json @@ -0,0 +1,14 @@ +{ + "command": "lookup", + "description": "Looks up a package URL by name.", + "usage": [ + "lookup " + ], + "options": [ + { + "shorthand": "-h", + "flag": "--help", + "description": "Show this help message" + } + ] +} \ No newline at end of file diff --git a/templates/std/info.std b/templates/std/info.std index d27df517..6a92181d 100644 --- a/templates/std/info.std +++ b/templates/std/info.std @@ -1,4 +1,4 @@ -{{#cyan}}{{package}}{{/cyan}} +{{#cyan}}{{name}}{{/cyan}} {{#if versions}} Versions: {{#condense}} diff --git a/templates/std/lookup.std b/templates/std/lookup.std new file mode 100644 index 00000000..3bab8249 --- /dev/null +++ b/templates/std/lookup.std @@ -0,0 +1,7 @@ +{{#condense}} +{{#if url}} +{{#cyan}}{{name}}{{/cyan}} {{url}} +{{else}} +Package not found. +{{/if}} +{{/condense}}