-
Notifications
You must be signed in to change notification settings - Fork 2
/
thanos.js
executable file
·36 lines (28 loc) · 951 Bytes
/
thanos.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
const fs = require('fs');
const path = require('path');
const walkSync = require('walk-sync');
const Confirm = require('prompt-confirm');
const thanos = async (thePath, confirmation) => {
if (!confirmation) {
const prompt = new Confirm({
message: `Do you really wish to randomly delete 50% of the files on '${thePath}' and its subdirectories?`,
default: false,
});
const answer = await prompt.run();
if (!answer) {
return;
}
}
console.log(`Randomly deleting 50% of the files on ${thePath}...`);
const files = walkSync(thePath, {
directories: false,
ignore: ['node_modules', 'vendor', '.git', '.gitignore'],
});
const randomFiles = files.sort(() => 0.5 - Math.random());
const randomArray = randomFiles.slice(0, files.length / 2);
randomArray.forEach((file) => {
console.log(`Deleting ${file}...`);
fs.unlinkSync(path.join(thePath, file));
});
};
module.exports = thanos;