-
Notifications
You must be signed in to change notification settings - Fork 1
/
devsetup.sh
executable file
·175 lines (140 loc) · 3.84 KB
/
devsetup.sh
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#!/bin/bash
set -ex
MAIN=fragdenstaat_at
# REPOS=("froide" "froide-campaign" "froide-legalaction" "froide-food" "froide-payment" "froide-crowdfunding" "froide-govplan" "froide-fax" "froide-exam" "django-filingcabinet")
REPOS=("froide" "froide-payment" "django-filingcabinet" )
# FRONTEND_DIR=("froide" "froide_food" "froide_exam" "froide_campaign" "froide_payment" "froide_legalaction" "filingcabinet")
FRONTEND_DIR=("froide" "froide_payment" "filingcabinet")
# FRONTEND=("froide" "froide_food" "froide_exam" "froide_campaign" "froide_payment" "froide_legalaction" "@okfde/filingcabinet")
FRONTEND=("froide" "froide_payment" "@okfde/filingcabinet")
FRONTEND_DEPS=("froide" "@okfde/filingcabinet")
ask() {
# https://djm.me/ask
local prompt default reply
if [ "${2:-}" = "Y" ]; then
prompt="Y/n"
default=Y
elif [ "${2:-}" = "N" ]; then
prompt="y/N"
default=N
else
prompt="y/n"
default=
fi
while true; do
# Ask the question (not using "read -p" as it uses stderr not stdout)
echo -n "$1 [$prompt] "
# Read the answer (use /dev/tty in case stdin is redirected from somewhere else)
read reply </dev/tty
# Default?
if [ -z "$reply" ]; then
reply=$default
fi
# Check if the reply is valid
case "$reply" in
Y*|y*) return 0 ;;
N*|n*) return 1 ;;
esac
done
}
install_precommit() {
local repo_dir="$1"
if [ -e "$repo_dir/.pre-commit-config.yaml" ]; then
pushd "$repo_dir"
pre-commit install
popd
fi
}
setup() {
echo "You need python3 >= 3.8 and yarn installed."
python3 --version
yarn --version
if [ ! -d fds-env ]; then
if ask "Do you want to create a virtual environment using $(python3 --version)?" Y; then
echo "Creating virtual environment with Python: $(python3 --version)"
python3 -m venv fds-env
fi
fi
if [ ! -d fds-env ]; then
echo "Could not find virtual environment fds-env"
fi
echo "Activating virtual environment..."
source fds-env/bin/activate
echo "Cloning / installing $MAIN"
if [ ! -d $MAIN ]; then
git clone git@github.com:fin/$MAIN.git
else
pushd $MAIN
git pull origin "$(git branch --show-current)"
popd
fi
pip install -U pip-tools
pip-sync $MAIN/requirements-dev.txt
pip install -e $MAIN
install_precommit "$MAIN"
echo "Cloning / installing all editable dependencies..."
for name in "${REPOS[@]}"; do
if [ ! -d $name ]; then
git clone git@github.com:fin/$name.git
else
pushd $name
git pull origin "$(git branch --show-current)"
popd
fi
pip uninstall -y $name
pip install -e $name
install_precommit "$name"
done
echo "Installing all frontend dependencies..."
frontend
fds-env/bin/python fragdenstaat_at/manage.py compilemessages -l de
echo "Done."
}
frontend() {
echo "Linking frontend dependencies..."
for name in "${FRONTEND_DIR[@]}"; do
pushd $(python -c "import $name as mod; print(mod.__path__[0])")/..
yarn link
popd
done
echo "Installing frontend dependencies..."
for name in "${FRONTEND_DIR[@]}"; do
pushd $(python -c "import $name as mod; print(mod.__path__[0])")/..
for dep in "${FRONTEND_DEPS[@]}"; do
if [ "$name" != "$dep" ]; then
yarn link $dep
fi
done
yarn install
popd
done
pushd $MAIN
for name in "${FRONTEND[@]}"; do
yarn link $name
done
yarn install
popd
}
forall() {
echo "Executing '$@' in all repos"
pushd $MAIN
"$@"
popd
for name in "${REPOS[@]}"; do
pushd $name
"$@"
popd
done
}
help() {
echo "Available commands:"
echo "setup: setup / update all repos"
echo "forall: run command in all repos"
}
if [[ $1 =~ ^(forall)$ ]]; then
"$@"
elif [[ $1 =~ ^(frontend)$ ]]; then
frontend
else
setup
fi