#!/usr/bin/env bash # # Build once, then put the result in both places, every time: # # /Applications/Work.app the copy being tested here # # Pass --dmg to also drop a drag-to-Applications installer on the Desktop, from # the same build — so the thing a tester runs is byte for byte the thing that # was just tested here, rather than a second build that drifted. set -euo pipefail WANT_DMG=0 [ "${1:-}" = "--dmg" ] && WANT_DMG=1 cd "$(dirname "$0")/.." APP="Work.app" BUILT="src-tauri/target/release/bundle/macos/$APP" DEST="/Applications/$APP" VERSION="$(node -p "require('./package.json').version")" DMG="$HOME/Desktop/Work-$VERSION.dmg" echo "==> building $VERSION" if [ "$WANT_DMG" = "1" ]; then npm run tauri build -- --bundles app,dmg else npm run tauri build -- --bundles app fi echo "==> quitting the running copy" osascript -e 'quit app "Work"' >/dev/null 2>&1 || true # A hung window would otherwise keep the bundle busy while it is replaced. pkill -f "Work.app/Contents/MacOS" >/dev/null 2>&1 || true for _ in 1 2 3 4 5 6 7 8 9 10; do pgrep -f "Work.app/Contents/MacOS" >/dev/null || break sleep 0.3 done echo "==> installing to $DEST" rm -rf "$DEST" cp -R "$BUILT" "$DEST" # The disk image, only when asked for — drag-to-Applications, which is what # someone expects to be handed rather than a bare bundle to file themselves. if [ "$WANT_DMG" = "1" ]; then echo "==> copying the installer to $DMG" BUILT_DMG="$(find src-tauri/target/release/bundle/dmg -name '*.dmg' -maxdepth 1 | head -1)" if [ -z "$BUILT_DMG" ]; then echo "no .dmg was produced — check the bundler output above" >&2 exit 1 fi rm -f "$DMG" cp "$BUILT_DMG" "$DMG" fi echo "==> launching" open "$DEST" if [ "$WANT_DMG" = "1" ]; then echo "==> done — $DEST and $DMG" else echo "==> done — $DEST" fi