2
votes

I have a project including a number of vendored javascripts, e.g. jQuery. I'm including these scripts as git submodules. However, for my build process, I need the built script, not the whole repository of that script. So I'm trying to set up a rake task to build each script - preferably using the script's own rakefile - and then copy the built script into my asset directory.

file "app/vendor/scriptname.js" do
    # Call the task that builds the script here
    sh "cp app/vendor/script-submodule/dist/scriptname.js app/vendor/"
end

desc "Make vendor scripts available for build"
task :vendor => "app/vendor/scriptname.js" do
end

If I use import 'app/vendor/scriptname/Rakefile' in my Rakefile, I should have access to the rake task that builds the script, right? How would I call it? Or should I just use sh "cd app/vendor/script-submodule/ && rake dist" and call it good?

1

1 Answers

0
votes

I'm working out a similar problem and it would seem to work just fine by calling the rake task as you normally would. Here's what my example looks like, see if you can get yours to fit.

# Rakefile
#!/usr/bin/env rake
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.

require File.expand_path('../config/application', __FILE__)
load 'engines/foo_engine/Rakefile'

MyApp::Application.load_tasks

Then in my submodule's Rakefile:

# engines/foo_engine/Rakefile
Dir[File.join(File.dirname(__FILE__), 'tasks/**/*.rake')].each do |f|
  load f
end

And a sample rake task:

# engines/foo_engine/lib/tasks/foo/bar/task.rake
namespace :foo do
  namespace :bar do
    desc "FooBar task"
    task :foo_bar => :environment do
      # perform task
    end
  end
end

Then from the command prompt:

rake foo:bar:task