mirror of
https://github.com/tcgdex/cards-database.git
synced 2025-04-22 10:52:10 +00:00
* feat: Add status Dashboard Still need some polishing like using the compiler instead of the live DB Signed-off-by: Avior <github@avior.me> * refactor: Simplified compiler files generators Signed-off-by: Avior <florian.bouillon@delta-wings.net> * chore: Add step to compiler for stats and optimize Signed-off-by: Avior <github@avior.me> * refactor: Remove unused variable Signed-off-by: Avior <github@avior.me>
61 lines
1.7 KiB
TypeScript
61 lines
1.7 KiB
TypeScript
/* eslint-disable max-statements */
|
|
import { FileFunction } from './compilerInterfaces'
|
|
import { promises as fs } from 'fs'
|
|
import { fetchRemoteFile } from './utils/util'
|
|
import { objectValues } from '@dzeio/object-util'
|
|
import { SupportedLanguages } from '../../interfaces'
|
|
|
|
const LANGS: Array<SupportedLanguages> = ['en', 'fr', 'es', 'it', 'pt', 'de']
|
|
|
|
const DIST_FOLDER = './generated'
|
|
|
|
;(async () => {
|
|
const paths = (await fs.readdir('./compiler/endpoints')).filter((p) => p.endsWith('.ts'))
|
|
|
|
// Prefetch the pictures at the start as it can bug because of bad connection
|
|
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 fn = (await import(`./endpoints/${file}`)).default as FileFunction
|
|
|
|
// Run the function
|
|
console.log(file, 'Running...')
|
|
const item = await fn(lang)
|
|
|
|
// Write to file
|
|
await fs.writeFile(`${folder}/${file.replace('.ts', '')}.json`, JSON.stringify(
|
|
item
|
|
))
|
|
|
|
console.log(file, 'Finished!')
|
|
}
|
|
}
|
|
|
|
// 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)
|
|
}
|
|
|
|
})()
|