• Stars
    star
    125
  • Rank 286,335 (Top 6 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 11 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Run commands when paths change.

Watchy

Run commands when paths change.

Install

You'll need to install Node.js to use Watchy. Node comes packaged with npm, which is Node's package manager, and the preferred method of installing Watchy. After installing Node, simply type

npm install -g watchy

and you should have the watchy command available!

Usage

Usage: watchy [options] -- command arg1 arg2 ...

Run commands when paths change.

Options:
  -V, --version                   output the version number
  -d, --debounce [seconds]        trigger a change at most every [seconds] seconds
  -k, --keep-alive                restart the process if it exits
  -p, --use-polling               use file polling even if fsevents or inotify is available
  -r, --restart [string]          send [string] to STDIN to restart the process
  -R, --no-restart-after-signal   disable process restart after being signaled and exited
  -s, --silent                    only output errors
  -S, --no-init-spawn             prevent spawn when the watcher is created
  -t, --shutdown-signal [signal]  use [signal] to shut down the process (default: "SIGTERM")
  -T, --reload-signal [signal]    use [signal] to reload the process (defaults to shutdown signal)
  -w, --watch [pattern]           watch [pattern] for changes, can be specified multiple times
  -W, --wait [seconds]            send SIGKILL to the process after [seconds] if it hasn't exited
  -h, --help                      output usage information

The watch patterns are extglob format.

Examples

# The simple case
watchy -w 'lib/**/*' -- say "The lib directory changed."

# Piping works as well
watchy -w 'styles/**/*.less' -- bash -c "lessc styles/main.less | autoprefixer -o .tmp/styles/main.css"

# Keep a process alive, restarting it as soon as it exits or "server.js"
# changes.
watchy -kw server.js -- node server.js

# Watch every file except dotfiles, the node_modules folder, and JSON files.
# NOTE: Listen to as few files as possible for better performance.
watchy -w . -i '/\.|/node_modules|\.json$' -- node server.js

# Tick tock!
watchy -ks -- bash -c 'date && sleep 1'

# Tick tock (annoying version)!
watchy -ks -- bash -c 'say "In case you were wondering, it is `date`" && sleep 5'

# $WATCHY_ACTION and $WATCHY_PATH are passed to the process.
watchy -w '**/*' -- bash -c 'echo $WATCHY_ACTION $WATCHY_PATH'
# => modified /Users/casey/Documents/code/watchy/README.md

Note: If you're using watchy for help with preprocessing, I'd recommend checking out my cogs project that is highly optimized for that case with in-memory processed file caching, directives, AMD support, and much more.

SIGTERM

By default, watchy will send SIGTERM to the running process after a change and wait for it to exit gracefully. By sending the --wait|-W n option, you can tell watchy to forcefully SIGKILL the process after n seconds. In general, you should try to clean up connections in your processes like so:

process.on('SIGTERM', function () {
  server.close();
  db.disconnect();
  redis.quit();
  // etc...
});

Node API

As of 0.9.0 watchy exposes a Node.js API.

const watchy = require('watchy');

watchy({
  patterns: ['js/**/*.js', 'css/**/*.css'],
  onError: error => console.error(error),
  onChange: ({action, path}) => console.log(action, path),
  usePolling: true // defaults to `false`, but will fallback when fsevents are not available
}).catch(er => {
  console.error(er);
  process.exit(1);
});

More Repositories

1

react-list

πŸ“œ A versatile infinite scroll React component.
JavaScript
1,951
star
2

cursors

Maintain your React state with Cursors.
JavaScript
80
star
3

CoffeeScript.mode

CoffeeScript syntax highlighting for Coda 2
44
star
4

cogs

The fast file transform pipeline.
JavaScript
31
star
5

formatted-text

A React component for formatting paragraphs, line breaks and links.
JavaScript
12
star
6

backbone-composite-keys

Composite key support for Backbone. Just set your `idAttribute` to an array of attributes and you're all set.
CoffeeScript
10
star
7

pave

Paving the way to better state management.
JavaScript
9
star
8

my-homebridge

My Homebridge set up with Docker. You can use it too!
Shell
6
star
9

herit

Easy to use JavaScript "Class" inheritance with support for "instance" and "static" properties.
JavaScript
5
star
10

blackmailr

Get what you want, when you want it, or else...
Ruby
5
star
11

amdainty

A small, simple AMD module resolver for use in single-file, AMD-style projects.
JavaScript
4
star
12

backbone-relations

Backbone one-to-one, one-to-many, and many-to-many relationships for the browser and nodejs.
JavaScript
4
star
13

underscore-express

Use Underscore templates easily in Express.
JavaScript
3
star
14

bob

Bob builds Docker images.
JavaScript
3
star
15

react-selectorer

A fully customizable React selector component.
JavaScript
3
star
16

guard-mirror

A CoffeeScript, Stylus, and Jade (HTML and JST) Guard that mirrors your source files (.coffee/.styl/.jst.jade/.html.jade) in another location (public/www/etc...).
Ruby
3
star
17

turbo-car-club

Welcome to The Club.
JavaScript
2
star
18

docdock

JavaScript
2
star
19

bruteball

Roll into stuff.
JavaScript
2
star
20

backbone-collection-crud

Add `save` and `destroy` to your collections.
CoffeeScript
2
star
21

borer

Bores HTTP tunnels
JavaScript
2
star
22

sock-band

Socket.io + Instruments = Sock Band
JavaScript
2
star
23

anagram-war

It's a war of the words. Uses Node, Backbone, Underscore, jQuery, Express, Connect, Socket.io, Zappa, and anything else you can dream of.
JavaScript
2
star
24

homekit-proxy

Proxy various non-HomeKit devices as HomeKit devices.
JavaScript
2
star
25

fort-knox

Get secrets from Vault
JavaScript
1
star
26

nfsevents

Proxy file events from one machine to another, useful for inotify over NFS.
JavaScript
1
star
27

cogs-transformer-terser

A terser transformer for Cogs.
JavaScript
1
star
28

nodekick

NKO 2013 Team Us Entry
JavaScript
1
star
29

dpr

Trying to make life easier in a world with too many device pixel ratios.
JavaScript
1
star
30

jobby

YET ANOTHER REDIS JOB QUEUE!
JavaScript
1
star
31

jquery-cwd

jQuery plugins by caseyWebDev
CoffeeScript
1
star
32

consul-lb

A Consul-aware load balancer powered by nginx and secured by Let's Encrypt.
Shell
1
star
33

bumpit

Easily bump versions for your package.json, bower.json, and/or component.json from the command line.
JavaScript
1
star
34

live-socket

WebSocket wrapper to add socket.io-like functionality around native WebSockets or polyfills.
JavaScript
1
star
35

eslint-config-coderiety

ESLint configuration used by Coderiety projects.
JavaScript
1
star
36

bootman

Start (and stop) services dependent on one another in order
JavaScript
1
star
37

docker-postgres

A containerpilot-wrapped postgres image.
Shell
1
star
38

caseywebdev.github.io

caseyWebDev GitHub Site
JavaScript
1
star
39

kiss-test

Keep It Simple, Stupid - Test
JavaScript
1
star
40

interaction

An interaction-style "class" for Node.js
JavaScript
1
star
41

jquery-mobile-events

A component for just the jquery-mobile events.
Makefile
1
star
42

extrascore

An extension for Underscore.js with some of the tools I reuse all the time.
CoffeeScript
1
star
43

cogs-transformer-marked

A marked transformer for Cogs.
JavaScript
1
star
44

containerpilot-consul

The official Consul image wrapped in ContainerPilot.
Shell
1
star