Repository navigation
Expand file tree
/
Copy pathdev.sh
More file actions
executable file
·65 lines (58 loc) · 2.07 KB
/
Copy pathdev.sh
File metadata and controls
executable file
·65 lines (58 loc) · 2.07 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
#!/usr/bin/env bash
# Launch the Flask backend and the Angular frontend together for local development, with each
# server's log lines labeled/colored ([API] / [WEB]) so it's clear which process produced which
# line of output.
#
# Usage:
# ./dev.sh
#
# Stops both servers on Ctrl+C (or if either one exits/crashes).
set -euo pipefail
cd "$(dirname "${BASH_SOURCE[0]}")"
# Only use color codes when stdout is an interactive terminal (avoids raw escape codes leaking
# into log files/CI output when make dev's output is redirected).
if [[ -t 1 ]]; then
API_COLOR=$'\033[36m' # cyan
WEB_COLOR=$'\033[35m' # magenta
RESET_COLOR=$'\033[0m'
else
API_COLOR=""
WEB_COLOR=""
RESET_COLOR=""
fi
# Prefix every line of stdin with a colored "[label] " tag, line-buffered so output shows up
# immediately instead of only once the pipe buffer fills.
label_output() {
local label="$1" color="$2"
sed -u "s/^/${color}[${label}]${RESET_COLOR} /"
}
cleanup() {
echo
echo "Stopping dev servers..."
[[ -n "${API_PID:-}" ]] && kill "$API_PID" 2>/dev/null || true
[[ -n "${WEB_PID:-}" ]] && kill "$WEB_PID" 2>/dev/null || true
wait 2>/dev/null || true
}
trap cleanup EXIT INT TERM
echo "Starting Flask backend on http://localhost:5001 ..."
(
cd flask_app
poetry run python app.py 2>&1 | label_output "API" "$API_COLOR"
) &
API_PID=$!
echo "Starting Angular frontend on http://localhost:4201 ..."
(
cd angular-app
# Explicitly install/use a Node version compatible with the Angular CLI (22.x >=22.22.3, or 24.x >=24.15.0, or >=26.0.0,
# see README) if nvm is available, regardless of the shell's default/active Node
# version or whether a (gitignored, developer-local) .nvmrc happens to be present.
if [[ -s "${NVM_DIR:-$HOME/.nvm}/nvm.sh" ]]; then
# shellcheck disable=SC1091
source "${NVM_DIR:-$HOME/.nvm}/nvm.sh"
nvm install 22.22.3 --silent >/dev/null 2>&1 || true
nvm use 22.22.3 --silent >/dev/null 2>&1 || true
fi
npm start 2>&1 | label_output "WEB" "$WEB_COLOR"
) &
WEB_PID=$!
wait "$API_PID" "$WEB_PID"