-
Notifications
You must be signed in to change notification settings - Fork 231
Expand file tree
/
Copy pathdev.sh
More file actions
executable file
·102 lines (87 loc) · 2.79 KB
/
dev.sh
File metadata and controls
executable file
·102 lines (87 loc) · 2.79 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/bin/bash
# Parse arguments
DEBUG=false
PORT_ARG=""
POSITIONAL_ARGS=()
while [[ $# -gt 0 ]]; do
case $1 in
--debug)
DEBUG=true
shift
;;
--port|-p)
if [[ -z "${2:-}" || "$2" == --* ]]; then
echo "Error: --port requires a numeric value."
exit 1
fi
PORT_ARG="$2"
shift 2
;;
*)
POSITIONAL_ARGS+=("$1")
shift
;;
esac
done
ENV=${POSITIONAL_ARGS[0]:-dev}
API_PORT=${PORT_ARG:-${POSITIONAL_ARGS[1]:-8088}}
if ! [[ "$API_PORT" =~ ^[0-9]+$ ]]; then
echo "Error: Invalid port '$API_PORT'. Use a numeric port (e.g. 8088)."
exit 1
fi
# 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" == native:* ]]; 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" == native:* ]] && [ -z "$LOCAL_IP" ]; then
LOCAL_IP="localhost"
echo "Warning: Could not detect local IP address, using localhost"
elif [[ "$ENV" == native:* ]]; 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" == native:* ]]; then
# Create a new tmux session
SESSION_NAME="native-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 "PORT=${API_PORT} 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}:${API_PORT} NEXT_PUBLIC_FIREBASE_ENV=${NEXT_ENV} yarn --cwd=native 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 PORT=${API_PORT} \
NEXT_PUBLIC_FIREBASE_ENV=${NEXT_ENV} \
yarn --cwd=backend/api $API_COMMAND" \
"cross-env NEXT_PUBLIC_API_URL=${LOCAL_IP}:${API_PORT} \
NEXT_PUBLIC_FIREBASE_ENV=${NEXT_ENV} \
yarn --cwd=web serve" \
"cross-env yarn --cwd=web ts-watch"
fi