git ssb

0+

cel-desktop / ssb-pkg



Tree: 938b7ea4cfaa3cef6e1690b9ef3ea8bd7a0d2de1

Files: 938b7ea4cfaa3cef6e1690b9ef3ea8bd7a0d2de1 / test / test-79-npm / times.js

1168 bytesRaw
1'use strict';
2
3const https = require('https');
4const foldyNames = process.argv[2].split(',');
5
6const results = {};
7process.on('exit', function () {
8 console.log(JSON.stringify(results));
9});
10
11for (let i = 0; i < 10; i += 1) {
12 nextJob();
13}
14
15function nextJob () {
16 if (foldyNames.length === 0) return;
17 queueJob(foldyNames.shift());
18}
19
20function 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
28function 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