mirror of
https://github.com/tcgdex/compiler.git
synced 2025-08-02 08:51:59 +00:00
Updated
Signed-off-by: Florian BOUILLON <florian.bouillon@delta-wings.net>
This commit is contained in:
@@ -3,20 +3,24 @@ import { fetchCard, isCardAvailable } from "../cardUtil"
|
||||
import { Langs } from "@tcgdex/sdk/interfaces/LangList"
|
||||
import { HpList } from "@tcgdex/sdk/interfaces/Hp"
|
||||
import { promises as fs } from 'fs'
|
||||
import Card from "@tcgdex/sdk/interfaces/Card"
|
||||
|
||||
import Logger from '@dzeio/logger'
|
||||
const logger = new Logger('hp/index')
|
||||
|
||||
const lang = process.env.CARDLANG as Langs || "en"
|
||||
const endpoint = getBaseFolder(lang, "hp")
|
||||
|
||||
|
||||
export default async () => {
|
||||
console.log(endpoint)
|
||||
const cards = getAllCards()
|
||||
logger.log('Fetching Cards')
|
||||
const cards = await getAllCards()
|
||||
|
||||
const hps: Array<number> = []
|
||||
|
||||
for (const i of cards) {
|
||||
const card = fetchCard(i)
|
||||
if (!isCardAvailable(card, lang) || !card.hp) continue
|
||||
const card: Card = (await import(i)).default
|
||||
if (!(await isCardAvailable(card, lang)) || !card.hp) continue
|
||||
|
||||
if (hps.includes(card.hp)) continue
|
||||
hps.push(card.hp)
|
||||
@@ -26,9 +30,10 @@ export default async () => {
|
||||
count: hps.length,
|
||||
list: hps.sort((a, b) => a > b ? 1 : -1)
|
||||
}
|
||||
logger.log('Writing to files')
|
||||
|
||||
await fs.mkdir(endpoint, {recursive: true})
|
||||
await fs.writeFile(`${endpoint}/index.json`, JSON.stringify(hpList))
|
||||
|
||||
console.log('ended ' + endpoint)
|
||||
logger.log('Finished')
|
||||
}
|
||||
|
@@ -5,6 +5,9 @@ import { Langs } from "@tcgdex/sdk/interfaces/LangList"
|
||||
import { HpSingle } from "@tcgdex/sdk/interfaces/Hp"
|
||||
import { promises as fs } from 'fs'
|
||||
|
||||
import Logger from '@dzeio/logger'
|
||||
const logger = new Logger('hp/item')
|
||||
|
||||
interface t {
|
||||
[key: number]: Array<Card>
|
||||
}
|
||||
@@ -13,13 +16,13 @@ const lang = process.env.CARDLANG as Langs || "en"
|
||||
const endpoint = getBaseFolder(lang, "hp")
|
||||
|
||||
export default async () => {
|
||||
console.log(endpoint)
|
||||
const files = getAllCards()
|
||||
logger.log('Fetching Cards')
|
||||
const files = await getAllCards()
|
||||
const pools: t = {}
|
||||
for (const file of files) {
|
||||
const card = fetchCard(file)
|
||||
const card: Card = (await import(file)).default
|
||||
|
||||
if (!isCardAvailable(card, lang) || !card.hp) continue
|
||||
if (!(await isCardAvailable(card, lang)) || !card.hp) continue
|
||||
|
||||
if (!(card.hp in pools)) pools[card.hp] = []
|
||||
pools[card.hp].push(card)
|
||||
@@ -27,6 +30,7 @@ export default async () => {
|
||||
|
||||
for (const hp in pools) {
|
||||
if (pools.hasOwnProperty(hp)) {
|
||||
logger.log('Processing HP', hp)
|
||||
const cards = pools[hp];
|
||||
|
||||
const toSave: HpSingle = {
|
||||
@@ -38,5 +42,5 @@ export default async () => {
|
||||
await fs.writeFile(`${endpoint}/${toSave.hp}/index.json`, JSON.stringify(toSave))
|
||||
}
|
||||
}
|
||||
console.log('ended ' + endpoint)
|
||||
logger.log('Finished')
|
||||
}
|
||||
|
Reference in New Issue
Block a user