import { readFile, writeFile } from 'node:fs/promises'; import type { AssetState } from './assets.js'; export interface PostState { ghostSlug: string; ghostTitle: string; documentUri?: string; documentCid?: string; articleUri?: string; articleCid?: string; } export interface AppState { publicationAtUri?: string; accountDid?: string; assets?: Record; posts: Record; } export async function loadState(path: string): Promise { try { const raw = await readFile(path, 'utf-8'); const parsed = JSON.parse(raw) as AppState; return Object.assign({ posts: {} }, parsed); } catch (err: any) { if (err?.code === 'ENOENT') { return { posts: {} }; } throw err; } } export async function saveState(path: string, state: AppState): Promise { await writeFile(path, JSON.stringify(state, null, 2), 'utf-8'); }