-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprebuild.js
36 lines (30 loc) · 1.12 KB
/
prebuild.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
import fs from 'fs';
import path from 'path';
async function init() {
const solutions = await fetch(`https://api.github.com/repos/Eimer-Archive/MineCrashSolutions/contents/solutions`)
.then(res => res.json())
.catch(err => {
console.error('Failed to fetch solutions:', err);
process.exit(1);
});
if (solutions.message) {
console.error('Failed to fetch solutions:', solutions.message);
}else{
const errors = solutions.map(solution => {
return {
slug: solution.name.replace('.json', '')
};
});
const errorDir = path.join(process.cwd(), 'static', 'error');
if (!fs.existsSync(errorDir)) {
fs.mkdirSync(errorDir, { recursive: true });
}
// if the file already exists, delete it
if (fs.existsSync(path.join(errorDir, 'slugs.json'))) {
fs.unlinkSync(path.join(errorDir, 'slugs.json'));
}
// save all the slugs in one file
fs.writeFileSync(path.join(errorDir, 'slugs.json'), JSON.stringify(errors, null, 4));
}
}
init();