-
Notifications
You must be signed in to change notification settings - Fork 47
Expand file tree
/
Copy pathdev.sh
More file actions
executable file
·74 lines (60 loc) · 1.87 KB
/
dev.sh
File metadata and controls
executable file
·74 lines (60 loc) · 1.87 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
#!/bin/bash
# DataBridge dev script — watch & auto-rebuild + relaunch as .app bundle
# Usage: ./dev.sh
set -e
APP_NAME="DataBridge"
BUILD_DIR=".build/debug"
APP_BUNDLE="$BUILD_DIR/$APP_NAME.app"
build_app_bundle() {
# Wrap the executable into a proper .app bundle with icon
local contents="$APP_BUNDLE/Contents"
local macos="$contents/MacOS"
local resources="$contents/Resources"
rm -rf "$APP_BUNDLE"
mkdir -p "$macos" "$resources"
# Copy executable
cp "$BUILD_DIR/$APP_NAME" "$macos/$APP_NAME"
# Copy Info.plist
cp "DataBridge/Resources/Info.plist" "$contents/Info.plist"
# Copy icon
cp "DataBridge/Resources/AppIcon.icns" "$resources/AppIcon.icns"
# Copy SPM-generated resources bundle (Assets.xcassets, entitlements)
if [ -d "$BUILD_DIR/${APP_NAME}_${APP_NAME}.bundle" ]; then
cp -R "$BUILD_DIR/${APP_NAME}_${APP_NAME}.bundle" "$resources/"
fi
# Refresh the Finder icon cache for this bundle
touch "$APP_BUNDLE"
}
cleanup() {
killall "$APP_NAME" 2>/dev/null || true
exit 0
}
trap cleanup SIGINT SIGTERM
build_and_run() {
echo "🔨 Building..."
killall "$APP_NAME" 2>/dev/null || true
if swift build 2>&1; then
echo "📦 Creating .app bundle..."
build_app_bundle
echo "✅ Build succeeded — launching app..."
open "$APP_BUNDLE"
else
echo "❌ Build failed"
fi
echo ""
echo "👀 Watching for changes... (Ctrl+C to stop)"
}
# Initial build
build_and_run
# Watch for .swift file changes using a simple polling loop
# Install fswatch for better performance: brew install fswatch
LAST_HASH=""
while true; do
sleep 2
CURRENT_HASH=$(find DataBridge -name "*.swift" -newer "$BUILD_DIR/$APP_NAME" 2>/dev/null | head -1)
if [ -n "$CURRENT_HASH" ]; then
echo ""
echo "📝 Change detected..."
build_and_run
fi
done