Question

I'm trying to utilize Sprockets on a non-Rails/Rack project and I came across a how-to guide by Simone Carletti

I have my project setup like so:

.
Gemfile
Rakefile
/src
    /javascripts
    /stylesheets
        960.css

Gemfile:

source "http://rubygems.org"

gem 'sass'
gem 'sprockets'

Rakefile:

require 'rubygems'
require 'bundler'
require 'pathname'
require 'logger'
require 'fileutils'

Bundler.require

ROOT        = Pathname(File.dirname(__FILE__))
LOGGER      = Logger.new(STDOUT)
BUNDLES     = %w( all.css all.js )
BUILD_DIR   = ROOT.join("build")
SOURCE_DIR  = ROOT.join("src")

task :compile => :cleanup do
  sprockets = Sprockets::Environment.new(ROOT) do |env|
    env.logger = LOGGER
  end

  sprockets.append_path(SOURCE_DIR.join('javascripts').to_s)
  sprockets.append_path(SOURCE_DIR.join('stylesheets').to_s)

  BUNDLES.each do |bundle|
    assets = sprockets.find_asset(bundle)
    prefix, basename = assets.pathname.to_s.split('/')[-2..-1]
    FileUtils.mkpath BUILD_DIR.join(prefix)

    assets.write_to(BUILD_DIR.join(prefix, basename))
    assets.to_a.each do |asset|
      # strip filename.css.foo.bar.css multiple extensions
      realname = asset.pathname.basename.to_s.split(".")[0..1].join(".")
      asset.write_to(BUILD_DIR.join(prefix, realname))
    end
  end
end

I run

bundle install

and the bundle installs successfully.

When I run

rake compile

I get the following error

rake aborted!
Don't know how to build task 'cleanup'

Tasks: TOP => compile
(See full trace by running task with --trace)

Any ideas on why this might be occurring? Using ruby 1.9.3p194 if that helps debug this issue.

Was it helpful?

Solution

task :compile => :cleanup do

It means the task :compile requires :cleanup but you have no :cleanup task defined. Change it to

task :compile do
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top