2022-09-24 16:20:54 +08:00
|
|
|
import axios from "axios";
|
|
|
|
import fs from "fs";
|
|
|
|
import jsYaml from "js-yaml";
|
2022-03-19 16:56:50 +08:00
|
|
|
|
2022-09-06 15:09:45 +08:00
|
|
|
const LANGS_FILEPATH = "./src/common/languageColors.json";
|
2022-03-19 16:56:50 +08:00
|
|
|
|
|
|
|
//Retrieve languages from github linguist repository yaml file
|
|
|
|
//@ts-ignore
|
2022-09-06 15:09:45 +08:00
|
|
|
axios
|
|
|
|
.get(
|
|
|
|
"https://raw.githubusercontent.com/github/linguist/master/lib/linguist/languages.yml",
|
|
|
|
)
|
|
|
|
.then((response) => {
|
|
|
|
//and convert them to a JS Object
|
|
|
|
const languages = jsYaml.load(response.data);
|
2022-03-19 16:56:50 +08:00
|
|
|
|
2022-09-06 15:09:45 +08:00
|
|
|
const languageColors = {};
|
2022-03-19 16:56:50 +08:00
|
|
|
|
2022-09-06 15:09:45 +08:00
|
|
|
//Filter only language colors from the whole file
|
|
|
|
Object.keys(languages).forEach((lang) => {
|
|
|
|
languageColors[lang] = languages[lang].color;
|
|
|
|
});
|
2022-03-19 16:56:50 +08:00
|
|
|
|
2022-09-06 15:09:45 +08:00
|
|
|
//Debug Print
|
|
|
|
//console.dir(languageColors);
|
|
|
|
fs.writeFileSync(
|
|
|
|
LANGS_FILEPATH,
|
|
|
|
JSON.stringify(languageColors, null, " "),
|
|
|
|
);
|
2022-03-19 16:56:50 +08:00
|
|
|
});
|