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