mirror of
https://github.com/tcgdex/compiler.git
synced 2025-07-03 12:19:18 +00:00
Initial Compiler
Signed-off-by: Avior <florian.bouillon@delta-wings.net>
This commit is contained in:
38
endpoints/sets/index.ts
Normal file
38
endpoints/sets/index.ts
Normal file
@ -0,0 +1,38 @@
|
||||
import Set from "../../db/interfaces/Set"
|
||||
import { Langs } from "../../db/interfaces/LangList"
|
||||
import { promises as fs } from 'fs'
|
||||
import { SetSimple, SetList } from "../../sdk/dist/types/interfaces/Set"
|
||||
import { getAllSets, getBaseFolder } from "../util"
|
||||
import { isSetAvailable, setToSetSimple } from "../setUtil"
|
||||
|
||||
const lang = process.env.CARDLANG as Langs || "en"
|
||||
|
||||
const endpoint = getBaseFolder(lang, "sets")
|
||||
|
||||
const bootstrap = async () => {
|
||||
const list = await getAllSets()
|
||||
const items: Array<SetSimple> = []
|
||||
for (let el of list) {
|
||||
el = el.replace("./", "../../")
|
||||
const set: Set = require(el).default
|
||||
|
||||
console.log(el)
|
||||
if (!isSetAvailable(set, lang)) continue
|
||||
items.push(
|
||||
setToSetSimple(set, lang)
|
||||
)
|
||||
}
|
||||
|
||||
const cardList: SetList = {
|
||||
count: items.length,
|
||||
list: items
|
||||
}
|
||||
|
||||
await fs.mkdir(`${endpoint}`, {recursive: true})
|
||||
await fs.writeFile(`${endpoint}/index.json`, JSON.stringify(cardList))
|
||||
|
||||
}
|
||||
|
||||
console.log("Building sets/index")
|
||||
|
||||
bootstrap()
|
28
endpoints/sets/item.ts
Normal file
28
endpoints/sets/item.ts
Normal file
@ -0,0 +1,28 @@
|
||||
import { getBaseFolder, getAllSets } from "../util"
|
||||
import Set from "../../db/interfaces/Set"
|
||||
import { Langs } from "../../db/interfaces/LangList"
|
||||
import { promises as fs } from 'fs'
|
||||
import { isSetAvailable, setToSetSingle } from "../setUtil"
|
||||
|
||||
const lang = process.env.CARDLANG as Langs || "en"
|
||||
|
||||
const endpoint = getBaseFolder(lang, "sets")
|
||||
|
||||
const bootstrap = async () => {
|
||||
const list = await getAllSets()
|
||||
for (let el of list) {
|
||||
el = el.replace("./", "../../")
|
||||
const set: Set = require(el).default
|
||||
|
||||
if (!isSetAvailable(set, lang)) continue
|
||||
console.log(el)
|
||||
|
||||
await fs.mkdir(`${endpoint}/${set.code}/`, {recursive: true})
|
||||
await fs.writeFile(`${endpoint}/${set.code}/index.json`, JSON.stringify(setToSetSingle(set, lang)))
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
console.log("Building sets/item")
|
||||
|
||||
bootstrap()
|
42
endpoints/sets/subitem.ts
Normal file
42
endpoints/sets/subitem.ts
Normal file
@ -0,0 +1,42 @@
|
||||
import { getBaseFolder, getAllSets } from "../util"
|
||||
import Set from "../../db/interfaces/Set"
|
||||
import { Langs } from "../../db/interfaces/LangList"
|
||||
import { promises as fs } from 'fs'
|
||||
import { isSetAvailable } from "../setUtil"
|
||||
import { getAllCards2 } from "../util"
|
||||
import Card from "../../db/interfaces/Card"
|
||||
import { cardToCardSingle, isCardAvailable } from "../cardUtil"
|
||||
|
||||
const lang = process.env.CARDLANG as Langs || "en"
|
||||
|
||||
const endpoint = getBaseFolder(lang, "sets")
|
||||
|
||||
const bootstrap = async () => {
|
||||
const list = await getAllSets()
|
||||
for (let el of list) {
|
||||
el = el.replace("./", "../../")
|
||||
const set: Set = require(el).default
|
||||
|
||||
console.log(el)
|
||||
if (!isSetAvailable(set, lang)) continue
|
||||
|
||||
const lit = await getAllCards2(set.code)
|
||||
for (let i of lit) {
|
||||
i = i.replace("./", "../../")
|
||||
const card: Card = require(i).default
|
||||
|
||||
if (!isCardAvailable(card, lang)) continue
|
||||
console.log(i)
|
||||
|
||||
await fs.mkdir(`${endpoint}/${set.code}/${card.localId}`, {recursive: true})
|
||||
await fs.writeFile(`${endpoint}/${set.code}/${card.localId}/index.json`, JSON.stringify(cardToCardSingle(card, lang)))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
console.log("Building sets/subitem")
|
||||
|
||||
bootstrap()
|
Reference in New Issue
Block a user