diff --git a/Home.md b/Home.md index fb1cbc7..c6a2722 100644 --- a/Home.md +++ b/Home.md @@ -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 \ No newline at end of file +- [com.noccy.pdo](com.noccy.pdo) - PDO Database helpers +- [com.noccy.watcher](com.noccy.watcher) - Run scripts when files are modified + diff --git a/com.noccy.watcher.md b/com.noccy.watcher.md new file mode 100644 index 0000000..184f4ee --- /dev/null +++ b/com.noccy.watcher.md @@ -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