-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdev.sh
More file actions
executable file
·78 lines (67 loc) · 2.5 KB
/
dev.sh
File metadata and controls
executable file
·78 lines (67 loc) · 2.5 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
#!/bin/bash
# Auto-hot-reload dev script for TaskRoulette
# Usage: ./dev.sh [chrome|linux] (default: linux)
# Watches lib/ for .dart file changes and triggers hot reload automatically.
# Requires: inotify-tools (sudo apt install -y inotify-tools)
DEVICE="${1:-linux}"
PID_FILE="/tmp/flutter-taskroulette.pid"
cleanup() {
echo "Stopping..."
if [ -n "$WATCHER_PID" ]; then
kill "$WATCHER_PID" 2>/dev/null
fi
if [ -n "$FLUTTER_PID" ]; then
kill "$FLUTTER_PID" 2>/dev/null
fi
# Don't rm $PID_FILE here — Flutter's --pid-file flag deletes it on
# shutdown. Removing it ourselves races with Flutter and causes
# "Failed to delete pid file" errors.
exit 0
}
trap cleanup SIGINT SIGTERM
# Load Firebase config from google-services.json (same paths as release.yml)
DART_DEFINES=""
GOOGLE_SERVICES="android/app/google-services.json"
if [ -f "$GOOGLE_SERVICES" ] && command -v jq &>/dev/null; then
FIREBASE_PROJECT_ID=$(jq -r '.project_info.project_id' "$GOOGLE_SERVICES")
FIREBASE_API_KEY=$(jq -r '.client[0].api_key[0].current_key' "$GOOGLE_SERVICES")
DART_DEFINES="--dart-define=FIREBASE_PROJECT_ID=$FIREBASE_PROJECT_ID --dart-define=FIREBASE_API_KEY=$FIREBASE_API_KEY"
fi
# Load desktop OAuth secrets from .env (optional)
if [ -f ".env" ]; then
while IFS='=' read -r key value; do
[ -z "$key" ] || [[ "$key" == \#* ]] && continue
DART_DEFINES="$DART_DEFINES --dart-define=$key=$value"
done < .env
fi
# Ensure sqflite web worker files exist for Chrome
if [ "$DEVICE" = "chrome" ]; then
if [ ! -f "web/sqflite_sw.js" ] || [ ! -f "web/sqlite3.wasm" ]; then
echo "Setting up sqflite web worker files..."
dart run sqflite_common_ffi_web:setup
fi
fi
# Start Flutter in the background with a PID file
flutter run -d "$DEVICE" --pid-file "$PID_FILE" $DART_DEFINES &
FLUTTER_PID=$!
# Wait for the PID file to appear (Flutter takes a moment to start)
echo "Waiting for Flutter to start..."
while [ ! -f "$PID_FILE" ]; do
sleep 1
# Check if Flutter exited early
if ! kill -0 "$FLUTTER_PID" 2>/dev/null; then
echo "Flutter failed to start."
exit 1
fi
done
DART_PID=$(cat "$PID_FILE")
echo "Flutter running (PID: $DART_PID). Watching lib/ for changes..."
# Watch for .dart file changes and send SIGUSR1 (hot reload)
inotifywait -m -r -e close_write,moved_to,create --include '\.dart$' lib/ | while read -r; do
echo "[$(date +%H:%M:%S)] Change detected — hot reloading..."
kill -USR1 "$DART_PID" 2>/dev/null
done &
WATCHER_PID=$!
# Wait for Flutter to finish
wait "$FLUTTER_PID"
cleanup