rubyist / guard-rake

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

Automatically create a Guardfile from Rake tasks #46

Closed edusantana closed 4 years ago

edusantana commented 4 years ago

this is my way to provide this feature #45

I woukd also update the README with:

Creating a rake task to generate a Guardfile

To make some useful code, you must define rake tasks with file dependencies. To make it easy to test, put this code inside your Rakefile:

files = Rake::FileList.new('*.md')

desc "Create a book"
task 'book' => files do
  sh "cat #{files.join(" ")} > book.txt"
end

Now you are ready to use. Put this inside your Rakefile:

require "guard/rake/task"

Guard::Rake::Task.new

Or, your may want to watch Rakefile as well:

Guard::Rake::Task.new do |t|
  t.watch_rakefile = true
end

You may define your own ERB template:

Guard::Rake::Task.new('guard') do |t|
 t.template=File.read('Guardfile.erb')
end

NOTE: You will have to provide you own Guardfile.erb for the above code to work.

All these code will create a task that can be run with:

rake guard

Examples:

rake guard
rake guard GUARDFILE=Guardfile2.rb      # output to differente file
edusantana commented 4 years ago

@rubyist please, have a look in this code and this pull request.

rubyist commented 4 years ago

:+1: Would you want to update the README with your suggestions and I'll merge it in? Thanks!

edusantana commented 4 years ago

See #47 instead.