#!/usr/bin/env just --justfile
#
# Language-specific recipes for the Swift package under swift/. Invoked
# from the repo root as `just swift <recipe>` via the `mod swift` import.

set working-directory := '.'

default:
    just check

# Build moq-ffi for the host, regenerate uniffi bindings, run swift test.

# Skips cleanly on non-macOS hosts.
check:
    bash scripts/check.sh

# Assemble the released wrapper package from Package.swift.template.

# Used by .github/workflows/release-swift-lib.yml.
package *args:
    bash scripts/package.sh {{ args }}

# Remove SwiftPM build output plus the XCFramework and generated bindings

# that scripts/check.sh lays down (see swift/.gitignore).
clean:
    rm -rf .build .swiftpm Package.resolved Sources/MoqFFI/Generated.swift MoqFFI.xcframework

# Full Swift CI: `check` already builds moq-ffi and runs swift test.
# Takes a newline-separated list of changed files; skips if FILES is
# non-empty and none match the Swift scope. Run `just swift ci` (no

# FILES) to force-run.
ci $FILES="":
    #!/usr/bin/env bash
    set -euo pipefail
    if [[ -n "$FILES" ]] && ! grep -qE '^(swift/|rs/moq-ffi/)' <<< "$FILES"; then
    	echo "swift: no Swift changes; skipping."
    	exit 0
    fi
    just check
