UNPKG

typescript-assistant

Version:

Combines and integrates professional Typescript tools into your project

30 lines (26 loc) 787 B
import * as chokidar from "chokidar"; import { Bus } from "./bus"; export interface Watcher { watchSourceFileChanged(): void; } export let createWatcher = (dependencies: { bus: Bus }): Watcher => { let { bus } = dependencies; return { watchSourceFileChanged: () => { let timeout: any; let watch = chokidar.watch("./**/*.ts", { ignored: [".d.ts", "node_modules", "build/**/*", "dist/**/*"], ignoreInitial: true, }); watch.on("all", () => { // batch events for a short amount of time to catch an IDE doing a save-all if (timeout === undefined) { timeout = setTimeout(() => { timeout = undefined; bus.signal("source-files-changed"); }, 200); } }); }, }; };