mirror of
https://github.com/tcgdex/compiler.git
synced 2025-07-03 12:19:18 +00:00
Moved files to link with the SDK
Signed-off-by: Avior <florian.bouillon@delta-wings.net>
This commit is contained in:
31
endpoints/types/index.ts
Normal file
31
endpoints/types/index.ts
Normal file
@ -0,0 +1,31 @@
|
||||
import Type, { TypeSimple } from "@tcgdex/sdk/interfaces/Type"
|
||||
import TranslationUtil from "@tcgdex/sdk/TranslationUtil"
|
||||
import { getBaseFolder } from "../util"
|
||||
import { Langs } from "@tcgdex/sdk/interfaces/LangList"
|
||||
import { promises as fs } from "fs"
|
||||
import { List } from "@tcgdex/sdk/interfaces/General"
|
||||
|
||||
const lang = process.env.CARDLANG as Langs || "en"
|
||||
const endpoint = getBaseFolder(lang, "types")
|
||||
|
||||
const btsp = async () => {
|
||||
|
||||
const typeArr: Array<TypeSimple> = []
|
||||
for (const i of Object.values(Type)) {
|
||||
if (typeof i !== "number") continue
|
||||
typeArr.push({
|
||||
id: i,
|
||||
name: TranslationUtil.translate("type", i, lang)
|
||||
})
|
||||
}
|
||||
|
||||
const typeList: List<TypeSimple> = {
|
||||
count: typeArr.length,
|
||||
list: typeArr
|
||||
}
|
||||
|
||||
await fs.mkdir(endpoint, {recursive: true})
|
||||
await fs.writeFile(`${endpoint}/index.json`, JSON.stringify(typeList))
|
||||
}
|
||||
|
||||
btsp()
|
53
endpoints/types/item.ts
Normal file
53
endpoints/types/item.ts
Normal file
@ -0,0 +1,53 @@
|
||||
import { getAllCards, getBaseFolder, urlize } from "../util"
|
||||
import { fetchCard, isCardAvailable, cardToCardSimple } from "../cardUtil"
|
||||
import Type, { TypeSingle } from "@tcgdex/sdk/interfaces/Type"
|
||||
import Card from "@tcgdex/sdk/interfaces/Card"
|
||||
import { Langs } from "@tcgdex/sdk/interfaces/LangList"
|
||||
import TranslationUtil from "@tcgdex/sdk/TranslationUtil"
|
||||
import { promises } from "fs"
|
||||
|
||||
type typeCards = {
|
||||
[key in Type]?: Array<Card>
|
||||
}
|
||||
|
||||
const lang = process.env.CARDLANG as Langs || "en"
|
||||
const endpoint = getBaseFolder(lang, "types")
|
||||
|
||||
|
||||
const btsp = async () => {
|
||||
const list = getAllCards()
|
||||
const arr: typeCards = {}
|
||||
for (const i of list) {
|
||||
const card = await fetchCard(i)
|
||||
|
||||
if (!isCardAvailable(card, lang) || !card.type) continue
|
||||
|
||||
for (const type of card.type) {
|
||||
if (!(type in arr)) arr[type] = []
|
||||
arr[type].push(card)
|
||||
}
|
||||
}
|
||||
|
||||
for (const type in arr) {
|
||||
if (arr.hasOwnProperty(type)) {
|
||||
const cards: Array<Card> = arr[type];
|
||||
const rType: Type = parseInt(type)
|
||||
const toSave: TypeSingle = {
|
||||
id: rType,
|
||||
name: TranslationUtil.translate("type", rType, lang),
|
||||
cards: cards.map(el => cardToCardSimple(el, lang))
|
||||
}
|
||||
|
||||
const index = `${endpoint}/${toSave.id}`
|
||||
const name = `${endpoint}/${urlize(toSave.name)}`
|
||||
|
||||
await promises.mkdir(index, {recursive: true})
|
||||
await promises.mkdir(name, {recursive: true})
|
||||
|
||||
await promises.writeFile(`${index}/index.json`, JSON.stringify(toSave))
|
||||
await promises.writeFile(`${name}/index.json`, JSON.stringify(toSave))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
btsp()
|
Reference in New Issue
Block a user