-
Notifications
You must be signed in to change notification settings - Fork 517
Expand file tree
/
Copy pathclear-docs.js
More file actions
58 lines (48 loc) · 1.58 KB
/
clear-docs.js
File metadata and controls
58 lines (48 loc) · 1.58 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/env node
import fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';
// Get __dirname equivalent in ES modules
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
/**
* Recursively remove all files and directories within a directory
* but keep the directory itself
*/
function clearDirectory(dirPath) {
if (!fs.existsSync(dirPath)) {
console.log(`Directory ${dirPath} does not exist.`);
return;
}
const items = fs.readdirSync(dirPath);
for (const item of items) {
const itemPath = path.join(dirPath, item);
const stat = fs.statSync(itemPath);
if (stat.isDirectory()) {
// Recursively remove directory and all its contents
fs.rmSync(itemPath, { recursive: true, force: true });
console.log(`Removed directory: ${itemPath}`);
} else {
// Remove file
fs.unlinkSync(itemPath);
console.log(`Removed file: ${itemPath}`);
}
}
}
function main() {
const docsPath = path.join(__dirname, '..', 'content', 'docs');
const apiDocsPath = path.join(__dirname, '..', 'content', 'api');
console.log('🧹 Clearing all files and directories in content/docs, and content/api');
console.log(`Target directory: ${docsPath}`);
console.log(`Target directory: ${apiDocsPath}`);
try {
clearDirectory(docsPath);
clearDirectory(apiDocsPath);
console.log('✅ Successfully cleared content/docs directory!');
} catch (error) {
console.error('❌ Error clearing content/docs directory:', error.message);
process.exit(1);
}
}
// Run the script
main();