Given a list of watched directories run given commands everytime there are changes.
Handy in cases when needed to run an app in watch mode to build direct/implicit dependencies on changes.
-
@sources = string[]
List of directories to watch -
@commands = string[]
List of taks to execute everytime (ie. nx build)
Place plugin files under "./tools/executors/nx-watch/
, and
Must be complieed before use, or if changes are made to the source imple.ts
file.
tsc --project tools/executors/nx-watch/tsconfig.json
Simply add a new task entry to workspace.json
under the project's target.
The following task will re-build ui-tokens
for ui-kit
everytime on changes:
// workspace.json
"version": 2,
// ...
"projects": {
"ui-kit": {
"watch": {
"executor": "./tools/executors/nx-watch:run",
"options": {
"sources": ["libs/ui-tokens"],
"commands": [
"nx build ui-tokens",
"echo rebulding cause of changes"
]
}
},
},
"ui-tokens": {
"build": {
// do build taks ...
}
},
// ...
}
Can also be combined with other nx task, like serving ui-kit
storybook while watching for changes on the buildable dependency ui-tokens
:
// workspace.json
"version": 2,
// ...
"projects": {
"ui-kit": {
"watch": {
// watch task ...
},
"serve": {
"builder": "@nrwl/workspace:run-commands",
"options": {
"commands": [
{
"command": "nx watch ui-kit"
},
{
"command": "nx storybook ui-kit"
}
]
}
},
},
"ui-tokens": {
"build": {
// do build taks ...
}
},
// ...
}
I updated your code to work with the latest version of
nx/workspace
(13.4.x as of writing): https://github.com/hevans90/idle-game/tree/main/tools/executors/watchI just want to thank you for the inspiration, this concept has enabled some amazing CI/CD workflow for my pet project!