-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathupdate-chrome.js
68 lines (61 loc) · 2 KB
/
update-chrome.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/* eslint-disable no-console */
const request = require('request');
const fs = require('fs');
const path = require('path');
const Chrome = require('../src/data/Chrome');
console.log('Updating chrome versions...');
const filepath = path.join(__dirname, '../data/browsers-chrome.js');
const fileStream = fs.createWriteStream(filepath);
const stable = {
desktop: [],
mobile: [],
};
function comparator(a, b) {
return parseInt(a, 10) - parseInt(b, 10);
}
request('http://omahaproxy.appspot.com/history', (err, response = {}) => {
if (err) {
return;
}
const omaha = response.body.split('\n');
omaha.forEach((line) => {
const [os, stability, version] = line.split(',');
if (os === 'mac' && stability === 'stable') {
stable.desktop.push(version.split('.').slice(0, 3).join('.'));
}
if (os === 'android' && stability === 'stable') {
stable.mobile.push(version.split('.').slice(0, 3).join('.'));
}
});
stable.desktop.sort(comparator);
stable.mobile.sort(comparator);
let countNewDesktop = 0;
stable.desktop.forEach((version) => {
if (!Chrome.DESKTOP[version]) {
Chrome.DESKTOP[version] = 'stable';
countNewDesktop++;
}
});
let countNewMobile = 0;
stable.mobile.forEach((version) => {
if (!Chrome.MOBILE[version]) {
Chrome.MOBILE[version] = 'stable';
countNewMobile++;
}
});
fileStream.write('module.exports = {\n');
fileStream.write(' DESKTOP: {\n');
Object.keys(Chrome.DESKTOP).forEach((version) =>
fileStream.write(` '${version}': '${Chrome.DESKTOP[version]}',\n`)
);
fileStream.write(' },\n');
fileStream.write(' MOBILE: {\n');
Object.keys(Chrome.MOBILE).forEach((version) =>
fileStream.write(` '${version}': '${Chrome.MOBILE[version]}',\n`)
);
fileStream.write(' },\n');
fileStream.write('};\n');
fileStream.end();
console.log(`Updated chrome with ${countNewDesktop} new stable version for DEKSTOP`);
console.log(`Updated chrome with ${countNewMobile} new stable version for MOBILE`);
});