2019-03-12 02:50:52 -07:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var fs = require('fs');
|
|
|
|
var path = require('path');
|
|
|
|
var UAParser = require('./ua-parser.min.js');
|
|
|
|
|
|
|
|
var cache = {};
|
|
|
|
var map = {};
|
|
|
|
|
|
|
|
var parser = new UAParser();
|
|
|
|
|
2019-03-14 07:20:52 -07:00
|
|
|
var write = ({name, content}, callback) => fs.writeFile('./browsers/' + name, content, 'utf8', e => {
|
|
|
|
if (e) {
|
|
|
|
console.log(e);
|
|
|
|
}
|
|
|
|
setTimeout(callback, 0);
|
|
|
|
console.log(name);
|
|
|
|
});
|
|
|
|
|
|
|
|
fs.readdir('./browsers/', async (err, files) => {
|
2019-03-12 02:50:52 -07:00
|
|
|
if (err) throw err;
|
|
|
|
for (const file of files) {
|
|
|
|
fs.unlinkSync(path.join('./browsers/', file), err => {
|
|
|
|
if (err) throw err;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
//
|
|
|
|
const list = [
|
|
|
|
...require('./list-1.json'),
|
2019-05-11 01:28:38 -07:00
|
|
|
...require('./list-2.json'),
|
|
|
|
...require('./list-3.json')
|
2019-03-12 02:50:52 -07:00
|
|
|
].filter((s, i, l) => l.indexOf(s) === i);
|
|
|
|
for (const ua of list) {
|
|
|
|
parser.setUA(ua);
|
|
|
|
const o = parser.getResult();
|
|
|
|
if (o.browser.name && o.os.name) {
|
2019-03-14 07:20:52 -07:00
|
|
|
if (o.os.name === 'WIndows') {
|
|
|
|
continue;
|
|
|
|
}
|
2019-03-12 02:50:52 -07:00
|
|
|
cache[o.browser.name] = cache[o.browser.name] || {};
|
|
|
|
map[o.browser.name] = map[o.browser.name] || {};
|
|
|
|
cache[o.browser.name][o.os.name] = cache[o.browser.name][o.os.name] || [];
|
|
|
|
map[o.browser.name][o.os.name] = map[o.browser.name][o.os.name] || true;
|
|
|
|
cache[o.browser.name][o.os.name].push(o);
|
|
|
|
}
|
2019-03-14 07:20:52 -07:00
|
|
|
else {
|
|
|
|
// console.log(ua);
|
|
|
|
}
|
2019-03-12 02:50:52 -07:00
|
|
|
}
|
2019-03-14 07:20:52 -07:00
|
|
|
const contents = [];
|
2019-03-12 02:50:52 -07:00
|
|
|
for (const browser of Object.keys(cache)) {
|
|
|
|
for (const os of Object.keys(cache[browser])) {
|
2019-03-14 07:20:52 -07:00
|
|
|
const name = browser + '-' + os.replace(/\//g, '-') + '.json';
|
|
|
|
const content = JSON.stringify(cache[browser][os]);
|
|
|
|
contents.push({
|
|
|
|
name,
|
|
|
|
content
|
|
|
|
});
|
2019-03-12 02:50:52 -07:00
|
|
|
}
|
|
|
|
}
|
2019-03-14 07:20:52 -07:00
|
|
|
const once = () => {
|
|
|
|
const obj = contents.shift();
|
|
|
|
if (obj) {
|
|
|
|
write(obj, once);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
console.log('done');
|
|
|
|
fs.writeFile('./map.json', JSON.stringify(map), () => {});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
once();
|
2019-03-12 02:50:52 -07:00
|
|
|
});
|
2019-03-14 07:20:52 -07:00
|
|
|
|