-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.mjs
42 lines (33 loc) · 1.13 KB
/
index.mjs
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
import { readdirSync, writeFileSync } from "node:fs";
import { join } from "node:path";
const getFilesRecursively = directory => {
return readdirSync(directory, { withFileTypes: true }).flatMap(file =>
file.isDirectory() ? getFilesRecursively(join(directory, file.name)) : join(directory, file.name)
);
};
const createList = () => {
const list = getFilesRecursively("./rules");
const mergedList = [];
for (let i = 0; i < list.length; i++) {
const [_, platform, __, ocVersion, cpuModel] = list[i].replace(/\\/g, "/").split("/");
mergedList.push({
cpuModel: `${platform}_${cpuModel.split(".")[0]}`,
ocVersion
});
}
const mergeObjects = mergedList.reduce((m, { cpuModel, ocVersion }) => {
m[cpuModel] = [...(m[cpuModel] || []), ocVersion];
return m;
}, {});
const returnList = Object.entries(mergeObjects).map(([codename, supportedVersions]) => ({
codename,
supportedVersions: supportedVersions.sort((a, b) => b.localeCompare(a))
}));
return returnList;
};
const createFile = input => {
const data = JSON.stringify(input);
writeFileSync("./oc_versions.json", data);
};
const list = createList();
createFile(list);