@write-for-christ/prophet-samuel
In the Bible, prophet Samuel always listen for God's Word before doing something, this module will help us listen for files changed and execute actions in reactive way.
Features
- Watch for all files changed.
- Parse file path from changed file.
- Execute actions based on filtered pattern.
- Support reactive functional programming.
Installation
npm install @write-for-christ/prophet-samuel
How to use?
const samuel = require('prophet-samuel');
// Simple usage, only watch on single directory
samuel().watch('/path/to/watch').subscribe((data) => {
console.log(data);
});
// Recursive mode
samuel().watch('/path/to/watch', { recursive: true}).subscribe((data) => {
console.log(data);
});
- Notice: Every time we call
samuel()
a new instance is allocated. - If a file changed at
/path/to/watch/sub/of/sub/dir/updated.txt
thedata
should be:
{
event: 'update',
path: '/path/to/watch/sub/of/sub/dir/updated.txt',
dir: '/path/to/full/file/',
root: '/',
base: 'updated.txt',
name: 'updated',
ext: '.txt',
rel: '/sub/of/sub/dir/'
}