chore: make Prettier
[webi-installers/.git] / watchexec / README.md
index 782bbebdc0556971ea7a6e37868be009d63d4af1..f3ee6bd11d9a3a08c2f1b0cfb4ad436e85740cf5 100644 (file)
@@ -5,53 +5,76 @@ tagline: |
   watchexec is a simple, standalone tool that watches a path and runs a command whenever it detects modifications.
 ---
 
-### Updating `watchexec`
-
-`webi watchexec@stable`
-
-Use the `@beta` tag for pre-releases.
+To update or switch versions, run `webi watchexec@stable` (or `@v1.17`, `@beta`,
+etc).
 
 ## Cheat Sheet
 
-Watch all JavaScript, CSS and HTML files in the current directory and all
-subdirectories for changes, running `make` when a change is detected:
+`watchexec` runs a given command when any files in watched directories change. \
+It respects `.[git]ignore`.
+
+Here's the shortlist of options we've found most useful:
 
-    $ watchexec --exts js,css,html make
+```txt
+-w, --watch     ./src/      watch the given directory
+-e, --exts      js,css      watch only the given extensions
+-i, --ignore    '*.md'      do not watch the given pattern
+-d, --debounce  5000        the minimum number of milleseconds
+                                to wait between changes
 
-Call `make test` when any file changes in this directory/subdirectory, except
-for everything below `target`:
+-r, --restart               restart the process (for servers, etc)
+-s, --signal    SIGHUP      like -r, but with a signal (ex: SIGHUP)
+-c, --clear                 clear the screen between command runs
+-W  (wait)                  ignore all changes as the command runs
 
-    $ watchexec -i target make test
+--              npm start   what command to run, with its arguments
 
-Call `ls -la` when any file changes in this directory/subdirectory:
+--no-ignore                 disregard both .ignore and .gitignore
+--no-vcs-ignore             disregard only .gitignore
+--no-default-ignore         disregard built-in ignore lists
+```
 
-    $ watchexec -- ls -la
+### How to use
 
-Call/restart `python server.py` when any Python file in the current directory
-(and all subdirectories) changes:
+Example: List the directory when any files change.
 
-    $ watchexec -e py -r python server.py
+```bash
+watchexec -c -- ls -lah
+```
 
-Call/restart `my_server` when any file in the current directory (and all
-subdirectories) changes, sending `SIGKILL` to stop the child process:
+### Advanced Usage Example
 
-    $ watchexec -r -s SIGKILL my_server
+Here's a "kitchen sink" example.
 
-Send a SIGHUP to the child process upon changes (Note: with using
-`-n | --no-shell` here, we're executing `my_server` directly, instead of
-wrapping it in a shell:
+```bash
+watchexec -c -r -s SIGKILL -d 2000 -W --verbose \
+    -w ./src -w ./server.js \
+    -e js,css,html \
+    -i '*.md' -i 'package-lock.json' \
+    -- npm run build
+```
 
-    $ watchexec -n -s SIGHUP my_server
+### How to use (Node, Go, Rust, rsync)
 
-Run `make` when any file changes, using the `.gitignore` file in the current
-directory to filter:
+These examples show how you might use this for builds, servers, and publishing
+or deploying.
 
-    $ watchexec make
+```bash
+# Node / npm
+watchexec -W -- npm run build
+watchexec -r -- npm start
 
-Run `make` when any file in `lib` or `src` changes:
+# Golang
+watchexec -- go build .
+watchexec -r -- go run .
 
-    $ watchexec -w lib -w src make
+# Rust
+watchexec -- cargo build --bin
+watchexec -r -- cargo run --bin
 
-Run `bundle install` when the `Gemfile` changes:
+# rsync (local copy)
+watchexec -- rsync -avhP ./ ./srv/MY_PROJECT/
 
-    $ watchexec -w Gemfile bundle install
+# rsync (remote publish)
+watchexec -- rsync -avhP ./ app@example.com:~/srv/MY_PROJECT/
+```