Textley / app · textley.ai / Scripts / build-app.sh
| 1 | #!/bin/bash |
| 2 | set -euo pipefail |
| 3 | umask 022 |
| 4 | |
| 5 | # Usage: Scripts/build-app.sh [OUTPUT_DIRECTORY] [debug|release] |
| 6 | # Set TEXTLEY_RELEASE=1 and TEXTLEY_SIGN_IDENTITY to build the Developer ID app with Sparkle. |
| 7 | root="$(cd "$(dirname "$0")/.." && pwd)" |
| 8 | output="${1:-$root/build}" |
| 9 | configuration="${2:-release}" |
| 10 | app="$output/Textley.app" |
| 11 | scratch="${TEXTLEY_BUILD_SCRATCH_PATH:-$output/.build}" |
| 12 | keychain="${TEXTLEY_SIGN_KEYCHAIN:-$HOME/Library/Keychains/login.keychain-db}" |
| 13 | |
| 14 | mkdir -p "$output/tmp" "$output/module-cache" |
| 15 | export TMPDIR="$output/tmp/" |
| 16 | export CLANG_MODULE_CACHE_PATH="$output/module-cache" |
| 17 | export SWIFTPM_MODULECACHE_OVERRIDE="$output/module-cache" |
| 18 | args=(--package-path "$root" --scratch-path "$scratch" -c "$configuration") |
| 19 | |
| 20 | identity="${TEXTLEY_SIGN_IDENTITY:--}" |
| 21 | signing_flags=() |
| 22 | sparkle='' |
| 23 | if [[ "${TEXTLEY_RELEASE:-0}" == 1 ]]; then |
| 24 | [[ "$identity" == "Developer ID Application: "* ]] || { echo 'Set TEXTLEY_SIGN_IDENTITY to a Developer ID Application identity.' >&2; exit 1; } |
| 25 | [[ "$configuration" == release ]] || { echo 'Distribution builds use the release configuration.' >&2; exit 1; } |
| 26 | /usr/bin/security find-identity -v -p codesigning "$keychain" | /usr/bin/grep -Fq "\"$identity\"" || { |
| 27 | echo 'The Developer ID Application identity is missing from the selected keychain.' >&2; exit 1; } |
| 28 | /usr/bin/grep -q TEXTLEY_SPARKLE_PUBLIC_KEY "$root/Scripts/Sparkle.plist" && { |
| 29 | echo 'Add the textley-direct Sparkle public key to Scripts/Sparkle.plist.' >&2; exit 1; } |
| 30 | signing_flags=(--timestamp --options runtime --keychain "$keychain") |
| 31 | sparkle="$(bash "$root/Scripts/prepare-sparkle.sh" "$output/sparkle")" |
| 32 | args+=(-Xswiftc -DTEXTLEY_SPARKLE -Xswiftc -F -Xswiftc "$sparkle" |
| 33 | -Xlinker -F -Xlinker "$sparkle" -Xlinker -rpath -Xlinker @executable_path/../Frameworks) |
| 34 | fi |
| 35 | |
| 36 | rm -rf "$app" |
| 37 | mkdir -p "$app/Contents/MacOS" "$app/Contents/Resources/TextleyClaudeMCP" |
| 38 | xcrun swift build "${args[@]}" |
| 39 | bin="$(xcrun swift build "${args[@]}" --show-bin-path)" |
| 40 | install -m 755 "$bin/Textley" "$app/Contents/MacOS/Textley" |
| 41 | install -m 644 "$root/Scripts/Info.plist" "$app/Contents/Info.plist" |
| 42 | install -m 644 "$root/Resources/TextleyClaudeMCP/manifest.json" "$root/Resources/TextleyClaudeMCP/server.js" \ |
| 43 | "$app/Contents/Resources/TextleyClaudeMCP" |
| 44 | iconset="$output/tmp/AppIcon.iconset" |
| 45 | mkdir -p "$iconset" |
| 46 | for size in 16 32 128 256 512; do |
| 47 | /usr/bin/sips -z "$size" "$size" "$root/Resources/AppIcon.png" --out "$iconset/icon_${size}x${size}.png" >/dev/null |
| 48 | twice=$((size * 2)) |
| 49 | /usr/bin/sips -z "$twice" "$twice" "$root/Resources/AppIcon.png" --out "$iconset/icon_${size}x${size}@2x.png" >/dev/null |
| 50 | done |
| 51 | /usr/bin/iconutil -c icns "$iconset" -o "$app/Contents/Resources/AppIcon.icns" |
| 52 | install -m 644 "$root/Resources/AgentSkill.md" "$root/Resources/AgentSkill-LICENSE.txt" "$app/Contents/Resources/" |
| 53 | |
| 54 | if [[ -n "$sparkle" ]]; then |
| 55 | /usr/libexec/PlistBuddy -c "Merge '$root/Scripts/Sparkle.plist'" "$app/Contents/Info.plist" |
| 56 | install -m 644 "$sparkle/LICENSE" "$app/Contents/Resources/Sparkle-LICENSE.txt" |
| 57 | install -m 644 "$root/Packaging/macOS/background.tiff" "$app/Contents/Resources/TextleyInstallerBackground.tiff" |
| 58 | framework="$app/Contents/Frameworks/Sparkle.framework" |
| 59 | ditto "$sparkle/Sparkle.framework" "$framework" |
| 60 | for component in "$framework/Versions/Current/XPCServices/"*.xpc \ |
| 61 | "$framework/Versions/Current/Autoupdate" "$framework/Versions/Current/Updater.app" "$framework"; do |
| 62 | /usr/bin/codesign --force --sign "$identity" "${signing_flags[@]}" "$component" |
| 63 | done |
| 64 | fi |
| 65 | find "$app" -type d -exec chmod 755 {} + |
| 66 | /usr/bin/codesign --force --sign "$identity" ${signing_flags[@]+"${signing_flags[@]}"} "$app" |
| 67 | /usr/bin/codesign --verify --deep --strict "$app" |
| 68 | printf '%s\n' "$app" |