MCPcopy Create free account
hub / github.com/MCSManager/MCSManager / sortLanguageFiles

Function sortLanguageFiles

scripts/sort-lang-key.mjs:8–35  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

6const languagesDir = path.join(import.meta.dirname, "../languages");
7
8export async function sortLanguageFiles() {
9 try {
10 const languageFiles = await fs.readdir(languagesDir);
11 await Promise.all(
12 languageFiles.map(async (file) => {
13 if (!file.endsWith(".json")) return;
14 console.log(`Sorting ${file}...`);
15 const filePath = path.join(languagesDir, file);
16 const content = await fs.readFile(filePath, "utf8");
17 const jsonContent = JSON.parse(content);
18 const keysCount = Object.keys(jsonContent).length;
19 const sortedContent = Object.keys(jsonContent)
20 .sort()
21 .reduce((obj, key) => {
22 obj[key] = jsonContent[key];
23 return obj;
24 }, {});
25 if (keysCount !== Object.keys(sortedContent).length) {
26 throw new Error(`Error: ${file} keys count is not equal`);
27 }
28 return await fs.writeFile(filePath, JSON.stringify(sortedContent, null, 2));
29 })
30 );
31 console.log("All language files sorted successfully");
32 } catch (err) {
33 console.error("Error sorting language files:", err);
34 }
35}
36
37sortLanguageFiles();

Callers 1

sort-lang-key.mjsFile · 0.85

Calls 5

logMethod · 0.80
keysMethod · 0.80
errorMethod · 0.80
readFileMethod · 0.45
writeFileMethod · 0.45

Tested by

no test coverage detected