X-Git-Url: https://git.josue.xyz/?a=blobdiff_plain;f=watchexec%2FREADME.md;h=f08dd16d549b11179852c1b1c666630d340b985f;hb=0aa421a04287a0b423f3aa5d64682d0590bf1e18;hp=782bbebdc0556971ea7a6e37868be009d63d4af1;hpb=8973d951e41765636b3e85b8453d8573b7149015;p=webi-installers%2F.git diff --git a/watchexec/README.md b/watchexec/README.md index 782bbeb..f08dd16 100644 --- a/watchexec/README.md +++ b/watchexec/README.md @@ -13,45 +13,71 @@ Use the `@beta` tag for pre-releases. ## 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`. - $ watchexec --exts js,css,html make +Here's the shortlist of options we've found most useful: -Call `make test` when any file changes in this directory/subdirectory, except -for everything below `target`: +```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 - $ watchexec -i target make test +-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 -Call `ls -la` when any file changes in this directory/subdirectory: +-- npm start what command to run, with its arguments - $ watchexec -- ls -la +--no-ignore disregard both .ignore and .gitignore +--no-vcs-ignore disregard only .gitignore +--no-default-ignore disregard built-in ignore lists +``` -Call/restart `python server.py` when any Python file in the current directory -(and all subdirectories) changes: +### How to use - $ watchexec -e py -r python server.py +Example: List the directory when any files change. -Call/restart `my_server` when any file in the current directory (and all -subdirectories) changes, sending `SIGKILL` to stop the child process: +```bash +watchexec -c -- ls -lah +``` - $ watchexec -r -s SIGKILL my_server +### Advanced Usage 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: +Here's a "kitchen sink" example. - $ watchexec -n -s SIGHUP my_server +```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 +``` -Run `make` when any file changes, using the `.gitignore` file in the current -directory to filter: +### How to use (Node, Go, Rust, rsync) - $ watchexec make +These examples show how you might use this for builds, servers, and publishing +or deploying. -Run `make` when any file in `lib` or `src` changes: +```bash +# Node / npm +watchexec -W -- npm run build +watchexec -r -- npm start - $ watchexec -w lib -w src make +# Golang +watchexec -- go build . +watchexec -r -- go run . -Run `bundle install` when the `Gemfile` changes: +# Rust +watchexec -- cargo build --bin +watchexec -r -- cargo run --bin - $ watchexec -w Gemfile bundle install +# rsync (local copy) +watchexec -- rsync -avhP ./ ./srv/MY_PROJECT/ + +# rsync (remote publish) +watchexec -- rsync -avhP ./ app@example.com:~/srv/MY_PROJECT/ +```