How to use chokidar - 10 common examples

To help you get started, we’ve selected a few chokidar 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 Bahmni / openmrs-module-bahmniapps / clinical-ui / node_modules / testacular / lib / watcher.js View on Github external
exports.watch = function(patterns, excludes, fileList) {
  var options = {
    ignorePermissionErrors: true,
    ignored: createIgnore(excludes)
  };
  var chokidarWatcher = new chokidar.FSWatcher(options);

  watchPatterns(patterns, chokidarWatcher);

  var bind = function(fn) {
    return function(path) {
      return fn.call(fileList, helper.normalizeWinPath(path));
    };
  };

  // register events
  chokidarWatcher.on('add', bind(fileList.addFile))
                 .on('change', bind(fileList.changeFile))
                 .on('unlink', bind(fileList.removeFile));

  return chokidarWatcher;
};
github facebook / metro / scripts / watch.js View on Github external
getPackages().forEach(p => {
  const srcDir = path.resolve(p, 'src');
  try {
    fs.accessSync(srcDir, fs.F_OK);
    chokidar
      .watch(path.resolve(p, 'src'), {ignoreInitial: true})
      .on('all', (event, filename) => {
        const filePath = path.resolve(srcDir, filename);

        if ((event === 'add' || event === 'change') && exists(filePath)) {
          // eslint-disable-next-line no-console
          console.log(chalk.green('->'), `${event}: ${filename}`);
          rebuild(filePath);
        } else if (event === 'unlink') {
          const buildFile = path.resolve(srcDir, '..', 'build', filename);
          try {
            fs.unlinkSync(buildFile);
            process.stdout.write(
              chalk.red('  \u2022 ') +
                path.relative(path.resolve(srcDir, '..', '..'), buildFile) +
                ' (deleted)' +
github samueleaton / screwy / src / scripts / watchConfig.js View on Github external
function createFileWatcher(pattern, command) {
	// default task is 'START' // check for blank spaces
	if ((/ /g).test(command) === false)
		command = 'START ' + command;

	const task = getTask(command);

	if (!task || !taskFunctionMap[task])
		return logger(invalidCommandMsg(command));

	const fileWatcher = chokidar.watch(pattern);
	const func = taskFunctionMap[task];
	const npmScript = command.slice(task.length).trim();
	
	fileWatcher.on('change', path => func(npmScript));
}
github parcel-bundler / parcel / packages / core / watcher / src / child.js View on Github external
function init(options: EncodedFSWatcherOptions) {
  let decodedOptions = decodeOptions(options);
  watcher = new FSWatcher(decodedOptions);
  watcher.on('all', sendEvent);
  sendEvent('ready');

  // only used for testing
  watcher.once('ready', async () => {
    // Wait an additional macrotask. This seems to be necessary before changes
    // can be picked up.
    await new Promise(resolve => setImmediate(resolve));
    sendEvent('_chokidarReady');
  });
}
github GitOfZGT / zero-design / zerod-webpack-conf / build / copy.js View on Github external
});
};
const copyFrom = `./${config.copyFolderName}`;
// 复制目录
var myCopy = function() {
    if (!fs.existsSync(copyFrom)) {
        return;
    }
    exists(copyFrom, './node_modules/' + config.copyName, copy);
};
if (config.copyName) {
    myCopy();
    var args = process.argv.splice(2);
    if (args.includes('watchChange')) {
        var chokidar = require('chokidar');
        chokidar.watch(copyFrom).on('change', myCopy);
    }
}
module.exports = myCopy;
github ulver2812 / aws-s3-backup / src / app / providers / job-scheduler.service.ts View on Github external
const cronRule = this.cronService.getCronStringFromJobPeriod(job.period);
      scheduler = schedule.scheduleJob({start: startTime, end: endTime, rule: cronRule}, () => {
        this.awsService.s3Sync(job);
      });
    } else if (job.type === JobType.Live) {
      // LIVE JOB
      const watchedPath = [];
      job.files.forEach((item) => {
        watchedPath.push(item.path);
      });

      const lazyS3Sync = sugar.Function.lazy(() => {
        this.awsService.s3Sync(job);
      }, 10000, true, 2);

      scheduler = chokidar.watch(watchedPath, {awaitWriteFinish: true});

      scheduler.on('ready', () => {
        lazyS3Sync();
        scheduler.on('all', (path, event) => {
          lazyS3Sync();
        });
      });

      scheduler.on('error', (err) => {
        this.logService.printLog(LogType.ERROR, 'Can\'t run live sync for ' + job.name + ' because of: \r\n' + err);
        job.alert = true;
        this.jobService.save(job);
      });
    }

    if (scheduler === null) {
github johandb / svg-drawing-tool / node_modules / @angular-devkit / core / node / host.js View on Github external
return new rxjs_1.Observable(obs => {
            const watcher = new FSWatcher({ persistent: true }).add(src_1.getSystemPath(path));
            watcher
                .on('change', path => {
                obs.next({
                    path: src_1.normalize(path),
                    time: new Date(),
                    type: 0 /* Changed */,
                });
            })
                .on('add', path => {
                obs.next({
                    path: src_1.normalize(path),
                    time: new Date(),
                    type: 1 /* Created */,
                });
            })
                .on('unlink', path => {
github seccubus / seccubus / angular-seccubus.old / bak / node_modules / @angular-devkit / core / node / host.js View on Github external
return new Observable_1.Observable(obs => {
            const watcher = new FSWatcher({ persistent: true }).add(this._getSystemPath(path));
            watcher
                .on('change', path => {
                obs.next({
                    path: src_1.normalize(path),
                    time: new Date(),
                    type: 0 /* Changed */,
                });
            })
                .on('add', path => {
                obs.next({
                    path: src_1.normalize(path),
                    time: new Date(),
                    type: 1 /* Created */,
                });
            })
                .on('unlink', path => {
github johandb / svg-drawing-tool / node_modules / @angular-devkit / core / node / host.js View on Github external
return new rxjs_1.Observable(obs => {
            const opts = { persistent: false };
            const watcher = new FSWatcher(opts).add(src_1.getSystemPath(path));
            watcher
                .on('change', path => {
                obs.next({
                    path: src_1.normalize(path),
                    time: new Date(),
                    type: 0 /* Changed */,
                });
            })
                .on('add', path => {
                obs.next({
                    path: src_1.normalize(path),
                    time: new Date(),
                    type: 1 /* Created */,
                });
            })
                .on('unlink', path => {
github openshift / console / frontend / node_modules / karma / lib / watcher.js View on Github external
exports.watch = function(patterns, excludes, fileList, usePolling, emitter) {
  var watchedPatterns = getWatchedPatterns(patterns);
  var options = {
    usePolling: usePolling,
    ignorePermissionErrors: true,
    ignoreInitial: true,
    ignored: createIgnore(watchedPatterns, excludes)
  };
  var chokidarWatcher = new chokidar.FSWatcher(options);

  watchPatterns(watchedPatterns, chokidarWatcher);

  var bind = function(fn) {
    return function(path) {
      return fn.call(fileList, helper.normalizeWinPath(path));
    };
  };

  // register events
  chokidarWatcher.on('add', bind(fileList.addFile))
                 .on('change', bind(fileList.changeFile))
                 .on('unlink', bind(fileList.removeFile))
                 // If we don't subscribe; unhandled errors from Chokidar will bring Karma down
                 // (see GH Issue #959)
                 .on('error', function(e) {

chokidar

Minimal and efficient cross-platform file watching library

MIT
Latest version published 11 months ago

Package Health Score

84 / 100
Full package analysis