1 |
|
2 | 'use strict';
|
3 |
|
4 |
|
5 | module.exports = function (extension) {
|
6 | var constructGlob = function (dirpath) {
|
7 | var glob = '/**/*' + extension;
|
8 | return dirpath + glob;
|
9 | };
|
10 |
|
11 | var watchTree = function (directories, log) {
|
12 | var Gaze = require('gaze');
|
13 | var watchedDirs = (typeof directories === 'string') ? constructGlob(directories) : directories.map(constructGlob);
|
14 | var watcher = new Gaze(watchedDirs);
|
15 | watcher.on('added', function (path) {
|
16 | watcher.emit('fileCreated', path);
|
17 | });
|
18 | watcher.on('changed', function (path) {
|
19 | watcher.emit('fileModified', path);
|
20 | });
|
21 | watcher.on('error', log.error);
|
22 | return watcher;
|
23 | };
|
24 |
|
25 | return {
|
26 | watchTree: watchTree
|
27 | };
|
28 | };
|