Modern-Apps.git
Publicgit clone https://git.maproj.org/Modern-Apps.gitModern-Apps.git / apple / FindFamily / scripts / assets.sh
assets.sh47 lines · 1.6 KiBRaw
| 1 | #!/usr/bin/env bash |
| 2 | # assets.sh compile (Mac only) rebuild Resources/Assets.car from FindFamilyiOS/Assets.xcassets |
| 3 | # assets.sh check (any OS) fail if Assets.car is stale relative to the .xcassets sources |
| 4 | set -euo pipefail |
| 5 | |
| 6 | cd "$(dirname "$0")/.." |
| 7 | SRC=FindFamilyiOS/Assets.xcassets |
| 8 | OUT=Resources |
| 9 | HASH_FILE="$OUT/Assets.xcassets.sha256" |
| 10 | |
| 11 | sources_hash() { |
| 12 | local sha |
| 13 | if command -v sha256sum >/dev/null; then sha="sha256sum"; else sha="shasum -a 256"; fi |
| 14 | find "$SRC" -type f ! -name '.DS_Store' -print0 | LC_ALL=C sort -z \ |
| 15 | | xargs -0 $sha | $sha | cut -d' ' -f1 |
| 16 | } |
| 17 | |
| 18 | case "${1:-}" in |
| 19 | compile) |
| 20 | mkdir -p "$OUT" |
| 21 | rm -f "$OUT/Assets.car" "$OUT/assets-partial-Info.plist" |
| 22 | xcrun actool "$SRC" \ |
| 23 | --compile "$OUT" \ |
| 24 | --platform iphoneos \ |
| 25 | --minimum-deployment-target 18.0 \ |
| 26 | --target-device iphone \ |
| 27 | --app-icon AppIcon \ |
| 28 | --accent-color AccentColor \ |
| 29 | --output-partial-info-plist "$OUT/assets-partial-Info.plist" \ |
| 30 | --output-format human-readable-text --notices --warnings --errors |
| 31 | sources_hash > "$HASH_FILE" |
| 32 | echo "assets: wrote $OUT/Assets.car ($(cat "$HASH_FILE"))" |
| 33 | ;; |
| 34 | check) |
| 35 | expected=$(cat "$HASH_FILE") |
| 36 | actual=$(sources_hash) |
| 37 | if [ "$expected" != "$actual" ]; then |
| 38 | echo "assets: $OUT/Assets.car is stale; run apple/FindFamily/scripts/assets.sh compile on a Mac" >&2 |
| 39 | exit 1 |
| 40 | fi |
| 41 | echo "assets: up to date" |
| 42 | ;; |
| 43 | *) |
| 44 | echo "usage: $0 compile|check" >&2 |
| 45 | exit 2 |
| 46 | ;; |
| 47 | esac |