I have guard (the ruby gem) setup and working it seems on my Mac and setting up a guard from guard-coffee and guard-shell seem to work fine. Here is the related section of my Guardfile below
guard 'coffeescript', :input => 'src/javascripts', :output => 'public/javascripts'
guard 'shell' do
watch( %r{^public/.+\.(js|css)$} ) do |m|
puts m.inspect
if m[1] == 'js'
puts 'a js is new!'
else
puts 'a css is new!'
end
puts %x{ echo #{File.mtime(m[0])} }
end
end
Which seems to output ‘a js is new’ twice if I edit a coffeescript file. With debug on it seems to run after
13:39:23 - DEBUG - Hook :run_on_changes_begin executed for Guard::CoffeeScript
13:39:23 - INFO - Compile src/javascripts/blah.coffee
13:39:23 - INFO - 01:39:23 PM Successfully generated public/javascripts/blah.js
["public/javascripts/blah.js", "js"]
a js is new!
and
13:39:23 - DEBUG - Hook :run_on_changes_end executed for Guard::CoffeeScript
["public/javascripts/blah.js", "js"]
a js is new!
It does seem to only fire once if I edit the blah.js file directly. I was a little confused by how hooks work, can I key into a hook from another guard? Should I just run this code in a callback in the coffeescript guard? I was trying to use groups and only do the shell part if I was in a group and didn’t want to have to repeat the coffee guard in the case where I would use a callback instead.
Any thoughts on how I can stop triggering the shell guard twice when the coffe one fires?
Prior to Guard 1.0.0, new files created and updated from a Guard plugin did not trigger a subsequent file change for other plugins. This was a problem for example with the CoffeeScript and LiveReload plugins: When a JavaScript file has been updated, then LiveReload did not reload the file. As a workaround I added some manual file trigger code. With the Listen gem this limitation has been removed, thus the CoffeeScript plugin triggers file changes twice.
I removed it on my master branch. Can you please give it a try before I release a new gem? You can do this easily by using my master branch by adding:
gem 'guard-coffeescript', :github => 'netzpirat/guard-coffeescript', :branch => 'master'
to your
Gemfile. I’ll release a new gem asap when it works fine.