This commit is contained in:
Ruben Fiszel
2025-10-18 06:28:40 +00:00
parent 3c114b0678
commit d5ca95e3ed
2 changed files with 31 additions and 6 deletions
+3 -6
View File
@@ -21,7 +21,7 @@ import {
import { inferContentTypeFromFilePath } from "./script_common.ts";
import { GlobalDeps, exts, findGlobalDeps } from "../commands/script/script.ts";
import { FSFSElement, findCodebase, yamlOptions } from "../commands/sync/sync.ts";
import { generateHash, readInlinePathSync, getHeaders } from "./utils.ts";
import { generateHash, readInlinePathSync, getHeaders, writeIfChanged } from "./utils.ts";
import { SyncCodebase } from "./codebase.ts";
import { FlowFile } from "../commands/flow/flow.ts";
import { replaceInlineScripts } from "../../windmill-utils-internal/src/inline-scripts/replacer.ts";
@@ -195,14 +195,11 @@ export async function generateFlowLockInternal(
);
inlineScripts
.forEach((s) => {
Deno.writeTextFileSync(
Deno.cwd() + SEP + folder + SEP + s.path,
s.content
);
writeIfChanged(Deno.cwd() + SEP + folder + SEP + s.path, s.content);
});
// Overwrite `flow.yaml` with the new lockfile references
await Deno.writeTextFile(
writeIfChanged(
Deno.cwd() + SEP + folder + SEP + "flow.yaml",
yamlStringify(flowValue as Record<string, any>)
);
+28
View File
@@ -208,3 +208,31 @@ export async function getIsWin(): Promise<boolean> {
}
return isWin;
}
/**
* Writes content to a file only if it differs from existing content.
* Creates parent directories if they don't exist.
*
* @param path - The file path to write to
* @param content - The content to write
* @returns true if file was written, false if skipped (content unchanged)
*/
export function writeIfChanged(path: string, content: string): boolean {
try {
const existing = Deno.readTextFileSync(path);
if (existing === content) {
// console.log(`Content unchanged for ${path}`);
return false; // Content unchanged, skip write
}
} catch (error) {
// File doesn't exist or can't be read, proceed with write
if (!(error instanceof Deno.errors.NotFound)) {
// If it's not a "not found" error, we might want to know about it
// but still proceed with the write attempt
}
}
// console.log(`Writing content to ${path}`);
Deno.writeTextFileSync(path, content);
return true; // File was written
}