Skip to content

Commit de80488

Browse files
authored
feat: added script to automate language color retrieval (#1654)
1 parent 104bdd6 commit de80488

File tree

3 files changed

+294
-194
lines changed

3 files changed

+294
-194
lines changed

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
"test": "jest --coverage",
88
"test:watch": "jest --watch",
99
"theme-readme-gen": "node scripts/generate-theme-doc",
10-
"preview-theme": "node scripts/preview-theme"
10+
"preview-theme": "node scripts/preview-theme",
11+
"generate-langs-json": "node scripts/generate-langs-json"
1112
},
1213
"author": "Anurag Hazra",
1314
"license": "MIT",
@@ -22,6 +23,7 @@
2223
"hjson": "^3.2.2",
2324
"husky": "^4.2.5",
2425
"jest": "^26.1.0",
26+
"js-yaml": "^4.1.0",
2527
"lodash.snakecase": "^4.1.1",
2628
"parse-diff": "^0.7.0",
2729
"prettier": "^2.1.2"

scripts/generate-langs-json.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
const fs = require('fs');
2+
const jsYaml = require('js-yaml');
3+
const axios = require('axios');
4+
5+
const LANGS_FILEPATH = "./src/common/languageColors.json"
6+
7+
//Retrieve languages from github linguist repository yaml file
8+
//@ts-ignore
9+
axios.get("https://raw.githubusercontent.com/github/linguist/master/lib/linguist/languages.yml")
10+
.then((response) => {
11+
12+
//and convert them to a JS Object
13+
const languages = jsYaml.load(response.data);
14+
15+
const languageColors = {};
16+
17+
//Filter only language colors from the whole file
18+
Object.keys(languages).forEach((lang) => {
19+
languageColors[lang] = languages[lang].color;
20+
});
21+
22+
//Debug Print
23+
//console.dir(languageColors);
24+
fs.writeFileSync(LANGS_FILEPATH, JSON.stringify(languageColors, null, ' '));
25+
26+
});

0 commit comments

Comments
 (0)