Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Watching Multiple Paths #145

Closed
FMCalisto opened this issue Mar 1, 2019 · 2 comments
Closed

Watching Multiple Paths #145

FMCalisto opened this issue Mar 1, 2019 · 2 comments

Comments

@FMCalisto
Copy link

Greetings,

I am trying to solve a particular issue regarding the use of your library. I need to watch two different paths. However, the watch library does not concern that (I think). For instance, if I do the following code, it will run it over and over. But, on the other hand, if I use one of the paths, it will run everything ok.

var filePath001 = path.resolve(rootPath, 'foo001', 'foo002');
var filePath002 = path.resolve(rootPath, 'foo003', 'foo004');

watch.watchTree(filePath001, function (f, curr, prev) {
  if (typeof f == "object" && prev === null && curr === null) {
    shell.exec('./scripts/run.sh');
  } else if (prev === null) {
    shell.exec('./scripts/run.sh');
  } else if (curr.nlink === 0) {
    shell.exec('./scripts/run.sh');
  } else {
    shell.exec('./scripts/run.sh');
  }
});

watch.watchTree(filePath002, function (f, curr, prev) {
  if (typeof f == "object" && prev === null && curr === null) {
    shell.exec('./scripts/run.sh');
  } else if (prev === null) {
    shell.exec('./scripts/run.sh');
  } else if (curr.nlink === 0) {
    shell.exec('./scripts/run.sh');
  } else {
    shell.exec('./scripts/run.sh');
  }
});

My question is, how can I have watching of several paths?

Thank you in advance. I would appreciate an answer.

@hyperking
Copy link

@FMCalisto I don't think this is available by default.

I have the same concern and here is an example how someone could perform a watch on multiple directories.

// This file name is cssbundler.js
const path = require('path');
const watch = require('watch');

const targetListOfCss =  ['path/to/foo', 'path/to/bar'];
targetListOfCss.forEach(cssPath =>{
  let fullcsspath = path.resolve(cssPath);
  watch.createMonitor(fullcsspath, (monitor)=>{
    monitor.on('changed', (fp, curr, prev) =>{
      console.log('do stuff to bundle '+fp);
    });
});
});

from the cli node cssbundler.js

@FMCalisto
Copy link
Author

Dear @hyperking, thank you for your contribution. It seems a valid approach also.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants