Files
openclaw/test/helpers/temp-repo.ts
2026-03-26 22:03:18 +00:00

21 lines
670 B
TypeScript

import fs from "node:fs";
import os from "node:os";
import path from "node:path";
export function makeTempRepoRoot(tempDirs: string[], prefix: string): string {
const repoRoot = fs.mkdtempSync(path.join(os.tmpdir(), prefix));
tempDirs.push(repoRoot);
return repoRoot;
}
export function writeJsonFile(filePath: string, value: unknown): void {
fs.mkdirSync(path.dirname(filePath), { recursive: true });
fs.writeFileSync(filePath, `${JSON.stringify(value, null, 2)}\n`, "utf8");
}
export function cleanupTempDirs(tempDirs: string[]): void {
for (const dir of tempDirs.splice(0, tempDirs.length)) {
fs.rmSync(dir, { recursive: true, force: true });
}
}