-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathclean.sh
More file actions
executable file
·67 lines (51 loc) · 1.18 KB
/
clean.sh
File metadata and controls
executable file
·67 lines (51 loc) · 1.18 KB
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
64
65
66
67
#!/bin/bash
set -eo pipefail
script_name="${0##*/}"
script_options="hiy"
function usage() {
end "Clean project by removing all build files and directories
Use: $script_name [-$script_options]
Options:
-h View this help
-i Perform NPM install after cleaning
-y Confirm yes to run
"
}
function end() {
local e=$? || :
set +e
trap - EXIT SIGHUP SIGINT SIGQUIT SIGTERM
local end_message="$1"
local end_code=${2:-$e}
[[ "$end_message" != "" ]] && echo "$end_message"
exit $end_code
}
trap end EXIT SIGHUP SIGINT SIGQUIT SIGTERM
function confirm_run() {
[[ ${yes:-0} -eq 1 ]] && return
read -p "${1:-Continue}? [y/N] " -n 1
[[ $REPLY == "" ]] && echo -en "\033[1A"
echo
[[ $REPLY =~ ^[Yy]$ ]] || end
}
npm_install=0
yes=0
while getopts "$script_options" OPTION; do
case "$OPTION" in
h) usage ;;
i) npm_install=1 ;;
y) yes=1 ;;
*) usage ;;
esac
done
shift $(($OPTIND - 1))
confirm_run "Clean project"
echo "Removing build files and directories..."
rm -rf ./.vscode-test
rm -rf ./node_modules
rm -rf ./dist
rm -f ./package-lock.json
if [[ $npm_install == 1 ]]; then
echo "Installing NPM packages..."
npm install
fi