How to use the createMonitor function from watch

Find comprehensive JavaScript watch.createMonitor code examples handpicked from public code repositorys.

95
96
97
98
99
100
101
102
103
104
 * Watch javascript source files.
 */
function watchFiles(srcDirectory, distDirectory) {
  var transpiler = javascripts.getTranspiler(srcDirectory, distDirectory, isAllowed, babelOptions, browserifyOptions);

  watch.createMonitor(srcDirectory, watchOptions, function(monitor) {
    monitor.on('created', function(filename, stats) {
      if (isAllowed(filename))
        transpiler.transpile(filename, []);
    });
fork icon7
star icon52
watch icon10

2
3
4
5
6
7
8
9
10
11
var watch = require('watch');
var debug = require('debug')('zotero:watch');
var exec  = require('child_process').exec;

['lib', 'test'].forEach(function (dir) {
  watch.createMonitor(dir, function (monitor) {
    monitor.on('changed', changed);
  });

  debug('watching %s directory', dir);
fork icon7
star icon26
watch icon9

13
14
15
16
17
18
19
20
21
22
23
24
25
})


function startWatch () {
  var counter = 0


  watch.createMonitor('app/', function (monitor) {
    console.log('watch is watching YOU, app/')


    monitor.on('changed', function () {
      console.log('changed')
fork icon4
star icon14
watch icon0

49
50
51
52
53
54
55
56
57
58
  });
}

function watch () {
  // TODO exit condition
  watcher.createMonitor(mount, {
    ignoreDotFiles: true
  }, function (monitor) {
    monitor.on('created', update);
    monitor.on('changed', update);
fork icon0
star icon7
watch icon3

38
39
40
41
42
43
44
45
46
47
  });
  debugServer.start(config);
}

function createMonitor(cb) {
  watch.createMonitor(process.cwd(), {
    ignoreDotFiles: true,
    interval: 1000
  }, function(monitor) {
    monitor.on('created', cb);
fork icon3
star icon0
watch icon2

71
72
73
74
75
76
77
78
79
  ignoreDotFiles: true,
  interval: options.interval,
  filter: filter
}

watch.createMonitor(rootDir, monitorOptions, function (monitor) {
  monitor.on('created', handleChange)
  monitor.on('changed', handleChange)
  monitor.on('removed', handleChange)
fork icon1
star icon3
watch icon1

28
29
30
31
32
33
34
35
36
37
  }


  searchOps = paramPathSearchOps(folderPath, searchOps)
  var loader = monitorLoader(folderPath, outPath, searchOps)
  watch.createMonitor((folderPath||'.'), watchOptions, loader)
}

/**
  f - file to write
fork icon1
star icon0
watch icon3

34
35
36
37
38
39
40
41
42
43
opts = common.assignOptions(this, opts);

this.watched = Object.create(null);
this.root = path.resolve(dir);

watch.createMonitor(
  this.root,
  {
    interval: opts.interval || DEFAULT_DELAY,
    filter: this.filter.bind(this),
fork icon0
star icon1
watch icon0

19
20
21
22
23
24
25
26
27
28
  const filesPath = path.join(context, file)
  const newFiles = glob.sync(filesPath)
  this.watchedFiles = this.watchedFiles.concat(newFiles)
})

watch.createMonitor(context, (monitor) => {
  monitor.on("changed", _.debounce(onChange.bind(this), 500))

  monitor.on("created",  _.debounce((file) => { updateMonitor(file, 'created', monitor) }, 500))
  monitor.on("removed", (file) => { updateMonitor(file, 'removed', monitor) })
fork icon0
star icon1
watch icon2

1
2
3
4
5
6
7
8
9
10
import {Actions} from './actions';
// Initialize watcher.
var watch = require('watch');

export function startWatch(){
  watch.createMonitor('./root', function (monitor) {
    monitor.files['./root/*'] // Stat object for my zshrc.
    monitor.on("created", function (f, stat) {
      // Handle new files
      console.log(f, " created");
fork icon0
star icon0
watch icon1

41
42
43
44
45
46
47
48
49
50
//  Init

function init() {
  console.log(colors.success(`compiling ${processedPath} \nto ${process.cwd()}/scenes-compiled.js`))

  watch.createMonitor(processedPath, watchOpts, (monitor) => {
    monitor.on('created', (f) => {
      console.log(colors.data(`created ${f}`))
        // Handle new files
      compile()
fork icon0
star icon0
watch icon2