mirror of
https://github.com/tcgdex/compiler.git
synced 2025-07-03 20:29:19 +00:00
42
endpoints/hp/item.ts
Normal file
42
endpoints/hp/item.ts
Normal file
@ -0,0 +1,42 @@
|
||||
import { getAllCards, getBaseFolder } from "../util"
|
||||
import { fetchCard, isCardAvailable, cardToCardSimple } from "../cardUtil"
|
||||
import Card from "../../db/interfaces/Card"
|
||||
import { Langs } from "../../db/interfaces/LangList"
|
||||
import { HpSingle } from "../../sdk/dist/types/interfaces/Hp"
|
||||
import { promises as fs } from 'fs'
|
||||
|
||||
interface t {
|
||||
[key: number]: Array<Card>
|
||||
}
|
||||
|
||||
const lang = process.env.CARDLANG as Langs || "en"
|
||||
const endpoint = getBaseFolder(lang, "hp")
|
||||
|
||||
const btsp = async () => {
|
||||
const files = getAllCards()
|
||||
const pools: t = {}
|
||||
for (const file of files) {
|
||||
const card = fetchCard(file)
|
||||
|
||||
if (!isCardAvailable(card, lang) || !card.hp) continue
|
||||
|
||||
if (!(card.hp in pools)) pools[card.hp] = []
|
||||
pools[card.hp].push(card)
|
||||
}
|
||||
|
||||
for (const hp in pools) {
|
||||
if (pools.hasOwnProperty(hp)) {
|
||||
const cards = pools[hp];
|
||||
|
||||
const toSave: HpSingle = {
|
||||
hp: hp as unknown as number,
|
||||
cards: cards.map(el => cardToCardSimple(el, lang))
|
||||
}
|
||||
|
||||
await fs.mkdir(`${endpoint}/${toSave.hp}/`, {recursive: true})
|
||||
await fs.writeFile(`${endpoint}/${toSave.hp}/index.json`, JSON.stringify(toSave))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
btsp()
|
Reference in New Issue
Block a user