name: Notes
options:
  bundleIdPrefix: dev.rzen.indie
  deploymentTarget:
    iOS: "26.0"
    macOS: "26.0"
    watchOS: "26.0"
  xcodeVersion: "26.0"
  defaultConfig: Debug

settings:
  base:
    SWIFT_VERSION: "6.0"
    DEVELOPMENT_TEAM: ${APPLE_TEAM_ID}
    MARKETING_VERSION: "0.2"
    CURRENT_PROJECT_VERSION: "1"
    ENABLE_USER_SCRIPT_SANDBOXING: "NO"

packages:
  IndieSync:
    url: https://git.rzen.dev/rzen/indie-sync.git
    from: "0.1.0"
  IndieAbout:
    url: https://git.rzen.dev/rzen/indie-about.git
    from: "0.1.0"
  IndieBackup:
    url: https://git.rzen.dev/rzen/indie-backup.git
    from: "2.0.0"

# Shared post-build phase — stamps CFBundleVersion (git commit count), BuildDate, and
# BuildHash into each target's (and dSYM's) Info.plist. Aliased into every code-bearing
# target below so the iOS app, Mac app, watch app, and watch widget stamp identical
# metadata (versions must match across bundles for App Store validation).
scriptAnchors:
  updateBuildInfo: &updateBuildInfo
    - script: '"${SRCROOT}/Scripts/update_build_number.sh"'
      name: Update Build Info
      shell: /bin/sh
      basedOnDependencyAnalysis: false
      inputFiles:
        - $(TARGET_BUILD_DIR)/$(INFOPLIST_PATH)
        - $(DWARF_DSYM_FOLDER_PATH)/$(DWARF_DSYM_FILE_NAME)/Contents/Info.plist

schemes:
  Notes:
    build:
      targets:
        Notes: all
        NotesTests: [test]
    run:
      config: Debug
    test:
      config: Debug
      targets:
        - NotesTests
    archive:
      config: Release
  # Per-target scheme so the watch app can be built / run on its own destination.
  Notes Watch App:
    build:
      targets:
        Notes Watch App: all
    run:
      config: Debug
    archive:
      config: Release

targets:
  NotesTests:
    type: bundle.unit-test
    platform: iOS
    sources:
      - NotesTests
    dependencies:
      - target: Notes
      - package: IndieSync
    settings:
      base:
        PRODUCT_BUNDLE_IDENTIFIER: dev.rzen.indie.NotesTests
        GENERATE_INFOPLIST_FILE: true
        SWIFT_STRICT_CONCURRENCY: complete
        IPHONEOS_DEPLOYMENT_TARGET: "26.0"
        # The app's PRODUCT_NAME is Contextful; xcodegen derives TEST_HOST
        # from the target name, so it must be pinned explicitly.
        TEST_HOST: $(BUILT_PRODUCTS_DIR)/Contextful.app/Contextful
        BUNDLE_LOADER: $(TEST_HOST)

  # ---- iOS app (owns iCloud Drive sync; embeds the watch app) ----------------
  Notes:
    type: application
    platform: iOS
    sources:
      # Cross-platform code shared with the watch app (WatchConnectivity payload
      # codec). Deliberately NOT compiled into NotesMac.
      - path: Shared
      - path: Notes
        excludes:
          - "Resources/Info-*.plist"
          - "Resources/*.entitlements"
      - path: CHANGELOG.md
        buildPhase: resources
        type: file
      - path: README.md
        buildPhase: resources
        type: file
      - path: LICENSE.md
        buildPhase: resources
        type: file
    dependencies:
      - package: IndieSync
      - package: IndieAbout
      - package: IndieBackup
      # XcodeGen auto-embeds the watchOS app into the iOS app's Watch/ folder.
      - target: Notes Watch App
    settings:
      base:
        PRODUCT_BUNDLE_IDENTIFIER: dev.rzen.indie.Notes
        PRODUCT_NAME: Contextful
        PRODUCT_MODULE_NAME: Notes
        INFOPLIST_FILE: Notes/Resources/Info-iOS.plist
        CODE_SIGN_ENTITLEMENTS: Notes/Resources/Notes-iOS.entitlements
        GENERATE_INFOPLIST_FILE: false
        SWIFT_STRICT_CONCURRENCY: complete
        IPHONEOS_DEPLOYMENT_TARGET: "26.0"
        ASSETCATALOG_COMPILER_APPICON_NAME: AppIcon
        ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME: AccentColor
        TARGETED_DEVICE_FAMILY: "1,2"
    postBuildScripts: *updateBuildInfo

  NotesMac:
    type: application
    platform: macOS
    sources:
      - path: Notes
        excludes:
          - "Resources/Info-*.plist"
          - "Resources/*.entitlements"
      - path: CHANGELOG.md
        buildPhase: resources
        type: file
      - path: README.md
        buildPhase: resources
        type: file
      - path: LICENSE.md
        buildPhase: resources
        type: file
    dependencies:
      - package: IndieSync
      - package: IndieAbout
      - package: IndieBackup
    settings:
      base:
        PRODUCT_BUNDLE_IDENTIFIER: dev.rzen.indie.Notes
        PRODUCT_NAME: Contextful
        PRODUCT_MODULE_NAME: Notes
        INFOPLIST_FILE: Notes/Resources/Info-macOS.plist
        CODE_SIGN_ENTITLEMENTS: Notes/Resources/Notes-macOS.entitlements
        GENERATE_INFOPLIST_FILE: false
        SWIFT_STRICT_CONCURRENCY: complete
        MACOSX_DEPLOYMENT_TARGET: "26.0"
        ASSETCATALOG_COMPILER_APPICON_NAME: AppIcon
        ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME: AccentColor
    postBuildScripts: *updateBuildInfo

  # ---- watchOS app (no iCloud; recordings transfer to the phone via WC) -------
  Notes Watch App:
    type: application
    platform: watchOS
    sources:
      - path: Shared
      - path: Notes Watch App
        excludes:
          - "Resources/Info-*.plist"
    dependencies:
      - package: IndieSync
      - target: Notes Watch Widget
        embed: true
    postBuildScripts: *updateBuildInfo
    settings:
      base:
        PRODUCT_BUNDLE_IDENTIFIER: dev.rzen.indie.Notes.watchkitapp
        PRODUCT_NAME: Contextful
        PRODUCT_MODULE_NAME: NotesWatchApp
        INFOPLIST_FILE: "Notes Watch App/Resources/Info-watchOS.plist"
        GENERATE_INFOPLIST_FILE: false
        SWIFT_STRICT_CONCURRENCY: complete
        WATCHOS_DEPLOYMENT_TARGET: "26.0"
        ASSETCATALOG_COMPILER_APPICON_NAME: AppIcon
        ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME: AccentColor
        TARGETED_DEVICE_FAMILY: "4"

  # ---- watchOS widget extension (a launcher complication for the watch face) --
  Notes Watch Widget:
    type: app-extension
    platform: watchOS
    sources:
      - path: Notes Watch Widget
        excludes:
          - "Resources/Info-*.plist"
    postBuildScripts: *updateBuildInfo
    settings:
      base:
        PRODUCT_BUNDLE_IDENTIFIER: dev.rzen.indie.Notes.watchkitapp.widget
        INFOPLIST_FILE: "Notes Watch Widget/Resources/Info-WatchWidget.plist"
        GENERATE_INFOPLIST_FILE: false
        SWIFT_STRICT_CONCURRENCY: complete
        WATCHOS_DEPLOYMENT_TARGET: "26.0"
        TARGETED_DEVICE_FAMILY: "4"
