-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathemulators.sh
More file actions
executable file
·77 lines (65 loc) · 2.12 KB
/
Copy pathemulators.sh
File metadata and controls
executable file
·77 lines (65 loc) · 2.12 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
#!/bin/bash
# Load nvm
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
nvm use 20
# Function to gracefully stop Firebase emulators on exit
cleanup() {
echo "🛑 Stopping Firebase emulators..."
kill $EMULATOR_PID
wait $EMULATOR_PID 2>/dev/null
echo "✅ Emulators stopped gracefully."
exit 0
}
# Function to wait until a specific port is open
wait_for_port() {
local host=$1
local port=$2
echo "⏳ Waiting for $host:$port to be available..."
while ! nc -z $host $port; do
sleep 1 # Wait for 1 second before checking again
done
echo "✅ $host:$port is now available!"
}
# Trap CTRL+C (SIGINT) for a clean shutdown
trap cleanup SIGINT SIGTERM
# Navigate to the functions directory and build
cd ./functions
npm run build
cd ../
# Start Firebase emulators in the background
# Check for --import-backup flag to add import parameter
if [[ "$*" == *"--import-backup"* ]]; then
if [ -d "./firestore-data" ]; then
echo "📥 Starting emulators with import from ./firestore-data..."
firebase emulators:start --project=prfctprotein-com --import=./firestore-data &
else
echo "⚠️ No firestore-data folder found, starting emulators without import..."
firebase emulators:start --project=prfctprotein-com &
fi
else
firebase emulators:start --project=prfctprotein-com &
fi
EMULATOR_PID=$!
# Wait for Firestore Emulator (127.0.0.1:8086)
wait_for_port "127.0.0.1" 8086
# Only wait for Auth emulator if it's actually configured
# wait_for_port "127.0.0.1" 9099
# Give emulators a moment to fully initialize
sleep 2
# Seed Firestore database
if [[ "$*" == *"--import-backup"* ]]; then
echo "✅ Data imported from ./firestore-data during emulator startup"
echo "🌱 Seeding foods collection..."
node populate-firestore.js --seed-foods
else
echo "🏗️ Seeding Firestore Database with test data..."
node populate-firestore.js
echo "🌱 Seeding foods collection..."
node populate-firestore.js --seed-foods
fi
# Create Firebase Auth test user
# echo "🏗️ Creating Firebase Auth test user..."
# node populate-auth.js
# Keep script running until terminated
wait $EMULATOR_PID