Skip to content

Instantly share code, notes, and snippets.

@lukemelia
Created March 23, 2012 03:26
Show Gist options
  • Save lukemelia/2166462 to your computer and use it in GitHub Desktop.
Save lukemelia/2166462 to your computer and use it in GitHub Desktop.
rake pipeline rack config
require 'bundler/setup'
require 'sass'
require 'compass'
require 'rake-pipeline'
require 'listen'
require 'rack/lock'
require 'ruby-debug'
require 'securerandom'
STDOUT.sync = true
root = File.expand_path File.dirname(__FILE__)
project = Rake::Pipeline::Project.new(File.join(root, 'Assetfile'))
#project.invoke_clean
cache_manifest_path = File.join(root, 'assets', 'cache.manifest')
require 'thread'
build_lock = Mutex.new
build_proc = lambda {|modified, added, removed|
build_lock.synchronize {
puts 'FILE CHANGE'
puts ' modified: ' + modified.join(', ') unless modified.empty?
puts ' added: ' + added.join(', ') unless added.empty?
puts ' removed: ' + removed.join(', ') unless removed.empty?
start = Time.now
if added.size > 0 || removed.size > 0
puts "BUILD (CLEAN) #{start}"
begin
project.invoke_clean
rescue
puts "ERROR: #{$!.inspect}"
end
else
puts "BUILD #{start}"
begin
project.invoke
rescue
puts "ERROR: #{$!.inspect}"
end
end
cache_manifest = File.read(cache_manifest_path)
cache_manifest.sub!(/Fingerprint:\ .+$/, "Fingerprint: #{SecureRandom.hex(16)}")
open(cache_manifest_path, 'w') {|f| f.write(cache_manifest)}
puts "FINISHED #{Time.now.to_i - start.to_i} seconds"
}
}
listen_paths = ['app', 'css', 'images']
queue = Queue.new
listen_paths.each do |listen_path|
listen_path = File.join(root, listen_path)
Thread.new do
listener = Listen.to(listen_path)
listener.change(&build_proc)
queue << listen_path
listener.start # enter the run loop
end
end
listen_paths.size.times do
puts "watching #{queue.pop}"
end
use Rack::Lock, build_lock
run Rack::File.new(root)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment