rubyist / guard-rake

guard-rake runs a rake task when files change
MIT License
94 stars 32 forks source link

Rake tasks getting defined 2+ times.. #29

Closed apinstein closed 11 years ago

apinstein commented 11 years ago

I am not sure if this is a rake or guard bug, but I'll start here...

So I have this:

guard 'rake', :task => 'tourbuilder:release' do
    watch(%r{^js-apps/tourbuilder/.+$})
end

And in my rake task I'm dynamically generating a dependency tree via globs, something like:

Dir.glob('/src/**/*.coffee').each do |coffee|
  # magic gsub nonsense...
  file jsOut => coffeeIn do |c|
    sh "coffee -o #{jsOutDir} -c #{coffeeIn}"
  end
end

Guard properly triggers whenever an input file changes, but every time a file changes I am getting 1 more task defined, so the coffeescript compiler command runs N times, N being how many files saves have happened since I ran guard.

The first hack way to try to fix it was just to shell out to the rake task so that I'd get a clean runtime on each invoke but I was hoping for something more, er, correct.

Any ideas?

apinstein commented 11 years ago

Well, I just found this and it seems to work...

  file jsOut => coffeeIn do |t|
    t.clear_actions()
    sh "coffee -o #{jsOutDir} -c #{coffeeIn}"
  end

That resets the action list each time I define the tasks and prevents the duplicate execution. Hopefully this will help others!