mirror of
https://github.com/tcgdex/cards-database.git
synced 2025-06-12 15:59:18 +00:00
feat: Move internals to bunJS (#459)
This commit is contained in:
BIN
server/bun.lockb
Normal file
BIN
server/bun.lockb
Normal file
Binary file not shown.
@ -118,7 +118,7 @@ export async function cardToCardSingle(localId: string, card: Card, lang: Suppor
|
||||
* @returns [the local id, the Card object]
|
||||
*/
|
||||
export async function getCard(serie: string, setName: string, id: string): Promise<Card> {
|
||||
return (await import(`../../${DB_PATH}/data/${serie}/${setName}/${id}.js`)).default
|
||||
return (await import(`../../${DB_PATH}/data/${serie}/${setName}/${id}.ts`)).default
|
||||
}
|
||||
|
||||
/**
|
||||
@ -128,7 +128,7 @@ export async function getCard(serie: string, setName: string, id: string): Promi
|
||||
* @returns An array with the 0 = localId, 1 = Card Object
|
||||
*/
|
||||
export async function getCards(lang: SupportedLanguages, set?: Set): Promise<Array<[string, Card]>> {
|
||||
const cards = await smartGlob(`${DB_PATH}/data/${(set && set.serie.name.en) ?? '*'}/${(set && set.name.en) ?? '*'}/*.js`)
|
||||
const cards = await smartGlob(`${DB_PATH}/data/${(set && set.serie.name.en) ?? '*'}/${(set && set.name.en) ?? '*'}/*.ts`)
|
||||
const list: Array<[string, Card]> = []
|
||||
for (const path of cards) {
|
||||
let items = path.split('/')
|
||||
|
@ -1,10 +1,10 @@
|
||||
import { Serie, Set, SupportedLanguages } from '../../../interfaces'
|
||||
import { SerieResume, Serie as SerieSingle } from '../../../meta/definitions/api'
|
||||
import { getSets, setToSetSimple } from './setUtil'
|
||||
import { DB_PATH, smartGlob } from './util'
|
||||
import { setToSetSimple, getSets } from './setUtil'
|
||||
import { Serie, SupportedLanguages, Set } from '../../../interfaces'
|
||||
import { Serie as SerieSingle, SerieResume } from '../../../meta/definitions/api'
|
||||
|
||||
export async function getSerie(name: string): Promise<Serie> {
|
||||
return (await import(`../../${DB_PATH}/data/${name}.js`)).default
|
||||
return (await import(`../../${DB_PATH}/data/${name}.ts`)).default
|
||||
}
|
||||
|
||||
export async function isSerieAvailable(serie: Serie, lang: SupportedLanguages): Promise<boolean> {
|
||||
@ -16,7 +16,7 @@ export async function isSerieAvailable(serie: Serie, lang: SupportedLanguages):
|
||||
}
|
||||
|
||||
export async function getSeries(lang: SupportedLanguages): Promise<Array<Serie>> {
|
||||
let series: Array<Serie> = (await Promise.all((await smartGlob(`${DB_PATH}/data/*.js`))
|
||||
let series: Array<Serie> = (await Promise.all((await smartGlob(`${DB_PATH}/data/*.ts`))
|
||||
// Find Serie's name
|
||||
.map((it) => it.substring(it.lastIndexOf('/') + 1, it.length - 3))
|
||||
// Fetch the Serie
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { Set, SupportedLanguages } from '../../../interfaces'
|
||||
import { DB_PATH, fetchRemoteFile, setIsLegal, smartGlob } from './util'
|
||||
import { cardToCardSimple, getCards } from './cardUtil'
|
||||
import { SetResume, Set as SetSingle } from '../../../meta/definitions/api'
|
||||
import { cardToCardSimple, getCards } from './cardUtil'
|
||||
import { DB_PATH, fetchRemoteFile, setIsLegal, smartGlob } from './util'
|
||||
|
||||
interface t {
|
||||
[key: string]: Set
|
||||
@ -20,11 +20,11 @@ export function isSetAvailable(set: Set, lang: SupportedLanguages): boolean {
|
||||
export async function getSet(name: string, serie = '*'): Promise<Set> {
|
||||
if (!setCache[name]) {
|
||||
try {
|
||||
const [path] = await smartGlob(`${DB_PATH}/data/${serie}/${name}.js`)
|
||||
const [path] = await smartGlob(`${DB_PATH}/data/${serie}/${name}.ts`)
|
||||
setCache[name] = (await import(`../../${path}`)).default
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
console.error(`Error trying to import importing (${`db/data/${serie}/${name}.js`})`)
|
||||
console.error(`Error trying to import importing (${`db/data/${serie}/${name}.ts`})`)
|
||||
process.exit(1)
|
||||
}
|
||||
}
|
||||
@ -34,7 +34,7 @@ export async function getSet(name: string, serie = '*'): Promise<Set> {
|
||||
// Dont use cache as it wont necessary have them all
|
||||
export async function getSets(serie = '*', lang: SupportedLanguages): Promise<Array<Set>> {
|
||||
// list sets names
|
||||
const rawSets = (await smartGlob(`${DB_PATH}/data/${serie}/*.js`)).map((set) => set.substring(set.lastIndexOf('/') + 1, set.lastIndexOf('.')))
|
||||
const rawSets = (await smartGlob(`${DB_PATH}/data/${serie}/*.ts`)).map((set) => set.substring(set.lastIndexOf('/') + 1, set.lastIndexOf('.')))
|
||||
// Fetch sets
|
||||
const sets = (await Promise.all(rawSets.map((set) => getSet(set, serie))))
|
||||
// Filter sets
|
||||
|
3998
server/package-lock.json
generated
3998
server/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -3,10 +3,9 @@
|
||||
"private": true,
|
||||
"main": "dist/index.js",
|
||||
"scripts": {
|
||||
"compile": "ts-node --project ../tsconfig.json compiler/index.ts",
|
||||
"dev": "ts-node-dev -T src/index.ts",
|
||||
"build": "tsc --project tsconfig.json",
|
||||
"start": "node dist/index.js"
|
||||
"compile": "bun compiler/index.ts",
|
||||
"dev": "bun --watch --hot src/index.ts",
|
||||
"start": "bun src/index.ts"
|
||||
},
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
|
Reference in New Issue
Block a user