Targets
A target is a compound identifier that pairs a scope to a task, separated by a
:
, in the format of scope:task
.
Targets are used by terminal commands...
$ moon run designSystem:build
And configurations for declaring cross-project or cross-task dependencies.
tasks:
build:
command: 'webpack'
deps:
- 'designSystem:build'
Common scopes
These scopes are available for both running targets and configuring them.
By project
The most common scope is the project scope, which requires the name of a project, as defined in
.moon/workspace.yml
. When paired with a task name, it will run a specific
task from that project.
# Run `lint` in project `app`
$ moon run app:lint
Run scopes
These scopes are only available on the command line when running targets.
By tagv1.4.0
Another way to target projects is with the tag scope, which requires the name of a tag prefixed with
#
, and will run a specific task in all projects with that tag.
# Run `lint` in projects with the tag `frontend`
$ moon run '#frontend:lint'
Because #
is a special character in the terminal (is considered a comment), you'll need to wrap
the target in quotes, or escape it like so \#
.
All projects
For situations where you want to run a specific target in all projects, for example lint
ing, you
can utilize the all projects scope by omitting the project name from the target: :lint
.
# Run `lint` in all projects
$ moon run :lint
Config scopes
These scopes are only available when configuring a task.
Dependencies ^
When you want to include a reference for each project that's depended on,
you can utilize the ^
scope. This will be expanded to all depended on projects. If you do not
want all projects, then you'll need to explicitly define them.
dependsOn:
- 'apiClients'
- 'designSystem'
# Configured as
tasks:
build:
command: 'webpack'
deps:
- '^:build'
# Resolves to
tasks:
build:
command: 'webpack'
deps:
- 'apiClients:build'
- 'designSystem:build'
Self ~
When referring to another task within the current project, you can utilize the ~
scope, or emit
the ~:
prefix altogether, which will be expanded to the current project's name. This is useful for
situations where the name is unknown, for example, when configuring
.moon/tasks.yml
, or if you just want a shortcut!
# Configured as
tasks:
lint:
command: 'eslint'
deps:
- '~:typecheck'
# OR
- 'typecheck'
typecheck:
command: 'tsc'
# Resolves to (assuming project is "foo")
tasks:
lint:
command: 'eslint'
deps:
- 'foo:typecheck'
typecheck:
command: 'tsc'