Permalink
Browse files

Added opts to file watch, more file-extensions in the default

  • Loading branch information...
1 parent e9761b9 commit 526cf3caab2c135f01ff5eec9955f1fb428877fe @mde committed May 30, 2013
Showing with 15 additions and 4 deletions.
  1. +15 −4 lib/file.js
View
@@ -18,7 +18,7 @@
var fs = require('fs')
, path = require('path')
- , JS_PAT = /\.(js|coffee)$/
+ , DEFAULT_FILE_PAT = /\.(js|coffee|css|less|scss)$/
, logger;
var logger = new (function () {
@@ -176,12 +176,23 @@ var fileUtils = new (function () {
};
// Recursively watch files with a callback
- _watch = function (path, callback) {
+ _watch = function () {
+ var args = Array.prototype.slice.call(arguments)
+ , path
+ , opts
+ , callback
+ , pat;
+
+ path = args.shift();
+ callback = args.pop();
+ opts = args.pop() || {};
+ pat = opts.pattern || DEFAULT_FILE_PAT;
+
fs.stat(path, function (err, stats) {
if (err) {
return false;
}
- if (stats.isFile() && JS_PAT.test(path)) {
+ if (stats.isFile() && pat.test(path)) {
fs.watchFile(path, callback);
}
else if (stats.isDirectory()) {
@@ -190,7 +201,7 @@ var fileUtils = new (function () {
return log.fatal(err);
}
for (var f in files) {
- _watch(path + '/' + files[f], callback);
+ _watch(path + '/' + files[f], opts, callback);
}
});
}

0 comments on commit 526cf3c

Please sign in to comment.