// Load era templates for the "Create scenario" path from disk (v0.31.0, #52). // Mirrors the preset store (server/presets.ts): each template is a JSON file // (presets/templates/.json) and index.json is the lightweight manifest used // to render the picker cards. The store is created with the resolved templates // directory so it works from repo root (dev) and /app (Docker) alike. import { readFileSync } from 'node:fs'; import type { EraTemplate, TemplateMeta } from '../shared/scenario'; export interface TemplateStore { listMeta(): TemplateMeta[]; get(id: string): EraTemplate | null; } export function createTemplateStore(dir: string): TemplateStore { const manifest = JSON.parse(readFileSync(`${dir}/index.json`, 'utf8')) as TemplateMeta[]; return { listMeta() { return manifest; }, get(id: string) { try { return JSON.parse(readFileSync(`${dir}/${id}.json`, 'utf8')) as EraTemplate; } catch { return null; } }, }; }