【问题标题】:How can I call a rake task on a git submodule?如何在 git 子模块上调用 rake 任务?
【发布时间】:2012-05-10 08:17:02
【问题描述】:

我有一个项目,其中包含许多供应商的 javascript,例如jQuery。我将这些脚本作为 git 子模块包含在内。但是,对于我的构建过程,我需要构建的脚本,而不是该脚本的整个存储库。所以我试图设置一个 rake 任务来构建每个脚本 - 最好使用脚本自己的 rakefile - 然后将构建的脚本复制到我的资产目录中。

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" 并称其为好?

【问题讨论】:

    标签: rake git-submodules rake-task rakefile


    【解决方案1】:

    我正在解决一个类似的问题,通过像往常一样调用 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
    

    然后在我的子模块的 Rakefile 中:

    # 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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-09-07
      • 2016-08-05
      • 1970-01-01
      • 1970-01-01
      • 2015-05-14
      • 2012-06-04
      • 1970-01-01
      • 2013-03-27
      相关资源
      最近更新 更多