Fix file generation infinite loop

This commit is contained in:
Konstantin Wohlwend 2025-02-18 21:38:42 -08:00
parent 6692194250
commit 229209f12a

View File

@ -124,7 +124,7 @@ function copyFromSrcToDest(
newContent = JSON.stringify(orderedJson, null, 2);
}
fs.writeFileSync(destPath, newContent);
writeFileSyncIfChanged(destPath, newContent);
}
}
}
@ -437,6 +437,16 @@ function processMacros(content: string, envs: string[]): string {
return result.join('\n');
}
function writeFileSyncIfChanged(path: string, content: string): void {
if (fs.existsSync(path)) {
const existingContent = fs.readFileSync(path, "utf-8");
if (existingContent === content) {
return;
}
}
fs.writeFileSync(path, content);
}
@ -448,7 +458,7 @@ const packageJsonWithComment = {
"//": COMMENT_LINE,
...packageJson
};
fs.writeFileSync(path.join(srcDir, 'package.json'), JSON.stringify(packageJsonWithComment, null, 2));
writeFileSyncIfChanged(path.join(srcDir, 'package.json'), JSON.stringify(packageJsonWithComment, null, 2));
generateFromTemplate({