Added docs for watcher plugin

Chris 2021-12-15 04:10:33 +01:00
parent 5e30f9c2ff
commit 05b7f28f35
2 changed files with 58 additions and 1 deletions

@ -5,4 +5,6 @@ Welcome to the Wiki.
### Core Plugins
- [com.noccy.apiclient](com.noccy.apiclient) - API catalog and request helper
- [com.noccy.pdo](com.noccy.pdo) - PDO Database helpers
- [com.noccy.pdo](com.noccy.pdo) - PDO Database helpers
- [com.noccy.watcher](com.noccy.watcher) - Run scripts when files are modified

55
com.noccy.watcher.md Normal file

@ -0,0 +1,55 @@
# Watcher Plugin
This plugin is capable of replacing node/npm for some use cases. Its only job is to
keep an eye on files, and do something useful when they are changed. This could
for example be checking a scss- or less-file for changes and automatically compiling
new css.
The action can be any executable command or other accepted script command including
the `@some-script` reference to defined scripts. Thus you can have a script named
`make-css` (callable with `spark run make-css`) and also a watcher for the relevant
files which in turn calls on `@make-css`!
Be aware that the functionality currently differs somewhat depending on if the inotify
extension is available. This will be fixed, but right now this is what you get:
With inotify you can watch a lot of directories, but unrelated changes may trigger
your rules. Without inotify you can watch *a few* files, but with a lot of files or
wildcards you may run into trouble. However, only watched files will trigger the
rule. So it all depends on if you want efficient but spontaneous, or slow but
reliable!
## Installation
Global installation (recommended, requires SPARK_PLUGINS environment):
1. Extract the plug into your global plugin directory (`$SPARK_PLUGINS`)
2. Go to your project directory and run `spark plugin --enable com.noccy.watcher`
Local installation:
1. Extract the directory into `.spark/plugins`, like a savage.
## Configuration
Create the config file `.spark/watchers.json`:
```json
{
"watchers": []
}
```
Add your rules as objects under the `watchers` key:
```json
{
"name": "Rebuild Stylesheets",
"initial-trigger": true,
"watch": [ "./templates/style.scss" ],
"actions": [ "@make-css" ]
}
```
After saving, you should be able to run `spark watch`:
$ spark watch