Skip to content

Commit 53d4afd

Browse files
feat: add generic tmux-based dev environment commands
Add /start-local for web development: - Auto-detects project types (Next.js, Vite, Django, Flask, etc.) - Environment file mapping (staging → .env.staging) - Random port assignment to prevent conflicts - Multi-window tmux layout (servers, logs, work, git) - Session metadata tracking Add /start-ios for iOS development: - Supports React Native, Capacitor, Native iOS - Auto-detects project structure - Poltergeist integration for auto-rebuild - Simulator management and log streaming - Build configuration mapping (Debug → .env.development) Add /start-android for Android development: - Supports React Native, Capacitor, Flutter, Native Android - Emulator management with port forwarding - Poltergeist integration for auto-rebuild - Build variant mapping (staging → .env.staging) - Multi-window tmux layout with logcat All commands are generic and work across any project.
1 parent f28cfac commit 53d4afd

File tree

6 files changed

+1234
-0
lines changed

6 files changed

+1234
-0
lines changed
Lines changed: 221 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,221 @@
1+
# /start-android - Start Android Development Environment in tmux
2+
3+
Start Android development with Emulator, dev server, and optional Poltergeist auto-rebuild.
4+
5+
## Usage
6+
7+
```bash
8+
/start-android # debug build, .env.development
9+
/start-android staging # staging build, .env.staging
10+
/start-android release # release build, .env.production
11+
/start-android debug Pixel_7 # Specific emulator
12+
```
13+
14+
## Process
15+
16+
### Step 1: Determine Build Variant
17+
18+
```bash
19+
VARIANT=${1:-debug}
20+
DEVICE=${2:-"Pixel_7_Pro"}
21+
22+
case $VARIANT in
23+
debug)
24+
ENV_FILE=".env.development"
25+
BUILD_TYPE="Debug"
26+
;;
27+
staging)
28+
ENV_FILE=".env.staging"
29+
BUILD_TYPE="Staging"
30+
;;
31+
release|production)
32+
ENV_FILE=".env.production"
33+
BUILD_TYPE="Release"
34+
;;
35+
esac
36+
37+
[ ! -f "$ENV_FILE" ] && ENV_FILE=".env"
38+
```
39+
40+
### Step 2: Detect Project Type
41+
42+
```bash
43+
detect_android_project() {
44+
if [ -d "android" ] && [ -f "android/build.gradle" ]; then
45+
[ -f "package.json" ] && grep -q "react-native" package.json && echo "react-native" && return
46+
[ -f "capacitor.config.json" ] && echo "capacitor" && return
47+
[ -f "pubspec.yaml" ] && echo "flutter" && return
48+
echo "native"
49+
else
50+
echo "unknown"
51+
fi
52+
}
53+
54+
PROJECT_TYPE=$(detect_android_project)
55+
56+
[ ! -d "android" ] && echo "❌ android/ directory not found" && exit 1
57+
```
58+
59+
### Step 3: Install Dependencies
60+
61+
```bash
62+
# Gradle wrapper
63+
[ -f "android/gradlew" ] && chmod +x android/gradlew
64+
65+
# npm
66+
if [ -f "package.json" ] && [ ! -d "node_modules" ]; then
67+
npm install
68+
fi
69+
```
70+
71+
### Step 4: Setup Android Emulator
72+
73+
```bash
74+
! command -v adb &> /dev/null && echo "❌ adb not found. Is Android SDK installed?" && exit 1
75+
76+
! emulator -list-avds 2>/dev/null | grep -q "^${DEVICE}$" && echo "❌ Emulator '$DEVICE' not found" && emulator -list-avds && exit 1
77+
78+
RUNNING_EMULATOR=$(adb devices | grep "emulator" | cut -f1)
79+
80+
if [ -z "$RUNNING_EMULATOR" ]; then
81+
emulator -avd "$DEVICE" -no-snapshot-load -no-boot-anim &
82+
adb wait-for-device
83+
sleep 5
84+
while [ "$(adb shell getprop sys.boot_completed 2>/dev/null | tr -d '\r')" != "1" ]; do
85+
sleep 2
86+
done
87+
fi
88+
89+
EMULATOR_SERIAL=$(adb devices | grep "emulator" | cut -f1 | head -1)
90+
```
91+
92+
### Step 5: Setup Port Forwarding
93+
94+
```bash
95+
# For dev server access from emulator
96+
if [ "$PROJECT_TYPE" = "react-native" ] || grep -q "\"dev\":" package.json 2>/dev/null; then
97+
DEV_PORT=$(shuf -i 3000-9999 -n 1)
98+
adb -s "$EMULATOR_SERIAL" reverse tcp:$DEV_PORT tcp:$DEV_PORT
99+
fi
100+
```
101+
102+
### Step 6: Configure Poltergeist (Optional)
103+
104+
```bash
105+
POLTERGEIST_AVAILABLE=false
106+
107+
if command -v poltergeist &> /dev/null; then
108+
POLTERGEIST_AVAILABLE=true
109+
110+
[ ! -f ".poltergeist.yml" ] && cat > .poltergeist.yml <<EOF
111+
platform: android
112+
watchPaths:
113+
- android/app/src/**/*.kt
114+
- android/app/src/**/*.java
115+
- android/app/src/**/*.xml
116+
ignorePaths:
117+
- android/app/build/**
118+
- android/.gradle/**
119+
buildCommand: |
120+
cd android && ./gradlew assemble${BUILD_TYPE} && cd ..
121+
installCommand: |
122+
adb -s $EMULATOR_SERIAL install -r android/app/build/outputs/apk/${VARIANT}/app-${VARIANT}.apk
123+
EOF
124+
fi
125+
```
126+
127+
### Step 7: Create tmux Session
128+
129+
```bash
130+
PROJECT_NAME=$(basename "$(pwd)")
131+
TIMESTAMP=$(date +%s)
132+
SESSION="android-${PROJECT_NAME}-${TIMESTAMP}"
133+
134+
tmux new-session -d -s "$SESSION" -n build
135+
```
136+
137+
### Step 8: Build & Install
138+
139+
```bash
140+
case $PROJECT_TYPE in
141+
react-native)
142+
tmux send-keys -t "$SESSION:build" "npx react-native run-android --variant=$VARIANT --deviceId=$EMULATOR_SERIAL" C-m
143+
;;
144+
capacitor)
145+
tmux send-keys -t "$SESSION:build" "npx cap sync android && npx cap run android --target=$EMULATOR_SERIAL" C-m
146+
;;
147+
flutter)
148+
tmux send-keys -t "$SESSION:build" "flutter run -d $EMULATOR_SERIAL --flavor $VARIANT" C-m
149+
;;
150+
native)
151+
tmux send-keys -t "$SESSION:build" "cd android && ./gradlew install${BUILD_TYPE} && cd .." C-m
152+
;;
153+
esac
154+
```
155+
156+
### Step 9: Setup Additional Windows
157+
158+
```bash
159+
# Dev server (if needed)
160+
if [ "$PROJECT_TYPE" = "react-native" ] || grep -q "\"dev\":" package.json 2>/dev/null; then
161+
tmux new-window -t "$SESSION" -n dev-server
162+
tmux send-keys -t "$SESSION:dev-server" "PORT=$DEV_PORT npm start | tee dev-server.log" C-m
163+
fi
164+
165+
# Poltergeist (if available)
166+
if [ "$POLTERGEIST_AVAILABLE" = true ]; then
167+
tmux new-window -t "$SESSION" -n poltergeist
168+
tmux send-keys -t "$SESSION:poltergeist" "poltergeist watch --platform android | tee poltergeist.log" C-m
169+
fi
170+
171+
# Logs
172+
tmux new-window -t "$SESSION" -n logs
173+
tmux send-keys -t "$SESSION:logs" "adb -s $EMULATOR_SERIAL logcat -v color" C-m
174+
175+
# Git
176+
tmux new-window -t "$SESSION" -n git
177+
tmux send-keys -t "$SESSION:git" "git status" C-m
178+
```
179+
180+
### Step 10: Save Metadata
181+
182+
```bash
183+
cat > .tmux-android-session.json <<EOF
184+
{
185+
"session": "$SESSION",
186+
"project": "$PROJECT_NAME",
187+
"type": "$PROJECT_TYPE",
188+
"variant": "$VARIANT",
189+
"environment": "$ENV_FILE",
190+
"emulator": {
191+
"name": "$DEVICE",
192+
"serial": "$EMULATOR_SERIAL"
193+
},
194+
"poltergeist": $POLTERGEIST_AVAILABLE,
195+
"created": "$(date -Iseconds)"
196+
}
197+
EOF
198+
```
199+
200+
### Step 11: Display Summary
201+
202+
```bash
203+
echo ""
204+
echo "✨ Android Dev Environment Started: $SESSION"
205+
echo ""
206+
echo "Variant: $VARIANT ($ENV_FILE)"
207+
echo "Emulator: $DEVICE ($EMULATOR_SERIAL)"
208+
[ "$POLTERGEIST_AVAILABLE" = true ] && echo "Poltergeist: Auto-rebuild enabled"
209+
echo ""
210+
echo "Attach: tmux attach -t $SESSION"
211+
echo "Status: /tmux-status"
212+
echo ""
213+
```
214+
215+
## Notes
216+
217+
- Auto-detects: React Native, Capacitor, Flutter, Native Android
218+
- Maps build variant to environment file
219+
- Poltergeist enables auto-rebuild on file changes
220+
- Port forwarding for emulator to access localhost dev server
221+
- Session persists across disconnects

0 commit comments

Comments
 (0)