This is lightweight task runner that effectively wraps listr to provide a UI on tasks, which are defined in tools/__tasks__/
.
It's intended to exist ‘behind the scenes’, and you should probably be running the tasks it runs from make
or something similar.
It takes one or more tasks to run as arguments, which should be relative paths within the __tasks__
directory, so that:
./tools/task-runner/runner.mjs fakemodule/fakemodule.js
will run the task defined in tools/__tasks__/fakemodule/fakemodule.js
.
You can pass a --dev
flag to prefer a dev version, if it exists (suffix the task's filename with .dev
), so that:
./tools/task-runner/runner.mjs fakemodule/fakemodule.dev.js
- runs
tools/__tasks__/fakemodule/fakemodule.dev.js
if it exists - reverts to
tools/__tasks__/fakemodule/fakemodule.js
if the above fails
Tasks can be run with --verbose
flag for fuller output, but this shouldn't usually be needed (hopefully).
For a full list, run ./tools/task-runner/runner.mjs -h
.
Task definitions are standard node modules that export a task object. As a minumum, they must export:
description
task
Describes the task!
Strings are treated as a standard terminal command:
module.exports = {
description: "Print 'hello'",
task: "echo 'hello'",
};
They are run with execa, which checks for locally installed binaries (./node_modules
) before global ones, just as with npm scripts.
module.exports = {
description: "run a JS function",
task: () => {...}
}
The 'Task' section of the listr docs covers this best (since they map directly onto them).
Tasks can also be an array of subtasks (which must also be valid tasks):
module.exports = {
description: 'my task',
task: [
{
description: 'a subtask',
task: 'command to run',
},
{
description: 'another subtask',
task: () => {
// do something...
},
},
],
};
If the task is an array of other tasks, you can also specify that its tasks should run concurrently:
module.exports = {
description: 'my concurrent task',
task: [
// tasks...
],
concurrent: true,
};
Since tasks are just JS objects, you can require
them in the standard node way too:
module.exports = {
description: 'run another task',
task: require('./another-task'),
};