Task runner
deno task
provides a cross platform way to define and execute custom commands
specific to a codebase.
To get started, define your commands in your codebase’s
Deno configuration file under a
"tasks"
key.
For example:
To get an output showing all the defined tasks, run:
To execute a specific task, run:
deno task task-name [additional args]...
In the example above, to run the data
task we would do:
deno task data
deno task
uses a cross platform shell that’s a subset of sh/bash to execute
defined tasks.
Boolean lists provide a way to execute additional commands based on the exit
code of the initial command. They separate commands using the &&
and ||
operators.
The &&
operator provides a way to execute a command and if it succeeds (has
an exit code of 0
) it will execute a second command:
deno run --allow-read=. --allow-write=. collect.ts && deno run --allow-read=. analyze.ts
deno run --allow-read=. --allow-write=. collect.ts || deno run play_sad_music.ts
Sequential lists
Sequential lists are similar to boolean lists, but execute regardless of whether
the previous command in the list passed or failed. Commands are separated with a
semi-colon (;
).
Async commands provide a way to make a command execute asynchronously. This can
be useful when starting multiple processes. To make a command asynchronous, add
an to the end of it. For example the following would execute
sleep 1 && deno run --allow-net client/main.ts
and
deno run --allow-net server/main.ts
at the same time:
sleep 1 && deno run --allow-net client/main.ts & deno run --allow-net server/main.ts
Environment variables
Environment variables are defined like the following:
export VAR_NAME=value
Here’s an example of using one in a task with shell variable substitution and then with it being exported as part of the environment of the spawned Deno process (note that in the JSON configuration file the double quotes would need to be escaped with backslashes):
export VAR=hello && echo $VAR && deno eval "console.log('Deno: ' + Deno.env.get('VAR'))"
Would output:
hello
Deno: hello
Setting environment variables for a command
To specify environment variable(s) before a command, list them like so:
VAR=hello VAR2=bye deno run main.ts
This will export those environment variable specifically for the following command.
Shell variables are similar to environment variables, but won’t be exported to spawned commands. They are defined with the following syntax:
If we use a shell variable instead of an environment variable in a similar example to what’s shown in the previous “Environment variables” section:
VAR=hello && echo $VAR && deno eval "console.log('Deno: ' + Deno.env.get('VAR'))"
hello
Deno: undefined
Shell variables can be useful when we want to re-use a value, but don’t want it available in any spawned processes.
Pipelines
Pipelines provide a way to pipe the output of one command to another. Currently only piping stdout is supported.
The following command pipes the output “Hello” to the stdin of the spawned Deno process:
The $(command)
syntax provides a way to use the output of a command in other
commands that get executed.
For example, to provide the output of getting the latest git revision to another command you could do the following:
deno run main.ts $(git rev-parse HEAD)
Another example using a shell variable:
REV=$(git rev-parse HEAD) && deno run main.ts $REV && echo $REV
Future syntax
We are planning to support redirects and in the future.
ships with several built-in commands that work the same out of the box on Windows, Mac, and Linux.
cp
- Copies files.- - Moves files.
rm
- Remove files or directories.- Ex:
rm -rf [FILE]...
- Commonly used to recursively delete files or directories.
- Ex:
- - Makes
directories.
- Ex.
mkdir -p DIRECTORY...
- Commonly used to make a directory and all its parents with no error if it exists.
- Ex.
pwd
- Prints the name of the current/working directory.- - Delays for a
specified amount of time.
- Ex.
sleep 1
to sleep for 1 second orsleep 0.5
to sleep for half a second
- Ex.
echo
- Displays a line of text.- - Causes the shell to exit.
If you find a useful flag missing on a command or have any suggestions for additional commands that should be supported out of the box, then please open an issue on the repo.