From db5b3deddc37d671318be8822d95580a5a68bd32 Mon Sep 17 00:00:00 2001 From: Jeff Dickey <216188+jdx@users.noreply.github.com> Date: Wed, 18 Sep 2024 16:07:11 -0500 Subject: [PATCH] feat(tasks): allow mise-tasks or .mise-tasks directories Fixes #2604 --- docs/cli/index.md | 6 ++++-- docs/cli/run.md | 3 ++- docs/cli/tasks/run.md | 3 ++- docs/tasks/script-tasks.md | 11 +++++++++-- mise.usage.kdl | 6 ++++-- src/cli/run.rs | 3 ++- src/config/mod.rs | 2 ++ src/task.rs | 10 ++++++++++ 8 files changed, 35 insertions(+), 9 deletions(-) diff --git a/docs/cli/index.md b/docs/cli/index.md index 510de19ea..7b56b1490 100644 --- a/docs/cli/index.md +++ b/docs/cli/index.md @@ -1047,7 +1047,8 @@ In .mise.toml, tasks take this form: outputs = ["dist/**/*.js"] Alternatively, tasks can be defined as standalone scripts. -These must be located in the `.mise/tasks`, `mise/tasks` or `.config/mise/tasks` directory. +These must be located in `mise-tasks`, `.mise-tasks`, `.mise/tasks`, `mise/tasks` or +`.config/mise/tasks`. The name of the script will be the name of the tasks. $ cat .mise/tasks/build< Vec { vec![ + "mise-tasks".into(), + ".mise-tasks".into(), ".mise/tasks".into(), ".config/mise/tasks".into(), "mise/tasks".into(), diff --git a/src/task.rs b/src/task.rs index fb118e0ad..68c5f14fe 100644 --- a/src/task.rs +++ b/src/task.rs @@ -164,6 +164,8 @@ fn name_from_path(root: impl AsRef, path: impl AsRef) -> Result p.strip_prefix("mise-tasks"), + p if p.starts_with(".mise-tasks") => p.strip_prefix(".mise-tasks"), p if p.starts_with(".mise/tasks") => p.strip_prefix(".mise/tasks"), p if p.starts_with("mise/tasks") => p.strip_prefix("mise/tasks"), p if p.starts_with(".config/mise/tasks") => p.strip_prefix(".config/mise/tasks"), @@ -332,6 +334,14 @@ impl TreeItem for (&Graph, NodeIndex) { fn config_root(config_source: &impl AsRef) -> Option<&Path> { for ancestor in config_source.as_ref().ancestors() { + if ancestor.ends_with("mise-tasks") { + return ancestor.parent(); + } + + if ancestor.ends_with(".mise-tasks") { + return ancestor.parent(); + } + if ancestor.ends_with(".mise/tasks") { return ancestor.parent()?.parent(); }