-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathbuild-devices.js
90 lines (80 loc) · 2.3 KB
/
build-devices.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
'use strict';
const fs = require('fs');
const path = require('path');
const airpods = require('./airpods.json');
const airtag = require('./airtag.json');
const apple_tv = require('./apple_tv.json');
const apple_watch = require('./apple_watch.json');
const homepod = require('./homepod.json');
const ipad = require('./ipad.json');
const ipad_air = require('./ipad_air.json');
const ipad_pro = require('./ipad_pro.json');
const ipad_mini = require('./ipad_mini.json');
const iphone = require('./iphone.json');
const ipod_touch = require('./ipod_touch.json');
const siri_remote = require('./siri_remote.json');
const DEVICES_OUTPUT_FILE = path.join( __dirname, 'devices.json');
const DEVICES_MIN_OUTPUT_FILE = path.join( __dirname, 'devices-min.json');
let devices, devicesMin;
function addDevice(d) {
if (typeof d.Identifier === 'string') {
devices.push({
name: d.Generation,
model: d.Identifier,
ANumber: d.ANumber,
FCCID: d.FCCID
});
devicesMin.push({
name: d.Generation,
model: d.Identifier
});
}
if (Array.isArray(d.Identifier)) {
d.Identifier.forEach(di => {
devices.push({
name: d.Generation,
model: di,
ANumber: d.ANumber,
FCCID: d.FCCID
});
devicesMin.push({
name: d.Generation,
model: di
});
});
}
}
function build() {
airpods.forEach(addDevice);
airtag.forEach(addDevice);
apple_tv.forEach(addDevice);
apple_watch.forEach(addDevice);
homepod.forEach(addDevice);
ipad.forEach(addDevice);
ipad_air.forEach(addDevice);
ipad_pro.forEach(addDevice);
ipad_mini.forEach(addDevice);
iphone.forEach(addDevice);
ipod_touch.forEach(addDevice);
siri_remote.forEach(addDevice);
}
function write() {
fs.writeFile( DEVICES_OUTPUT_FILE, JSON.stringify( devices, null, 2 ), err => {
if ( err ) {
throw err;
}
console.log( 'Devices list saved to ' + DEVICES_OUTPUT_FILE );
console.log( 'Total ' + devices.length + ' records' );
fs.writeFile( DEVICES_MIN_OUTPUT_FILE, JSON.stringify( devicesMin, null, 2 ), err => {
if ( err ) {
throw err;
}
console.log( 'Devices list saved to ' + DEVICES_MIN_OUTPUT_FILE );
console.log( 'Total ' + devicesMin.length + ' records' );
});
});
}
devices = [];
devicesMin = [];
build();
write();