{"id":13659001,"url":"https://github.com/caseywebdev/watchy","last_synced_at":"2025-04-06T20:13:54.076Z","repository":{"id":7713189,"uuid":"9078393","full_name":"caseywebdev/watchy","owner":"caseywebdev","description":"Run commands when paths change.","archived":false,"fork":false,"pushed_at":"2024-06-04T13:21:34.000Z","size":75,"stargazers_count":124,"open_issues_count":0,"forks_count":14,"subscribers_count":6,"default_branch":"main","last_synced_at":"2025-03-30T18:08:35.124Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/caseywebdev.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2013-03-28T14:08:12.000Z","updated_at":"2025-02-01T18:53:40.000Z","dependencies_parsed_at":"2024-06-18T15:33:29.853Z","dependency_job_id":null,"html_url":"https://github.com/caseywebdev/watchy","commit_stats":{"total_commits":75,"total_committers":7,"mean_commits":"10.714285714285714","dds":"0.10666666666666669","last_synced_commit":"0f5876c53a47ae249ed55c69e45a69a4a676835a"},"previous_names":[],"tags_count":53,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/caseywebdev%2Fwatchy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/caseywebdev%2Fwatchy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/caseywebdev%2Fwatchy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/caseywebdev%2Fwatchy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/caseywebdev","download_url":"https://codeload.github.com/caseywebdev/watchy/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247543595,"owners_count":20955865,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-02T05:01:04.455Z","updated_at":"2025-04-06T20:13:54.056Z","avatar_url":"https://github.com/caseywebdev.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# Watchy\n\nRun commands when paths change.\n\n## Install\n\nYou'll need to install [Node.js] to use Watchy. Node comes packaged with [npm],\nwhich is Node's package manager, and the preferred method of installing Watchy.\nAfter installing Node, simply type\n\n```bash\nnpm install -g watchy\n```\n\nand you should have the `watchy` command available!\n\n## Usage\n\n```\nUsage: watchy [options] -- command arg1 arg2 ...\n\nRun commands when paths change.\n\nOptions:\n  -V, --version                   output the version number\n  -d, --debounce [seconds]        trigger a change at most every [seconds] seconds\n  -k, --keep-alive                restart the process if it exits\n  -p, --use-polling               use file polling even if fsevents or inotify is available\n  -r, --restart [string]          send [string] to STDIN to restart the process\n  -R, --no-restart-after-signal   disable process restart after being signaled and exited\n  -s, --silent                    only output errors\n  -S, --no-init-spawn             prevent spawn when the watcher is created\n  -t, --shutdown-signal [signal]  use [signal] to shut down the process (default: \"SIGTERM\")\n  -T, --reload-signal [signal]    use [signal] to reload the process (defaults to shutdown signal)\n  -w, --watch [pattern]           watch [pattern] for changes, can be specified multiple times\n  -W, --wait [seconds]            send SIGKILL to the process after [seconds] if it hasn't exited\n  -h, --help                      output usage information\n```\n\nThe watch patterns are [extglob] format.\n\n## Examples\n\n```bash\n# The simple case\nwatchy -w 'lib/**/*' -- say \"The lib directory changed.\"\n\n# Piping works as well\nwatchy -w 'styles/**/*.less' -- bash -c \"lessc styles/main.less | autoprefixer -o .tmp/styles/main.css\"\n\n# Keep a process alive, restarting it as soon as it exits or \"server.js\"\n# changes.\nwatchy -kw server.js -- node server.js\n\n# Watch every file except dotfiles, the node_modules folder, and JSON files.\n# NOTE: Listen to as few files as possible for better performance.\nwatchy -w . -i '/\\.|/node_modules|\\.json$' -- node server.js\n\n# Tick tock!\nwatchy -ks -- bash -c 'date \u0026\u0026 sleep 1'\n\n# Tick tock (annoying version)!\nwatchy -ks -- bash -c 'say \"In case you were wondering, it is `date`\" \u0026\u0026 sleep 5'\n\n# $WATCHY_ACTION and $WATCHY_PATH are passed to the process.\nwatchy -w '**/*' -- bash -c 'echo $WATCHY_ACTION $WATCHY_PATH'\n# =\u003e modified /Users/casey/Documents/code/watchy/README.md\n```\n\n\u003e Note: If you're using `watchy` for help with preprocessing, I'd recommend\n\u003e checking out my [cogs] project that is highly optimized for that case with\n\u003e in-memory processed file caching, directives, AMD support, and much more.\n\n## SIGTERM\n\nBy default, `watchy` will send `SIGTERM` to the running process after a change\nand wait for it to exit gracefully. By sending the `--wait|-W n` option, you can\ntell `watchy` to forcefully `SIGKILL` the process after `n` seconds. In general,\nyou should try to clean up connections in your processes like so:\n\n```js\nprocess.on('SIGTERM', function () {\n  server.close();\n  db.disconnect();\n  redis.quit();\n  // etc...\n});\n```\n\n## Node API\n\nAs of `0.9.0` watchy exposes a Node.js API.\n\n```js\nconst watchy = require('watchy');\n\nwatchy({\n  patterns: ['js/**/*.js', 'css/**/*.css'],\n  onError: error =\u003e console.error(error),\n  onChange: ({action, path}) =\u003e console.log(action, path),\n  usePolling: true // defaults to `false`, but will fallback when fsevents are not available\n}).catch(er =\u003e {\n  console.error(er);\n  process.exit(1);\n});\n```\n\n[cogs]: https://github.com/caseywebdev/cogs\n[extglob]: https://www.linuxjournal.com/content/bash-extended-globbing\n[Node.js]: https://nodejs.org\n[npm]: https://www.npmjs.com\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcaseywebdev%2Fwatchy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcaseywebdev%2Fwatchy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcaseywebdev%2Fwatchy/lists"}