make Prettier
[webi-installers/.git] / flutter / releases.js
1 'use strict';
2
3 var map = {};
4
5 module.exports = function (request) {
6   var all = {
7     download: '',
8     releases: []
9   };
10   return Promise.all(
11     ['macos', 'linux', 'windows'].map(function (osname) {
12       return request({
13         url:
14           'https://storage.googleapis.com/flutter_infra/releases/releases_' +
15           osname +
16           '.json',
17         json: true
18       }).then(function (resp) {
19         var body = resp.body;
20         all.download = body.base_url + '/{{ download }}';
21         body.releases.forEach(function (asset) {
22           if (!map[asset.channel]) {
23             map[asset.channel] = true;
24             console.log('a', asset.channel);
25           }
26           all.releases.push({
27             // nix leading 'v'
28             version: asset.version.replace(/v/, ''),
29             lts: false,
30             channel: asset.channel,
31             date: asset.release_date.replace(/T.*/, ''),
32             os: osname,
33             arch: 'amd64',
34             hash: '-', // not sure about including hash / sha256 yet
35             download: asset.archive
36           });
37         });
38       });
39     })
40   ).then(function () {
41     all.releases.sort(function (a, b) {
42       if ('stable' === a.channel && a.channel !== b.channel) {
43         return -1;
44       }
45       if ('stable' === b.channel && a.channel !== b.channel) {
46         return 1;
47       }
48       if ('beta' === a.channel && a.channel !== b.channel) {
49         return -1;
50       }
51       if ('beta' === b.channel && a.channel !== b.channel) {
52         return 1;
53       }
54       return new Date(b.date).valueOf() - new Date(a.date).valueOf();
55     });
56     return all;
57   });
58 };
59
60 if (module === require.main) {
61   module.exports(require('@root/request')).then(function (all) {
62     all.releases = all.releases.slice(25);
63     console.log(JSON.stringify(all, null, 2));
64   });
65 }