Search code examples
rubyrakerake-pipeline

Running Rake::Pipeline.build inside of Rakefile


I'm trying to kick off a Rake Pipeline task from inside a Rakefile. From what I can tell the process to do that would be to do something like the example here.

However, that isn't working. Here is a gist reducing that example to barebones.

It shows a reduced test case where it works using rake-pipeline's Assetfile, but when trying to include that same exact code in a Rakefile it doesn't work.

  1. Why is it failing?
  2. What is a solution to make this work? (No cheating and running a system call as part of the Rakefile.)

Thanks for your help!


Solution

  • Works

    It looks like one way to handle this is to execute a file, like so:

    project = Rake::Pipeline::Project.new('Assetfile')
    # project.clean      # Required for rake-pipeline 0.7.0
    project.invoke
    

    However, this is annoying as I have to create a file for every single rake task.

    Doesn't Work

    Looking at the code for Rake::Pipeline it should allow me to pass in a Pipeline, such that this code works:

    pipeline = Rake::Pipeline.build do
      output "js"
      puts Dir.pwd
      input "js" do
        match "*.js" do
          # concatenate all JS files into a single file
          filter Rake::Pipeline::ConcatFilter, "application.js"
        end
      end
    end
    
    project = Rake::Pipeline::Project.new(pipeline)
    project.invoke
    

    Anybody know why this won't work? The error:

    undefined method `manifest' for nil:NilClass
    rake-pipeline-0.8.0/lib/rake-pipeline.rb:408:in `manifest'
    rake-pipeline-0.8.0/lib/rake-pipeline.rb:456:in `block in record_input_files'
    rake-pipeline-0.8.0/lib/rake-pipeline.rb:453:in `each'
    rake-pipeline-0.8.0/lib/rake-pipeline.rb:453:in `record_input_files'
    rake-pipeline-0.8.0/lib/rake-pipeline.rb:340:in `setup'
    rake-pipeline-0.8.0/lib/rake-pipeline.rb:326:in `block in invoke'
    <internal:prelude>:10:in `synchronize'
    rake-pipeline-0.8.0/lib/rake-pipeline.rb:321:in `invoke'
    rake-pipeline-0.8.0/lib/rake-pipeline/project.rb:126:in `each'
    rake-pipeline-0.8.0/lib/rake-pipeline/project.rb:126:in `block in invoke'
    <internal:prelude>:10:in `synchronize'
    rake-pipeline-0.8.0/lib/rake-pipeline/project.rb:112:in `invoke'
    Rakefile:23:in `block in <top (required)>'