bdmgrdts/instance/src/lib/config.ts

21 lines
697 B
TypeScript

import { container_paths } from "./paths.ts";
import { exists } from "./utils.ts";
export type ContainerConfig = ReturnType<typeof new_container_config>;
export function new_container_config(name: string) {
return {
name,
version: 0,
redirects: [] as [number, number][],
};
}
export async function load_container_config(name: string) {
const config_path = container_paths(name).config;
if (!exists(config_path)) return null;
const content = await Deno.readTextFile(config_path);
const read = JSON.parse(content);
const default_ = new_container_config(name);
if (read.version < default_.version) throw new Error("read conf version is outdated");
return { ...default_, ...read };
}