This repository has been archived by the owner on Nov 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
reset-dev-env.bash
executable file
·114 lines (98 loc) · 2.16 KB
/
reset-dev-env.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/usr/bin/env bash
set -o errexit -o noclobber -o nounset -o pipefail
usage() {
cat >&2 <<'EOF'
./reset-dev-env.bash --all
./reset-dev-env.bash [--delete] [--hooks] [--node] [--python] [--submodule]
./reset-dev-env.bash --help
`--all` implies `--delete --hooks --node --python --submodule`.
EOF
}
arguments="$(getopt --options '' \
--longoptions all,delete,help,hooks,node,python,submodule --name "$0" -- "$@")"
eval set -- "$arguments"
unset arguments
while true; do
case "$1" in
--all)
delete=1
hooks=1
node=1
python=1
submodule=1
shift
;;
--delete)
delete=1
shift
;;
--help)
usage
exit
;;
--hooks)
hooks=1
shift
;;
--node)
node=1
shift
;;
--python)
python=1
shift
;;
--submodule)
submodule=1
shift
;;
--)
shift
break
;;
*)
printf 'Not implemented: %q\n' "$1" >&2
exit 1
;;
esac
done
if [[ -z ${hooks-} ]] &&
[[ -z ${node-} ]] &&
[[ -z ${python-} ]] &&
[[ -z ${submodule-} ]]; then
usage
exit 1
fi
cd "$(dirname "${BASH_SOURCE[0]}")"
if [[ -n ${delete-} ]]; then
echo "Cleaning Git repository"
git clean -d --exclude='.idea' --force -x
fi
if [[ -n ${submodule-} ]]; then
echo "Updating submodules"
git submodule update --init
fi
if [[ -n ${node-} ]]; then
if [[ -n ${delete-} ]]; then
echo "Removing Node.js packages"
rm --force --recursive ./node_modules
fi
echo "Installing Node.js packages"
npm ci
fi
if [[ -n ${python-} ]]; then
if [[ -n ${delete-} ]]; then
echo "Removing Python packages"
rm --force --recursive ./.venv
fi
echo "Installing Python packages"
poetry env use "$(cat .python-version)"
poetry install --all-extras --no-root --sync
fi
if [[ -n ${hooks-} ]]; then
echo "Installing Git hooks"
# shellcheck source=/dev/null
. .venv/bin/activate
pre-commit install --hook-type=commit-msg --overwrite
pre-commit install --hook-type=pre-commit --overwrite
fi