• Stars
    star
    1,155
  • Rank 40,228 (Top 0.8 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created about 12 years ago
  • Updated about 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

🔮 A globbing fs.watch wrapper built from the best parts of other fine watch libs.

gaze Build Status Build status

A globbing fs.watch wrapper built from the best parts of other fine watch libs.
Compatible with Node.js >= 4.x, Windows, macOS, and Linux.

gaze

NPM

Usage

Install the module with: npm install gaze or place into your package.json and run npm install.

const gaze = require('gaze');

// Watch all .js files/dirs in process.cwd()
gaze('**/*.js', (err, watcher) => {
  // Files have all started watching

  // Get all watched files
  const watched = watcher.watched();

  // On file changed
  watcher.on('changed', filepath => {
    console.log(filepath + ' was changed');
  });

  // On file added
  watcher.on('added', filepath => {
    console.log(filepath + ' was added');
  });

  // On file deleted
  watcher.on('deleted', filepath => {
    console.log(filepath + ' was deleted');
  });

  // On changed/added/deleted
  watcher.on('all', (event, filepath) => {
    console.log(filepath + ' was ' + event);
  });

  // Get watched files with relative paths
  const files = watcher.relative();
});

// Also accepts an array of patterns
gaze(['stylesheets/*.css', 'images/**/*.png'], () => {
  // Add more patterns later to be watched
  watcher.add(['js/*.js']);
});

Alternate Interface

const {Gaze} = require('gaze');

const gaze = new Gaze('**/*');

// Files have all started watching
gaze.on('ready', watcher => { });

// A file has been added/changed/deleted has occurred
gaze.on('all', (event, filepath) => { });

Errors

gaze('**/*', (error, watcher) => {
  if (error) {
    // Handle error if it occurred while starting up
  }
});

// Or with the alternative interface
const gaze = new Gaze();
gaze.on('error', error => {
  // Handle error here
});
gaze.add('**/*');

Minimatch / Glob

See isaacs's minimatch for more information on glob patterns.

Documentation

gaze([patterns, options, callback])

  • patterns {String|Array} File patterns to be matched
  • options {Object}
  • callback {Function}
    • err {Error | null}
    • watcher {Object} Instance of the Gaze watcher

Class: gaze.Gaze

Create a Gaze object by instancing the gaze.Gaze class.

const Gaze = require('gaze').Gaze;
const gaze = new Gaze(pattern, options, callback);

Properties

  • options The options object passed in.
    • interval {integer} Interval to pass to fs.watchFile
    • debounceDelay {integer} Delay for events called in succession for the same file/event in milliseconds
    • mode {string} Force the watch mode. Either 'auto' (default), 'watch' (force native events), or 'poll' (force stat polling).
    • cwd {string} The current working directory to base file patterns from. Default is process.cwd().

Events

  • ready(watcher) When files have been globbed and watching has begun.
  • all(event, filepath) When an added, changed, renamed, or deleted event occurs.
  • added(filepath) When a file has been added to a watch directory.
  • changed(filepath) When a file has been changed.
  • deleted(filepath) When a file has been deleted.
  • renamed(newPath, oldPath) When a file has been renamed.
  • end() When the watcher is closed and watches have been removed.
  • error(err) When an error occurs.
  • nomatch When no files have been matched.

Methods

  • emit(event, [...]) Wrapper for EventEmitter.emit. added|changed|renamed|deleted events will also trigger the all event.
  • close() Unwatch all files and reset the watch instance.
  • add(patterns, callback) Adds file(s) patterns to be watched.
  • remove(filepath) Removes a file or directory from being watched. Does not recurse directories.
  • watched() Returns the currently watched files.
  • relative([dir, unixify]) Returns the currently watched files with relative paths.
    • dir {string} Only return relative files for this directory.
    • unixify {boolean} Return paths with / instead of \\ if on Windows.

Similar Projects

Other great watch libraries to try are:

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using grunt.

Release History

  • 1.1.3 - Fix for Node 10 support (@aredridel). Officially dropping support for Node < 4.
  • 1.1.2 - Prevent more ENOENT errors from escaping (@alexgorbatchev).
  • 1.1.1 - Prevent fs.watch errors from escaping error handler (@rosen-vladimirov). Fix _addToWatched without path.sep (@wyicwx).
  • 1.1.0 - Update to [email protected] with minimatch >= 3.0.0.
  • 1.0.0 - Revert back to 0.5.2. Drop support for Node.js v0.8. Fix for maxListeners. Update globule to 0.2.0.
  • 0.6.4 - Catch and emit error from readdir (@oconnore). Fix for 0 maxListeners. Use graceful-fs to avoid EMFILE errors in other places fs is used. Better method to determine if pathwatcher was built. Fix keeping process alive too much, only init pathwatcher if a file is being watched. Set min required to Windows Vista when building on Windows (@pvolok).
  • 0.6.3 - Add support for Node.js v0.11
  • 0.6.2 - Fix argument error with watched(). Fix for erroneous added events on folders. Ignore msvs build error 4244.
  • 0.6.1 - Fix for absolute paths.
  • 0.6.0 - Uses native OS events (fork of pathwatcher) but can fall back to stat polling. Everything is async to avoid blocking, including relative() and watched(). Better error handling. Update to [email protected]. No longer watches cwd by default. Added mode option. Better EMFILE message. Avoids ENOENT errors with symlinks. All constructor arguments are optional.
  • 0.5.2 - Fix for ENOENT error with non-existent symlinks [BACKPORTED].
  • 0.5.1 - Use setImmediate (process.nextTick for Node.js v0.8) to defer ready/nomatch events (@amasad).
  • 0.5.0 - Process is now kept alive while watching files. Emits a nomatch event when no files are matching.
  • 0.4.3 - Track file additions in newly created folders (@brett-shwom).
  • 0.4.2 - Fix .remove() method to remove a single file in a directory (@kaelzhang). Fixing “Cannot call method 'call' of undefined” (@krasimir). Track new file additions within folders (@brett-shwom).
  • 0.4.1 - Fix watchDir not respecting close in race condition (@chrisirhc).
  • 0.4.0 - Drop support for Node.js v0.6. Use globule for file matching. Avoid Node.js v0.10 path.resolve/join errors. Register new files when added to non-existent folder. Multiple instances can now poll the same files (@jpommerening).
  • 0.3.4 - Code clean up. Fix “path must be strings” errors (@groner). Fix incorrect added events (@groner).
  • 0.3.3 - Fix for multiple patterns with negate.
  • 0.3.2 - Emit end before removeAllListeners.
  • 0.3.1 - Fix added events within subfolder patterns.
  • 0.3.0 - Handle safewrite events, forceWatchMethod option removed, bug fixes and watch optimizations (@rgaskill).
  • 0.2.2 - Fix issue where subsequent add calls dont get watched (@samcday). removeAllListeners on close.
  • 0.2.1 - Fix issue with invalid added events in current working dir.
  • 0.2.0 - Support and mark folders with path.sep. Add forceWatchMethod option. Support renamed events.
  • 0.1.6 - Recognize the cwd option properly
  • 0.1.5 - Catch “too many open file” errors
  • 0.1.4 - Really fix the race condition with 2 watches
  • 0.1.3 - Fix race condition with 2 watches
  • 0.1.2 - Read triggering changed event fix
  • 0.1.1 - Minor fixes
  • 0.1.0 - Initial release

License

Copyright (c) 2018 Kyle Robinson Young
Licensed under the MIT license.

More Repositories

1

webpack-stream

🍹 Run webpack through a stream interface
JavaScript
1,392
star
2

letswritecode

🎓 code examples for Let's Write Code
JavaScript
792
star
3

napa

🍷 A helper for installing stuff without a package.json with npm.
JavaScript
412
star
4

grunt-hub

🐗 A Grunt task to watch and run tasks on multiple Grunt projects
JavaScript
194
star
5

nodewebkit

💻 An installer for node-webkit
JavaScript
152
star
6

on-load

On load/unload events for DOM elements using a MutationObserver
JavaScript
113
star
7

workerify

Transform web workers into browserified inline Blobs with browserify.
JavaScript
113
star
8

yo-yoify

Transform choo, yo-yo or bel template strings into pure and fast document calls
JavaScript
111
star
9

voxel-drone

🎲🚁 An AR Drone simulator in voxeljs.com
JavaScript
99
star
10

base-element

🔰 An element authoring library for creating standalone and performant elements.
JavaScript
81
star
11

testron

🔌 CI your client side tests with Electron
JavaScript
71
star
12

es6-loader

ES6 module loader for webpack
JavaScript
61
star
13

grunt-benchmark

🐗⌚ Grunt task for benchmarking
JavaScript
60
star
14

atlaspack

🌌 Pack images into a texture atlas.
JavaScript
50
star
15

csv-viewer

A WIP CSV viewer element.
JavaScript
49
star
16

vinyl-named

💽 Give vinyl files arbitrary names.
JavaScript
46
star
17

fs-explorer

A WIP file system explorer element.
JavaScript
44
star
18

grunt-beep

🐗💥 It beeps. What more do you need?
JavaScript
37
star
19

posix-tools

🔧 A collection of pure JavaScript POSIX-like tools
JavaScript
36
star
20

grunt-ejs

A grunt task for rendering ejs templates.
JavaScript
31
star
21

ember-webpack-resolver

An Ember resolver for use with webpack
JavaScript
31
star
22

grunt-gulp

Run gulp tasks through declarative Grunt config
JavaScript
31
star
23

voxel-sky

🎲🌕☀️ A sky for voxeljs.com
JavaScript
26
star
24

view-list

📜 An infinite scrolling list view element built on a virtual DOM.
JavaScript
24
star
25

voxel-snow

🎲❄️ Let it voxel.js snow!
JavaScript
24
star
26

voxel-texture

🎲🌅 A texture helper for http://voxeljs.com.
JavaScript
24
star
27

cakebox

A Dropbox API Plugin for CakePHP 2.x
PHP
23
star
28

grunt-docs

A grunt plugin to compile using DocPad.
JavaScript
23
star
29

webpackify

Use webpack through a Browserify plugin
JavaScript
22
star
30

resize-event

Detect resize on an element without polling or iframes
JavaScript
22
star
31

base-router

🚉 A simple and portable router for the client and server.
JavaScript
21
star
32

modal-element

🔲 A basic modal element built on a virtual DOM.
JavaScript
21
star
33

navelgazer

🍊🔮 A super fast, light weight, simple file watcher and platform layer for gaze.
C++
21
star
34

voxel-virus

🎲👾 Spread a virus in voxel.js
JavaScript
20
star
35

grunt-spell

🐗🔤 A Grunt plugin for spellchecking
JavaScript
20
star
36

level-rest

📊💤 A REST adapter for LevelUP
JavaScript
20
star
37

tune

🎶 Tune up baudio
JavaScript
20
star
38

userhome

🏠 A platform independent path to the user's home.
JavaScript
19
star
39

timecat.us

⏰🐱 time cat - everyone's favorite game
JavaScript
19
star
40

browser-module-cache

Caches browserify-cdn modules using level.js
JavaScript
18
star
41

voxel-critter

🎲🐀 Make your voxelbuilder.com critter come to life!
JavaScript
17
star
42

dontkry.com

⛔😢 My website
JavaScript
16
star
43

craft

🔨 An HTML5 crafting API.
JavaScript
16
star
44

scriptify

📃 Browserify inline script tags in HTML
JavaScript
16
star
45

ndthree

The unholy union of three.js and Mikola Lysenko's ndarrays.
JavaScript
15
star
46

voxel-share

Take a snapshot of voxel.js and share on imgur/twitter
JavaScript
14
star
47

animate-styles

Composable CSS Animations Built On animate.css
JavaScript
14
star
48

tic

⌛ setInterval/setTimeout using a delta tick. Useful for timing things with games.
JavaScript
14
star
49

voxel-avatar

Overlay an image or video on a minecraft skin in voxel.js
JavaScript
12
star
50

grunt-minjson

A Grunt plugin for minifying json files.
JavaScript
11
star
51

whatever_modules

❓ Finally! We can rename the `node_modules` folder to whatever we want. The tyranny is over! Now we can put whatever modules we want in there! Wooo!
JavaScript
11
star
52

CakePHP-Wordpress-Component

THIS REPOSITORY IS DEPRECATED
PHP
11
star
53

voxel-portal-gun

A portal gun in voxel.js
JavaScript
11
star
54

first-person-camera

A generic first person camera for WebGL.
JavaScript
10
star
55

blaster

🔫 A router for generating a static site that can turn into a single page app
JavaScript
10
star
56

attach-css

💅 Localizes CSS based on a virtual DOM tree.
JavaScript
10
star
57

computed-proxy

Computed properties with JavaScript Proxy
JavaScript
10
star
58

jmpress.js

This repo has moved! The repo you are looking for is now at jmpressjs/jmpress.js.
10
star
59

dtype

Return a data type from a string representing the type
JavaScript
9
star
60

button-styles

Modular CSS button styles
JavaScript
9
star
61

voxel-clouds

🎲☁️ Clouds for voxel.js
JavaScript
9
star
62

oven

A CakePHP 2 Re-Baker and CMS Plugin / BETA
PHP
9
star
63

voxel-trajectory

Calculate trajectories in voxel.js
JavaScript
9
star
64

grunt-jam

A Grunt task for compiling Jam packages
JavaScript
8
star
65

voxel-throw

Pick up and throw voxels in voxel.js
JavaScript
8
star
66

ember-templates-loader

Load templates into Ember with webpack.
JavaScript
8
star
67

freshcake

FreshBooks API Wrapper for CakePHP
PHP
8
star
68

grunt-openport

A grunt plugin to find open ports
JavaScript
8
star
69

cake-grunt-compass

An example CakePHP app that uses Grunt, Compass and JamJS.
JavaScript
8
star
70

filepicker-element

An button for opening the file picker dialog and returning the files picked.
JavaScript
8
star
71

locastore

👝 A localStorage wrapper that falls back to memory in private browsing mode.
JavaScript
7
star
72

voxel-ssao

Experimental SSAO for voxel.js
JavaScript
6
star
73

voxel-tile

Load google map or open street map tiles into http://voxeljs.com.
JavaScript
6
star
74

voxel-infinite

A WIP infinite voxel world generator
JavaScript
5
star
75

grunt-net

Run grunt tasks over a network using dnode.
JavaScript
5
star
76

voxel-debug

Debug helpers for voxel.js
JavaScript
5
star
77

voxel-camera

A video camera for voxeljs.com
JavaScript
5
star
78

webpack-yo-yo

An example using yo-yo with webpack
JavaScript
5
star
79

gruntfile

Gruntfile helper for making modular gruntfiles.
JavaScript
5
star
80

flatearth

Flatten all your nested deps just like the earth.
JavaScript
5
star
81

CakePHP-Dropbox-Component

THIS REPOSITORY IS DEPRECATED
PHP
4
star
82

drone-hud

A WIP HUD for drone-video (https://github.com/TooTallNate/node-drone-video)
JavaScript
4
star
83

twitterbootcake

Twitter Bootstrap CakePHP Admin Theme
PHP
4
star
84

leveler

A streaming stat leveling API.
JavaScript
4
star
85

dom-tilemap

Render a tilemap from a ndarray to the DOM.
JavaScript
4
star
86

eatcake

A convenient way to install CakePHP with Composer.
PHP
4
star
87

willitmerge

A command line tool to check if pull requests are mergeable.
JavaScript
4
star
88

gamescript

an event based game engine
JavaScript
4
star
89

grunt-step

🐗🐾 Add confirmation steps to your Grunt flow.
JavaScript
4
star
90

grunt-required

A Grunt task for detecting required modules and option to automatically install with npm.
JavaScript
4
star
91

base-svg-element

A layer on base-element for SVG elements.
JavaScript
3
star
92

cruveejs

cruveejs: A Cruvee API Wrapper for NodeJS
JavaScript
3
star
93

shama

Things for helping me build other things.
JavaScript
3
star
94

grunt-willitmerge

A Grunt plugin to check if open Github pull requests can be merged.
JavaScript
3
star
95

checkbox-element

☑️ A basic checkbox element built on a virtual DOM.
JavaScript
3
star
96

beep_game

JavaScript
3
star
97

voxel-settings

voxel.js setting config for cettings
JavaScript
3
star
98

metamorph

Morphs package meta files into each other.
JavaScript
3
star
99

grunt-prompts

Built-in prompts for a grunt style generator.
JavaScript
3
star
100

browser-test-helpers

A small set of generic test helpers for browser interaction tests.
JavaScript
3
star