-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdev.sh
More file actions
executable file
·105 lines (86 loc) · 2.66 KB
/
dev.sh
File metadata and controls
executable file
·105 lines (86 loc) · 2.66 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
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
#!/bin/bash
set -o pipefail
self_path=$(dirname "$0")
self=$(basename "$0")
cd "$self_path"
function elog { printf '%s\n' "$self: $*" >&2; }
function log { printf '%s\n' "$self: $*"; }
function trap_exit {
if [[ -n "$killed" ]]; then exit; fi
sleep 1.5
echo
elog killing processes
if [[ -n "$postgrest_pid" ]]; then kill "$postgrest_pid"; fi
if [[ -n "$backend_pid" ]]; then kill "$backend_pid"; fi
if [[ -n "$frontend_pid" ]]; then kill "$frontend_pid"; fi
killed=1
# to pile onto the broken mindset of javascript developers, create-react-app
# has also decided that, yes, this fucking ~~enhanced log viewer~~ needs to
# set application keypad too; which of course mucks up the terminal when it
# is killed, so fixed this garbage too. ffs.
printf '\x1b>'
exit
}
trap "trap_exit" INT KILL QUIT EXIT ERR
function try_enter_venv {
for path in backend/.venv backend/.env backend/venv backend/env; do
if [[ -d "$path" ]]; then
if [[ -f "$path/bin/activate" ]]; then
elog entering virtual environment $path
source "$path/bin/activate"
return
elif [[ -f "$path/Scripts/activate" ]]; then
elog entering virtual environment $path
source "$path/bin/activate"
return
fi
fi
done
elog not in a virtual environment and could not find one, exiting
killed=1
exit
}
if [[ -z "$VIRTUAL_ENV" ]]; then
try_enter_venv
fi
log checking for migrations
log \$ backend-migrate
backend-migrate 2>&1 | sed 's/^\(.*\)$/\x1b\[95m\1\x1b\[39m/'
if [[ -z "$NO_NPM" ]]; then
log updating npm
cd frontend
log \$ npm install --include=dev
npm install --include=dev 2>&1 | sed 's/^\(.*\)$/\x1b\[91m\1\x1b\[39m/'
cd ..
fi
echo
if [[ -e "backend/postgrest.conf" ]]; then
postgrest_cfg="backend/postgrest.conf"
else
postgrest_cfg="backend/postgrest.default.conf"
fi
log starting postgrest
log \$ postgrest $postgrest_cfg
postgrest "$postgrest_cfg" 2>&1 | sed 's/^\(.*\)$/\x1b\[92m\1\x1b\[39m/'&
postgrest_pid=$!
echo
log starting backend
log \$ backend
backend 2>&1 | sed 's/^\(.*\)$/\x1b\[95m\1\x1b\[39m/' &
backend_pid=$!
echo
log starting frontend dev
# create-react-app's npm scripts fucking clears the terminal with no intended
# toggle to disable, so fucking disable the CSI clear sequence for that process.
# in addition, for whatever fucking reason someone had the bright idea to launch
# the system browser, so shut that the fuck down (at least they put in a toggle)
cd frontend/
log \$ npm run start
PORT=8080 BROWSER=none npm run start 2>&1 \
| sed -e 's/\x1b\[:digit:J//' -e 's/^\(.*\)$/\x1b\[91m\1\x1b\[39m/' &
frontend_pid=$!
cd ..
echo
wait "$postgrest_pid"
wait "$backend_pid"
wait "$frontend_pid"