-
Notifications
You must be signed in to change notification settings - Fork 3
/
generate_json.js
56 lines (47 loc) · 1.37 KB
/
generate_json.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
// this is designed to be run in a node environment!
const filename_match = {
'Avatar_Gnd_': 'Download Avatar Goggles',
'Avatar_Sky_': 'Download Sky',
'AvatarMini_Sky': 'Download Mini Sky',
'AvatarMini_Gnd': 'Download Recon HD',
'AvatarSE_Gnd': 'Download VRX',
'AvatarSE_Sky': 'Download ???',
'Avatar': 'Download'
}
const fs = require('fs');
const crypto = require('crypto');
// get input version
const version = process.argv[2];
// scan the directory
const directory = `./_firmwares/${version}`;
const files = fs.readdirSync(directory);
const output = {
badges: [
"official",
"CHANGE ME"
],
date: new Date().toISOString().split('T')[0],
version: version,
notes: "CHANGE ME",
downloads: []
}
// calculate hashes
for (const file of files.reverse()) {
const data = fs.readFileSync(`${directory}/${file}`);
const hash = crypto.createHash('sha1').update(data).digest('hex').toUpperCase();
// find the first match in filename_match
let button_text = 'Download';
for (const key in filename_match) {
if (file.startsWith(key)) {
button_text = filename_match[key];
break;
}
}
output.downloads.push({
btn: button_text,
sha1: hash,
url: `/dl/${version}/${file}`,
filename: file
});
}
console.log(JSON.stringify(output, null, 4));