Skip to content

Commit e001787

Browse files
committed
Add run_local_emulated.sh
1 parent cc4277a commit e001787

1 file changed

Lines changed: 62 additions & 0 deletions

File tree

scripts/run_local_emulated.sh

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#!/bin/bash
2+
3+
# What runs on each port?
4+
# - 4000: Firebase emulator
5+
# - 3000: Front end
6+
# - 8088: Back end
7+
8+
# How to view users? Each user is stored in two locations for two different purposes:
9+
# In the auth system (firebase emulator) to see the auth info (email, provider, etc.): http://127.0.0.1:4000/auth
10+
# In the database (dev supabase project, users and private_users table) to see the user info specific to compass (username, notif preferences, etc.): use DBeaver to connect to the dev supabase db
11+
12+
# Clean ghost processes
13+
kill_ghosts() {
14+
for p in 3000 4000 4400 4500 8088; do
15+
pids=$(lsof -ti :$p 2>/dev/null)
16+
if [ -n "$pids" ]; then
17+
kill $pids || true
18+
fi
19+
done
20+
}
21+
kill_ghosts
22+
23+
set -euo pipefail
24+
25+
# Function to clean up background processes
26+
cleanup() {
27+
echo "Stopping background processes..."
28+
for pid in "${PIDS[@]:-}"; do
29+
if kill -0 "$pid" 2>/dev/null; then
30+
kill "$pid" || true
31+
wait "$pid" 2>/dev/null || true
32+
echo "Killed PID $pid"
33+
fi
34+
done
35+
kill_ghosts
36+
}
37+
38+
# Trap EXIT, INT, TERM to run cleanup automatically
39+
trap cleanup EXIT INT TERM
40+
41+
cd "$(dirname "$0")"/..
42+
43+
export NEXT_PUBLIC_API_URL=localhost:8088
44+
export NEXT_PUBLIC_FIREBASE_ENV=DEV
45+
export NEXT_PUBLIC_FIREBASE_EMULATOR=true
46+
export FIREBASE_AUTH_EMULATOR_HOST=127.0.0.1:9099
47+
export FIREBASE_STORAGE_EMULATOR_HOST=127.0.0.1:9199
48+
49+
# Start servers in background and store their PIDs
50+
PIDS=()
51+
npx nyc --reporter=lcov yarn --cwd=web serve & PIDS+=($!)
52+
npx nyc --reporter=lcov yarn --cwd=backend/api dev & PIDS+=($!)
53+
yarn emulate & PIDS+=($!)
54+
55+
npx wait-on http://localhost:3000
56+
57+
# This creates a new user in firebase auth only (not in the db, hence it won't show in the list of profiles)
58+
npx tsx scripts/setup-auth.ts
59+
60+
read -p "Press enter to exit..." < /dev/tty
61+
62+
exit ${TEST_FAILED:-0}

0 commit comments

Comments
 (0)