-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathclear_dist.mjs
More file actions
34 lines (30 loc) · 952 Bytes
/
Copy pathclear_dist.mjs
File metadata and controls
34 lines (30 loc) · 952 Bytes
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
import fs from "node:fs";
import path from "node:path";
const dist_path = path.resolve("dist");
const white_list_folders = ["records", "vendor", "drivers"];
function createMainFolders() {
for (const folder of white_list_folders) {
const abs_path = path.resolve("dist", folder);
if (fs.existsSync(abs_path)) continue;
fs.mkdirSync(abs_path);
}
}
try {
console.log("Checking for dist directory...");
if (fs.existsSync(dist_path)) {
const files = fs.readdirSync(dist_path);
for (const file of files) {
const abs_path = path.resolve("dist", file);
if (white_list_folders.includes(file)) continue;
if (fs.lstatSync(abs_path).isDirectory())
fs.rmSync(abs_path, { recursive: true });
else fs.rmSync(abs_path);
}
createMainFolders();
} else {
fs.mkdirSync(dist_path);
createMainFolders();
}
} catch (err) {
console.log(`Error in clearing dist directory: ${err.message}`);
}