import { readGameDbTable } from './game-db-source.mjs'; import { readFile, writeFile } from 'node:fs/promises'; import path from 'node:path'; const projectRoot = path.resolve(path.dirname(new URL(import.meta.url).pathname.replace(/^\/(?=[A-Za-z]:)/, '')), '..'); const catalogPath = path.join(projectRoot, 'src/lib/data/exact-chart-catalog.json'); const musicRows = readGameDbTable('kor', 'Music.json'); const musicById = new Map(musicRows.map((row) => [row.data?.id ?? row.id, row.data ?? row])); const compactSingerType = (value) => typeof value === 'string' ? value.split('_').at(-1)?.toLowerCase() ?? null : null; const catalog = JSON.parse(await readFile(catalogPath, 'utf8')); for (const entry of catalog.charts) { const music = musicById.get(entry.songId); if (!music) throw new Error(`Missing DB song: ${entry.songId}`); entry.singerType = compactSingerType(music?.musicSingerType); entry.singerCharacterIds = music?.characterIds ?? []; const chartPath = path.join(projectRoot, 'static', entry.path.replace(/^\//, '').replace(/^data[\\/]charts[\\/]/, 'data/charts/')); const chart = JSON.parse(await readFile(chartPath, 'utf8')); chart.singerType = entry.singerType; chart.singerCharacterIds = entry.singerCharacterIds; await writeFile(chartPath, JSON.stringify(chart), 'utf8'); } await writeFile(catalogPath, `${JSON.stringify(catalog, null, 2)}\n`, 'utf8'); console.log(`${catalog.charts.length}개 채보에 가창자 정보를 추가했습니다.`);