refactor: finish moving ssh-* scripts to own installers
[webi-installers/.git] / chromedriver / releases.js
1 'use strict';
2
3 var matchers = {
4   key: /.*Key>(.*)<\/Key.*/,
5   generation: /.*Generation>(.*)<\/Generation.*/,
6   metaGeneration: /.*MetaGeneration>(.*)<\/MetaGeneration.*/,
7   lastModified: /.*LastModified>(.*)<\/LastModified.*/,
8   etag: /.*ETag>(.*)<\/ETag.*/,
9   size: /.*Size>(.*)<\/Size.*/
10 };
11 var baseUrl = 'https://chromedriver.storage.googleapis.com';
12
13 module.exports = function (request) {
14   var all = {
15     download: '',
16     releases: []
17   };
18
19   // XML
20   return request({
21     url: 'https://chromedriver.storage.googleapis.com/',
22     json: false
23   })
24     .then(function (resp) {
25       var body = resp.body;
26       var groups = body.split(/<\/?Contents>/g);
27       // get rid of leading and trailing junk
28       groups.shift();
29       groups.pop();
30       var metas = groups.map(function (group) {
31         return {
32           key: group.replace(matchers.key, '$1'),
33           //generation: group.replace(matchers.generation, '$1'),
34           //metaGeneration: group.replace(matchers.metaGeneration, '$1'),
35           lastModified: group.replace(matchers.lastModified, '$1')
36           //etag: group.replace(matchers.etag, '$1'),
37           //size: group.replace(matchers.size, '$1')
38         };
39       });
40       all.download = baseUrl + '/{{ download }}';
41       metas.forEach(function (asset) {
42         if (!asset.key.includes('chromedriver')) {
43           // skip the indexes, images, etc
44           return null;
45         }
46
47         var osname = asset.key.replace(/.*(win|mac|linux)/, '$1');
48         var arch;
49         if (asset.key.includes('linux')) {
50           osname = 'linux';
51         } else if (asset.key.includes('mac64')) {
52           osname = 'macos';
53           if (asset.key.includes('_m1.')) {
54             arch = 'arm64';
55           }
56         } else if (asset.key.includes('win')) {
57           osname = 'windows';
58           arch = 'amd64';
59         }
60         all.releases.push({
61           // 87.0.4280.88/chromedriver_win32.zip => 87.0.4280.88
62           version: asset.key.replace(/(.*)\/.*/, '$1'),
63           lts: false,
64           channel: 'stable',
65           date: asset.lastModified.replace(/T.*/, '$1'),
66           os: osname,
67           arch: arch,
68           hash: '-', // not sure about including etag as hash yet
69           download: asset.key
70         });
71       });
72     })
73     .then(function () {
74       all.releases.sort(function (a, b) {
75         return new Date(b.date).valueOf() - new Date(a.date).valueOf();
76       });
77       return all;
78     });
79 };
80
81 if (module === require.main) {
82   module.exports(require('@root/request')).then(function (all) {
83     all = require('../_webi/normalize.js')(all);
84     // just select the latest 5 for demonstration
85     all.releases = all.releases.slice(-20);
86     console.info(JSON.stringify(all, null, 2));
87   });
88 }