Skip to content

Commit

Permalink
feat: added script to automate language color retrieval (anuraghazra#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Davoleo authored Mar 19, 2022
1 parent 104bdd6 commit de80488
Show file tree
Hide file tree
Showing 3 changed files with 294 additions and 194 deletions.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"test": "jest --coverage",
"test:watch": "jest --watch",
"theme-readme-gen": "node scripts/generate-theme-doc",
"preview-theme": "node scripts/preview-theme"
"preview-theme": "node scripts/preview-theme",
"generate-langs-json": "node scripts/generate-langs-json"
},
"author": "Anurag Hazra",
"license": "MIT",
Expand All @@ -22,6 +23,7 @@
"hjson": "^3.2.2",
"husky": "^4.2.5",
"jest": "^26.1.0",
"js-yaml": "^4.1.0",
"lodash.snakecase": "^4.1.1",
"parse-diff": "^0.7.0",
"prettier": "^2.1.2"
Expand Down
26 changes: 26 additions & 0 deletions scripts/generate-langs-json.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const fs = require('fs');
const jsYaml = require('js-yaml');
const axios = require('axios');

const LANGS_FILEPATH = "./src/common/languageColors.json"

//Retrieve languages from github linguist repository yaml file
//@ts-ignore
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);

const languageColors = {};

//Filter only language colors from the whole file
Object.keys(languages).forEach((lang) => {
languageColors[lang] = languages[lang].color;
});

//Debug Print
//console.dir(languageColors);
fs.writeFileSync(LANGS_FILEPATH, JSON.stringify(languageColors, null, ' '));

});
Loading

0 comments on commit de80488

Please sign in to comment.