This commit is contained in:
2024-11-10 01:06:11 -05:00
parent 23e234eac0
commit 70a1b2f768
6 changed files with 274 additions and 21 deletions
+21
View File
@@ -0,0 +1,21 @@
import fs from 'fs-extra';
export const saveFileIfItChanged = (newContent, filePath) => {
try {
// Check if file exists and read the current content
if (fs.existsSync(filePath)) {
const currentContent = fs.readFileSync(filePath, 'utf-8');
// Compare current content with new content
if (currentContent === newContent) {
return; // Exit function if content is the same
}
}
// Write new content to the file if it is different or file doesn't exist
fs.writeFileSync(filePath, newContent, 'utf-8');
} catch (error) {
console.error('Error handling file:', error);
}
}