Skip to content

Instantly share code, notes, and snippets.

@lukemelia
Created July 4, 2012 22:06
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lukemelia/3049756 to your computer and use it in GitHub Desktop.
Save lukemelia/3049756 to your computer and use it in GitHub Desktop.
Example rack app for Ember development
require 'bundler/setup'
require 'sass'
require 'compass'
require 'rake-pipeline'
require 'listen'
require 'rack/lock'
require 'ruby-debug'
require 'securerandom'
require 'ruby_gntp'
STDOUT.sync = true
root = File.expand_path File.dirname(__FILE__)
project = Rake::Pipeline::Project.new(File.join(root, 'Assetfile'))
project.pipelines.each do |pipeline|
pipeline.rake_application = Rake.application
pipeline.setup
end
project.invoke_clean
cache_manifest_path = File.join(root, 'build', 'cache.manifest')
require 'thread'
if ENV['TEST']
test_mutex = Mutex.new
test_resource = ConditionVariable.new
end
build_lock = Mutex.new
build_proc = lambda {|modified, added, removed|
success = true
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
success = false
puts "ERROR: #{$!.inspect}"
GNTP.notify({
:app_name => "yapp-mobile",
:title => "yapp-mobile error",
:text => "ERROR: #{$!.inspect}"
}) rescue nil
end
else
puts "BUILD #{start}"
begin
project.invoke
rescue
success = false
puts "ERROR: #{$!.inspect}"
GNTP.notify({
:app_name => "yapp-mobile",
:title => "yapp-mobile error",
:text => "ERROR: #{$!.inspect}"
}) rescue nil
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"
}
# after UNLOCK
if ENV['TEST'] && success
test_mutex.synchronize do
test_resource.signal
end
end
}
watcher_queue = Queue.new
watcher_thread = Thread.new do
listener = Listen.to('app', 'css', 'images', 'test', '../yapp-themes/sass_shared')
listener.change(&build_proc)
watcher_queue << listener
listener.start # enter the run loop
end
watcher_thread.abort_on_exception = true
puts "Watching #{watcher_queue.pop.directories}"
if ENV['TEST']
test_thread = Thread.new do
while true
test_mutex.synchronize do
test_resource.wait(test_mutex)
end
puts 'RUNNING TESTS'
if system('rake test')
GNTP.notify({
:app_name => "yapp-mobile",
:title => "yapp-mobile error",
:text => "JS test GREEN!"
}) rescue nil
else
GNTP.notify({
:app_name => "yapp-mobile",
:title => "yapp-mobile error",
:text => "JS test RED!"
}) rescue nil
end
end
end
end
use Rack::Lock, build_lock
run Rack::File.new(File.join(root, 'build'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment