add clean to build

This commit is contained in:
Rene Haas
2022-10-31 11:00:33 +01:00
parent 7c0fd242ca
commit 3d095f747d
5 changed files with 47 additions and 13 deletions
+24
View File
@@ -0,0 +1,24 @@
const path = require('path');
const fs = require('fs');
module.exports = ({ paths = [], verbose = false } = {}) => {
let cleaned = false;
return {
name: 'clean',
async buildStart() {
if (!cleaned) {
paths.forEach((currPath) => {
const resolvedPath = path.resolve(currPath);
if (fs.existsSync(resolvedPath)) {
if (verbose) {
// eslint-disable-next-line no-console
console.log(`Clean: ${resolvedPath}`);
}
fs.rmSync(resolvedPath, { recursive: true });
}
});
cleaned = true;
}
},
};
};