-
Notifications
You must be signed in to change notification settings - Fork 88
/
app.js
62 lines (52 loc) · 1.81 KB
/
app.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
const https = require('https');
const fs = require('fs');
const prefix = 'https://api.github.com/';
const repos = 'repos/';
const repositories = 'repositories/';
const postfix = '/releases/latest';
let inputJSON = fs.readFileSync('mods.json');
let modList = JSON.parse(inputJSON);
let result = []
function isNumeric(value) {
return /^-?\d+$/.test(value);
}
modList.mods.forEach(mod =>
https.get(`${prefix}${!isNumeric(mod.gitPath) ? repos : repositories}${mod.gitPath}${postfix}`, { headers: { 'User-Agent' : 'DeadlyKitten/MonkeModInfo' ,'Authorization': `Token ${process.env.SECRET}`}},(res) => {
let body = "";
res.on("data", (chunk) => {
body += chunk;
});
res.on("end", () => {
try {
let json = JSON.parse(body);
result.push({
'name': mod.name,
'author': mod.author,
'version': json.tag_name.replace(/[^\d\n,.]/g,''),
'dependencies': mod.dependencies,
'dependents': mod.dependents,
'install_location': mod.installPath,
'git_path': mod.gitPath,
'group': mod.group,
'download_url': json.assets[mod.releaseId].browser_download_url
});
} catch (error) {
console.error(mod.gitPath);
console.error(error.message);
};
});
}));
let attempts = 0;
let timeout = 20;
let interval = setInterval(() => {
if (result.length === modList.mods.length || attempts > timeout) {
result.sort(function(a,b) {
if (a.name === b.name) return 0;
return (a.name > b.name) ? 1 : -1;
});
fs.writeFileSync('modinfo.json', JSON.stringify(result, null, 2));
clearInterval(interval);
} else {
attempts++;
}
}, 100);