{"id":15639844,"url":"https://github.com/danawoodman/cng","last_synced_at":"2025-06-15T16:01:50.880Z","repository":{"id":203448890,"uuid":"709624818","full_name":"danawoodman/cng","owner":"danawoodman","description":"🔭 Run commands on file change using glob patterns","archived":false,"fork":false,"pushed_at":"2024-02-27T20:13:11.000Z","size":58,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-23T23:16:51.915Z","etag":null,"topics":["cli","go","golang","onchange","process","runner","task","util","watch","watcher"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/danawoodman.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2023-10-25T04:17:28.000Z","updated_at":"2024-10-26T06:42:01.000Z","dependencies_parsed_at":null,"dependency_job_id":"c00e7fdb-4f53-45a2-a0af-20e8d7875b1b","html_url":"https://github.com/danawoodman/cng","commit_stats":null,"previous_names":["danawoodman/gochange","danawoodman/cng"],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danawoodman%2Fcng","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danawoodman%2Fcng/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danawoodman%2Fcng/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danawoodman%2Fcng/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/danawoodman","download_url":"https://codeload.github.com/danawoodman/cng/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246249222,"owners_count":20747167,"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":["cli","go","golang","onchange","process","runner","task","util","watch","watcher"],"created_at":"2024-10-03T11:27:59.076Z","updated_at":"2025-03-29T21:40:34.966Z","avatar_url":"https://github.com/danawoodman.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 🔭 cng - run commands on file ChaNGes\n\n\u003e Run commands on file change using glob patterns, heavily inspired by the excellent [onchange][onchange], but written in Go.\n\n## Notes\n\n- This is a new, experimental project. I use it in multiple projects on a daily basis and it's working great for me. That said it hasn't been heavily tested, so please open an issue if you run into any problems.\n- I haven't tested this much outside of my personal system (macOS). Theoretically this should work on \\*nix systems and even Windows, but I haven't yet tested it on them.\n\n## Install\n\nDownload a [release](https://github.com/danawoodman/cng/releases) for your platform and add it to your path.\n\nOr just install with Golang:\n\n```shell\ngo install github.com/danawoodman/cng\n```\n\n## Usage\n\n```shell\n# Run `go run ./cmd/myapp` when any .go or .html files change.\n# `-i` runs the command once initially, without any event\n# `-k`` kills running processes between changes\n# The command you want to run is followed by the `--` separator:\ncng -ik '**/*.go' 'templates/**/*.html' -- go run ./cmd/myapp\n\n# Run tests when your source or tests change:\ncng 'app/**/*.{ts,tsx}' '**/*.test.ts' -- npm test\n\n# Wait 500ms before running the command again:\ncng -d 500 '*.md' -- echo \"changed!\"\n\n# Ignore/exclude some paths:\ncng -e 'path/to/exclude/*.go' '**/*.go' -- echo \"changed!\"\n```\n\n## Features\n\n- Watch for changes using global patterns like `'*.go'` or `'src/**/*.jsx?'` (using [doublestar][doublestar], which is a much more flexible option than Go's built in glob matching). Watching is done using the very fast [fsnotify][fsnotify] library.\n- Run any command you want, like `go run ./cmd/myapp` or `npm test`\n- Optionally kill running processes between changes, useful for when running web servers for example. Importantly, cng kills all child processes as well, so your ports get properly freed between runs (avoids errors like `\"bind: address already in use\"`)\n- Optionally run the task immediately or only run when a change is detected (default)\n- Pass in a delay to wait between re-runs. If a change is detected in the delay window, the command will not be re-run. This is useful for when you're making a lot of changes at once and don't want to run the command for each change.\n- Optionally exclude paths from triggering the command\n\n## Options\n\n```\n$ cng\nRuns a command when file changes are detected\n\nUsage:\n  cng [flags] [paths] -- [command]\n\nFlags:\n  -a, --add               execute command for initially added paths\n  -d, --delay int         delay between process changes in milliseconds\n  -e, --exclude strings   exclude matching paths\n  -h, --help              help for cng\n  -i, --initial           execute command once on load without any event\n  -k, --kill              kill running processes between changes\n  -v, --verbose           enable verbose logging\n```\n\n## Notes and Limitations\n\nCurrently, cng only supports a subset of the onchange commands, but I'm open to adding more. Please open an issue if you have a feature request.\n\nThis is a very new project and hasn't been tested really anywhere outside of my machine (macOS), if you run into any issues, please open an issue!\n\nNo test suite as of yet, but I aspire to add one 😇.\n\n## Motivations\n\nMostly, this project was an excuse to play more with Go, but also I wanted a more portable version of onchange.\n\nI also couldn't find the tool I wanted in the Go (or broader) ecosystem that was a portable binary. I tried out [air][air], [gow][gow], [Task][task] and others but none of them really fit my needs (still great tools tho!). For me, air didn't work well when I tried it with `go run`. `gow` does work with `go run` but it's not generic enough to use outside of go projects. `Task` is a cool modern alternative to make but I also could get it working well with `go run` and killing my web server processes (and associated port binding).\n\nI loved onchange but the combo of requiring Node, not being maintained anymore, and not being a portable binary was a deal breaker for me (well that and I just wanted to try and make it myself in Go 😅).\n\n## Development\n\nPRs welcome!\n\nWe use Cobra to parse command line arguments.\n\n```shell\n# Build the CLI\nmake build\n\n# Run tests once\nmake test\nmake test-unit\nmake test-e2e\n\n# Run tests in watch mode\nmake watch-test\nmake watch-unit-test\nmake watch-e2e-test\n\n# Install the CLI locally\nmake install\n\n# Reinstall the CLI after making changes:\nmake watch-install\n```\n\n## License\n\nMIT\n\n## Credits\n\nWritten by [Dana Woodman](https://danawoodman.com) with heavy inspiration from [onchange][onchange].\n\n[onchange]: https://github.com/Qard/onchange\n[air]: https://github.com/cosmtrek/air\n[gow]: https://github.com/mitranim/gow\n[task]: https://github.com/go-task/task\n[doublestar]: https://github.com/bmatcuk/doublestar\n[fsnotify]: https://github.com/fsnotify/fsnotify\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanawoodman%2Fcng","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdanawoodman%2Fcng","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanawoodman%2Fcng/lists"}