mirror of
https://github.com/tcgdex/cards-database.git
synced 2025-07-29 03:09:49 +00:00
feature: Implement new Server infrastructure with GraphQL. (#132)
* Added new compiler to db Signed-off-by: Avior <florian.bouillon@delta-wings.net> * Add compiled DB to artifacts Signed-off-by: Avior <florian.bouillon@delta-wings.net> * Fixed space error Signed-off-by: Avior <florian.bouillon@delta-wings.net> * Fixed? Signed-off-by: Avior <florian.bouillon@delta-wings.net> * Update node.js.yml * Update node.js.yml * Made change so the db is no longer dependent on the SDK Signed-off-by: Avior <florian.bouillon@delta-wings.net> * f Signed-off-by: Avior <florian.bouillon@delta-wings.net> * Fixed artifact Signed-off-by: Avior <florian.bouillon@delta-wings.net> * U Signed-off-by: Avior <florian.bouillon@delta-wings.net> * \Changed folder Signed-off-by: Avior <florian.bouillon@delta-wings.net> * Fixede? Signed-off-by: Avior <florian.bouillon@delta-wings.net> * Try with everything * saved the file ;) * ignore compiler * Fixed prebuild being run again * Fixed public folder Signed-off-by: Avior <github@avior.me> * fixed graphql file Signed-off-by: Avior <github@avior.me> * fixed? Signed-off-by: Avior <github@avior.me> * Check tree because life is potato Signed-off-by: Avior <github@avior.me> * this is harder Signed-off-by: Avior <github@avior.me> * f Signed-off-by: Avior <github@avior.me> * Fixed? Signed-off-by: Avior <github@avior.me> * r Signed-off-by: Avior <github@avior.me> * fd Signed-off-by: Avior <github@avior.me> * added back context Signed-off-by: Avior <github@avior.me> * ah Signed-off-by: Avior <github@avior.me> * AAH Signed-off-by: Avior <github@avior.me> * AAAH Signed-off-by: Avior <github@avior.me> * ffffffffffffffffff Signed-off-by: Avior <github@avior.me> * fix: Changed the default builder Signed-off-by: Avior <github@avior.me> * Removed useless tree function Signed-off-by: Avior <github@avior.me>
This commit is contained in:
63
server/compiler/index.ts
Normal file
63
server/compiler/index.ts
Normal file
@ -0,0 +1,63 @@
|
||||
/* eslint-disable max-statements */
|
||||
import { Endpoint } from './compilerInterfaces'
|
||||
import { promises as fs } from 'fs'
|
||||
import { fetchRemoteFile } from './utils/util'
|
||||
|
||||
const LANGS = ['en', 'fr', 'es', 'it', 'pt', 'de']
|
||||
|
||||
const DIST_FOLDER = './generated'
|
||||
|
||||
;(async () => {
|
||||
const paths = (await fs.readdir('./compiler/endpoints')).filter((p) => p.endsWith('.ts'))
|
||||
|
||||
console.log('Prefetching pictures')
|
||||
await fetchRemoteFile('https://assets.tcgdex.net/datas.json')
|
||||
|
||||
// Delete dist folder to be sure to have a clean base
|
||||
try {
|
||||
await fs.rm(DIST_FOLDER, {recursive: true})
|
||||
} catch {}
|
||||
|
||||
|
||||
console.log('Let\'s GO !')
|
||||
|
||||
// Process each languages
|
||||
for await (const lang of LANGS) {
|
||||
console.log('Processing', lang)
|
||||
// loop through """endpoints"""
|
||||
for await (const file of paths) {
|
||||
|
||||
// final folder path
|
||||
const folder = `${DIST_FOLDER}/${lang}`
|
||||
|
||||
// Make the folder
|
||||
await fs.mkdir(folder, {recursive: true})
|
||||
|
||||
// Import the """Endpoint"""
|
||||
const Ep = (await import(`./endpoints/${file}`)).default
|
||||
|
||||
const endpoint = new Ep(lang) as Endpoint
|
||||
|
||||
console.log(file, 'Running Common')
|
||||
let common: any | null = null
|
||||
|
||||
if (endpoint.common) {
|
||||
common = await endpoint.common()
|
||||
}
|
||||
|
||||
console.log(file, 'Running Item')
|
||||
const item = await endpoint.item(common)
|
||||
|
||||
// Write to file
|
||||
await fs.writeFile(`${folder}/${file.replace('.ts', '')}.json`, JSON.stringify(item))
|
||||
|
||||
console.log(file, 'Finished Item')
|
||||
}
|
||||
}
|
||||
|
||||
// Finally copy definitions files to the public folder :D
|
||||
for await (const file of await fs.readdir('../meta/definitions')) {
|
||||
await fs.copyFile('../meta/definitions/' + file, './public/v2/' + file)
|
||||
}
|
||||
|
||||
})()
|
Reference in New Issue
Block a user