UNPKG

707 BJavaScriptView Raw
1
2'use strict';
3
4// Watch a file tree for changes using Gaze
5module.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};