2

我有一个项目,其中包括许多供应商的 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

如果我import 'app/vendor/scriptname/Rakefile'在我的 Rakefile 中使用,我应该可以访问构建脚本的 rake 任务,对吧?我该怎么称呼它?还是我应该使用sh "cd app/vendor/script-submodule/ && rake dist"并称其为好?

4

1 回答 1

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

然后在我的子模块的 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
于 2013-09-20T14:50:24.843 回答