-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcleanup_cms_temp.js
More file actions
92 lines (73 loc) · 2.25 KB
/
cleanup_cms_temp.js
File metadata and controls
92 lines (73 loc) · 2.25 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/usr/bin/env node
/**
* Cleans up temporary folders created by Sveltia CMS.
*
* When using Sveltia CMS with multiple_folders i18n structure,
* the CMS sometimes creates folders with temporary hex IDs like:
* content/docs/en/24ef675958d5/
* content/docs/es/8c088a0d76ee/
*
* This script finds and removes these folders.
* Usage: node cleanup_cms_temp.js [--dry-run]
*/
const fs = require("fs");
const path = require("path");
const ROOT = __dirname;
const CONTENT_DIRS = [
"content/docs/en",
"content/docs/es",
"content/tutorials/en",
"content/tutorials/es",
];
// Regex to match CMS temporary folder names (12 hex characters)
const CMS_TEMP_FOLDER_REGEX = /^[0-9a-f]{12}$/i;
const isDryRun = process.argv.includes("--dry-run");
function findTempFolders(dir) {
const tempFolders = [];
if (!fs.existsSync(dir)) {
return tempFolders;
}
const entries = fs.readdirSync(dir, { withFileTypes: true });
for (const entry of entries) {
if (entry.isDirectory() && CMS_TEMP_FOLDER_REGEX.test(entry.name)) {
tempFolders.push(path.join(dir, entry.name));
}
}
return tempFolders;
}
function main() {
console.log("🧹 Looking for CMS temporary folders...\n");
if (isDryRun) {
console.log("(Dry run mode - no files will be deleted)\n");
}
let allTempFolders = [];
for (const contentDir of CONTENT_DIRS) {
const fullPath = path.join(ROOT, contentDir);
const tempFolders = findTempFolders(fullPath);
allTempFolders = allTempFolders.concat(tempFolders);
}
if (allTempFolders.length === 0) {
console.log("✅ No CMS temporary folders found!");
return;
}
console.log(`Found ${allTempFolders.length} temporary folder(s):\n`);
for (const folder of allTempFolders) {
const relativePath = path.relative(ROOT, folder);
if (isDryRun) {
console.log(` Would delete: ${relativePath}`);
} else {
fs.rmSync(folder, { recursive: true, force: true });
console.log(` ✓ Deleted: ${relativePath}`);
}
}
if (!isDryRun) {
console.log(
`\n✅ Cleaned up ${allTempFolders.length} temporary folder(s)!`,
);
console.log("\nRemember to commit these deletions:");
console.log(
" git add -A && git commit -m 'chore: remove CMS temp folders'",
);
}
}
main();