mirror of
https://github.com/SrIzan10/nodemon.git
synced 2026-05-01 10:55:09 +00:00
57 lines
1.4 KiB
JavaScript
57 lines
1.4 KiB
JavaScript
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();
|
||
});
|
||
});
|
||
} |