Refactor empty of build directory

This commit is contained in:
Mariano Aguero 2018-10-23 20:22:05 -03:00
parent f85ff5c951
commit abc32c968f
1 changed files with 30 additions and 1 deletions

View File

@ -45,7 +45,9 @@ measureFileSizesBeforeBuild(paths.appBuild)
.then(previousFileSizes => {
// Remove all content but keep the directory so that
// if you're in it, you don't end up in Trash
fs.emptyDirSync(paths.appBuild);
deleteFolderRecursive(paths.appBuild);
// Merge with the public folder
copyPublicFolder();
// Start the webpack build
@ -142,3 +144,30 @@ function copyPublicFolder() {
filter: file => file !== paths.appHtml,
});
}
function deleteFolderRecursive(pathApp) {
const pathBuild = path.join(__dirname, `../build`)
const pathContract = path.join(__dirname, `../build/contracts`)
const pathMetadata = path.join(__dirname, `../build/metadata`)
if (pathApp === pathContract || pathApp === pathMetadata) {
console.log(`Path excluded to delete: ${pathApp}`)
return
} else {
if (fs.existsSync(pathApp)) {
fs.readdirSync(pathApp).forEach(function(file) {
let curPath = `${pathApp}/${file}`
if (fs.lstatSync(curPath).isDirectory()) {
// recurse
deleteFolderRecursive(curPath)
} else {
// delete file
fs.unlinkSync(curPath)
}
})
if (pathApp !== pathBuild) {
fs.rmdirSync(pathApp)
}
}
}
}