Updated Compiler to be quicker

Signed-off-by: Avior <florian.bouillon@delta-wings.net>
This commit is contained in:
2020-05-05 11:46:36 +02:00
parent 346168d68b
commit 557dad7e33
29 changed files with 153 additions and 82 deletions

View File

@ -91,3 +91,7 @@ export function isCardAvailable(card: Card, lang: Langs): boolean {
export function fetchCard(card: string, set?: string, expansion?: string): Card {
return require(`../db/cards/${expansion && (expansion + "/") || ""}${set && (set + "/") || ""}${card}`).default
}
export async function fetchCardAsync(card: string, set?: string, expansion?: string): Promise<Card> {
return (await import(`../db/cards/${expansion && (expansion + "/") || ""}${set && (set + "/") || ""}${card}`)).default
}

View File

@ -9,7 +9,8 @@ const lang = process.env.CARDLANG as Langs || "en"
const endpoint = getBaseFolder(lang, "cards")
const bootstrap = async () => {
export default async () => {
console.log(endpoint)
const list = await getAllCards2()
const items: Array<CardSimple> = []
for (let el of list) {
@ -32,6 +33,5 @@ const bootstrap = async () => {
await fs.mkdir(`${endpoint}`, {recursive: true})
await fs.writeFile(`${endpoint}/index.json`, JSON.stringify(cardList))
console.log('ended ' + endpoint)
}
bootstrap()

View File

@ -8,7 +8,8 @@ const lang = process.env.CARDLANG as Langs || "en"
const endpoint = getBaseFolder(lang, "cards")
const bootstrap = async () => {
export default async () => {
console.log(endpoint)
const list = await getAllCards2()
for (let el of list) {
el = el.replace("./", "../../")
@ -21,6 +22,5 @@ const bootstrap = async () => {
// if (if (typeof card.set.availability === "undefined"))
}
console.log('ended ' + endpoint)
}
bootstrap()

View File

@ -7,7 +7,8 @@ import { promises as fs } from 'fs'
const lang = process.env.CARDLANG as Langs || "en"
const endpoint = getBaseFolder(lang, "categories")
const btsp = async () => {
export default async () => {
console.log(endpoint)
const list: Array<CategorySimple> = []
for (const cat of Object.values(Category)) {
@ -25,5 +26,5 @@ const btsp = async () => {
await fs.mkdir(endpoint, {recursive: true})
await fs.writeFile(`${endpoint}/index.json`, JSON.stringify(res))
console.log('ended ' + endpoint)
}
btsp()

View File

@ -14,7 +14,8 @@ const lang = process.env.CARDLANG as Langs || "en"
const endpoint = getBaseFolder(lang, "categories")
const btsp = async () => {
export default async () => {
console.log(endpoint)
const list = getAllCards()
const arr: categoryCards = {}
for (const i of list) {
@ -49,6 +50,5 @@ const btsp = async () => {
await promises.writeFile(`${name}/index.json`, JSON.stringify(toSave))
}
}
console.log('ended ' + endpoint)
}
btsp()

View File

@ -10,7 +10,8 @@ const lang = process.env.CARDLANG as Langs || "en"
const endpoint = getBaseFolder(lang, "expansions")
const btsp = async () => {
export default async () => {
console.log(endpoint)
const expansions = getAllExpansions()
let list: Array<{
release: string,
@ -40,6 +41,5 @@ const btsp = async () => {
await fs.mkdir(endpoint, {recursive: true})
await fs.writeFile(`${endpoint}/index.json`, JSON.stringify(res))
console.log('ended ' + endpoint)
}
btsp()

View File

@ -8,7 +8,8 @@ const lang = process.env.CARDLANG as Langs || "en"
const endpoint = getBaseFolder(lang, "expansions")
const btsp = async () => {
export default async () => {
console.log(endpoint)
const list = getAllExpansions()
for (const i of list) {
const expansion = fetchExpansion(i)
@ -17,6 +18,5 @@ const btsp = async () => {
await fs.mkdir(`${endpoint}/${expansion.code}/`, {recursive: true})
await fs.writeFile(`${endpoint}/${expansion.code}/index.json`, JSON.stringify(expansionToExpansionSingle(expansion, lang)))
}
console.log('ended ' + endpoint)
}
btsp()

View File

@ -8,7 +8,8 @@ const lang = process.env.CARDLANG as Langs || "en"
const endpoint = getBaseFolder(lang, "hp")
const btsp = async () => {
export default async () => {
console.log(endpoint)
const cards = getAllCards()
const hps: Array<number> = []
@ -29,6 +30,5 @@ const btsp = async () => {
await fs.mkdir(endpoint, {recursive: true})
await fs.writeFile(`${endpoint}/index.json`, JSON.stringify(hpList))
console.log('ended ' + endpoint)
}
btsp()

View File

@ -12,7 +12,8 @@ interface t {
const lang = process.env.CARDLANG as Langs || "en"
const endpoint = getBaseFolder(lang, "hp")
const btsp = async () => {
export default async () => {
console.log(endpoint)
const files = getAllCards()
const pools: t = {}
for (const file of files) {
@ -37,6 +38,5 @@ const btsp = async () => {
await fs.writeFile(`${endpoint}/${toSave.hp}/index.json`, JSON.stringify(toSave))
}
}
console.log('ended ' + endpoint)
}
btsp()

View File

@ -6,7 +6,8 @@ import { promises as fs} from "fs"
const lang = process.env.CARDLANG || "en"
const endpoint = getBaseFolder(lang, "illustrators")
const btsp = async () => {
export default async () => {
console.log(endpoint)
const db = await fetchIllustrators()
@ -17,6 +18,5 @@ const btsp = async () => {
await fs.mkdir(endpoint, {recursive: true})
await fs.writeFile(`${endpoint}/index.json`, JSON.stringify(res))
console.log('ended ' + endpoint)
}
btsp()

View File

@ -13,7 +13,8 @@ interface t {
[key: string]: Array<Card>
}
const btsp = async () => {
export default async () => {
console.log(endpoint)
const db = await fetchIllustrators()
const cards = getAllCards()
@ -44,6 +45,5 @@ const btsp = async () => {
await fs.writeFile(`${endpoint}/${toSave.id}/index.json`, JSON.stringify(toSave))
}
}
console.log('ended ' + endpoint)
}
btsp()

View File

@ -6,7 +6,7 @@ import { illustratorsFile, fetchIllustrators } from "../illustratorUtil"
const dbFile = illustratorsFile
const btsp = async () => {
export default async () => {
const db = await fetchIllustrators()
@ -26,5 +26,3 @@ const btsp = async () => {
await fs.writeFile(dbFile, JSON.stringify(db))
}
btsp()

View File

@ -7,7 +7,8 @@ import Rarity, { RaritySimple, RarityList } from "@tcgdex/sdk/interfaces/Rarity"
const lang = process.env.CARDLANG as Langs || "en"
const endpoint = getBaseFolder(lang, "rarities")
const btsp = async () => {
export default async () => {
console.log(endpoint)
const list: Array<RaritySimple> = []
for (const cat of Object.values(Rarity)) {
@ -25,5 +26,5 @@ const btsp = async () => {
await fs.mkdir(endpoint, {recursive: true})
await fs.writeFile(`${endpoint}/index.json`, JSON.stringify(res))
console.log('ended ' + endpoint)
}
btsp()

View File

@ -1,5 +1,5 @@
import { getAllCards, getBaseFolder, urlize } from "../util"
import { fetchCard, isCardAvailable, cardToCardSimple } from "../cardUtil"
import { fetchCard, isCardAvailable, cardToCardSimple, fetchCardAsync } from "../cardUtil"
import Card from "@tcgdex/sdk/interfaces/Card"
import { Langs } from "@tcgdex/sdk/interfaces/LangList"
import TranslationUtil from "@tcgdex/sdk/TranslationUtil"
@ -14,11 +14,12 @@ const lang = process.env.CARDLANG as Langs || "en"
const endpoint = getBaseFolder(lang, "rarities")
const btsp = async () => {
export default async () => {
console.log(endpoint)
const list = getAllCards()
const arr: rarityCards = {}
for (const i of list) {
const card = await fetchCard(i)
const card = await fetchCardAsync(i)
if (!isCardAvailable(card, lang)) continue
@ -49,6 +50,5 @@ const btsp = async () => {
await promises.writeFile(`${name}/index.json`, JSON.stringify(toSave))
}
}
console.log('ended ' + endpoint)
}
btsp()

View File

@ -8,7 +8,8 @@ import { Langs } from "@tcgdex/sdk/interfaces/LangList"
const lang = (process.env.CARDLANG || "en") as Langs
const endpoint = getBaseFolder(lang, "retreat")
const btsp = async () => {
export default async () => {
console.log(endpoint)
const files = await getAllCards2()
const count: Array<number> = []
for (let file of files) {
@ -30,6 +31,5 @@ const btsp = async () => {
await fs.mkdir(endpoint, {recursive: true})
await fs.writeFile(`${endpoint}/index.json`, JSON.stringify(list))
console.log('ended ' + endpoint)
}
btsp()

View File

@ -8,7 +8,8 @@ import { Langs } from "@tcgdex/sdk/interfaces/LangList"
const lang = (process.env.CARDLANG || "en") as Langs
const endpoint = getBaseFolder(lang, "retreat")
const btsp = async () => {
export default async () => {
console.log(endpoint)
const files = await getAllCards2()
const count: Array<Array<Card>> = []
for (let file of files) {
@ -36,6 +37,5 @@ const btsp = async () => {
await fs.writeFile(`${endpoint}/${item.id}/index.json`, JSON.stringify(item))
}
}
console.log('ended ' + endpoint)
}
btsp()

View File

@ -9,7 +9,9 @@ const lang = process.env.CARDLANG as Langs || "en"
const endpoint = getBaseFolder(lang, "sets")
const bootstrap = async () => {
export default async () => {
console.log(endpoint)
const list = await getAllSets()
let items: Array<Set> = []
for (let el of list) {
@ -34,6 +36,5 @@ const bootstrap = async () => {
await fs.mkdir(`${endpoint}`, {recursive: true})
await fs.writeFile(`${endpoint}/index.json`, JSON.stringify(cardList))
console.log('ended ' + endpoint)
}
bootstrap()

View File

@ -8,7 +8,8 @@ const lang = process.env.CARDLANG as Langs || "en"
const endpoint = getBaseFolder(lang, "sets")
const bootstrap = async () => {
export default async () => {
console.log(endpoint)
const list = await getAllSets()
for (let el of list) {
el = el.replace("./", "../../")
@ -21,6 +22,5 @@ const bootstrap = async () => {
}
console.log('ended ' + endpoint)
}
bootstrap()

View File

@ -11,7 +11,8 @@ const lang = process.env.CARDLANG as Langs || "en"
const endpoint = getBaseFolder(lang, "sets")
const bootstrap = async () => {
export default async () => {
console.log(endpoint)
const list = await getAllSets()
for (let el of list) {
el = el.replace("./", "../../")
@ -33,6 +34,5 @@ const bootstrap = async () => {
}
console.log('ended ' + endpoint)
}
bootstrap()

View File

@ -7,7 +7,8 @@ import Tag, { TagSimple, TagList } from "@tcgdex/sdk/interfaces/Tag"
const lang = process.env.CARDLANG as Langs || "en"
const endpoint = getBaseFolder(lang, "tags")
const btsp = async () => {
export default async () => {
console.log(endpoint)
const list: Array<TagSimple> = []
for (const cat of Object.values(Tag)) {
@ -25,5 +26,5 @@ const btsp = async () => {
await fs.mkdir(endpoint, {recursive: true})
await fs.writeFile(`${endpoint}/index.json`, JSON.stringify(res))
console.log('ended ' + endpoint)
}
btsp()

View File

@ -15,7 +15,8 @@ const lang = process.env.CARDLANG as Langs || "en"
const endpoint = getBaseFolder(lang, "tags")
const btsp = async () => {
export default async () => {
console.log(endpoint)
const list = getAllCards()
const arr: tagCards = {}
for (const i of list) {
@ -49,6 +50,5 @@ const btsp = async () => {
await promises.writeFile(`${name}/index.json`, JSON.stringify(toSave))
}
}
console.log('ended ' + endpoint)
}
btsp()

View File

@ -8,8 +8,8 @@ import { List } from "@tcgdex/sdk/interfaces/General"
const lang = process.env.CARDLANG as Langs || "en"
const endpoint = getBaseFolder(lang, "types")
const btsp = async () => {
export default async () => {
console.log(endpoint)
const typeArr: Array<TypeSimple> = []
for (const i of Object.values(Type)) {
if (typeof i !== "number") continue
@ -26,6 +26,5 @@ const btsp = async () => {
await fs.mkdir(endpoint, {recursive: true})
await fs.writeFile(`${endpoint}/index.json`, JSON.stringify(typeList))
console.log('ended ' + endpoint)
}
btsp()

View File

@ -14,7 +14,8 @@ const lang = process.env.CARDLANG as Langs || "en"
const endpoint = getBaseFolder(lang, "types")
const btsp = async () => {
export default async () => {
console.log(endpoint)
const list = getAllCards()
const arr: typeCards = {}
for (const i of list) {
@ -48,6 +49,5 @@ const btsp = async () => {
await promises.writeFile(`${name}/index.json`, JSON.stringify(toSave))
}
}
console.log('ended ' + endpoint)
}
btsp()