diff --git a/types/gaze/gaze-tests.ts b/types/gaze/gaze-tests.ts new file mode 100644 index 0000000000..3db5c45fb1 --- /dev/null +++ b/types/gaze/gaze-tests.ts @@ -0,0 +1,29 @@ +import gaze = require('gaze'); + +gaze('**/*.js', null, (err, watcher) => { + watcher.watched(); + watcher.relative('./', false); +}); +gaze(['stylesheets/*.css', 'images/**/*.png'], { + interval: 5, + debounceDelay: 10, + mode: "auto", + cwd: './' +}, (err, watcher) => { + watcher.add(['js/*.js']); +}); + +const gazeInstance = new gaze.Gaze('**/*.js', null, (err, watcher) => { + watcher.add('file.js'); + watcher.close(); + watcher.emit('ready'); + watcher.remove('file.js'); + watcher.watched(); + watcher.relative('.', true); +}); +gazeInstance.add('file.js'); +gazeInstance.close(); +gazeInstance.emit('ready'); +gazeInstance.remove('file.js'); +gazeInstance.watched(); +gazeInstance.relative('.', true); diff --git a/types/gaze/index.d.ts b/types/gaze/index.d.ts new file mode 100644 index 0000000000..f2aaf55dda --- /dev/null +++ b/types/gaze/index.d.ts @@ -0,0 +1,75 @@ +// Type definitions for gaze 1.1 +// Project: https://github.com/shama/gaze +// Definitions by: Adam Zerella +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// Minimum TypeScript Version: 3.1 + +type Mode = 'auto' | 'watch' | 'poll'; + +interface Options { + /** + * Interval to pass to fs.watchFile. + */ + interval?: number; + /** + * Delay for events called in succession for the same file/event in milliseconds. + */ + debounceDelay?: number; + /** + * Force the watch mode. Either 'auto' (default), + * 'watch' (force native events), or 'poll' (force stat polling). + */ + mode?: Mode; + /** + * The current working directory to base file patterns from. Default is `process.cwd()`. + */ + cwd?: string; +} + +declare namespace gaze { + class Gaze { + constructor( + patterns: string | string[], + options?: Options | null, + callback?: (error: Error | null, watcher: Gaze) => void + ); + + /** + * Wrapper for EventEmitter.emit. `added`|`changed`|`renamed`|`deleted` events will also trigger the `all` event. + */ + emit(event: string, ...args: any): boolean; + + /** + * Unwatch all files and reset the watch instance. + */ + close(): void; + + /** + * Adds file(s) patterns to be watched. + */ + add(patterns: string | string[]): void; + + /** + * Removes a file or directory from being watched. Does not recurse directories. + */ + remove(filepath: string): void; + + /** + * Returns the currently watched files. + */ + watched(): string[]; + + /** + * Returns the currently watched files with relative paths. + */ + relative(dir: string, unixify: boolean): string[]; + } +} + +declare function gaze( + patterns: string | string[], + options?: Options | null, + callback?: (error: Error | null, watcher: gaze.Gaze) => void +): void; + +export = gaze; diff --git a/types/gaze/tsconfig.json b/types/gaze/tsconfig.json new file mode 100644 index 0000000000..440159cdd7 --- /dev/null +++ b/types/gaze/tsconfig.json @@ -0,0 +1,25 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [ + + ], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "gaze-tests.ts" + ] +} diff --git a/types/gaze/tslint.json b/types/gaze/tslint.json new file mode 100644 index 0000000000..e60c15844f --- /dev/null +++ b/types/gaze/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "dtslint/dt.json" +} \ No newline at end of file