-
Notifications
You must be signed in to change notification settings - Fork 1
/
lint-host-targets.js
107 lines (90 loc) · 2.4 KB
/
lint-host-targets.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
'use strict';
let HostTargets = require('./host-targets.js');
let uaMap = require('./uas.json');
let uas = Object.keys(uaMap);
let partialsMap = {};
let termsMap = {};
let termNames = Object.keys(HostTargets.TERMS);
for (let term of termNames) {
termsMap[term] = 0;
}
function main() {
//let hostTargets = HostTargets.create({});
let tripletsMap = {};
for (let ua of uas) {
let terms = [];
let parts = ua.split(/\s+/g);
for (let part of parts) {
let _terms = part.split(/\//g);
for (let term of _terms) {
if (HostTargets.TERMS[term]) {
// TODO how to account for non-exact matches
// abXXXXXXXX, android12-*, and MINGW*
termsMap[term] += 1;
}
}
terms = terms.concat(_terms);
}
let target = {};
let bogoTerms;
try {
bogoTerms = HostTargets.termsToTarget(target, terms);
} catch (e) {
// we can't realistically guarantee what the user should get
throw e;
}
if (!target.arch) {
// 'curl/x.y.z', 'MS', 'Wget'
if (parts.length !== 1) {
let msg = `'arch' not detected for '${ua}'`;
let err = new Error(msg);
console.error('Error:', err.message);
}
continue;
}
if (!target.os) {
// 'curl/x.y.z', 'MS', 'Wget'
if (parts.length !== 1) {
let msg = `'os' not detected for '${ua}'`;
let err = new Error(msg);
console.error('Error:', err.message);
}
continue;
}
if (!bogoTerms) {
continue;
}
for (let term of bogoTerms) {
let strs = term.split(/[\.]+/g);
for (let str of strs) {
if (!partialsMap[str]) {
partialsMap[str] = 0;
}
partialsMap[str] += 1;
}
}
let triplet = `${target.arch}-${target.vendor}-${target.os}-${target.libc}`;
tripletsMap[triplet] = true;
if (!target.os || !target.arch) {
throw new Error(`missing 'os' or 'arch' in '${ua}'`);
}
if (!target.libc) {
// TODO
console.error(`missing 'libc' in '${ua}'`);
}
//console.log(bogoTerms);
}
console.info('');
console.info('Partial Terms');
console.log(partialsMap);
console.info('');
console.log('Known Terms:');
console.log(termsMap);
let triplets = Object.keys(tripletsMap);
console.info('');
console.info('Triplets');
for (let triplet of triplets) {
console.info(` ${triplet}`);
}
}
main();