Watch your files and run commands on changes from a crystal script
-
Add the dependency to your
shard.yml
:dependencies: watch: github: danreeves/watch
-
Run
shards install
Create a crystal file to be your task manager, something like watch.cr
require "watch"
Watch.watch "./src/**/*.cr", "crystal build src/main.cr"
Watch.watch "./*", "echo \"wow a file changed\"", opts: [:verbose, :log_changes]
Watch.run
Now you can run it with crystal watch.cr
and rebuild your main application whenever a file changes. Useful for webservers like Kemal!
Every Watch.watch
command is run in it's own Fiber so you can have multiple tasks running different commands while watching different files.
watch
takes a glob of files to watch and a command to run. Configuration is provided by opts
and includes:
:on_start
: Run the command immediately as well as on file changes:log_changes
: Print a message when a file changes:verbose
: Increases the verbosity of the message to includes how many files changed and whether they were new files, deletions, or changes.
Required to be called at the end of your watch script
- Fork it (https://github.com/danreeves/watch/fork)
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request
- Dan Reeves - creator and maintainer