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

set working-directory := '.'

default:
    just check

# Build moq-ffi for the host, regenerate uniffi bindings, and run
# :moq-ffi:jvmTest + :moq:jvmTest. Missing tools are errors so wrapper drift
# cannot slip past a green check.
check:
    bash scripts/check.sh

# Regenerate the checked-in uniffi bindings and host native library without
# compiling or testing. For environments that intentionally lack Gradle.
generate:
    bash scripts/generate.sh

# Assemble the KMP module from per-target moq-ffi binaries + bindings.
# Used by .github/workflows/release-kt-ffi.yml; see kt/README.md for the

# expected --lib-dir layout.
package *args:
    bash scripts/package.sh {{ args }}

# Remove gradle output plus the moq-ffi bindings and native libs that
# scripts/check.sh generates into the source tree (see kt/.gitignore).
clean:
    #!/usr/bin/env bash
    set -euo pipefail
    find . -name .claude -prune -o -type d \( -name build -o -name .gradle -o -name .kotlin \) -prune -exec rm -rf {} +
    rm -rf local.properties \
    	moq/src/jvmAndAndroidMain/kotlin/uniffi \
    	moq/src/jvmMain/resources \
    	moq/src/androidMain/jniLibs

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

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