UNPKG

1.75 kBTypeScriptView Raw
1// Imported from: https://github.com/soywiz/typescript-node-definitions/watch.d.ts
2
3/// <reference types="node" />
4
5import fs = require("fs");
6import events = require("events");
7
8export interface Files {
9 [key: string]: fs.Stats;
10}
11
12export interface Monitor extends events.EventEmitter {
13 files: Files;
14
15 on(event: "created" | "removed", listener: (f: string, stat: fs.Stats) => void): this;
16 on(event: "changed", listener: (f: string, current: fs.Stats, prev: fs.Stats) => void): this;
17 on(event: string, listener: (...args: any[]) => void): this;
18 stop(): void;
19}
20
21export interface BaseOptions {
22 ignoreDotFiles?: boolean | undefined;
23 filter?(path: string, stat: fs.Stats): boolean;
24}
25
26export interface Options extends BaseOptions {
27 interval?: number | undefined;
28}
29
30export interface WalkOptions extends BaseOptions {
31 ignoreUnreadableDir?: boolean | undefined;
32 ignoreNotPermitted?: boolean | undefined;
33 ignoreDirectoryPattern?: RegExp | undefined;
34}
35
36export function watchTree(root: string, callback: (f: string, curr: fs.Stats, prev: fs.Stats) => void): void;
37export function watchTree(
38 root: string,
39 options: Options,
40 callback: (f: string, curr: fs.Stats, prev: fs.Stats) => void,
41): void;
42export function unwatchTree(root: string): void;
43export function createMonitor(root: string, callback: (monitor: Monitor) => void): void;
44export function createMonitor(root: string, options: Options, callback: (monitor: Monitor) => void): void;
45export function walk(root: string, callback: (error: Error | null, files: Files | undefined) => void): void;
46export function walk(
47 root: string,
48 options: WalkOptions,
49 callback: (error: Error | null, files: Files | undefined) => void,
50): void;