-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.clean.bash
executable file
·63 lines (53 loc) · 1019 Bytes
/
.clean.bash
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
#!/usr/bin/env bash
# set options
# fail on any failed command and undefined variables
set -eu
# pipes fail if any command in that pipeline fails
set -o pipefail
# save global ARGS
ARGS="$@"
# display usage and help information for this script
display_help() {
cat <<EOF
Usage: clean [-hf]
Delete build files
-h display this help
-f full clean up including 'node_modules'
EOF
}
# check if current PWD is a project root
is_project_root() {
[ -f "package.json" -a -f ".gitignore" ]
}
# performs the cleanup
cleanup() {
if ! is_project_root; then
echo "ERROR: $PWD is not a project root"
exit 3
fi
for dir in $@; do
echo "deleting: $dir"
rm -rf "$dir"
done
}
# main loop
run() {
targets=(
"build"
)
while getopts :hf opt; do
case $opt in
h)
display_help
return 0 ;;
f)
targets+=("node_modules")
return 0 ;;
?)
echo "ERROR: Unknown option -$OPTARG"
return 1
esac
done
cleanup "${targets[@]}"
}
run "${ARGS[@]}"