Permalink
Browse files

Using `fs.watch` for Windows compatibility.

Now watches whole directories, not specific files. Allows removal of lots of code from utils/fs.
  • Loading branch information...
domenic committed May 2, 2012
1 parent 5c1a367 commit be2fe18f5561f7bbd3bd0099bb47f7e58c23638d
Showing with 5 additions and 40 deletions.
  1. +5 −5 lib/codex/cli/index.js
  2. +0 −35 lib/codex/utils/fs.js
@@ -234,16 +234,16 @@ cli.on('watch', function (args) {
logObject('error', d.data);
});
var files = _.files(opts.dataDir);
files = files.concat(_.files(opts.templateDir));
_.watch(files, function (file) {
function rebuild() {
project.flush();
project.build(function () {
log.info('Project rebuilt successfully');
log.info('Watching...');
});
});
}
fs.watch(opts.dataDir, rebuild);
fs.watch(opts.templateDir, rebuild);
});
function padAfter (str, len) {
@@ -42,38 +42,3 @@ exports.mkdir = function (_path, mode, callback) {
callback(null);
});
};
var ignore = [ 'node_modules', '.git' ];
function ignored (file) {
return !~ignore.indexOf(file);
}
var extension = [ '.js' ,'.jade', '.md', '.styl', '.json' ];
function ext (file) {
var ex = path.extname(file);
return ~extension.indexOf(ex);
}
exports.files = function (dir, arr) {
arr = arr || [];
fs.readdirSync(dir)
.filter(ignored)
.forEach(function (p) {
p = path.join(dir, p);
if (fs.statSync(p).isDirectory()){
exports.files(p, arr);
} else if (ext(p)) {
arr.push(p);
}
});
return arr;
};
exports.watch = function (files, fn) {
var options = { intervale: 100 };
files.forEach(function (file) {
fs.watchFile(file, options, function (c, p) {
if (p.mtime < c.mtime) fn(file);
});
});
};

0 comments on commit be2fe18

Please sign in to comment.