2012-04-30 35 views
2

我有一個項目,其中包括許多出售的javascript,例如jQuery的。我將這些腳本包含爲git子模塊。但是,對於我的構建過程,我需要構建的腳本,而不是該腳本的整個存儲庫。所以我試圖設置一個rake任務來構建每個腳本 - 最好使用腳本自己的rakefile - 然後將構建的腳本複製到我的資產目錄中。如何在git子模塊上調用rake任務?

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 

如果我用我的Rakefile import 'app/vendor/scriptname/Rakefile',我應該有機會獲得一個構建腳本rake任務,對不對?我怎麼稱呼它?或者我應該只使用sh "cd app/vendor/script-submodule/ && rake dist"並稱它爲好?

回答

0

我正在研究一個類似的問題,通過像平常一樣調用rake任務,它似乎可以正常工作。這是我的例子的樣子,看看你是否能讓你的身材適合。

# 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 
在我的子模塊的Rake文件

然後:

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

和樣品rake任務:

# 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 
從命令提示符

然後:

rake foo:bar:task