forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request DefinitelyTyped#3796 from reppners/chokidar
+ chokidar type defs including tests
- Loading branch information
Showing
2 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/// <reference path="chokidar.d.ts" /> | ||
|
||
import fs = require('fs'); | ||
import chokidar = require('chokidar'); | ||
|
||
var watcher = chokidar.watch('file, dir, or glob', { | ||
ignored: /[\/\\]\./, persistent: true | ||
}); | ||
|
||
var log = console.log.bind(console); | ||
|
||
watcher | ||
.on('add', function(path:string) { log('File', path, 'has been added'); }) | ||
.on('addDir', function(path:string) { log('Directory', path, 'has been added'); }) | ||
.on('change', function(path:string) { log('File', path, 'has been changed'); }) | ||
.on('unlink', function(path:string) { log('File', path, 'has been removed'); }) | ||
.on('unlinkDir', function(path:string) { log('Directory', path, 'has been removed'); }) | ||
.on('error', function(error:any) { log('Error happened', error); }) | ||
.on('ready', function() { log('Initial scan complete. Ready for changes.'); }) | ||
.on('raw', function(event:Event, path:string, details:any) { log('Raw event info:', event, path, details); }) | ||
|
||
// 'add', 'addDir' and 'change' events also receive stat() results as second | ||
// argument when available: http://nodejs.org/api/fs.html#fs_class_fs_stats | ||
watcher.on('change', function(path:string, stats:fs.Stats) { | ||
if (stats) console.log('File', path, 'changed size to', stats.size); | ||
}); | ||
|
||
// Watch new files. | ||
watcher.add('new-file'); | ||
watcher.add(['new-file-2', 'new-file-3', '**/other-file*']); | ||
|
||
// Un-watch some files. | ||
watcher.unwatch('new-file*'); | ||
|
||
// Only needed if watching is `persistent: true`. | ||
watcher.close(); | ||
|
||
// One-liner | ||
require('chokidar').watch('.', {ignored: /[\/\\]\./}).on('all', function(event:string, path:string) { | ||
console.log(event, path); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Type definitions for chokidar 1.0.0 | ||
// Project: https://github.com/paulmillr/chokidar | ||
// Definitions by: Stefan Steinhart <https://github.com/reppners/> | ||
// Definitions: https://github.com/borisyankov/DefinitelyTyped | ||
|
||
/// <reference path="../node/node.d.ts" /> | ||
|
||
declare module "fs" | ||
{ | ||
interface FSWatcher | ||
{ | ||
add(fileDirOrGlob:string):void; | ||
add(filesDirsOrGlobs:Array<string>):void; | ||
unwatch(fileDirOrGlob:string):void; | ||
unwatch(filesDirsOrGlobs:Array<string>):void; | ||
} | ||
} | ||
|
||
declare module "chokidar" | ||
{ | ||
interface WatchOptions | ||
{ | ||
persistent?:boolean; | ||
ignored?:any; | ||
ignoreInitial?:boolean; | ||
followSymlinks?:boolean; | ||
cwd?:string; | ||
usePolling?:boolean; | ||
useFsEvents?:boolean; | ||
alwaysStat?:boolean; | ||
depth?:number; | ||
interval?:number; | ||
binaryInterval?:number; | ||
ignorePermissionErrors?:boolean; | ||
atomic?:boolean; | ||
} | ||
|
||
import fs = require("fs"); | ||
|
||
function watch( fileDirOrGlob:string, options?:WatchOptions ):fs.FSWatcher; | ||
function watch( filesDirsOrGlobs:Array<string>, options?:WatchOptions ):fs.FSWatcher; | ||
} |