mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-12 21:53:00 -06:00
c70aee247e
* refactor(scripts): migrate JavaScript tools to TypeScript * fix(ci): keep changed-scope preflight zero-install * fix(ci): preserve zero-install script owners * fix(ci): complete script migration follow-through * fix(release): keep stable closeout zero-install * fix(scripts): preserve standalone execution boundaries * fix(scripts): repair standalone loader boundaries * fix(scripts): normalize gateway observation ids * fix(scripts): keep Docker packager standalone * test(scripts): preserve rebase cleanup helpers * test(sessions): use tracked temp directory
32 lines
825 B
TypeScript
32 lines
825 B
TypeScript
import fs from "node:fs/promises";
|
|
import path from "node:path";
|
|
|
|
type GeneratedTextAssetFs = Pick<typeof fs, "mkdir" | "readFile" | "writeFile">;
|
|
|
|
/**
|
|
* Writes a generated text asset only when its contents changed.
|
|
*/
|
|
export async function writeGeneratedTextAsset(
|
|
filePath: string,
|
|
contents: string,
|
|
params: { fs?: GeneratedTextAssetFs } = {},
|
|
) {
|
|
const fsImpl = params.fs ?? fs;
|
|
let currentContents = null;
|
|
try {
|
|
currentContents = await fsImpl.readFile(filePath, "utf8");
|
|
} catch (error) {
|
|
if (!(error instanceof Error && "code" in error && error.code === "ENOENT")) {
|
|
throw error;
|
|
}
|
|
}
|
|
|
|
if (currentContents === contents) {
|
|
return false;
|
|
}
|
|
|
|
await fsImpl.mkdir(path.dirname(filePath), { recursive: true });
|
|
await fsImpl.writeFile(filePath, contents, "utf8");
|
|
return true;
|
|
}
|