@travetto/watch
Version:
Support for making files watchable during runtime
32 lines (24 loc) • 1.72 kB
Markdown
<!-- This file was generated by @travetto/doc and should not be modified directly -->
<!-- Please modify https://github.com/travetto/travetto/tree/main/module/watch/doc.ts and execute "npx trv doc" to rebuild -->
# Watch
## Support for making files watchable during runtime
**Install: @travetto/watch**
```bash
npm install @travetto/watch
```
This module is intended to be used during development, and is not during production. This constraint is tied to the performance hit the functionality could have at run-time. To that end, this is primarily an utility for other modules, but it's functionality could prove useful to others during development.
## File Watching
This module is the base file system watching support for [Travetto](https://travetto.dev) applications. In addition to file system scanning, the framework offers a simple file watching library. The goal is to provide a substantially smaller footprint than [gaze](https://github.com/shama/gaze) or [chokidar](https://github.com/paulmillr/chokidar). Utilizing the patterns from the file scanning, you create a [Watcher](https://github.com/travetto/travetto/tree/main/module/watch/src/watcher.ts#L21) that either has files added manually, or has patterns added that will recursively look for files.
**Code: Example of watching for specific files**
```typescript
import { Watcher } from '@travetto/watch';
export function main(): void {
const watcher = new Watcher('base/path/to/...')
.on('all', ({ event, entry }) => {
if (entry.file.endsWith('.config') || entry.file.endsWith('.config.json')) {
console.log('File Event', { event, file: entry.file });
}
});
setTimeout(() => watcher.close(), 1000);
}
```