If you have a project for which you've built a Rakefile and it includes a subproject which has its own Rakefile, you can 'bridge' the subproject into the super project with a single line: 'subproject(dir)'. With this in place, all the subproject's tasks can be called in the super project.
Here's what it looks like:
require 'rake/subproject'
subproject 'foo'
task :clean => 'foo:clean'
task :default => ['foo/bar', 'foo:bar:baz']
require 'rake/clean'
file 'bar' do |t|
touch t.name
end
CLEAN.include 'bar'
namespace 'bar' do
task 'baz' do
$stdout.puts "SUCCESS"
end
end
Now, let's execute the top-level Rakefile twice:
$ find .
.
./foo
./foo/Rakefile
./Rakefile
$ rake
touch bar
SUCCESS
$ find .
.
./foo
./foo/bar
./foo/Rakefile
./Rakefile
$ rake
SUCCESS
$ rake clean
$ rake
touch bar
SUCCESS
$ rake foo:bar:baz
SUCCESS
There are some interesting things to observe:
-
The task
foo/bar
was only executed the first time because:- It was a FileTask and
- the first time created it so the second time it was skipped
-
The namespace
foo:
passes through to the subproject and calls the task locally there. -
The file
bar
is created relative to the subproject even though we are calling it from the super-project -
The
:clean
task is bridged into the subproject's:clean
task -
We can directly call
foo:bar:baz
from the command-line
Add this line to your application's Gemfile:
gem 'rake-subproject'
And then execute:
$ bundle
Or install it yourself as:
$ gem install rake-subproject
TODO: Write usage instructions here
- Fork it ( http://github.com//rake-subproject/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 new Pull Request