Skip to content

Commit

Permalink
Merge 73b8d5d into 4bf576a
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidMLPalma committed Apr 3, 2024
2 parents 4bf576a + 73b8d5d commit a7a2348
Showing 1 changed file with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,29 @@ export const splittedProjectFolderNames = [
'eventsFunctionsExtensions',
];

const deleteExistingFilesFromDirs = (projectPath: string) => {
const entries = fs.readdirSync(projectPath);
return new Promise((resolve, reject) => {
//Project file
if (entries.length === 1) resolve();

//If multiFile enabled in settings and directories exist!
entries.forEach(entry => {
let dirPath = projectPath.concat('\\', entry);
if (fs.statSync(dirPath).isDirectory()) {
const filenames = fs.readdirSync(dirPath);
filenames.forEach(file => {
let result = dirPath.concat('\\', file);
fs.unlink(result, (err => {
if (err) return reject(err);
}));
});
}
});
resolve();
});
};

const checkFileContent = (filePath: string, expectedContent: string) => {
const time = performance.now();
return new Promise((resolve, reject) => {
Expand Down Expand Up @@ -142,6 +165,12 @@ export const onSaveProject = (
};

const projectPath = path.dirname(filePath);

deleteExistingFilesFromDirs(projectPath).catch(err => {
console.error('Unable to delete files in the project:', err);
throw err;
});

return writeProjectFiles(project, filePath, projectPath).then(() => {
return { wasSaved: true, fileMetadata: newFileMetadata }; // Save was properly done
});
Expand Down

0 comments on commit a7a2348

Please sign in to comment.