How to use gaze - 10 common examples

To help you get started, we’ve selected a few gaze 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 FWeinb / metalsmith-watch / lib / index.js View on Github external
var startWatching = function ( source, pattern, rebuild, done) {
  console.log ( chalk.green('Started watching ') + chalk.cyan(pattern));

  var gaze = new Gaze(pattern, { cwd : source });

  gaze.on('ready', _.once(function(){
    done();
  }));

  gaze.on('all', function ( event, filepath ) {
    var name = relative(source, filepath);

    fs.lstat(filepath, function(err, stats){
      // Ignore errors and directorys
      if ( err || stats.isDirectory() === true ) { return; }

      console.log ( chalk.cyan( name ) + ' was ' + chalk.green( event ) );

      // rebuild the current file `filepath`
      // using the metalsmith rebuilder.
github alleyinteractive / huron / js / init-kss.js View on Github external
export default function initKSS() {
  const gaze = new Gaze(program.source);

  // Run once no matter what to show most up to date
  kssTraverse(gaze.watched());

  gaze.on('error', (error) => {
    console.log(`An error has occured: ${error}`);
    return;
  });

  gaze.on('nomatch', () => {
    console.log('No matches found');
    return;
  });

  gaze.on('all', (event, filepath) => {
    // Adding/Deleting files
github publiclab / PublicLab.Editor / node_modules / grunt-contrib-watch / tasks / watch.js View on Github external
if (typeof target.options.event === 'string') {
        target.options.event = [target.options.event];
      }

      var eventCwd = process.cwd();
      if (target.options.cwd && target.options.cwd.event) {
        eventCwd = target.options.cwd.event;
      }

      // Set cwd if options.cwd.file is set
      if (typeof target.options.cwd !== 'string' && target.options.cwd.files) {
        target.options.cwd = target.options.cwd.files;
      }

      // Create watcher per target
      watchers.push(new Gaze(patterns, target.options, function(err) {
        if (err) {
          if (typeof err === 'string') {
            err = new Error(err);
          }
          grunt.log.writeln('ERROR'.red);
          grunt.fatal(err);
          return taskrun.done();
        }

        // Log all watched files with --verbose set
        if (grunt.option('verbose')) {
          var watched = this.watched();
          Object.keys(watched).forEach(function(watchedDir) {
            watched[watchedDir].forEach(function(watchedFile) {
              grunt.log.writeln('Watching ' + path.relative(process.cwd(), watchedFile) + ' for changes.');
            });
github oddbird / portfoliyo / node_modules / grunt-contrib-watch / tasks / watch.js View on Github external
targets.forEach(function(target, i) {
      if (typeof target.files === 'string') {
        target.files = [target.files];
      }

      // Process into raw patterns
      var patterns = grunt.util._.chain(target.files).flatten().map(function(pattern) {
        return grunt.config.process(pattern);
      }).value();

      // Default options per target
      var options = grunt.util._.defaults(target.options || {}, defaults);

      // Create watcher per target
      var gaze = new Gaze(patterns, options, function(err) {
        if (err) {
          grunt.log.error(err.message);
          return done();
        }

        // On changed/added/deleted
        this.on('all', function(status, filepath) {
          filepath = path.relative(process.cwd(), filepath);
          changedFiles[filepath] = status;
          runTasks(i, target.tasks, options);
        });

        // On watcher error
        this.on('error', function(err) { grunt.log.error(err); });
      });
    });
github pokemontrades / flairhq / node_modules / grunt-contrib-watch / tasks / watch.js View on Github external
var patterns = _.chain(target.files).flatten().map(function(pattern) {
        return grunt.config.process(pattern);
      }).value();

      // Validate the event option
      if (typeof target.options.event === 'string') {
        target.options.event = [target.options.event];
      }

      // Set cwd if options.cwd.file is set
      if (typeof target.options.cwd !== 'string' && target.options.cwd.files) {
        target.options.cwd = target.options.cwd.files;
      }

      // Create watcher per target
      watchers.push(new Gaze(patterns, target.options, function(err) {
        if (err) {
          if (typeof err === 'string') { err = new Error(err); }
          grunt.log.writeln('ERROR'.red);
          grunt.fatal(err);
          return taskrun.done();
        }

        // Log all watched files with --verbose set
        if (grunt.option('verbose')) {
          var watched = this.watched();
          Object.keys(watched).forEach(function(watchedDir) {
            watched[watchedDir].forEach(function(watchedFile) {
              grunt.log.writeln('Watching ' + path.relative(process.cwd(), watchedFile) + ' for changes.');
            });
          });
        }
github FWeinb / metalsmith-watch / src / index.es View on Github external
// metalsmith-collections fix: keep filename as metadata
    saveFilenameInFilesData(files)

    const patterns = {}
    Object.keys(options.paths).map(pattern => {
      let watchPattern = pattern.replace("${source}", metalsmith.source())
      if (!isAbsolutePath(watchPattern)){
        watchPattern = resolvePath(metalsmith.directory(), pattern);
      }
      const watchPatternRelative = relativePath(metalsmith.directory(), watchPattern)

      patterns[watchPatternRelative] = options.paths[pattern]
    })

    gaze(
      Object.keys(patterns),
      {
        ...options.gaze,
        cwd: metalsmith._directory,
      },
      function watcherReady(err, watcher) {
        if (err) {throw err}

        Object.keys(patterns).forEach(pattern => {
          options.log(`${ok} Watching ${color.cyan(pattern)}`)
        })

        const previousFilesMap = {...files}

        // Delay watch update to be able to bundle multiples update in the same build
        // Saving multiples files at the same time create multiples build otherwise
github buddebej / elasticterrain / ol3 / tasks / serve.js View on Github external
if (err) {
        log.error('serve', 'Parsing failed');
        log.error('serve', err.message);
        process.exit(1);
      }
      server.listen(options.port, function() {
        log.info('serve', 'Listening on http://localhost:' +
            options.port + '/ (Ctrl+C to stop)');
      });
      server.on('error', function(err) {
        log.error('serve', 'Server failed to start: ' + err.message);
        process.exit(1);
      });
    });

    var gaze = new Gaze('examples/**/*');
    var debouncedBuild = debounce(buildExamplesOrFatal, 250);
    gaze.on('all', function(event, filepath) {
      log.verbose('serve', 'Watch event: ' + event + ' ' + filepath);
      debouncedBuild();
    });
  });
github skovhus / css-modules-flow-types / packages / css-modules-flow-types-cli / src / cli.js View on Github external
if (!watch) {
    const cssFiles = filesList ? filesList : globby.sync(filesPattern);
    cssFiles.forEach(handleFile);

    if (!filesList) {
      detectDanlingFlowFiles(filesPattern, cssFiles);
    }
  } else {
    if (!filePath) {
      console.error(
        chalk.red(`Watch mode requires a single path... Not ${filesList}`)
      );
      return;
    }
    gaze(filesPattern, function(err, files) {
      this.on('changed', handleFile);
      this.on('added', handleFile);
    });
  }
};
github rakuten-frontend / bower-browser / lib / index.js View on Github external
BowerBrowser.prototype.readBowerJson = function (callback) {
  var self = this;
  var json = null;
  var error = null;
  try {
    var buffer = fs.readFileSync(jsonPath);
    if (!gaze) {
      gaze = new Gaze('bower.json', {cwd: cwd});
      gaze.on('all', function () {
        self.sendBowerData();
      });
    }
    json = JSON.parse(buffer);
  }
  catch (e) {
    error = e;
  }
  if (typeof callback === 'function') {
    callback(error, json);
  }
};
github mautic / documentation / bin / utils.js View on Github external
function watch(dir) {
    var d = Q.defer();
    dir = path.resolve(dir);

    var gaze = new Gaze("**/*.md", {
        cwd: dir
    });

    gaze.once("all", function(e, filepath) {
        gaze.close();

        d.resolve(filepath);
    });
    gaze.once("error", function(err) {
        gaze.close();

        d.reject(err);
    });

    return d.promise;
}

gaze

A globbing fs.watch wrapper built from the best parts of other fine watch libs.

MIT
Latest version published 7 years ago

Package Health Score

68 / 100
Full package analysis

Popular gaze functions