GitXplorerGitXplorer
t

simple-recursive-watch

public
0 stars
0 forks
0 issues

Commits

List of commits on branch master.
Unverified
6c5e15d2f3d4b793dde50e85314c4a4ebd0a187e

Release v2.0.5

tthealjey committed 9 years ago
Unverified
9291acf0189979bfa5578fec10fd65fd865efab6

[added] a deprecation warning

tthealjey committed 9 years ago
Unverified
e91cec7ba16b5b361e15b8a52867df717a813657

Release v2.0.4

tthealjey committed 9 years ago
Unverified
d5ca47ca3ff9743a5d6e841987c172ff4dc38e70

[added] release tools

tthealjey committed 9 years ago
Unverified
48cb01666b05c265337dee2efe685806d7ca44df

[fixed] updated to NodeJS v4.1.1

tthealjey committed 9 years ago
Unverified
3810bf563b60bb735d07f8a4fd82105fde5b926a

[added] eslintrc to support in-browser linting

tthealjey committed 9 years ago

README

The README file for this repository.



DEPRECATION WARNING

This project has been deprecated and will no longer receive updates.

Please consider using Watchman and the watch function from webcompiler instead.




simple-recursive-watch

A simple cross platform recursive directory watcher for NodeJS, based on fs.watch, but not relying on its recursive option.

Build Status Coverage Status Code Climate Dependency Status devDependency Status peerDependency Status npm version Slack channel

I just got tired of gulp.watch and gulp-watch. Because they rely on a hopelessly broken gaze library, which besides being too resource intensive for my liking, also crashes all the time.

Errors happen all the time, we cannot completely prevent them from happening. A good application is the one that handles those errors gracefully instead of dying all the time, producing a long and unreadable error stack that prevents you from seeing what really matters.

Fortunately, NodeJS contains a very handy utility called fs.watch, which is much more performant and less resource intensive, because it uses native operating system events to do it's job.

Unfortunately, though it cannot be reliably used to spy on a whole tree of folders recursively. Which is what this library is for.

Installation

npm i simple-recursive-watch --save

API Documentation

To get better acquainted with the available tools feel free to skim through the auto-generated API Docs.

Exposes 1 class

DirectoryWatcher - recursively watches for file changes in a directory

interface DirectoryWatcher {
  constructor(dir: string, type: RegExp, ...exclude: Array<string>);
  start();
  stop();
  static watch(dir: string, extension: string, callback: Function, ...exclude: Array<string>): DirectoryWatcher;
}

Arguments

  1. dir - a full system path to a directory
  2. type - a regular expression to match files
  3. exclude - files/directories to exclude (not full paths, just file/directory names)
  4. extension - a file extension to watch for
  5. callback - a callback function to execute whenever a file system change occurs

Example usage

import {DirectoryWatcher} from 'simple-recursive-watch';
import {join} from 'path';

var libDir = join(__dirname, 'lib');

DirectoryWatcher.watch(libDir, 'js', function () {
  // some JavaScript file, not named "ignoreMe.js" and not residing
  // in a "__tests__" directory, was changed in the "lib" directory
}, '__tests__', 'ignoreMe.js');

Explanation

The provided callback is invoked, immediately and only once, when somewhere in the src directory a ".js" file is created, edited, renamed, moved around or deleted, excluding those residing in a "__tests__" directory or having a name "ignoreMe.js".

You can specify any number of file or directory names to ignore.