This commit is contained in:
2025-12-27 13:42:50 +01:00
parent c107ec9b5b
commit eed4a0e438
8 changed files with 100 additions and 51 deletions
+13 -1
View File
@@ -13,9 +13,21 @@ export async function read<T extends object>(
await fs.access(filePath);
} catch {
await fs.mkdir(dirPath, { recursive: true });
await fs.writeFile(filePath, JSON.stringify(template, null, 2), "utf-8");
await fs.writeFile(filePath, JSON.stringify(template(), null, 2), "utf-8");
}
const content = await fs.readFile(filePath, "utf-8");
return JSON.parse(content);
}
export async function write<T extends object>(
val: T,
fp: string,
...filePaths: string[]
) {
const filePath = path.join(process.cwd(), fp, ...filePaths);
const dirPath = path.dirname(filePath);
await fs.mkdir(dirPath, { recursive: true });
await fs.writeFile(filePath, JSON.stringify(val, null, 2), "utf-8");
}
View File