-
Notifications
You must be signed in to change notification settings - Fork 77
Optimize macOS build script and add auto-rebuild watch mode #1646
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
4df6ed4
Optimize build script and add auto-rebuild watch mode
ashleeradka f3459f7
Update README to focus on usage not implementation details
ashleeradka aff2971
Address PR review feedback
ashleeradka de50928
Fix daemon binary detection for first-time addition
ashleeradka e3c6ed7
Fix fswatch filter to exclude non-Swift files
ashleeradka d22ec54
Add delay after killing legacy vellum-assistant process
ashleeradka 8434ba5
Fix critical issues and improve documentation
ashleeradka bfd4db2
Document directory timestamp limitation for framework checks
ashleeradka c4bb656
Fix resource bundle updates when only resources change
ashleeradka 24d4872
Fix critical incremental build and watch mode issues
ashleeradka 79e8234
Fix critical watch mode UX and release build safety
ashleeradka 57a05df
Fix critical debouncing logic and Package.resolved watching
ashleeradka dc041b5
Fix debouncing by draining pipe after build completes
ashleeradka 097dc58
Add fswatch cleanup trap and daemon-bin watching
ashleeradka 5d34b7d
Fix critical bash 3.2 compatibility and codesigning issues
ashleeradka 0791968
Fix fswatch cleanup by using FIFO instead of process substitution
ashleeradka fab8976
Fix critical syntax error: missing while read loop opener
ashleeradka f456575
Fix daemon-bin filter: add include pattern before catch-all
ashleeradka File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| #!/bin/bash | ||
| set -euo pipefail | ||
|
|
||
| # Auto-rebuild and relaunch on file save | ||
| # Usage: ./watch.sh | ||
|
|
||
| SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | ||
| cd "$SCRIPT_DIR" | ||
|
|
||
| # Colors | ||
| GREEN='\033[0;32m' | ||
| BLUE='\033[0;34m' | ||
| YELLOW='\033[1;33m' | ||
| RED='\033[0;31m' | ||
| NC='\033[0m' # No Color | ||
|
|
||
| # Check if fswatch is installed | ||
| if ! command -v fswatch &> /dev/null; then | ||
| if ! command -v brew &> /dev/null; then | ||
| echo -e "${RED}Error: fswatch is required but not installed, and Homebrew is not available.${NC}" | ||
| echo -e "Install fswatch manually: ${BLUE}https://github.com/emcrisostomo/fswatch${NC}" | ||
| exit 1 | ||
| fi | ||
|
|
||
| echo -e "${YELLOW}fswatch is not installed. Install it via Homebrew? (y/N)${NC}" | ||
| read -r response | ||
| if [[ "$response" =~ ^[Yy]$ ]]; then | ||
| brew install fswatch | ||
| else | ||
| echo -e "${RED}fswatch is required for watch mode. Exiting.${NC}" | ||
| exit 1 | ||
| fi | ||
| fi | ||
|
|
||
| echo -e "${BLUE}👀 Watching for file changes (Swift, resources, dependencies)...${NC}" | ||
| echo -e "${YELLOW}Press Ctrl+C to stop${NC}" | ||
| echo "" | ||
|
|
||
| # Initial build and launch | ||
| echo -e "${BLUE}🔨 Initial build...${NC}" | ||
| ./build.sh run | ||
| echo "" | ||
|
|
||
| # Set up FIFO for fswatch communication (allows capturing PID for cleanup) | ||
| FIFO=$(mktemp -u) | ||
| mkfifo "$FIFO" | ||
| FSWATCH_PID="" | ||
|
|
||
| # Trap to clean up fswatch process and FIFO on exit | ||
| trap 'if [ -n "$FSWATCH_PID" ]; then kill $FSWATCH_PID 2>/dev/null; fi; rm -f "$FIFO"; exit' INT TERM | ||
|
|
||
| # Read from FIFO in a loop - this processes fswatch events | ||
| while read -r _; do | ||
| echo "" | ||
| echo -e "${YELLOW}📝 Change detected - rebuilding...${NC}" | ||
|
|
||
| # Run build synchronously | ||
| if ./build.sh run; then | ||
| echo -e "${GREEN}✅ Build successful${NC}" | ||
| else | ||
| echo -e "${RED}❌ Build failed${NC}" | ||
| fi | ||
|
|
||
| # Drain any events that accumulated during the build (debounce) | ||
| # This prevents N rapid saves from triggering N sequential rebuilds | ||
| # Note: Use integer timeout (bash 3.2 on macOS doesn't support fractional seconds) | ||
| # read -r -t 1 returns exit code 1 on timeout, but bash exempts | ||
| # commands in while conditions from set -e, so this is safe | ||
| DRAINED=0 | ||
| while read -r -t 1 _; do | ||
| DRAINED=$((DRAINED + 1)) | ||
| done | ||
| if [ "$DRAINED" -gt 0 ]; then | ||
| echo -e "${YELLOW}⏭️ Skipped $DRAINED buffered change(s) (coalesced)${NC}" | ||
| fi | ||
|
|
||
| echo -e "${BLUE}👀 Watching...${NC}" | ||
| done < "$FIFO" & | ||
|
ashleeradka marked this conversation as resolved.
|
||
|
|
||
| # Start fswatch in background, writing to FIFO, and capture its PID | ||
| fswatch -o \ | ||
| --exclude='\.build/' \ | ||
| --exclude='dist/' \ | ||
| --exclude='\.swiftpm/' \ | ||
| --exclude='\.git/' \ | ||
| --include='\.swift$' \ | ||
| --include='\.png$' \ | ||
| --include='\.jpg$' \ | ||
| --include='\.jpeg$' \ | ||
| --include='\.svg$' \ | ||
| --include='\.json$' \ | ||
| --include='\.ttf$' \ | ||
| --include='\.otf$' \ | ||
| --include='\.xcassets' \ | ||
| --include='Package\.resolved$' \ | ||
| --include='daemon-bin/' \ | ||
| --exclude='.*' \ | ||
|
devin-ai-integration[bot] marked this conversation as resolved.
|
||
| --event Created \ | ||
| --event Updated \ | ||
| --event Removed \ | ||
| --latency 0.5 \ | ||
| vellum-assistant \ | ||
| vellum-assistant-app \ | ||
| daemon-bin \ | ||
| Package.swift \ | ||
| Package.resolved > "$FIFO" & | ||
| FSWATCH_PID=$! | ||
|
|
||
| # Wait for the read loop to finish (it runs in background via &) | ||
| wait | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.