WIP
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user