# Copyright © SixtyFPS GmbH <info@slint.dev>
# SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0

# Use https://mise.jdx.dev/schema/mise-task.json for validation.

### fixes

["fix:cpp:format"]
description = "Run clang format fix on all C++ files"
run = '''fd '.*\.(h|H|hpp|hxx|h\+\+|c|C|cpp|cxx|c\+\+)$' -0 | xargs -0 clang-format -i'''
tools = { "pipx:clang-format" = "20.1.3" }

["fix:rust:lockfile:root"]
description = "Update the main lockfile (if absolutely necessary)"
# Use cargo build -p xtask to test if the lockfile needs upating.
# The fix:legal:copyright task needs the xtask anyhow, so this has a double use.
run = "cargo build --locked -p xtask || (echo \"### Updating Main Lockfile! ###\" && cargo update)"

["fix:rust:lockfile:bevy"]
description = "Update the bevy example lockfile (if absolutely necessary)"
# Use cargo metadata to test if the lockfile needs upating.
# --format-version suppresses "warning: please specify `--format-version` flag explicitly to avoid compatibility problems"
run = "cargo metadata --locked --format-version=1 > /dev/null || (echo \"### Updating Main Lockfile! ###\" && cargo update)"
dir = "examples/bevy"

["fix:legal:copyright"]
description = "Run the check_license_headers --fix xtask"
run = "cargo xtask check_license_headers --fix-it"
depends = ["fix:rust:lockfile:root"]

["fix:python:format"]
description = "Run ruff format"
# Run via uv as the ruff installation via mise is unreliable in the CI.
# It keeps failing to find ruff, despite saying that it was installed.
run = "uv tool run ruff@0.11.8 format"

["fix:rust:format"]
description = "Run cargo fmt --all"
run = "cargo fmt --all"

["fix:rust:format:root"]
description = "Run cargo fmt --all"
run = "cargo fmt --all"
dir = "."

["fix:rust:format:bevy"]
description = "Run cargo fmt --all"
run = "cargo fmt --all"
dir = "examples/bevy"

["fix:rust:format:servo"]
description = "Run cargo fmt --all"
run = "cargo fmt --all"
dir = "examples/servo"

["fix:rust:format:safeui"]
description = "Run cargo fmt --all"
run = "cargo fmt --all"
dir = "examples/safe-ui"

["fix:rust:format:all"]
depends = ["fix:rust:format:root", "fix:rust:format:bevy", "fix:rust:format:servo", "fix:rust:format:safeui"]

["fix:toml:format"]
description = "Run taplo format"
run = "taplo format"

["fix:pnpm:lock"]
description = "Update pnpm lock file"
run = "pnpm i --lockfile-only"

["fix:pnpm:dedupe"]
description = "Run pnpm dedupe"
run = "pnpm dedupe"
depends = ["prepare:pnpm-install"]

["fix:ts:format"]
description = "Run pnpm format:fix"
run = "pnpm run format:fix"
depends = ["prepare:pnpm-install"]

["fix:ts:biome"]
description = "Run pnpm lint:fix"
run = "pnpm run lint:fix"
depends = ["prepare:pnpm-install"]

### Lints

["lint:ts:typecheck"]
description = "Run pnpm format:fix"
run = "pnpm type-check:ci"
depends = ["prepare:pnpm-install"]

["lint:ts:knip"]
description = "Run knip"
run = "pnpm knip"
depends = ["prepare:pnpm-install"]

### Build

["build:lsp:wasm"]
description = "Build the LSP (WASM)"
dir = "editors/vscode"
sources = ["tools/lsp/Cargo.toml", "tools/lsp/**/*.rs", "tools/lsp/ui/**/*.slint"]
outputs = ["tools/lsp/pkg/*"]
run = "pnpm run build:wasm_lsp"
tools = { "ubi:drager/wasm-pack" = "0.13.1" }
depends = ["prepare:pnpm-install"]

["build:interpreter:wasm"]
description = "Build the Slint interpreteer (WASM)"
dir = "tools/slintpad"
sources = ["api/wasm-interpreter/Cargo.toml", "api/wasm-interpreter/src/**/*.rs"]
outputs = ["api/wasm-interpreter/pkg/*"]
run = "pnpm run build:wasm_interpreter"
tools = { "ubi:drager/wasm-pack" = "0.13.1" }
depends = ["prepare:pnpm-install"]

["prepare:pnpm-install"]
hide = true
run = "pnpm install --frozen-lockfile"
depends = ["fix:pnpm:lock"]


### CI

["ci:autofix:fix"]
description = "CI autofix job -- fix steps"
depends = [
  "fix:cpp:format",
  "fix:legal:copyright",
  "fix:python:format",
  "fix:rust:format:all",
  "fix:text:trailing_spaces",
  "fix:toml:format",
  "fix:pnpm:lock",
  "fix:pnpm:dedupe",
  "fix:ts:biome",
  "fix:ts:format",
  "fix:rust:lockfile:root",
  "fix:rust:lockfile:bevy",
]

["ci:autofix:lint"]
description = "CI autofix job -- lint steps"
depends = ["lint:legal:reuse", "lint:ts:typecheck", "lint:ts:knip"]
