Skip to content

Commit be2fe18

Browse files
committed
Using fs.watch for Windows compatibility.
Now watches whole directories, not specific files. Allows removal of lots of code from utils/fs.
1 parent 5c1a367 commit be2fe18

File tree

2 files changed

+5
-40
lines changed

2 files changed

+5
-40
lines changed

lib/codex/cli/index.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -234,16 +234,16 @@ cli.on('watch', function (args) {
234234
logObject('error', d.data);
235235
});
236236

237-
var files = _.files(opts.dataDir);
238-
files = files.concat(_.files(opts.templateDir));
239-
240-
_.watch(files, function (file) {
237+
function rebuild() {
241238
project.flush();
242239
project.build(function () {
243240
log.info('Project rebuilt successfully');
244241
log.info('Watching...');
245242
});
246-
});
243+
}
244+
245+
fs.watch(opts.dataDir, rebuild);
246+
fs.watch(opts.templateDir, rebuild);
247247
});
248248

249249
function padAfter (str, len) {

lib/codex/utils/fs.js

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -42,38 +42,3 @@ exports.mkdir = function (_path, mode, callback) {
4242
callback(null);
4343
});
4444
};
45-
46-
var ignore = [ 'node_modules', '.git' ];
47-
function ignored (file) {
48-
return !~ignore.indexOf(file);
49-
}
50-
51-
var extension = [ '.js' ,'.jade', '.md', '.styl', '.json' ];
52-
function ext (file) {
53-
var ex = path.extname(file);
54-
return ~extension.indexOf(ex);
55-
}
56-
57-
exports.files = function (dir, arr) {
58-
arr = arr || [];
59-
fs.readdirSync(dir)
60-
.filter(ignored)
61-
.forEach(function (p) {
62-
p = path.join(dir, p);
63-
if (fs.statSync(p).isDirectory()){
64-
exports.files(p, arr);
65-
} else if (ext(p)) {
66-
arr.push(p);
67-
}
68-
});
69-
return arr;
70-
};
71-
72-
exports.watch = function (files, fn) {
73-
var options = { intervale: 100 };
74-
files.forEach(function (file) {
75-
fs.watchFile(file, options, function (c, p) {
76-
if (p.mtime < c.mtime) fn(file);
77-
});
78-
});
79-
};

0 commit comments

Comments
 (0)