Watchman: Examples?

Created on 6 May 2014  路  6Comments  路  Source: facebook/watchman

I've been googling around for some examples on how to use this, but I can't find anything...

Don't get me wrong, the documentation seems extensive, I just wish it had a for examples.

Any blog posts that someone can point me to?

Better yet, wanna show me a complete example that say, watches a jsx/ folder and compiles the React components while also watching a sass/ folder and compiling to a css file?

Most helpful comment

Landed here looking for the same thing. Documentation is good, and a variety of usage examples would be very helpful.

All 6 comments

Take a look at https://algorithms.rdio.com/post/make/ for an example.

For your use case, I'd probably do something like this, which runs make whenever any file in the jsx folder is changed, or any .css file in the sass is changed (note: changed also includes created or deleted):

watchman -j <<-EOT
["trigger", "/path/to/root", {
  "name": "assets",
  "expression": ["anyof",
       ["match", "jsx/*", "wholename"],
       ["match", "sass/*.css", "wholename"]
  ],
  "command": ["make"]
}]
EOT

Watchman doesn't know anything about building anything; it knows when things change and how to trigger a command when that happens. This means that it is up to you to fill in the logic for building stuff.

Watchman is a little different from most other watching utilities because it is optimized for machines and not really for humans; the output of your triggered commands lands in a log file and not in your terminal.

Thank you very much for the examples. I was some how missing how these commands were issued to watchman. I'm guessing I could put that JSON in to a file and pass the filename to watchman as an argument?

Just this basic example has made the rest of the documentation in the README make complete sense! Thanks again :)

You can either type the command as I pasted it above, or put the json in a file named, say, trigger.json and then run watchman -j < trigger.json.

The example I pasted was slightly modified from one that was actually in the README. Is there a specific spot in the README where you started to feel lost/tuned out? We should probably juggle things around a bit to make the docs more accessible, and your feedback on this would help us do that.

Thanks again!

I think the main issue is with the "legacy" command line stuff that is mixed in with the newer, JSON commands. I haven't really made a connection on how the two are related.

If there were just 3-4 common use examples it would help out a lot. It would be nice if each example showed both the CLI version as well as the JSON version. Personally, I'd rather use the CLI version so I don't have to hardcode or fiddle around with absolute paths in a block of JSON.

I still haven't figured out how to translate your above example to CLI or to use relative paths in the JSON... I could write a script to generate the absolute path in the JSON, but I've shaved enough yaks for the day. :smile:

And put something about watchman -j < trigger.json in there as well, that is pretty helpful! I know that is a shell command but when I'm using a new tool for the first time it can be hard to shift gears.

Yep agree with the above. A couple of solid, common CLI examples at the top of the README would go a long way.

Landed here looking for the same thing. Documentation is good, and a variety of usage examples would be very helpful.

Was this page helpful?
0 / 5 - 0 ratings