[config]
skip_core_tasks = true

[env.TUI_FEATURES]
source = "${CARGO_MAKE_RUST_TARGET_OS}"
default_value = "unknown"

[env.TUI_FEATURES.mapping]
linux = "serde,crossterm,termion,rustbox,curses"
macos = "serde,crossterm,termion,rustbox,curses"
windows = "serde,crossterm"

[tasks.default]
dependencies = [
  "check",
]

[tasks.ci]
dependencies = [
  "fmt",
  "check",
  "test",
  "clippy",
]


[tasks.fmt]
command = "cargo"
args = [
  "fmt",
  "--all",
  "--",
  "--check",
]

[tasks.check]
command = "cargo"
args = [
  "check",
  "--no-default-features",
  "--features",
  "${TUI_FEATURES}",
  "--all-targets",
]

[tasks.build]
command = "cargo"
args = [
  "build",
  "--no-default-features",
  "--features",
  "${TUI_FEATURES}",
  "--all-targets",
]

[tasks.clippy]
command = "cargo"
args = [
  "clippy",
  "--no-default-features",
  "--features",
  "${TUI_FEATURES}",
  "--",
  "-D",
  "warnings",
]

[tasks.test]
linux_alias = "test-unix"
mac_alias = "test-unix"
windows_alias = "test-windows"

[tasks.test-unix]
command = "cargo"
args = [
  "test",
  "--no-default-features",
  "--features",
  "${TUI_FEATURES}"
]

# Documentation tests cannot be run on Windows for now
[tasks.test-windows]
command = "cargo"
args = [
  "test",
  "--no-default-features",
  "--features",
  "${TUI_FEATURES}",
  "--lib",
  "--tests",
  "--examples",
]

[tasks.run-example]
private = true
condition = { env_set = ["TUI_EXAMPLE_NAME", "TUI_FEATURES"] }
command = "cargo"
args = [
    "run",
    "--features",
    "${TUI_FEATURES}",
    "--release",
    "--example",
    "${TUI_EXAMPLE_NAME}"
]

[tasks.run-example-windows]
private = true
condition = { env = {"TUI_EXAMPLE_NAME" = "crossterm_demo"} }
run_task = "run-example"

[tasks.run-example-router]
private = true
run_task = [
    { name = "run-example-windows", condition = { platforms = ["window"] } },
    { name = "run-example" }
]

[tasks.build-examples]
condition = { env_set = ["TUI_FEATURES"] }
command = "cargo"
args = [
    "build",
    "--examples",
    "--features",
    "${TUI_FEATURES}",
    "--release"
]

[tasks.run-examples]
dependencies = ["build-examples"]
script = '''
#!@duckscript
files = glob_array ./examples/*.rs
for file in ${files}
  name = basename ${file}
  name = substring ${name} -3
  set_env TUI_EXAMPLE_NAME ${name}
  cm_run_task run-example-router
end
'''
