name: OmniTrack
options:
  bundleIdPrefix: com.omnitransit
  deploymentTarget:
    iOS: "17.0"
  createIntermediateGroups: true
packages:
  MapLibre:
    url: https://github.com/maplibre/maplibre-gl-native-distribution
    from: 6.8.0
  SocketIO:
    url: https://github.com/socketio/socket.io-client-swift
    from: 16.1.0
settings:
  base:
    SWIFT_VERSION: "5.9"
    MARKETING_VERSION: "1.0.0"
    CURRENT_PROJECT_VERSION: "1"
    DEVELOPMENT_TEAM: ""
targets:
  OmniTrack:
    type: application
    platform: iOS
    sources:
      - path: OmniTrack
        excludes:
          - Resources/**
          - Assets.xcassets/**
          - PrivacyInfo.xcprivacy
      - path: OmniTrack/Resources
        type: folder
        buildPhase: resources
    configFiles:
      Release: Signing.Release.xcconfig
    settings:
      PRODUCT_BUNDLE_IDENTIFIER: com.omnitransit.pro
      INFOPLIST_FILE: OmniTrack/Info.plist
      CODE_SIGN_ENTITLEMENTS: OmniTrack/OmniTrack.entitlements
      ENABLE_PREVIEWS: YES
    postbuildScripts:
      - name: Sign embedded SPM bundles before app codesign
        basedOnDependencyAnalysis: false
        script: |
          set -euo pipefail
          APP="${CODESIGNING_FOLDER_PATH:-}"
          if [ -z "$APP" ] || [ ! -d "$APP" ]; then
            APP="${BUILT_PRODUCTS_DIR}/${WRAPPER_NAME}"
          fi
          if [ ! -d "$APP" ]; then exit 0; fi
          if [ -z "${EXPANDED_CODE_SIGN_IDENTITY:-}" ] || [ "${EXPANDED_CODE_SIGN_IDENTITY}" = "-" ]; then
            exit 0
          fi
          xattr -cr "$APP"
          find "$APP" -depth -type d -name '*.bundle' -print0 | while IFS= read -r -d '' item; do
            /usr/bin/codesign --force --sign "${EXPANDED_CODE_SIGN_IDENTITY}" \
              --preserve-metadata=identifier,entitlements,flags \
              --timestamp=none \
              "$item"
          done
        showEnvVars: false
    dependencies:
      - package: MapLibre
        product: MapLibre
      - package: SocketIO
        product: SocketIO
  OmniTrackTests:
    type: bundle.unit-test
    platform: iOS
    sources:
      - OmniTrackTests
    dependencies:
      - target: OmniTrack
    settings:
      PRODUCT_BUNDLE_IDENTIFIER: com.omnitransit.pro.tests
      GENERATE_INFOPLIST_FILE: YES
      CODE_SIGNING_ALLOWED: NO
schemes:
  OmniTrack:
    build:
      targets:
        OmniTrack: all
    run:
      config: Debug
    archive:
      config: Release
    test:
      targets:
        - OmniTrackTests
