forked from Ottermandias/SeaOfStars
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
66 lines (55 loc) · 1.68 KB
/
index.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
const fs = require("fs");
const extraTag = "Sea Of Stars";
const reposMeta = JSON.parse(fs.readFileSync("./meta.json", "utf8"));
const final = [];
async function recoverPlugin(internalName) {
if (!fs.existsSync("./repo.json")) {
console.error("!!! Tried to recover plugin when repo isn't generated");
process.exit(1);
}
const oldRepo = JSON.parse(fs.readFileSync("./repo.json", "utf8"));
const plugin = oldRepo.find((x) => x.InternalName === internalName);
if (!plugin) {
console.error(`!!! ${plugin} not found in old repo`);
process.exit(1);
}
final.push(plugin);
console.log(`Recovered ${internalName} from last manifest`);
}
async function doRepo(url, plugins) {
console.log(`Fetching ${url}...`);
const repo = await fetch(url, {
headers: {
'user-agent': 'SeaOfStars/1.0.0',
},
}).then((res) => res.json());
for (const internalName of plugins) {
const plugin = repo.find((x) => x.InternalName === internalName);
if (!plugin) {
console.warn(`!!! ${plugin} not found in ${url}`);
recoverPlugin(internalName);
continue;
}
// Inject our custom tag
const tags = plugin.Tags || [];
tags.push(extraTag);
plugin.Tags = tags;
final.push(plugin);
}
}
async function main() {
for (const meta of reposMeta) {
try {
await doRepo(meta.repo, meta.plugins);
} catch (e) {
console.error(`!!! Failed to fetch ${meta.repo}`);
console.error(e);
for (const plugin of meta.plugins) {
recoverPlugin(plugin);
}
}
}
fs.writeFileSync("./repo.json", JSON.stringify(final, null, 2));
console.log(`Wrote ${final.length} plugins to repo.json.`);
}
main();