forked from DevExpress/device-specs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update.js
38 lines (27 loc) · 1.32 KB
/
update.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
var fs = require('fs');
var path = require('path');
var request = require('request-promise');
var currentDevicesList = require('./emulated-devices.json');
var JSON_URL = 'https://chromium.googlesource.com/chromium/blink/+/master/Source/devtools/front_end/emulated_devices/module.json?format=TEXT';
var FILE_PATH = path.join(__dirname, 'emulated-devices.json');
var TITLES_PATH = path.join(__dirname, 'devices.md');
function mergeLists (oldList, newList) {
var removedItems = [];
oldList.forEach(oldItem => {
if (newList.every(newItem => newItem.title.toLowerCase() !== oldItem.title.toLowerCase()))
removedItems.push(oldItem);
});
return removedItems.concat(newList);
}
request({ url: JSON_URL })
.then(function (body) {
var buf = new Buffer(body, 'base64');
var content = JSON.parse(buf);
var newDevicesList = content.extensions.map(function (item) {
return item.device;
});
newDevicesList = mergeLists(currentDevicesList, newDevicesList);
fs.writeFileSync(FILE_PATH, JSON.stringify(newDevicesList, null, 2));
var titles = newDevicesList.map(x => ' * ' + x.title).join('\n\n');
fs.writeFileSync(TITLES_PATH, '## Titles of Emulated Devices\n\n' + titles);
});