import config from "../config.json" with { type: "json" }; import { existsSync, readFileSync, writeFileSync } from "fs"; import type { IState } from "./types.js"; let state: IState = { users: [], }; const load = () => { if (!existsSync(config.storePath)) { return; } console.log("loading data..."); const json = readFileSync(config.storePath).toString(); state = JSON.parse(json) as IState; }; const save = () => { console.log("saving data..."); const json = JSON.stringify(state); writeFileSync(config.storePath, json); }; export { state, load, save };