-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.js
More file actions
64 lines (60 loc) · 1.47 KB
/
build.js
File metadata and controls
64 lines (60 loc) · 1.47 KB
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
64
const fs = require("node:fs");
const yaml = require("js-yaml");
const digitToWord = [
"zero",
"one",
"two",
"three",
"four",
"five",
"six",
"seven",
"eight",
"nine",
];
/**
* reads from github's linguist and creates a css file with the colors of the languages
*/
async function main() {
const resp = await fetch(
"https://raw.githubusercontent.com/github/linguist/master/lib/linguist/languages.yml"
);
if (!resp.ok) throw new Error("Failed to fetch languages.yml");
const langs = yaml.load(await resp.text());
const langColors = Object.keys(langs).reduce((acc, val) => {
acc[
val
.replaceAll("+", "P")
.replaceAll("#", "-Sharp")
.replace(/\s/g, "-")
.replaceAll(".", "-")
.replace(/["'()]/g, "")
.replace(/^\d/, (match) => digitToWord[match])
] = langs[val].color;
return acc;
}, {});
const payloadArry = Object.entries(langColors).filter(([_, val]) =>
Boolean(val)
);
fs.writeFileSync(
"index.css",
payloadArry.map(([key, val]) => `.${key}{color: ${val};}`).join("")
);
fs.writeFileSync(
"background.css",
payloadArry
.map(([key, val]) => `.${key}-bg{background-color: ${val};}`)
.join("")
);
fs.writeFileSync("langs.json", JSON.stringify(langColors));
fs.writeFileSync(
"raw_langs.json",
JSON.stringify(
Object.keys(langs).reduce((acc, val) => {
acc[val] = langs[val].color;
return acc;
}, {})
)
);
}
main();