Table of Contents
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):
- Extract the plug into your global plugin directory (
$SPARK_PLUGINS
) - Go to your project directory and run
spark plugin --enable com.noccy.watcher
Local installation:
- Extract the directory into
.spark/plugins
, like a savage.
Configuration
Create the config file .spark/watchers.json
:
{
"watchers": []
}
Add your rules as objects under the watchers
key:
{
"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