0.0.12 • Published 4 years ago
@luoxiu/watch v0.0.12
Watch
Do something exciting on file changes!
Install
$ npm install -g @luoxiu/watch
$ yarn add -g @luoxiu/watch
$ pnpm add -g @luoxiu/watchUsage
In your working directory, create a file named watch.config.js:
$ cd ./wd && touch watch.config.jsand execute:
$ watchwatch.config.js
The following example will format your swift code as it changes:
// watch.config.js
module.exports = {
watchers: [
{
paths: ["Source/**/*.swift", "Tests/**/*.swift"],
options: {
ignored: ["*.generated.swift"],
},
callbacks: [
{
events: ["change"],
callback: async (path) => {
await $`swiftformat ${path}`
}
}
]
}
]
}
// or
module.exports = async () => {
return {
// ...
}
}watch uses chokidar to watch file changes, so you can watch add | change | unlink(remove) | etc events on file | dir | glob | etc.
Please refer to chokidar#api to learn more about paths, options, events and callbacks.
watch uses zx to execute callbacks, so you can write expressive scripts like:
{
events: ["changes"],
callback: async (path) => {
const resp = await fetch('https://wttr.in')
const text = await fs.readFile(path)
console.log(chalk.blue('Hello world!'))
cd('/a-path')
await $`pwd` // outputs /tmp
}
}Please refer to zx#documentation to learn more about zx.