Files
archived-nodemon/lib/monitor/changed-since.js
Remy Sharp b0fd56f7de refactor: move watch out in favour of chokidar
Plus jscs clean ups
2015-08-31 18:25:55 +01:00

57 lines
1.4 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
var fs = require('fs');
var config = require('../config');
var path = require('path');
module.exports = changedSince;
// This is a fallback function is only used if fs.watch does not work
function changedSince(time, dir, callback) {
if (!callback) {
callback = dir;
}
var changed = [],
todo = 0,
done = function () { // why you no use async, remy? Remy
todo--;
if (todo === 0) {
callback(changed);
}
};
dir = dir && typeof dir !== 'function' ? [dir] : config.dirs;
dir.forEach(function (dir) {
todo++;
fs.readdir(dir, function (err, files) {
if (err) {
done();
return;
}
files.forEach(function (file) {
if (config.options.hidden === true || !config.options.hidden && file.indexOf('.') !== 0) {
todo++;
file = path.resolve(dir + path.sep + file);
fs.stat(file, function (err, stat) {
if (stat) {
if (stat.isDirectory()) {
todo++;
changedSince(time, file, function (subChanged) {
if (subChanged.length) {
changed = changed.concat(subChanged);
}
done();
});
} else if (stat.mtime > time) {
changed.push(file);
}
}
done();
});
}
});
done();
});
});
}