Be hesitatnt to try this at home. This tool is very wobbly.
$ yarn add -D observations
// ./observations.js
import Observations from 'observations'
Observations.register({
name: 'js-watcher',
match: ['./**/*.js', './**/*.jsx'],
ignore: './watch.config.js',
hanleError(error) {
// Apply whatever functionality you like when
// a process encounters an error.
console.log(`Got an error, dude!`)
},
handleOutput(output) {
// Apply whatever functionality you like when
// a managed process provides output.
console.log(`Got output, dude!`)
},
handleChange(change) {
// Apply whatever functionality you like when
// an observed path changes, and then programatically
// provide the next set of instructions.
change.exec([
'echo $VIRTUAL_HOST',
'ls ./public/css',
'webpack'
])
}
})
$ node observations
An array of globs/patterns to watch.
[optional] Not yet used for anything.
[optional] An array of globs/patterns to ignore.
[optional] Whether or not the process should exit on its own or stay alive.
[optional] A function to execute to handle process output.
[optional] A function to execute when process throws an error.
[optional] A function to execute when a watched file changes. handleChange
is provided with a change
object that contains data explaining the change
and an exec
method that allows you to provide which commands to execute
after your custom functionality has completed.