watch-and-sync

0.7.0 • Public • Published

watch-and-sync

A script to watch a directory on your local machine and copy it to a remote when changes are detected

Usage

npx watch-and-sync --help

Notes and observations

The script uses Node's fs.watch API to handle the directory watching. There are a few third-party packages that do similar things that I considered but chose not too as I didn't encounter the problems they claim to solve.

chokidar, for example, claims that fs.watch:

  • Doesn't report filenames on OS X
  • Doesn't report events at all when using editors like Sublime on OS X
  • Does not provide an easy way to recursively watch file trees
  • Often reports events twice

I tested the first three points and found that they simply aren't the case; I assume they were problems that have since been fixed in later versions of Node.js. I did observe fs.watch reporting events twice (see debounce below).

Dependencies

rsync

  • Widely-used and stable
  • Used to do the actual syncing between local and remote
  • Script assumes the executable is present in your PATH

debounce

  • npm package
  • fs.watch seems to often get called twice for the same file change
    • Not sure on the cause - initial investigation seems to point to it coming from the underlying FSEvents API

/watch-and-sync/

    Package Sidebar

    Install

    npm i watch-and-sync

    Weekly Downloads

    3

    Version

    0.7.0

    License

    MIT

    Unpacked Size

    5.33 kB

    Total Files

    9

    Last publish

    Collaborators

    • alexchesters