mirror of
https://github.com/tcgdex/compiler.git
synced 2025-04-22 02:32:10 +00:00
Changes the order of the series
Signed-off-by: Avior <florian.bouillon@delta-wings.net>
This commit is contained in:
parent
5e50e352e5
commit
729787ae68
@ -1,12 +1,16 @@
|
||||
import { smartGlob } from "./util"
|
||||
import { setToSetSimple, getSets } from "./setUtil"
|
||||
import { Serie, SupportedLanguages } from 'db/interfaces'
|
||||
import { Serie, SupportedLanguages, Set } from 'db/interfaces'
|
||||
import { Serie as SerieSingle, SerieResume } from '@tcgdex/sdk/interfaces'
|
||||
|
||||
export async function getSeries(): Promise<Array<Serie>> {
|
||||
return Promise.all((await smartGlob('./db/data/*.js'))
|
||||
const series = await Promise.all((await smartGlob('./db/data/*.js'))
|
||||
.map((it) => it.substring(it.lastIndexOf('/') + 1, it.length - 3))
|
||||
.map((it) => getSerie(it)))
|
||||
const tmp: Array<[Serie, Set]> = await Promise.all(series.map( async (it) => {
|
||||
return [it, (await getSets(it.name.en)).reduce<Set | undefined>((p, c) => p ? p.releaseDate < c.releaseDate ? p : c : c, undefined) as Set] as [Serie, Set]
|
||||
}))
|
||||
return tmp.sort((a, b) => a[1].releaseDate > b[1].releaseDate ? 1 : -1).map((it) => it[0])
|
||||
}
|
||||
|
||||
export async function getSerie(name: string): Promise<Serie> {
|
||||
|
@ -12,17 +12,17 @@ const setCache: t = {}
|
||||
// Dont use cache as it wont necessary have them all
|
||||
export async function getSets(serie = '*'): Promise<Array<Set>> {
|
||||
const sets = (await smartGlob(`./db/data/${serie}/*.js`)).map((set) => set.substring(set.lastIndexOf('/')+1, set.lastIndexOf('.')))
|
||||
return Promise.all(sets.map((set) => getSet(set)))
|
||||
return Promise.all(sets.map((set) => getSet(set, serie)))
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the set
|
||||
* @param name the name of the set (don't include.js/.ts)
|
||||
*/
|
||||
export async function getSet(name: string): Promise<Set> {
|
||||
export async function getSet(name: string, serie = '*'): Promise<Set> {
|
||||
if (!setCache[name]) {
|
||||
try {
|
||||
const [path] = await smartGlob(`./db/data/*/${name}.js`)
|
||||
const [path] = await smartGlob(`./db/data/${serie}/${name}.js`)
|
||||
setCache[name] = (await import(path.replace('./', '../'))).default
|
||||
} catch (e) {
|
||||
const set = (await getSets()).find((s) => s.id === name)
|
||||
|
Loading…
x
Reference in New Issue
Block a user