-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclean.js
executable file
·46 lines (38 loc) · 1.05 KB
/
clean.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
let exec = require('child_process').exec,
paths = ['./build', './dist']
let emoji = require('node-emoji'),
coffee = emoji.get('coffee'),
x = emoji.get('x'),
check = emoji.get('white_check_mark')
let getArguments = () => {
return process.argv
}
let isDeepClean = () => {
let arguments = getArguments();
return arguments.indexOf('--deep') > -1
}
let outputToTerminal = (emoji, text) => {
console.log(emoji, text)
}
let cleanDirectory = () => {
for (let i = 0; i < paths.length; i++) {
let path = paths[i]
let command = `npx rimraf ${path}`
exec(command, (err, stdout, stderr) => {
if (err) {
outputToTerminal(x, `Error removing ${path}`)
} else {
outputToTerminal(check, `Successfully removed ${path}`)
}
})
}
}
let handleDeepClean = () => {
if (isDeepClean()) paths.push('./node_modules')
}
let initClean = () => {
handleDeepClean()
outputToTerminal(coffee, 'Cleaning directory...')
cleanDirectory()
}
initClean()