Files: 65191f9a9664f013ebe726bb95a1a54b086e1bd5 / test / test-79-npm / times.js
1168 bytesRaw
1 | ; |
2 | |
3 | const https = require('https'); |
4 | const foldyNames = process.argv[2].split(','); |
5 | |
6 | const results = {}; |
7 | process.on('exit', function () { |
8 | console.log(JSON.stringify(results)); |
9 | }); |
10 | |
11 | for (let i = 0; i < 10; i += 1) { |
12 | nextJob(); |
13 | } |
14 | |
15 | function nextJob () { |
16 | if (foldyNames.length === 0) return; |
17 | queueJob(foldyNames.shift()); |
18 | } |
19 | |
20 | function queueJob (foldyName) { |
21 | getLatestTime(foldyName, function (error, latestTime) { |
22 | if (error) console.error(error); |
23 | results[foldyName] = (new Date(latestTime)).getTime(); |
24 | setTimeout(nextJob, 0); |
25 | }); |
26 | } |
27 | |
28 | function getLatestTime (foldyName, cb) { |
29 | https.get('https://registry.npmjs.org/' + foldyName, function (response) { |
30 | let s = ''; |
31 | response.on('data', function (chunk) { |
32 | s += chunk; |
33 | }); |
34 | response.on('end', function () { |
35 | const json = JSON.parse(s); |
36 | const distTags = json['dist-tags']; |
37 | if (!distTags) return cb(undefined, Date.now()); // express-with-jade |
38 | const latest = distTags.latest; |
39 | cb(undefined, json.time[latest]); |
40 | }); |
41 | response.on('error', function (error) { |
42 | cb(error); |
43 | }); |
44 | }).on('error', function (error) { |
45 | cb(error); |
46 | }); |
47 | } |
48 |
Built with git-ssb-web