support/watcher.js
function setupWatchers(path) {
    // We want to track the watchers now and return if we are already watching this folder
    if (watchingFolders[path]) { return; }

    watchingFolders[path] = fs.watch(path, getWatcher(path + "/"));
    watchingFolders[path].on('error', function() {  verifyWatches(); });
    var fileList = fs.readdirSync(path);
    var stats;
    for (var i = 0; i < fileList.length; i++) {
        try {
            stats = fs.statSync(path + "/" + fileList[i]);
        }
        catch (e) {
            continue;
        }
        if (isWatching(fileList[i])) {
            timeStamps[path + "/" + fileList[i]] = stats.mtime.getTime();
        } else {
            if (stats.isDirectory()) {
                if (fileList[i] === "node_modules") {
                    watchingFolders[path + "/" + fileList[i]] = true;
                    continue;
                }
                if (fileList[i] === "tns_modules") {
                    watchingFolders[path + "/" + fileList[i]] = true;
                    continue;
                }
                if (fileList[i] === "App_Resources") {
                    watchingFolders[path + "/" + fileList[i]] = true;
                    continue;
                }
                setupWatchers(path + "/" + fileList[i]);
            }
        }
    }
}
function setupWatchers(path) {
    // We want to track the watchers now and return if we are already watching this folder
    if (watchingFolders[path]) { return; }

    watchingFolders[path] = fs.watch(path, getWatcher(path + "/"));
    watchingFolders[path].on('error', function() {  verifyWatches(); });
    var fileList = fs.readdirSync(path);
    var stats;
    for (var i = 0; i < fileList.length; i++) {
        try {
            stats = fs.statSync(path + "/" + fileList[i]);
        }
        catch (e) {
            continue;
        }
        if (isWatching(fileList[i])) {
            timeStamps[path + "/" + fileList[i]] = stats.mtime.getTime();
        } else {
            if (stats.isDirectory()) {
                if (fileList[i] === "node_modules") {
                    watchingFolders[path + "/" + fileList[i]] = true;
                    continue;
                }
                if (fileList[i] === "tns_modules") {
                    watchingFolders[path + "/" + fileList[i]] = true;
                    continue;
                }
                if (fileList[i] === "App_Resources") {
                    watchingFolders[path + "/" + fileList[i]] = true;
                    continue;
                }
                setupWatchers(path + "/" + fileList[i]);
            }
        }
    }
}
function setupWatchers ( path ) { // We want to track the watchers now and return if we are already watching this folder if ( watchingFolders [ path ] ) { return ; } watchingFolders [ path ] = fs . watch ( path , getWatcher ( path + "/" ) ) ; watchingFolders [ path ] . on ( 'error' , function ( ) { verifyWatches ( ) ; } ) ; var fileList = fs . readdirSync ( path ) ; var stats ; for ( var i = 0 ; i < fileList . length ; i ++ ) { try { stats = fs . statSync ( path + "/" + fileList [ i ] ) ; } catch ( e ) { continue ; } if ( isWatching ( fileList [ i ] ) ) { timeStamps [ path + "/" + fileList [ i ] ] = stats . mtime . getTime ( ) ; } else { if ( stats . isDirectory ( ) ) { if ( fileList [ i ] === "node_modules" ) { watchingFolders [ path + "/" + fileList [ i ] ] = true ; continue ; } if ( fileList [ i ] === "tns_modules" ) { watchingFolders [ path + "/" + fileList [ i ] ] = true ; continue ; } if ( fileList [ i ] === "App_Resources" ) { watchingFolders [ path + "/" + fileList [ i ] ] = true ; continue ; } setupWatchers ( path + "/" + fileList [ i ] ) ; } } } }
This setups a watcher on a directory
@param path
This setups a watcher on a directory