mirror of
https://github.com/bower/bower.git
synced 2026-02-11 22:44:58 -05:00
Also: - Fix some errors not being emitted when a command failed. - Update semver module; no need to check .valid against null.
55 lines
1.3 KiB
JavaScript
55 lines
1.3 KiB
JavaScript
var EventEmitter = require('events').EventEmitter;
|
|
var mout = require('mout');
|
|
var Q = require('q');
|
|
var RegistryClient = require('bower-registry-client');
|
|
var cli = require('../util/cli');
|
|
var defaultConfig = require('../config');
|
|
|
|
function lookup(name, config) {
|
|
var registryClient;
|
|
var emitter = new EventEmitter();
|
|
|
|
config = mout.object.deepMixIn(config || {}, defaultConfig);
|
|
config.cache = config.storage.registry;
|
|
|
|
registryClient = new RegistryClient(config);
|
|
|
|
Q.nfcall(registryClient.lookup.bind(registryClient), name)
|
|
.then(function (entry) {
|
|
// 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
|
|
});
|
|
})
|
|
.fail(function (error) {
|
|
emitter.emit('error', error);
|
|
});
|
|
|
|
return emitter;
|
|
}
|
|
|
|
// -------------------
|
|
|
|
lookup.line = function (argv) {
|
|
var options = lookup.options(argv);
|
|
var name = options.argv.remain[1];
|
|
|
|
if (!name) {
|
|
return null;
|
|
}
|
|
|
|
return lookup(name);
|
|
};
|
|
|
|
lookup.options = function (argv) {
|
|
return cli.readOptions(argv);
|
|
};
|
|
|
|
lookup.completion = function () {
|
|
// TODO:
|
|
};
|
|
|
|
module.exports = lookup;
|