Florian Bouillon b524f47a88
Fixed old endpoint
Signed-off-by: Avior <florian.bouillon@delta-wings.net>
2020-03-11 11:36:26 +01:00

30 lines
819 B
TypeScript

import { getBaseFolder } from "../util"
import Category, { CategorySimple, CategoryList } from '@tcgdex/sdk/interfaces/Category'
import TranslationUtil from "@tcgdex/sdk/TranslationUtil"
import { Langs } from "@tcgdex/sdk/interfaces/LangList"
import { promises as fs } from 'fs'
const lang = process.env.CARDLANG as Langs || "en"
const endpoint = getBaseFolder(lang, "categories")
const btsp = async () => {
const list: Array<CategorySimple> = []
for (const cat of Object.values(Category)) {
if (typeof cat !== "number") continue
list.push({
id: cat,
name: TranslationUtil.translate("category", cat, lang)
})
}
const res: CategoryList = {
count: list.length,
list: list
}
await fs.mkdir(endpoint, {recursive: true})
await fs.writeFile(`${endpoint}/index.json`, JSON.stringify(res))
}
btsp()