1 |
|
2 |
|
3 |
|
4 |
|
5 | var path = require("path");
|
6 |
|
7 | function WatcherManager() {
|
8 | this.directoryWatchers = {};
|
9 | }
|
10 |
|
11 | WatcherManager.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 |
|
24 | WatcherManager.prototype.watchFile = function watchFile(p, options, startTime) {
|
25 | var directory = path.dirname(p);
|
26 | return this.getDirectoryWatcher(directory, options).watch(p, startTime);
|
27 | };
|
28 |
|
29 | WatcherManager.prototype.watchDirectory = function watchDirectory(directory, options, startTime) {
|
30 | return this.getDirectoryWatcher(directory, options).watch(directory, startTime);
|
31 | };
|
32 |
|
33 | module.exports = new WatcherManager();
|