Updated illustrators

Signed-off-by: Avior <florian.bouillon@delta-wings.net>
This commit is contained in:
2020-03-10 14:39:23 +01:00
parent 552e4b49fa
commit 55c33bb2a3
5 changed files with 103 additions and 2 deletions

View File

@ -0,0 +1,22 @@
import { fetchIllustrators, illustratorToIllustratorSimple } from "../illustratorUtil"
import { IllustratorsList } from "../../sdk/dist/types/interfaces/Illustrator"
import { getBaseFolder } from "../util"
import { promises as fs} from "fs"
const lang = process.env.CARDLANG || "en"
const endpoint = getBaseFolder(lang, "illustrators")
const btsp = async () => {
const db = await fetchIllustrators()
const res: IllustratorsList = {
count: db.length,
list: db.map((ill, index) => illustratorToIllustratorSimple(ill, index))
}
await fs.mkdir(endpoint, {recursive: true})
await fs.writeFile(`${endpoint}/index.json`, JSON.stringify(res))
}
btsp()

View File

@ -0,0 +1,49 @@
import { fetchIllustrators } from "../illustratorUtil"
import { IllustratorSingle } from "../../sdk/dist/types/interfaces/Illustrator"
import { getBaseFolder, getAllCards } from "../util"
import { promises as fs} from "fs"
import Card from "../../db/interfaces/Card"
import { isCardAvailable, cardToCardSimple } from "../cardUtil"
import { Langs } from "../../db/interfaces/LangList"
const lang = process.env.CARDLANG as Langs || "en"
const endpoint = getBaseFolder(lang, "illustrators")
interface t {
[key: string]: Array<Card>
}
const btsp = async () => {
const db = await fetchIllustrators()
const cards = getAllCards()
const tmp: t = {}
for (const i of cards) {
const card: Card = require(`../../db/cards/${i}`).default
if (!isCardAvailable(card, lang) || !card.illustrator) continue
if (!(card.illustrator in tmp)) tmp[card.illustrator] = []
tmp[card.illustrator].push(card)
}
for (const illustrator in tmp) {
if (tmp.hasOwnProperty(illustrator)) {
const list = tmp[illustrator];
const toSave: IllustratorSingle = {
id: db.indexOf(illustrator),
name: illustrator,
cards: list.map(el => cardToCardSimple(el, lang))
}
await fs.mkdir(`${endpoint}/${toSave.id}`, {recursive: true})
await fs.writeFile(`${endpoint}/${toSave.id}/index.json`, JSON.stringify(toSave))
}
}
}
btsp()

View File

@ -0,0 +1,31 @@
import { getAllCards2 } from "../util"
import Card from "../../db/interfaces/Card"
import { promises as fs} from "fs"
import { illustratorsFile, fetchIllustrators } from "../illustratorUtil"
const dbFile = illustratorsFile
const btsp = async () => {
const db = await fetchIllustrators()
const list = getAllCards2()
for (let i of list) {
i = i.replace("./", "../../")
const card: Card = require(i).default
if (!card.illustrator) continue
console.log(i)
const illustrator = card.illustrator
if (!db.includes(illustrator)) {
db.push(illustrator)
}
}
await fs.writeFile(dbFile, JSON.stringify(db))
}
btsp()