init
This commit is contained in:
commit
44825c4c31
11 changed files with 247 additions and 0 deletions
21
src/lib/config.ts
Normal file
21
src/lib/config.ts
Normal file
|
@ -0,0 +1,21 @@
|
|||
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 };
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue