Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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 be2fe18
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 40 deletions.
10 changes: 5 additions & 5 deletions lib/codex/cli/index.js
Expand Up @@ -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) {
Expand Down
35 changes: 0 additions & 35 deletions lib/codex/utils/fs.js
Expand Up @@ -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.