support/watcher.js
function getWatcher(dir) {
    return function (event, fileName) {
        if (event === "rename") {
            verifyWatches();
            if (fileName) {
                if (!fs.existsSync(dir + fileName)) { return; }
                var dirStat;
                try {
                    dirStat = fs.statSync(dir + fileName);
                } catch (err) {
                    // This means the File disappeared out from under me...
                    return;
                }
                if (dirStat.isDirectory()) {
                    if (!watchingFolders[dir + fileName]) {
                        console.log("Adding new directory to watch: ", dir + fileName);
                        setupWatchers(dir + fileName);
                    }
                    return;
                }
            } else {
                checkForChangedFolders(dir);
            }
            return;
        }

        if (!fileName) {
            fileName = checkForChangedFiles(dir);
            if (fileName) {
                checkCache(fileName);
            }
        }
        else {
            if (isWatching(fileName)) {
                if (!fs.existsSync(dir + fileName)) {
                    return;
                }

                var stat;
                try {
                    stat = fs.statSync(dir + fileName);
                }
                catch (e) {
                    // This means the file disappeared between exists and stat...
                    return;
                }
                if (stat.size === 0) { return; }
                if (timeStamps[dir + fileName] === undefined || timeStamps[dir + fileName] !== stat.mtime.getTime()) {
                    //console.log("Found 2: ", event, dir+fileName, stat.mtime.getTime(), stat.mtime, stat.ctime.getTime(), stat.size);
                    timeStamps[dir + fileName] = stat.mtime.getTime();
                    checkCache(dir + fileName);
                }

            }

        }
    };
}
function getWatcher(dir) {
    return function (event, fileName) {
        if (event === "rename") {
            verifyWatches();
            if (fileName) {
                if (!fs.existsSync(dir + fileName)) { return; }
                var dirStat;
                try {
                    dirStat = fs.statSync(dir + fileName);
                } catch (err) {
                    // This means the File disappeared out from under me...
                    return;
                }
                if (dirStat.isDirectory()) {
                    if (!watchingFolders[dir + fileName]) {
                        console.log("Adding new directory to watch: ", dir + fileName);
                        setupWatchers(dir + fileName);
                    }
                    return;
                }
            } else {
                checkForChangedFolders(dir);
            }
            return;
        }

        if (!fileName) {
            fileName = checkForChangedFiles(dir);
            if (fileName) {
                checkCache(fileName);
            }
        }
        else {
            if (isWatching(fileName)) {
                if (!fs.existsSync(dir + fileName)) {
                    return;
                }

                var stat;
                try {
                    stat = fs.statSync(dir + fileName);
                }
                catch (e) {
                    // This means the file disappeared between exists and stat...
                    return;
                }
                if (stat.size === 0) { return; }
                if (timeStamps[dir + fileName] === undefined || timeStamps[dir + fileName] !== stat.mtime.getTime()) {
                    //console.log("Found 2: ", event, dir+fileName, stat.mtime.getTime(), stat.mtime, stat.ctime.getTime(), stat.size);
                    timeStamps[dir + fileName] = stat.mtime.getTime();
                    checkCache(dir + fileName);
                }

            }

        }
    };
}
function getWatcher ( dir ) { return function ( event , fileName ) { if ( event === "rename" ) { verifyWatches ( ) ; if ( fileName ) { if ( ! fs . existsSync ( dir + fileName ) ) { return ; } var dirStat ; try { dirStat = fs . statSync ( dir + fileName ) ; } catch ( err ) { // This means the File disappeared out from under me... return ; } if ( dirStat . isDirectory ( ) ) { if ( ! watchingFolders [ dir + fileName ] ) { console . log ( "Adding new directory to watch: " , dir + fileName ) ; setupWatchers ( dir + fileName ) ; } return ; } } else { checkForChangedFolders ( dir ) ; } return ; } if ( ! fileName ) { fileName = checkForChangedFiles ( dir ) ; if ( fileName ) { checkCache ( fileName ) ; } } else { if ( isWatching ( fileName ) ) { if ( ! fs . existsSync ( dir + fileName ) ) { return ; } var stat ; try { stat = fs . statSync ( dir + fileName ) ; } catch ( e ) { // This means the file disappeared between exists and stat... return ; } if ( stat . size === 0 ) { return ; } if ( timeStamps [ dir + fileName ] === undefined || timeStamps [ dir + fileName ] !== stat . mtime . getTime ( ) ) { //console.log("Found 2: ", event, dir+fileName, stat.mtime.getTime(), stat.mtime, stat.ctime.getTime(), stat.size); timeStamps [ dir + fileName ] = stat . mtime . getTime ( ) ; checkCache ( dir + fileName ) ; } } } } ; }
This is the watcher callback to verify the file actually changed
@param dir
@returns {Function}
This is the watcher callback to verify the file actually changed