-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgeneratedata.js
63 lines (55 loc) · 1.76 KB
/
generatedata.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
const fs = require('fs');
const path = require('path');
const dataFolderPath = './data';
const finalData = [];
// Function to read parts.json file
const readPartsJson = (folderPath) => {
const partsJsonPath = path.join(folderPath, 'parts.json');
try {
const partsData = fs.readFileSync(partsJsonPath, 'utf8');
return JSON.parse(partsData);
} catch (error) {
console.error(`Error reading parts.json in ${folderPath}: ${error}`);
return [];
}
};
// Function to read info.json file
const readInfoJson = (folderPath) => {
const infoJsonPath = path.join(folderPath, 'info.json');
try {
const infoData = fs.readFileSync(infoJsonPath, 'utf8');
return JSON.parse(infoData);
} catch (error) {
console.error(`Error reading info.json in ${folderPath}: ${error}`);
return {};
}
};
// Main function to process each mod
const processMod = (modName) => {
const modPath = path.join(dataFolderPath, modName);
const partsData = readPartsJson(modPath);
const infoData = readInfoJson(modPath);
const modEntry = {
modName,
preferredName: infoData.preferredName || '',
link: infoData.link || '',
parts: partsData.map(part => ({
name: part.name,
filePath: part.filePath
}))
};
finalData.push(modEntry);
};
// Main function to iterate through subfolders (mods)
const main = () => {
try {
const mods = fs.readdirSync(dataFolderPath);
mods.forEach(processMod);
fs.writeFileSync('data.json', JSON.stringify(finalData, null, 2));
console.log('Final data compiled successfully.');
} catch (error) {
console.error('Error processing mods:', error);
}
};
// Run the main function
main();