1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | 'use strict';
|
9 |
|
10 | var utils = require('./utils');
|
11 |
|
12 | module.exports = function get(repos, cb) {
|
13 | if (typeof cb !== 'function') {
|
14 | throw new TypeError('expected callback to be a function');
|
15 | }
|
16 |
|
17 | if (typeof repos === 'string') {
|
18 | repos = [repos];
|
19 | }
|
20 |
|
21 | if (!Array.isArray(repos)) {
|
22 | throw new TypeError('expected the first argument to be a string or array');
|
23 | }
|
24 |
|
25 | utils.async.map(repos, utils.pkg, function(err, res) {
|
26 | if (err) {
|
27 | if (err.message !== 'document not found') {
|
28 | cb(err);
|
29 | return;
|
30 | }
|
31 |
|
32 | var len = res.length;
|
33 | var idx = -1;
|
34 | var arr = [];
|
35 | while (++idx < len) {
|
36 | if (typeof res[idx] === 'undefined') {
|
37 | console.log();
|
38 | var symbol = utils.yellow(utils.warning);
|
39 | console.error('', symbol, 'WARNING: npm package "' + repos[idx] + '" does not exist');
|
40 | } else {
|
41 | arr.push(res[idx]);
|
42 | }
|
43 | }
|
44 | res = arr;
|
45 | }
|
46 | cb(null, res);
|
47 | });
|
48 | };
|