forked from ByMykel/CSGO-API
-
Notifications
You must be signed in to change notification settings - Fork 0
/
group.js
46 lines (39 loc) · 1.46 KB
/
group.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
import fs from "fs";
import path from "path";
import { LANGUAGES_URL } from "./constants.js";
const inputFilePathsTemplate = [
"./public/api/{lang}/agents.json",
"./public/api/{lang}/collectibles.json",
"./public/api/{lang}/collections.json",
"./public/api/{lang}/crates.json",
"./public/api/{lang}/graffiti.json",
"./public/api/{lang}/keys.json",
"./public/api/{lang}/music_kits.json",
"./public/api/{lang}/patches.json",
"./public/api/{lang}/skins_not_grouped.json",
"./public/api/{lang}/stickers.json",
];
for (let langObj of LANGUAGES_URL) {
const lang = langObj.folder;
const allData = {};
const inputFilePaths = inputFilePathsTemplate.map((templatePath) =>
templatePath.replace("{lang}", lang)
);
for (let filePath of inputFilePaths) {
const fullPath = path.join(process.cwd(), filePath);
// Check if file exists before reading
if (fs.existsSync(fullPath)) {
const fileData = JSON.parse(fs.readFileSync(fullPath, "utf-8"));
if (Array.isArray(fileData)) {
fileData.forEach((item) => {
allData[item.id] = item;
});
}
} else {
console.warn(`File ${fullPath} not found.`);
}
}
const outputFilePath = `./public/api/${lang}/all.json`;
fs.writeFileSync(outputFilePath, JSON.stringify(allData, null, 4));
console.log(`all.json for ${lang} has been generated.`);
}