-
Notifications
You must be signed in to change notification settings - Fork 356
/
cleanup.js
46 lines (38 loc) · 1.54 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
const fs = require('fs');
const path = require('path');
const glob = require('glob');
// Define the target directories
const targetDirs = ["student-cvs"];
targetDirs.forEach(targetDir => {
if (fs.existsSync(targetDir)) {
const dirs = glob.sync(`${targetDir}/**/*.*`, { nodir: false });
// Rename folder names, replacing '.' with '(dot)'
dirs.forEach(dir => {
if (fs.lstatSync(dir).isDirectory()) {
const parentDir = path.dirname(dir);
const baseName = path.basename(dir);
const newName = baseName.replace('.', '(dot)');
const newPath = path.join(parentDir, newName);
if (dir !== newPath) {
fs.renameSync(dir, newPath);
}
}
});
// Delete files that match the .gitignore file
const gitignorePath = path.join(targetDir, '.gitignore');
if (fs.existsSync(gitignorePath)) {
const gitignore = fs.readFileSync(gitignorePath, 'utf-8');
const patterns = gitignore.split('\n').filter(pattern => pattern.trim() !== '');
patterns.forEach(pattern => {
const files = glob.sync(path.join(targetDir, pattern));
files.forEach(file => {
if (fs.existsSync(file)) {
fs.unlinkSync(file);
}
});
});
}
} else {
console.log(`The target directory "${targetDir}" does not exist. Please check the path.`);
}
});