ogle

0.1.0 • Public • Published

Ogle

Thin wrapper for fs.watch with glob-pattern matching.

Example

var watcher = new Ogle(['lib/some-dir/', 'lib/some-dir/*.js']);
 
watcher.on('add', function(dir, newFile) {
  console.log("File %s added to directory %s", newFile, dir);
});
 
watcher.on('change', function(filePath) {
  console.log("File %s changed", filePath);
});
 
watcher.on('remove', function(filePath) {
  console.log("File %s was deleted", filePath);
});
 
watcher.on('all', function(event, filePath, otherPath) {
  switch(event) {
    case 'add':
      console.log("File %s added to directory %s", filePath, otherPath);
      break;
    case 'change':
      console.log("File %s changed", filePath);
      break;
    case 'remove':
      console.log("File %s deleted", filePath);
      break;
  }
});

Why?

There are already many wrappers on fs.watch/fs.watchFile. Unfortunately, non of them seemed to be usable without making sacrifices. Ogle chooses the following advantages:

  • glob pattern matching
  • all/remove/change events on files
  • all/add/remove/change events on directories
  • Auto-adding of listeners for new files in directories (if we are watching the directory)
  • Use of fs.watch instead of fs.watchFile. See here for why.

Complete documentation

Coming soon...

Readme

Keywords

none

Package Sidebar

Install

npm i ogle

Weekly Downloads

0

Version

0.1.0

License

MIT

Last publish

Collaborators

  • rschmukler