Crystal shard to watch file changes. This shard use the same code implemented here (Guardian) and here (Sentry).
Add this to your application's shard.yml:
dependencies:
watcher:
github: faustinoaq/watcherUse the keyword watch to watch files or file groups, for example:
require "watcher"
watch "src/assets/js/*.js" do |event|
event.on_change do |files|
files.each do |file, {first, timestamp}|
puts "File #{file} has changed at #{timestamp}"
end
# ...
end
endAlso you can have more than one watcher, just use spawn
spawn do
watch ["src/assets/*.css", "src/views/*.html"] do |event|
event.on_change do
# ...
end
end
end
# Other watcher
watch ... do |event|
#...
endAnd you can change time interval for a watcher.
watch "public/*.json", interval: 0.5 do |event|
event.on_change do
# ...
end
endAlso you can use Watcher.watch instead of watch.
Watcher uses timestamps to check file changes every second, if you want some more advanced then you can use Watchbird that uses libnotify to check events like modify, access and delete but just work in Linux for now.
- Fork it ( https://github.com/faustinoaq/watcher/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
- faustinoaq Faustino Aguilar - creator, maintainer
