Last active
June 15, 2024 10:16
-
-
Save ddanier/c08e8efd49d864e37ddb971846a6ac9e to your computer and use it in GitHub Desktop.
Create `nurfile` containing all tasks/commands from `justfile` when using `just` or `build/Taskfile` when using `b5`. Use https://github.com/ddanier/nur/blob/main/scripts/nurify.nu for latest version.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# IMPORTANT: | |
# An up to date version is available here: https://github.com/ddanier/nur/blob/main/scripts/nurify.nu | |
# How I installed this: | |
# > mkdir $env.NU_LIB_DIRS.0 | |
# > vim ($env.NU_LIB_DIRS.0 | path join "nurify.nu") | |
# PUT CODE IN HERE | |
# > vim $nu.config-path | |
# Add `use nurify.nu *` at the end | |
def nurify-from-b5 [] { | |
let global_tasks = ( | |
if (glob ~/.b5/Taskfile | first | path exists) { | |
cat ~/.b5/Taskfile | lines | filter { | |
|it| $it starts-with "task:" | |
} | each { | |
|it| $it | parse --regex "^task:(?P<name>[^(]+).*" | get name | first | |
} | |
} else [] | |
) | |
"# FILE GENERATED BY nurify COMMAND\n\n" | save -f nurfile | |
b5 --quiet help --tasks | lines | filter { | |
|it| $it not-in $global_tasks | |
} | each { | |
|it| $"def --wrapped \"nur ($it | str replace --all ':' ' ')\" [...args] {\n ^b5 --quiet \"($it)\" ...$args\n}\n" | |
} | save -f -a nurfile | |
} | |
def nurify-from-just [] { | |
"# FILE GENERATED BY nurify COMMAND\n\n" | save -f nurfile | |
^just --unsorted --dump --dump-format json | |
| from json | |
| get recipes | |
| transpose k v | |
| each { | |
|it| $"def --wrapped \"nur ($it.k)\" [...args] {\n ^just --quiet \"($it.k)\" ...$args\n}\n" | |
} | save -f -a nurfile | |
} | |
# Create nurfile from b5's Taskfile or just's justfile. The nurfile will contain tasks to wrap | |
# all tasks and run original task/command runner. | |
export def nurify [] { | |
if ("build/Taskfile" | path exists) { | |
nurify-from-b5 | |
} else if ("justfile" | path exists) { | |
nurify-from-just | |
} else { | |
error make {"msg": "Cound not find any existing task/command runner, please run nurify in project root"} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment