-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.js
executable file
·53 lines (44 loc) · 1.15 KB
/
index.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
47
48
49
50
51
52
53
#!/usr/bin/env node
const fs = require('fs')
const path = require('path')
const argv = require('minimist')(process.argv)
let allFiles = []
const showHelp = () => {
return console.log(`
THANOS NodeJS by Tiago Danin
Inspired by https://thanosjs.org
Reduce the file size of your project down to 50%,
by randomly deleting half of the files.
Use: thanos --universe [dir]
You can save a single file with --ironman [file]
`)
}
const getFiles = (dir) => {
fs.readdirSync(dir).map((f) => {
let fullPath = path.join(dir, f)
if (fs.statSync(fullPath).isDirectory()) {
getFiles(fullPath)
} else {
allFiles.push(fullPath)
}
})
}
const main = () => {
getFiles(path.resolve(process.cwd(), argv.universe))
if (argv.ironman) {
allFiles = allFiles.filter(f => f != path.resolve(argv.ironman))
}
const max = Math.round(allFiles.length / 2)
for (let i = 0; i < max; i++) {
let pathRandom = allFiles[Math.floor((Math.random() * allFiles.length))]
allFiles = allFiles.filter(f => f != pathRandom)
fs.unlinkSync(pathRandom)
}
return console.log(`
Thanos deleted half of the files! :)
`)
}
if (!argv.universe || argv.help) {
return showHelp()
}
return main()