import {readdir, readFile, stat} from 'fs/promises'; import {join} from 'path'; const BASE_PATH = 'public/games'; export type Game = { id: string, name: string, main: string, thumbnail?: string, data: { aspectRatio: number, }, } export const getAvailableGames = async (): Promise => { const dirs = await readdir(BASE_PATH); const dirStat = await Promise.all(dirs.map(async (d) => ({ id: d, stat: await stat(join(BASE_PATH, d)), }))); const gameStat = dirStat.filter((d) => d.stat.isDirectory()); return Promise.all(gameStat.map(async (g) => { const manifestBuffer = await readFile(join(BASE_PATH, g.id, 'manifest.json')); const manifestString = manifestBuffer.toString('utf-8'); const manifestJson = JSON.parse(manifestString); return { ...manifestJson, id: g.id, }; })); }