-
Notifications
You must be signed in to change notification settings - Fork 5
/
cleanBuild.js
34 lines (30 loc) · 931 Bytes
/
cleanBuild.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
const fs = require("fs");
const path = require("path");
const pathToDir = path.join(__dirname, "dist");
const cleanDirectory = (path) => {
if (fs.existsSync(path)) {
const files = fs.readdirSync(path);
if(files.length > 0){
files.forEach(filename => {
if(fs.statSync(`${path}/${filename}`).isDirectory()) {
cleanDirectory(`${path}/${filename}`);
}
else {
fs.unlinkSync(`${path}/${filename}`);
}
});
fs.rmdirSync(path);
}
else {
fs.rmdirSync(path)
}
if (path === pathToDir) {
console.log("Successfully removed previous build and preparing new build...");
}
}
else {
console.log("No previous build to remove");
}
};
console.log("Removing previous build...");
cleanDirectory(pathToDir);