mirror of
https://github.com/bower/bower.git
synced 2026-01-20 03:38:07 -05:00
- Tracking should be consistent with `info` command; tracking should register upon user calling the command, not when the command is completed - Vocabulary should be consistent with other tracking - if only tracking upon calling the command, should use the present tense of the verb without -"ed" This is an improvement for tracking and reporting consistency, please see https://github.com/bower/bower/issues/1164#issuecomment-39385297
56 lines
1.4 KiB
JavaScript
56 lines
1.4 KiB
JavaScript
var mout = require('mout');
|
|
var Q = require('q');
|
|
var Logger = require('bower-logger');
|
|
var RegistryClient = require('bower-registry-client');
|
|
var cli = require('../util/cli');
|
|
var Tracker = require('../util/analytics').Tracker;
|
|
var defaultConfig = require('../config');
|
|
|
|
function search(name, config) {
|
|
var registryClient;
|
|
var promise;
|
|
var tracker;
|
|
var logger = new Logger();
|
|
|
|
config = mout.object.deepFillIn(config || {}, defaultConfig);
|
|
config.cache = config.storage.registry;
|
|
|
|
registryClient = new RegistryClient(config, logger);
|
|
tracker = new Tracker(config);
|
|
tracker.track('search', name);
|
|
|
|
// If no name was specified, list all packages
|
|
if (!name) {
|
|
promise = Q.nfcall(registryClient.list.bind(registryClient));
|
|
// Otherwise search it
|
|
} else {
|
|
promise = Q.nfcall(registryClient.search.bind(registryClient), name);
|
|
}
|
|
|
|
promise
|
|
.done(function (results) {
|
|
logger.emit('end', results);
|
|
}, function (error) {
|
|
logger.emit('error', error);
|
|
});
|
|
|
|
return logger;
|
|
}
|
|
|
|
// -------------------
|
|
|
|
search.line = function (argv) {
|
|
var options = search.options(argv);
|
|
return search(options.argv.remain.slice(1).join(' '), options);
|
|
};
|
|
|
|
search.options = function (argv) {
|
|
return cli.readOptions(argv);
|
|
};
|
|
|
|
search.completion = function () {
|
|
// TODO:
|
|
};
|
|
|
|
module.exports = search;
|