refactor: finish moving ssh-* scripts to own installers
[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           }
25           all.releases.push({
26             // nix leading 'v'
27             version: asset.version.replace(/v/, ''),
28             lts: false,
29             channel: asset.channel,
30             date: asset.release_date.replace(/T.*/, ''),
31             os: osname,
32             arch: 'amd64',
33             hash: '-', // not sure about including hash / sha256 yet
34             download: asset.archive
35           });
36         });
37       });
38     })
39   ).then(function () {
40     all.releases.sort(function (a, b) {
41       if ('stable' === a.channel && a.channel !== b.channel) {
42         return -1;
43       }
44       if ('stable' === b.channel && a.channel !== b.channel) {
45         return 1;
46       }
47       if ('beta' === a.channel && a.channel !== b.channel) {
48         return -1;
49       }
50       if ('beta' === b.channel && a.channel !== b.channel) {
51         return 1;
52       }
53       return new Date(b.date).valueOf() - new Date(a.date).valueOf();
54     });
55     return all;
56   });
57 };
58
59 if (module === require.main) {
60   module.exports(require('@root/request')).then(function (all) {
61     all.releases = all.releases.slice(25);
62     console.info(JSON.stringify(all, null, 2));
63   });
64 }