Reputation: 2270
I have a rakefile with a task that copies the contents of a directory to somewhere else on disk. When the rakefile is executing, I need this task to run if any of the contents of this directory have changed since the last execution of the rakefile (or if the copy has never occurred). This includes changes to modification dates or file names. (Note that changing the names of files does not change their modification date.)
Put another way, I want something that works the same way as a file task that has a dependency on another file. But rather than it involving individual files, I want the task to generate a directory structure and for its dependency to be another directory structure.
What would be the best method of accomplishing this? I need a cross platform solution as this rakefile is run on Windows, OS X, and Linux.
Upvotes: 2
Views: 176
Reputation: 8638
rake
is described as
Rake is a Make-like program implemented in Ruby.
Like make
it allows defining dependencies and run tasks only if needed.
See also this RubyTapa.
It boils down to:
file 'target' => 'source' do
sh "your_transform_command"
end
You can also write general rules:
rule '.html' => '.md' do |file|
sh "pandoc -o #{file.name} #{file.souce}"
end
and then run this command to transform README.md to README.haml only if README.md is newer than README.html:
rake README.html
Upvotes: 0