UNPKG

1.12 kBJavaScriptView Raw
1/*
2 MIT License http://www.opensource.org/licenses/mit-license.php
3 Author Tobias Koppers @sokra
4*/
5var path = require("path");
6
7function WatcherManager() {
8 this.directoryWatchers = {};
9}
10
11WatcherManager.prototype.getDirectoryWatcher = function(directory, options) {
12 var DirectoryWatcher = require("./DirectoryWatcher");
13 options = options || {};
14 var key = directory + " " + JSON.stringify(options);
15 if(!this.directoryWatchers[key]) {
16 this.directoryWatchers[key] = new DirectoryWatcher(directory, options);
17 this.directoryWatchers[key].on("closed", function() {
18 delete this.directoryWatchers[key];
19 }.bind(this));
20 }
21 return this.directoryWatchers[key];
22};
23
24WatcherManager.prototype.watchFile = function watchFile(p, options, startTime) {
25 var directory = path.dirname(p);
26 return this.getDirectoryWatcher(directory, options).watch(p, startTime);
27};
28
29WatcherManager.prototype.watchDirectory = function watchDirectory(directory, options, startTime) {
30 return this.getDirectoryWatcher(directory, options).watch(directory, startTime);
31};
32
33module.exports = new WatcherManager();