1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | 'use strict';
|
9 |
|
10 | var chalk = require('chalk');
|
11 | var async = require('async');
|
12 | var filter = require('filter-object');
|
13 | var pkg = require('package-json');
|
14 |
|
15 | module.exports = function get(repos, pattern, cb) {
|
16 | if (typeof pattern === 'function') {
|
17 | cb = pattern; pattern = '*';
|
18 | }
|
19 |
|
20 | async.reduce(arrayify(repos), [], function(acc, repo, next) {
|
21 | pkg(repo, 'latest', function (err, json) {
|
22 | if (err) {
|
23 | console.log(chalk.red(err + ': "') + chalk.bold(repo) + '"');
|
24 | return next(err);
|
25 | }
|
26 | next(null, acc.concat(filter(json, pattern)));
|
27 | });
|
28 | }, cb);
|
29 | };
|
30 |
|
31 | function arrayify(val) {
|
32 | return !Array.isArray(val) ? [val] : val;
|
33 | }
|