mirror of
https://github.com/tcgdex/compiler.git
synced 2025-07-03 04:09:19 +00:00
Moved files to link with the SDK
Signed-off-by: Avior <florian.bouillon@delta-wings.net>
This commit is contained in:
@ -1,10 +1,11 @@
|
||||
import Rarity from "../db/interfaces/Rarity";
|
||||
import { Langs } from "../db/interfaces/LangList";
|
||||
import Rarity from "@tcgdex/sdk/interfaces/Rarity";
|
||||
import { Langs } from "@tcgdex/sdk/interfaces/LangList";
|
||||
import { raritySimple } from "./rarities/rarity";
|
||||
import TranslationUtil from "@tcgdex/sdk/TranslationUtil";
|
||||
|
||||
export function rarityToRaritySimple(rarity: Rarity, lang: Langs): raritySimple {
|
||||
return {
|
||||
id: rarity,
|
||||
name: Rarity.toLang(rarity, lang)
|
||||
name: TranslationUtil.translate("rarity", rarity, lang)
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,11 @@
|
||||
import Tag from "../db/interfaces/Tag";
|
||||
import { Langs } from "../db/interfaces/LangList";
|
||||
import Tag from "@tcgdex/sdk/interfaces/Tag";
|
||||
import { Langs } from "@tcgdex/sdk/interfaces/LangList";
|
||||
import { tagSimple } from "./tags/tag";
|
||||
import TranslationUtil from "@tcgdex/sdk/TranslationUtil";
|
||||
|
||||
export function tagToTagSimple(tag: Tag, lang: Langs): tagSimple {
|
||||
return {
|
||||
id: tag,
|
||||
name: Tag.toLang(tag, lang)
|
||||
name: TranslationUtil.translate("tag", tag, lang)
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,8 @@
|
||||
import Ability from "../db/interfaces/Ability";
|
||||
import { Langs } from "../db/interfaces/LangList";
|
||||
import AbilityType from "../db/interfaces/AbilityType";
|
||||
import { AbilitySimple, AbilitySingle } from "../sdk/dist/types/interfaces/Ability";
|
||||
import Ability from "@tcgdex/sdk/interfaces/Ability";
|
||||
import { Langs } from "@tcgdex/sdk/interfaces/LangList";
|
||||
import AbilityType from "@tcgdex/sdk/interfaces/AbilityType";
|
||||
import { AbilitySimple, AbilitySingle } from "@tcgdex/sdk/interfaces/Ability";
|
||||
import TranslationUtil from "@tcgdex/sdk/TranslationUtil";
|
||||
|
||||
export function abilityToAbilitySimple(ability: Ability, lang: Langs): AbilitySimple {
|
||||
return {
|
||||
@ -15,7 +16,7 @@ export function abilityToAbilitySingle(ability: Ability, lang: Langs): AbilitySi
|
||||
text: ability.text[lang],
|
||||
type: {
|
||||
id: ability.type,
|
||||
name: AbilityType.toLang(ability.type, lang)
|
||||
name: TranslationUtil.translate("abilityType", ability.type, lang)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,13 @@
|
||||
import Attack from "../db/interfaces/Attack";
|
||||
import { Langs } from "../db/interfaces/LangList";
|
||||
import Type from "../db/interfaces/Type";
|
||||
import { AttackSingle } from "../sdk/dist/types/interfaces/Attack";
|
||||
import Attack from "@tcgdex/sdk/interfaces/Attack";
|
||||
import { Langs } from "@tcgdex/sdk/interfaces/LangList";
|
||||
import Type from "@tcgdex/sdk/interfaces/Type";
|
||||
import { AttackSingle } from "@tcgdex/sdk/interfaces/Attack";
|
||||
import TranslationUtil from "@tcgdex/sdk/TranslationUtil";
|
||||
|
||||
export function attackToAttackSingle(attack: Attack, lang: Langs): AttackSingle {
|
||||
return {
|
||||
name: attack.name[lang],
|
||||
cost: attack.cost && attack.cost.map(el => Type.toLang(el, lang)),
|
||||
cost: attack.cost && attack.cost.map(el => TranslationUtil.translate("type", el, lang)),
|
||||
text: attack.text && attack.text[lang],
|
||||
damage: attack.damage && attack.damage
|
||||
}
|
||||
|
@ -1,16 +1,16 @@
|
||||
import { CardSimple, CardSingle } from "../sdk/dist/types/interfaces/Card";
|
||||
import Card from "../db/interfaces/Card";
|
||||
import { Langs } from "../db/interfaces/LangList";
|
||||
import Card, { CardSimple, CardSingle } from "@tcgdex/sdk/interfaces/Card";
|
||||
import { Langs } from "@tcgdex/sdk/interfaces/LangList";
|
||||
import { typeToTypeSimple } from "./typeUtil";
|
||||
import { rarityToRaritySimple } from "./RarityUtil";
|
||||
import { tagToTagSimple } from "./TagUtil";
|
||||
import Category from "../db/interfaces/Category";
|
||||
import Category from "@tcgdex/sdk/interfaces/Category";
|
||||
import { attackToAttackSingle } from "./attackUtil";
|
||||
import { abilityToAbilitySingle } from "./abilityUtil";
|
||||
import { getExpansion } from "./expansionUtil";
|
||||
import { getSet } from "./setUtil";
|
||||
import Expansion from "../db/interfaces/Expansion";
|
||||
import Expansion from "@tcgdex/sdk/interfaces/Expansion";
|
||||
import { fetchIllustrators, fetchIllustratorsSync } from "./illustratorUtil";
|
||||
import TranslationUtil from "@tcgdex/sdk/TranslationUtil";
|
||||
|
||||
export function cardToCardSimple(card: Card, lang: Langs): CardSimple {
|
||||
return {
|
||||
@ -68,7 +68,7 @@ export function cardToCardSingle(card: Card, lang: Langs): CardSingle {
|
||||
|
||||
category: {
|
||||
id: card.category,
|
||||
name: Category.toLang(card.category, lang)
|
||||
name: TranslationUtil.translate("category", card.category, lang)
|
||||
},
|
||||
|
||||
set: {
|
||||
|
@ -1,7 +1,7 @@
|
||||
import Card from "../../db/interfaces/Card"
|
||||
import { Langs } from "../../db/interfaces/LangList"
|
||||
import Card from "@tcgdex/sdk/interfaces/Card"
|
||||
import { Langs } from "@tcgdex/sdk/interfaces/LangList"
|
||||
import { promises as fs } from 'fs'
|
||||
import { CardList, CardSimple } from "../../sdk/dist/types/interfaces/Card"
|
||||
import { CardList, CardSimple } from "@tcgdex/sdk/interfaces/Card"
|
||||
import { cardToCardSimple, isCardAvailable } from "../cardUtil"
|
||||
import { getBaseFolder, getAllCards2 } from "../util"
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { getAllCards2, getBaseFolder } from "..//util"
|
||||
import Card from "../../db/interfaces/Card"
|
||||
import { Langs } from "../../db/interfaces/LangList"
|
||||
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"
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
import Expansion from "../db/interfaces/Expansion"
|
||||
import Set from "../db/interfaces/Set"
|
||||
import Expansion from "@tcgdex/sdk/interfaces/Expansion"
|
||||
import Set from "@tcgdex/sdk/interfaces/Set"
|
||||
import * as glob from 'glob'
|
||||
import { Langs } from "../db/interfaces/LangList"
|
||||
import { ExpansionSingle } from "../sdk/dist/types/interfaces/Expansion"
|
||||
import { Langs } from "@tcgdex/sdk/interfaces/LangList"
|
||||
import { ExpansionSingle } from "@tcgdex/sdk/interfaces/Expansion"
|
||||
import { getAllSets } from "./util"
|
||||
import { setToSetSimple, fetchSet } from "./setUtil"
|
||||
|
||||
|
@ -1,10 +1,10 @@
|
||||
import { getAllExpansions, expansionToExpansionSimple } from "../expansionUtil"
|
||||
import Expansion from "../../db/interfaces/Expansion"
|
||||
import Expansion from "@tcgdex/sdk/interfaces/Expansion"
|
||||
import { getAllSets, getBaseFolder } from "../util"
|
||||
import { fetchSet } from "../setUtil"
|
||||
import { promises as fs } from 'fs'
|
||||
import { ExpansionList } from '../../sdk/dist/types/interfaces/Expansion'
|
||||
import { Langs } from "../../db/interfaces/LangList"
|
||||
import { ExpansionList } from '@tcgdex/sdk/interfaces/Expansion'
|
||||
import { Langs } from "@tcgdex/sdk/interfaces/LangList"
|
||||
|
||||
const lang = process.env.CARDLANG as Langs || "en"
|
||||
const endpoint = getBaseFolder(lang, "expansions")
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { getAllExpansions, fetchExpansion, expansionToExpansionSingle } from "../expansionUtil"
|
||||
import { Langs } from "../../db/interfaces/LangList"
|
||||
import { Langs } from "@tcgdex/sdk/interfaces/LangList"
|
||||
import { getBaseFolder } from "../util"
|
||||
import { promises as fs } from 'fs'
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { getAllCards, getBaseFolder } from "../util"
|
||||
import { fetchCard, isCardAvailable } from "../cardUtil"
|
||||
import { Langs } from "../../db/interfaces/LangList"
|
||||
import { HpList } from "../../sdk/dist/types/interfaces/Hp"
|
||||
import { Langs } from "@tcgdex/sdk/interfaces/LangList"
|
||||
import { HpList } from "@tcgdex/sdk/interfaces/Hp"
|
||||
import { promises as fs } from 'fs'
|
||||
|
||||
const lang = process.env.CARDLANG as Langs || "en"
|
||||
|
@ -1,8 +1,8 @@
|
||||
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 Card from "@tcgdex/sdk/interfaces/Card"
|
||||
import { Langs } from "@tcgdex/sdk/interfaces/LangList"
|
||||
import { HpSingle } from "@tcgdex/sdk/interfaces/Hp"
|
||||
import { promises as fs } from 'fs'
|
||||
|
||||
interface t {
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { promises as fs} from "fs"
|
||||
import * as fsSync from 'fs'
|
||||
import { IllustratorSimple } from "../sdk/dist/types/interfaces/Illustrator"
|
||||
import { IllustratorSimple } from "@tcgdex/sdk/interfaces/Illustrator"
|
||||
|
||||
export const illustratorsFile = "./generated/illustrators.json"
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { fetchIllustrators, illustratorToIllustratorSimple } from "../illustratorUtil"
|
||||
import { IllustratorsList } from "../../sdk/dist/types/interfaces/Illustrator"
|
||||
import { IllustratorsList } from "@tcgdex/sdk/interfaces/Illustrator"
|
||||
import { getBaseFolder } from "../util"
|
||||
import { promises as fs} from "fs"
|
||||
|
||||
|
@ -1,10 +1,10 @@
|
||||
import { fetchIllustrators } from "../illustratorUtil"
|
||||
import { IllustratorSingle } from "../../sdk/dist/types/interfaces/Illustrator"
|
||||
import { IllustratorSingle } from "@tcgdex/sdk/interfaces/Illustrator"
|
||||
import { getBaseFolder, getAllCards } from "../util"
|
||||
import { promises as fs} from "fs"
|
||||
import Card from "../../db/interfaces/Card"
|
||||
import Card from "@tcgdex/sdk/interfaces/Card"
|
||||
import { isCardAvailable, cardToCardSimple } from "../cardUtil"
|
||||
import { Langs } from "../../db/interfaces/LangList"
|
||||
import { Langs } from "@tcgdex/sdk/interfaces/LangList"
|
||||
|
||||
const lang = process.env.CARDLANG as Langs || "en"
|
||||
const endpoint = getBaseFolder(lang, "illustrators")
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { getAllCards2 } from "../util"
|
||||
import Card from "../../db/interfaces/Card"
|
||||
import Card from "@tcgdex/sdk/interfaces/Card"
|
||||
|
||||
import { promises as fs} from "fs"
|
||||
import { illustratorsFile, fetchIllustrators } from "../illustratorUtil"
|
||||
|
@ -1,9 +1,9 @@
|
||||
import Card from "../../db/interfaces/Card"
|
||||
import Card from "@tcgdex/sdk/interfaces/Card"
|
||||
import { getAllCards2, getBaseFolder } from "../util"
|
||||
import { promises as fs } from 'fs'
|
||||
import { isCardAvailable } from "../cardUtil"
|
||||
import { RetreatList } from '../../sdk/dist/types/interfaces/Retreat'
|
||||
import { Langs } from "../../db/interfaces/LangList"
|
||||
import { RetreatList } from '@tcgdex/sdk/interfaces/Retreat'
|
||||
import { Langs } from "@tcgdex/sdk/interfaces/LangList"
|
||||
|
||||
const lang = (process.env.CARDLANG || "en") as Langs
|
||||
const endpoint = getBaseFolder(lang, "retreat")
|
||||
|
@ -1,9 +1,9 @@
|
||||
import Card from "../../db/interfaces/Card"
|
||||
import Card from "@tcgdex/sdk/interfaces/Card"
|
||||
import { getAllCards2, getBaseFolder } from "../util"
|
||||
import { promises as fs } from 'fs'
|
||||
import { isCardAvailable, cardToCardSimple } from "../cardUtil"
|
||||
import { RetreatSingle } from '../../sdk/dist/types/interfaces/Retreat'
|
||||
import { Langs } from "../../db/interfaces/LangList"
|
||||
import { RetreatSingle } from '@tcgdex/sdk/interfaces/Retreat'
|
||||
import { Langs } from "@tcgdex/sdk/interfaces/LangList"
|
||||
|
||||
const lang = (process.env.CARDLANG || "en") as Langs
|
||||
const endpoint = getBaseFolder(lang, "retreat")
|
||||
|
@ -1,10 +1,10 @@
|
||||
import Set from "../db/interfaces/Set"
|
||||
import Card from "../db/interfaces/Card"
|
||||
import Set from "@tcgdex/sdk/interfaces/Set"
|
||||
import Card from "@tcgdex/sdk/interfaces/Card"
|
||||
import * as glob from 'glob'
|
||||
import { Langs } from "../db/interfaces/LangList"
|
||||
import { SetSimple, SetSingle } from "../sdk/dist/types/interfaces/Set"
|
||||
import { Langs } from "@tcgdex/sdk/interfaces/LangList"
|
||||
import { SetSimple, SetSingle } from "@tcgdex/sdk/interfaces/Set"
|
||||
import { cardToCardSimple } from "./cardUtil"
|
||||
import { CardSimple } from "../sdk/dist/types/interfaces/Card"
|
||||
import { CardSimple } from "@tcgdex/sdk/interfaces/Card"
|
||||
import { getAllCards2 } from "./util"
|
||||
|
||||
interface t<T = Set> {
|
||||
|
@ -1,7 +1,7 @@
|
||||
import Set from "../../db/interfaces/Set"
|
||||
import { Langs } from "../../db/interfaces/LangList"
|
||||
import Set from "@tcgdex/sdk/interfaces/Set"
|
||||
import { Langs } from "@tcgdex/sdk/interfaces/LangList"
|
||||
import { promises as fs } from 'fs'
|
||||
import { SetSimple, SetList } from "../../sdk/dist/types/interfaces/Set"
|
||||
import { SetSimple, SetList } from "@tcgdex/sdk/interfaces/Set"
|
||||
import { getAllSets, getBaseFolder } from "../util"
|
||||
import { isSetAvailable, setToSetSimple } from "../setUtil"
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { getBaseFolder, getAllSets } from "../util"
|
||||
import Set from "../../db/interfaces/Set"
|
||||
import { Langs } from "../../db/interfaces/LangList"
|
||||
import Set from "@tcgdex/sdk/interfaces/Set"
|
||||
import { Langs } from "@tcgdex/sdk/interfaces/LangList"
|
||||
import { promises as fs } from 'fs'
|
||||
import { isSetAvailable, setToSetSingle } from "../setUtil"
|
||||
|
||||
|
@ -1,10 +1,10 @@
|
||||
import { getBaseFolder, getAllSets } from "../util"
|
||||
import Set from "../../db/interfaces/Set"
|
||||
import { Langs } from "../../db/interfaces/LangList"
|
||||
import Set from "@tcgdex/sdk/interfaces/Set"
|
||||
import { Langs } from "@tcgdex/sdk/interfaces/LangList"
|
||||
import { promises as fs } from 'fs'
|
||||
import { isSetAvailable } from "../setUtil"
|
||||
import { getAllCards2 } from "../util"
|
||||
import Card from "../../db/interfaces/Card"
|
||||
import Card from "@tcgdex/sdk/interfaces/Card"
|
||||
import { cardToCardSingle, isCardAvailable } from "../cardUtil"
|
||||
|
||||
const lang = process.env.CARDLANG as Langs || "en"
|
||||
|
@ -1,10 +1,10 @@
|
||||
import Type from "../db/interfaces/Type";
|
||||
import LangList, { Langs } from "../db/interfaces/LangList";
|
||||
import { typeSimple } from "./types/type";
|
||||
import Type, { TypeSimple } from "@tcgdex/sdk/interfaces/Type";
|
||||
import LangList, { Langs } from "@tcgdex/sdk/interfaces/LangList";
|
||||
import TranslationUtil from "@tcgdex/sdk/TranslationUtil";
|
||||
|
||||
export function typeToTypeSimple(type: Type, lang: Langs): typeSimple {
|
||||
export function typeToTypeSimple(type: Type, lang: Langs): TypeSimple {
|
||||
return {
|
||||
id: type,
|
||||
name: Type.toLang(type, lang)
|
||||
name: TranslationUtil.translate("type", type, lang)
|
||||
}
|
||||
}
|
||||
|
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