-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrmStaging.ts
More file actions
36 lines (31 loc) · 1.08 KB
/
Copy pathrmStaging.ts
File metadata and controls
36 lines (31 loc) · 1.08 KB
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
import fs from "fs";
import path from "path";
import config from "./config.json"
/**
* remove the staging folder that was defined in the `config.json` file
*/
export function rmStaging():void {
console.log('🔃 removing staging dir...');
try {
// Read all items inside the directory
const files = fs.readdirSync(config.stagingHtmlDir);
// Loop through and delete the contents, not the parent folder
for (const file of files) {
fs.rmSync(path.join(config.stagingHtmlDir, file), {
recursive: true,
force: true,
maxRetries: 10,
retryDelay: 100
});
}
console.log('✅ staging dir emptied!');
} catch (error: any) {
if (error.code === 'ENOENT') {
console.log('✅ staging dir does not exist yet, safe to proceed.');
} else {
console.error('❌ Failed to empty directory:', error.message);
}
}
}
// most likely running directly from console
if (process.env.NODE_ENV == undefined) rmStaging();