#!/usr/bin/env bash # Usage: scripts/bundle.sh [--install] [--force] # --install copy "build/Helder.app" to ~/Applications # --force let --install replace an app that has a different bundle id set -euo pipefail source "$(dirname "$0")/env.sh" install=false force=false for arg in "$@"; do case "$arg" in --install) install=true ;; --force) force=true ;; *) echo "unknown option: $arg" >&2; exit 2 ;; esac done BUNDLE_ID=nl.blijnder.helder VERSION=0.2.0 APP="build/Helder.app" swift build -c release --product Helder BIN="$(swift build -c release --show-bin-path)" rm -rf "$APP" mkdir -p "$APP/Contents/MacOS" "$APP/Contents/Resources" "$APP/Contents/Helpers" cp "$BIN/Helder" "$APP/Contents/MacOS/Helder" # SwiftPM resource bundles go in Contents/Resources: the .app root would break # the code signature. FontRegistry and SwiftTerm both look there. for bundle in "$BIN"/*.bundle; do cp -R "$bundle" "$APP/Contents/Resources/" done # ripgrep powers search and the file list. ExecutableLocator checks Contents/Helpers first. RG="${RG_BINARY:-}" [[ -z "$RG" && -x vendor/ripgrep/rg ]] && RG=vendor/ripgrep/rg [[ -z "$RG" ]] && RG="$(command -v rg || true)" if [[ -n "$RG" && -x "$RG" ]]; then cp "$RG" "$APP/Contents/Helpers/rg" else echo "warning: no ripgrep found (set RG_BINARY); search falls back to a slow walk" >&2 fi ICONSET="$(mktemp -d)/Helder.iconset" mkdir -p "$ICONSET" for size in 16 32 128 256 512; do sips -z $size $size assets/icon.png --out "$ICONSET/icon_${size}x${size}.png" >/dev/null sips -z $((size * 2)) $((size * 2)) assets/icon.png --out "$ICONSET/icon_${size}x${size}@2x.png" >/dev/null done iconutil -c icns "$ICONSET" -o "$APP/Contents/Resources/Helder.icns" rm -rf "$(dirname "$ICONSET")" cat > "$APP/Contents/Info.plist" < CFBundleExecutableHelder CFBundleIdentifier$BUNDLE_ID CFBundleNameHelder CFBundleDisplayNameHelder CFBundlePackageTypeAPPL CFBundleShortVersionString$VERSION CFBundleVersion$VERSION CFBundleIconFileHelder CFBundleInfoDictionaryVersion6.0 LSMinimumSystemVersion14.0 LSApplicationCategoryTypepublic.app-category.developer-tools NSHighResolutionCapable NSPrincipalClassNSApplication PLIST codesign --force --deep -s - "$APP" codesign --verify --deep --strict "$APP" echo "built $APP" if $install; then target="$HOME/Applications/Helder.app" if [[ -d "$target" ]]; then existing="$(/usr/libexec/PlistBuddy -c 'Print :CFBundleIdentifier' "$target/Contents/Info.plist" 2>/dev/null || true)" if [[ "$existing" != "$BUNDLE_ID" && "$force" != true ]]; then echo "refusing to replace $target (bundle id '$existing'); pass --force to overwrite it" >&2 exit 1 fi rm -rf "$target" fi mkdir -p "$HOME/Applications" cp -R "$APP" "$target" echo "installed $target" fi