11#! /usr/bin/env bash
2- #
3- # run_all.sh
4- #
5- # Runs both the frontend (Angular dev mode) and backend (Firebase).
6- # Update commands/path if your project or run commands differ.
2+
3+ set -e # Exit on error
4+
5+ # Process IDs for cleanup
6+ FRONTEND_PID=" "
7+ BACKEND_PID=" "
8+
9+ # Cleanup function to kill both frontend and backend
10+ cleanup () {
11+ echo " Cleaning up..."
12+ if [ -n " $FRONTEND_PID " ] && ps -p $FRONTEND_PID > /dev/null; then
13+ echo " Killing frontend (PID $FRONTEND_PID )..."
14+ kill $FRONTEND_PID
15+ fi
16+ if [ -n " $BACKEND_PID " ] && ps -p $BACKEND_PID > /dev/null; then
17+ echo " Killing backend (PID $BACKEND_PID )..."
18+ kill $BACKEND_PID
19+ fi
20+ wait
21+ echo " Shutdown complete."
22+ }
23+
24+ # Trap errors and signals to run cleanup
25+ trap cleanup EXIT SIGINT SIGTERM ERR
26+
27+ # Create dummy environment.ts if missing
28+ ENV_FILE=" /Users/riffled/Desktop/Olaf/frontend/src/environments/environment.ts"
29+ if [ ! -f " $ENV_FILE " ]; then
30+ echo " environment.ts not found. Creating dummy version..."
31+ mkdir -p " $( dirname " $ENV_FILE " ) "
32+ cat << EOT > "$ENV_FILE "
33+ export const environment = {
34+ dummy: true,
35+ };
36+ EOT
37+ fi
38+
39+ # Start backend
740echo " === Starting Olaf Backend (Firebase) ==="
841cd backend || exit
942chmod +x run_firebase.sh
10- ./run_firebase.sh &
43+ ./run_firebase.sh
44+ BACKEND_PID=$!
45+ echo " Backend started (PID $BACKEND_PID )"
1146
47+ # Start frontend
1248echo " === Starting Olaf Frontend in Development Mode ==="
1349cd ../frontend || exit
1450npm install
15- npm run dev & # run in the background
51+ npm run dev &
52+ FRONTEND_PID=$!
53+ echo " Frontend started (PID $FRONTEND_PID )"
1654
17- echo " Frontend started in background."
18- echo
19- # Once Firebase stops or is killed, the script ends.
20- # If you want to also kill the frontend automatically upon exit,
21- # you can track its PID and kill it here.
55+ # Wait for backend to finish (or be killed)
56+ wait $BACKEND_PID
0 commit comments