Skip to content

Commit

Permalink
docs: Add more examples for toml tasks (jdx#3491)
Browse files Browse the repository at this point in the history
* docs: Add more examples for toml tasks

* update

* [autofix.ci] apply automated fixes

* fix

* update

* update

* [autofix.ci] apply automated fixes

* code group

* wip

* [autofix.ci] apply automated fixes

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
  • Loading branch information
2 people authored and miguelmig committed Dec 21, 2024
1 parent d21597c commit 4002496
Show file tree
Hide file tree
Showing 3 changed files with 345 additions and 51 deletions.
90 changes: 59 additions & 31 deletions docs/tasks/file-tasks.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,72 @@ Here is an example of a file task that builds a Rust CLI:
cargo build
```

::: tip Important
Ensure that the file is executable, otherwise mise will not be able to detect it.

:::tip
The `mise:description` comment is optional but recommended. It will be used in the output of `mise tasks`.
The other configuration for "script" tasks is supported in this format so you can specify things like the
following-note that this is parsed a TOML table:
```shell
chmod +x mise-tasks/build
```

:::

Having the code in a bash file and not TOML helps make it work
better in editors since they can do syntax highlighting and linting more easily.

They also still work great for non-mise users—though
of course they'll need to find a different way to install their dev tools the tasks might use.

## Task Configuration

The same configuration options as for [TOML tasks](/tasks/toml-tasks.html) are supported.
You can provide additional configuration for file tasks by adding `#MISE` comments at the top of the file.

```bash
#MISE description="Build the CLI"
#MISE alias="b"
#MISE sources=["Cargo.toml", "src/**/*.rs"]
#MISE outputs=["target/debug/mycli"]
#MISE env={RUST_BACKTRACE = "1"}
#MISE depends=["lint", "test"]
```

Assuming that file was located in `.mise/tasks/build`, it can then be run with `mise run build` (or with its alias: `mise run b`).
This script can be edited with by running `mise task edit build` (using $EDITOR). If it doesn't exist it will be created.
These are convenient for quickly making new scripts. Having the code in a bash file and not TOML helps make it work
better in editors since they can do syntax highlighting and linting more easily. They also still work great for non-mise users—though
of course they'll need to find a different way to install their dev tools the tasks might use.
Assuming that file was located in `mise-tasks/build`, it can then be run with `mise run build` (or with its alias: `mise run b`).

## Shebang

The shebang line is optional, but if it is present, it will be used to determine the shell to run the script with.
You can also use it to run the script with various programming languages.

::: code-group

```js [node]
#!/usr/bin/env node

console.log("Hello, World!");
```

```python
#!/usr/bin/env python

print('Hello, World!')
```

```ts [deno]
#!/usr/bin/env -S deno run --allow-env

console.log(`PATH, ${Deno.env.get("PATH")}`);
```

:::

## Editing tasks

This script can be edited with by running `mise task edit build` (using `$EDITOR`). If it doesn't exist it will be created.
This is convenient for quickly editing or creating new scripts.

## Task Grouping

File tasks in `.mise/tasks`, `mise/tasks`, or `.config/mise/tasks` can be grouped into
File tasks in `mise-tasks`, `.mise/tasks`, `mise/tasks`, or `.config/mise/tasks` can be grouped into
sub-directories which will automatically apply prefixes to their names
when loaded.

Expand All @@ -51,22 +92,21 @@ when loaded.
With a folder structure like below:

```text
.mise
└── tasks
├── build
└── test
├── integration
└── units
mise-tasks
├── build
└── test
├── integration
└── units
```

Running `mise tasks` will give the below output:

```text
$ mise tasks
Name Description Source
build .../.mise/tasks/build
test:integration .../.mise/tasks/test/integration
test:units .../.mise/tasks/test/units
build .../mise-tasks/build
test:integration .../mise-tasks/test/integration
test:units .../mise-tasks/test/units
```

## Arguments
Expand Down Expand Up @@ -132,15 +172,3 @@ mise run ./path/to/script.sh
```

Note that the path must start with `/` or `./` to be considered a file path. (On Windows it can be `C:\` or `.\`)

## Remote tasks

Task files can be fetched via http:

```toml
[tasks.build]
file = "https://example.com/build.sh"
```

Currently, they're fetched everytime they're executed, but we may add some cache support later.
This could be extended with other protocols like mentioned in [this ticket](https://github.com/jdx/mise/issues/2488) if there were interest.
6 changes: 3 additions & 3 deletions docs/tasks/running-tasks.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,14 @@ It wouldn't be hard to add checksum support.

## Watching files

Run a task when the source changes with `mise watch`:
Run a task when the source changes with [`mise watch`](/cli/watch.html)

```bash
mise watch build
```

Currently, this just shells out to watchexec-which you can install however you want including with mise: `mise use -g watchexec@latest`.
This may change in the future.
Currently, this just shells out to `watchexec` (which you can install however you want including with mise: `mise use -g watchexec@latest`.
This may change in the future.)

## `mise run` shorthand

Expand Down
Loading

0 comments on commit 4002496

Please sign in to comment.