lib/dev.js
function watchModule (module, modulesDir) {

    const pathToModule = resolve(modulesDir, module);
    const pathToHandlers = resolve(HANDLER_BASE, module);


    modules[module] = {
        handlers: []
    };
    fs.readdir(pathToHandlers, (err, files) => {

        if (err) {
            return console.log(new Error('Failed to get handler files for module: ' + module));
        }

        files.forEach(file => {

            if (file.length < 3 || file.indexOf('bundle.') === 0 || file.substr(file.length - 3) !== '.js') {
                return;
            }

            modules[module].handlers.push(pathToHandlers + '/' + file);
        });

        let watchList = modules[module].handlers.concat([pathToModule]);
        let watcher = chokidar.watch(watchList, {
            ignored: /(^|[\/\\])\../,
            persistent: true
        });
        watcher.on('change', (path, stats) => {

            // rebundle based on the type of the file
            if (modules[module].handlers.indexOf(path) < 0) {
                modules[module].handlers.forEach(handler => bundleHandler(pathToHandlers, module, handler.substr(handler.lastIndexOf('/') + 1)));
            } else {
                bundleHandler(pathToHandlers, module, path.substr(path.lastIndexOf('/') + 1));
            }
        });
    });
}
function watchModule (module, modulesDir) {

    const pathToModule = resolve(modulesDir, module);
    const pathToHandlers = resolve(HANDLER_BASE, module);


    modules[module] = {
        handlers: []
    };
    fs.readdir(pathToHandlers, (err, files) => {

        if (err) {
            return console.log(new Error('Failed to get handler files for module: ' + module));
        }

        files.forEach(file => {

            if (file.length < 3 || file.indexOf('bundle.') === 0 || file.substr(file.length - 3) !== '.js') {
                return;
            }

            modules[module].handlers.push(pathToHandlers + '/' + file);
        });

        let watchList = modules[module].handlers.concat([pathToModule]);
        let watcher = chokidar.watch(watchList, {
            ignored: /(^|[\/\\])\../,
            persistent: true
        });
        watcher.on('change', (path, stats) => {

            // rebundle based on the type of the file
            if (modules[module].handlers.indexOf(path) < 0) {
                modules[module].handlers.forEach(handler => bundleHandler(pathToHandlers, module, handler.substr(handler.lastIndexOf('/') + 1)));
            } else {
                bundleHandler(pathToHandlers, module, path.substr(path.lastIndexOf('/') + 1));
            }
        });
    });
}
function watchModule ( module , modulesDir ) { const pathToModule = resolve ( modulesDir , module ) ; const pathToHandlers = resolve ( HANDLER_BASE , module ) ; modules [ module ] = { handlers : [ ] } ; fs . readdir ( pathToHandlers , ( err , files ) => { if ( err ) { return console . log ( new Error ( 'Failed to get handler files for module: ' + module ) ) ; } files . forEach ( file => { if ( file . length < 3 || file . indexOf ( 'bundle.' ) === 0 || file . substr ( file . length - 3 ) !== '.js' ) { return ; } modules [ module ] . handlers . push ( pathToHandlers + '/' + file ) ; } ) ; let watchList = modules [ module ] . handlers . concat ( [ pathToModule ] ) ; let watcher = chokidar . watch ( watchList , { ignored : / (^|[\/\\])\.. / , persistent : true } ) ; watcher . on ( 'change' , ( path , stats ) => { // rebundle based on the type of the file if ( modules [ module ] . handlers . indexOf ( path ) < 0 ) { modules [ module ] . handlers . forEach ( handler => bundleHandler ( pathToHandlers , module , handler . substr ( handler . lastIndexOf ( '/' ) + 1 ) ) ) ; } else { bundleHandler ( pathToHandlers , module , path . substr ( path . lastIndexOf ( '/' ) + 1 ) ) ; } } ) ; } ) ; }
this will watch for changes in a module or its handlers
this will watch for changes in a module or its handlers