-
Notifications
You must be signed in to change notification settings - Fork 161
/
dev.sh
executable file
·70 lines (58 loc) · 2.06 KB
/
dev.sh
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
#!/bin/bash
ENV=${1:-dev}
DEBUG=${2:-false}
# Set environment based on whether "prod" is in the ENV string
if [[ "$ENV" == *"prod"* ]]; then
FIREBASE_PROJECT=prod
NEXT_ENV=PROD
else
FIREBASE_PROJECT=dev
NEXT_ENV=DEV
fi
# Set working directory and other environment-specific variables
if [[ "$ENV" == mani:* ]]; then
# Try to get local IP address from WiFi interface first, then ethernet
LOCAL_IP=$(ipconfig getifaddr en0)
if [ -z "$LOCAL_IP" ]; then
LOCAL_IP=$(ipconfig getifaddr en1)
fi
else
LOCAL_IP="localhost"
fi
firebase use $FIREBASE_PROJECT
API_COMMAND="dev"
if [ "$DEBUG" = "true" ]; then
API_COMMAND="debug"
fi
# Fallback to localhost if no IP is found for mani environments
if [[ "$ENV" == mani:* ]] && [ -z "$LOCAL_IP" ]; then
LOCAL_IP="localhost"
echo "Warning: Could not detect local IP address, using localhost"
elif [[ "$ENV" == mani:* ]]; then
echo "Using local IP address: $LOCAL_IP"
fi
# You need to install tmux, on mac you can do this with `brew install tmux`
if [[ "$ENV" == mani:* ]]; then
# Create a new tmux session
SESSION_NAME="mani-dev"
# Kill existing session if it exists
tmux kill-session -t $SESSION_NAME 2>/dev/null
# Create new session with API server
tmux new-session -d -s $SESSION_NAME "NEXT_PUBLIC_FIREBASE_ENV=${NEXT_ENV} yarn --cwd=backend/api $API_COMMAND"
# Split window horizontally and start Expo
tmux split-window -h "NEXT_PUBLIC_API_URL=${LOCAL_IP}:8088 NEXT_PUBLIC_FIREBASE_ENV=${NEXT_ENV} yarn --cwd=mani start:${FIREBASE_PROJECT}"
# Select the Expo pane (for input)
tmux select-pane -t 1
# Attach to the session
tmux attach-session -t $SESSION_NAME
else
npx concurrently \
-n API,NEXT,TS \
-c white,magenta,cyan \
"cross-env NEXT_PUBLIC_FIREBASE_ENV=${NEXT_ENV} \
yarn --cwd=backend/api $API_COMMAND" \
"cross-env NEXT_PUBLIC_API_URL=${LOCAL_IP}:8088 \
NEXT_PUBLIC_FIREBASE_ENV=${NEXT_ENV} \
yarn --cwd=web serve" \
"cross-env yarn --cwd=web ts-watch"
fi