import fetch from 'node-fetch'; import { parse, stringify } from 'yaml'; import slugify from 'slugify'; import { paramCase } from 'change-case'; import { writeFile, readFile } from 'node:fs/promises'; import Handlebars from 'handlebars'; import { mkdirp } from 'mkdirp' const LINGUIST_URL = "https://raw.githubusercontent.com/github/linguist/master/lib/linguist/languages.yml"; function slugifyLanguage(language) { return paramCase(language.replace("#", " Sharp").replace("++", " Plus Plus")); } async function main() { await mkdirp("dist"); const response = await fetch(LINGUIST_URL); const body = parse(await response.text()); const colours = {}; for (const [key, value] of Object.entries(body)) { if (!value.color) { continue; } const languageName = slugifyLanguage(key); if (languageName in colours) { throw "CONFLICT" + key; } colours[key] = { slug: languageName, color: value.color }; } await writeFile("dist/out.json", JSON.stringify(colours)); const cssTemplate = Handlebars.compile((await readFile("scripts/templates/template.css")).toString()); await writeFile("dist/out.css", cssTemplate({data: Object.values(colours)})); const scssTemplate = Handlebars.compile((await readFile("scripts/templates/template.scss")).toString()); await writeFile("dist/out.scss", scssTemplate({data: Object.values(colours)})); } main();