How to use the watch.watchTree function in watch

To help you get started, we’ve selected a few watch examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github JetBrains / ring-ui / tools / watch-doc.js View on Github external
};

function runScript(scriptPath, args, callback) {
  var process = childProcess.fork(scriptPath, args);

  process.on('error', callback);

  process.on('exit', function (code) {
    var err = code === 0 ? null : new Error('exit code ' + code);
    callback(err);
  });
}

var isAlreadyGenerating = false;

watch.watchTree(watchPath, watchOptions, function onChange(file, curr, prev) {

  if (typeof file === 'string' && prev !== null && curr !== null && curr.nlink !== 0) {
    // file was changed
    var fileName = file.match(/[\w.-]+$/)[0];
    console.log('File changed:', fileName);

    if (isAlreadyGenerating){
      console.log('Documentation generation is in progress, change skipped');
      return;
    }

    isAlreadyGenerating = true;
    runScript(path.resolve(__dirname, './generate-documentation.js'), [fileName], function (err) {
      isAlreadyGenerating = false;
      if (err) {
        console.log(err);
github davidmurdoch / shopify-theme-sync / app.js View on Github external
function watchShop ( shopConfig ) {
	var directory = shopConfig.directory;
	if ( directory ) {
		if ( fs.existsSync( directory ) ) {

			var shopify = new ShopifySyncer( shopConfig ),
				shopOptions = shopConfig.options;

			console.log( util.format( "Walking directory tree: %s\n", directory) );

			watch.watchTree( directory, shopOptions, function sync( f, curr, prev ) {
				if ( typeof f == "object" && prev === null && curr === null ) {
					// we're done walking!

					console.log( util.format( "Now watching directory tree: %s\n", directory ).rainbow );
				}

				// we can't actually delete the root (at Shopify), so don't try.
				else if ( f !== directory ) {

					// `walk` sometimes lets dot files through (usually on creation), so we need to double check.
					if ( shopOptions.ignoreDotFiles && path.basename(f)[0] === "." ) {
						console.log( util.format( "dotFile file ignored: %s\n", f ) );
						return;
					}

					// `walk` sometimes lets filtered files through (usually on creation), so we need to double check.
github google / clasp / src / commands / push.ts View on Github external
export default async (cmd: { watch: boolean; force: boolean }) => {
  await checkIfOnline();
  await loadAPICredentials();
  await isValidManifest();
  const { rootDir } = await getProjectSettings();

  if (cmd.watch) {
    console.log(LOG.PUSH_WATCH);
    const patterns = await DOTFILE.IGNORE();
    /**
     * @see https://www.npmjs.com/package/watch
     */
    // TODO check alternative https://github.com/paulmillr/chokidar
    watchTree(rootDir || '.', async (f, curr, prev) => {
      // The first watch doesn't give a string for some reason.
      if (typeof f === 'string') {
        console.log(`\n${LOG.PUSH_WATCH_UPDATED(f)}\n`);
        if (multimatch([f], patterns, { dot: true }).length) {
          // The file matches the ignored files patterns so we do nothing
          return;
        }
      }
      if (!cmd.force && (await manifestHasChanges()) && !(await confirmManifestUpdate())) {
        console.log('Stopping push...');
        return;
      }
      console.log(LOG.PUSHING);
      pushFiles();
    });
  } else {
github partageit / vegetables / lib / serve.js View on Github external
logger.success('Vegetables started, at this address: localhost:' + config.port);
	logger.info('It is available %s', (config.host ? 'from this computer only' : 'from your network'));

	require('./generate')(argv, true, function(err) {
		if (err) {
			logger.error('First regeneration finished with errors');
		}
		if (config.serveAutoOpen) {
			openBrowser('http://localhost:' + config.port);
		}
		logger.info('Waiting for file updates...');
	});

	var firstTime = true;
	// and watch:
	watch.watchTree(
		'.',
		{
			'ignoreDotFiles': true,
			'ignoreUnreadableDir': true,
			'filter': function(file) {
				// watch template, root, not .vegetables
				if (['.vegetables', 'node_modules'].indexOf(file.split(path.sep)[0]) !== -1) {
					return false;
				}
				logger.debug('Watched file:', file);
				return true;
			}
		},
		function (f) {
			if (firstTime) {
				firstTime = false;
github kupriyanenko / jsttojs / lib / jsttojs.js View on Github external
compile: function(options, callback) {
    this.options = options;
    this.createWalker(callback);

    if (this.options.watch) {
      console.log(moment().format('[[]h:mm:ss YYYY-D-MM[]] ') + 'watch start...');

      watch.watchTree(this.options.root, {
          interval: 1000
        }, function (f, curr, prev) {
        if (typeof f == 'object' && prev === null && curr === null) {
          // Finished walking the tree
        } else {
          this.createWalker(callback);
        }
      }.bind(this));
    }
  }
}
github magicode / express-hot-reload / run.js View on Github external
}

function loadApp(){
	var loadDomain = domain.create();	
	loadDomain.on('error', function(err) { console.error(err.stack); });
	loadDomain.run(function(){
		require(appFile)(obj);
	});
	return loadDomain;
}
    
loadApp();
 
var willReload = false;

watch.watchTree( __dirname ,  
		{ filter: function(f,stats){ return !(/(.js|.json)$/).test(f) && stats.isFile(); } }  , 
		function (f, curr, prev) {
			if (typeof f == "object" && prev === null && curr === null) { } else {
				
				if(willReload) return; willReload = true;
				setTimeout(function(){
					willReload = false;
					clearCache();
					loadApp();
					console.log("reload app");
				},1000);
				
			}
});

http.createServer(function(){
github boscoh / embellish / embellish.js View on Github external
function watchSite(site) {
  let finalhandler = require("finalhandler");
  let serveStatic = require("serve-static");
  let serve = serveStatic(site.outputDir);

  require("http")
    .createServer((req, res) => serve(req, res, finalhandler(req, res)))
    .listen(8000);

  console.log("Serving on http://localhost:8000");

  require("watch").watchTree(site.contentDir, f => processSite(site));

  console.log(`Watching files in ${site.contentDir}`);
}
github santoshrajan / lispyscript / lib / lispy.js View on Github external
(function() {
                            var cwd = process.cwd();
                            console.log('Watching',cwd,'for .ls file changes...');
                            watch.watchTree(cwd,{
                                filter: function(f,stat) {
                                    return (stat.isDirectory() || (f.indexOf('.ls') !== -1));
                                },
                                ignoreDotFiles: true,
                                ignoreDirectoryPattern: /node_modules/
                            },function(f,curr,prev) {
                                return ((curr && (curr.nlink !== 0)) ?
                                    (require("child_process")).spawn("lispy",[f.substring(cwd.length+1)],{stdio: "inherit"}) :
                                    (((Object.prototype.toString.call(f) === "[object Object]") && (prev === null) && (curr === null)) ?
                                        (function(o,f,s) {
                                            var _k = Object.keys(o);
                                            return (_k).forEach(function(elem) {
                                                return f.call(s,o[elem],elem,o);
                                            });
                                        })(f,function(stat,initialf) {
                                            return ((!(initialf === cwd)) ?
github fuse-box / fuse-box / dist / commonjs / FuseBox.js View on Github external
bundle(str, daemon) {
        if (daemon) {
            watch.watchTree(this.context.homeDir, { interval: 0.2 }, () => {
                this.initiateBundle(str);
            });
        }
        else {
            return this.initiateBundle(str);
        }
    }
    process(bundleData, standalone) {

watch

Utilities for watching file trees.

Apache-2.0
Latest version published 7 years ago

Package Health Score

65 / 100
Full package analysis