-
Notifications
You must be signed in to change notification settings - Fork 3
/
clean.js
37 lines (32 loc) · 1.04 KB
/
clean.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
35
36
37
import fs from 'fs';
import { fileURLToPath } from "url";
function getCurrentFolder() {
const folder = fileURLToPath(new URL(".", import.meta.url));
// for windows OS, convert backslash to regular slash and drop drive letter from path
const path = folder.includes('\\')? folder.replaceAll('\\', '/') : folder;
const colon = path.indexOf(':');
return colon == 1? path.substring(colon+1) : path;
}
function getFolder(target) {
return getCurrentFolder() + target;
}
function removeDirectory(folder) {
if (fs.existsSync(folder)) {
fs.readdirSync(folder).forEach(f => {
const path = `${folder}/${f}`
const stats = fs.statSync(path);
if (stats.isDirectory()) {
removeDirectory(path);
} else {
fs.rmSync(path);
}
})
fs.rmdirSync(folder);
}
}
const coverage = getFolder('coverage');
const dist = getFolder('dist');
const tmp = getFolder('tmp');
removeDirectory(coverage);
removeDirectory(dist);
removeDirectory(tmp);