mirror of
https://github.com/tcgdex/compiler.git
synced 2025-04-22 10:42:09 +00:00
31 lines
913 B
TypeScript
31 lines
913 B
TypeScript
import { getAllCards2, getBaseFolder } from "..//util"
|
|
import Card from "@tcgdex/sdk/interfaces/Card"
|
|
import { Langs } from "@tcgdex/sdk/interfaces/LangList"
|
|
import { promises as fs } from 'fs'
|
|
import { cardToCardSingle, isCardAvailable } from "../cardUtil"
|
|
|
|
const lang = process.env.CARDLANG as Langs || "en"
|
|
|
|
const endpoint = getBaseFolder(lang, "cards")
|
|
|
|
export default async () => {
|
|
console.log(endpoint)
|
|
const list = await getAllCards2()
|
|
for (let el of list) {
|
|
el = el.replace("./", "../../")
|
|
const card: Card = require(el).default
|
|
|
|
if (!isCardAvailable(card, lang)) continue
|
|
|
|
try {
|
|
await fs.mkdir(`${endpoint}/${encodeURI(card.id)}/`, {recursive: true})
|
|
await fs.writeFile(`${endpoint}/${encodeURI(card.id)}/index.json`, JSON.stringify(await cardToCardSingle(card, lang)))
|
|
} catch {
|
|
|
|
}
|
|
|
|
// if (if (typeof card.set.availability === "undefined"))
|
|
}
|
|
console.log('ended ' + endpoint)
|
|
}
|