-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcleanup.js
55 lines (48 loc) · 1.37 KB
/
cleanup.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import fs from 'fs';
import { promisify } from 'util';
const unlinkAsync = promisify(fs.unlink);
const rmdirAsync = promisify(fs.rm);
const existsAsync = promisify(fs.exists);
const filesToRemove = [
'index.html',
'page2.html',
'page3.html',
'page4.html',
'page5.html',
'search.html',
'space_status.json'
];
const dirsToRemove = [
'dist',
'public'
];
export async function cleanup() {
let cleanupSuccessful = true;
await Promise.all(filesToRemove.map(async (file) => {
try {
if (await existsAsync(file)) {
await unlinkAsync(file);
console.log(`Cleaned up: ${file}`);
}
} catch (error) {
cleanupSuccessful = false;
console.error(`Failed to clean up ${file}`);
}
}));
await Promise.all(dirsToRemove.map(async (dir) => {
try {
if (await existsAsync(dir)) {
await rmdirAsync(dir, { recursive: true, force: true });
console.log(`Cleaned up directory: ${dir}`);
}
} catch (error) {
cleanupSuccessful = false;
console.error(`Failed to clean up directory: ${dir}`);
}
}));
if (cleanupSuccessful) {
console.log('Cleanup completed successfully');
} else {
console.log('Cleanup completed with some errors');
}
}