Skip to content

Instantly share code, notes, and snippets.

@henrypoydar
Created September 2, 2009 20:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save henrypoydar/179949 to your computer and use it in GitHub Desktop.
Save henrypoydar/179949 to your computer and use it in GitHub Desktop.
namespace :heroku do
desc "Prepare and deploy the application to heroku"
task :deploy => ['heroku:deploy:default']
namespace :deploy do
task :default => ['assets:compile', 'assets:minify', :commit, :push, 'assets:cleanup']
desc "Commit pre-deployment changes"
task :commit do
puts 'Committing deployment changes'
system "git add public/stylesheets/compiled public/sprockets.js && git commit -m 'Prepared for heroku deployment'"
end
desc "Push application to heroku"
task :push do
puts 'Pushing application to heroku'
system "git push heroku master"
end
desc "Prepare and deploy the application to heroku and run pending migrations"
task :migrations => :default do
puts 'Running pending migrations'
system "heroku rake db:migrate"
end
end
end
namespace :assets do
desc "Compiles and concatenates javascripts and stylesheets"
task :compile => ['sprockets:install_script', 'sprockets:install_assets'] do
puts "Compiled and concatenated javascripts"
system "compass -e production --force"
puts "Compiled and concatenated stylesheets"
end
desc "Minifies cached javascript and stylesheets"
task :minify do
require 'rubygems'
require 'jsmin'
require 'cssmin'
Dir.glob("#{File.dirname(__FILE__)}/../../public/stylesheets/compiled/*.css").each do |css|
f = ""
File.open(css, 'r') {|file| f << CSSMin.minify(file)}
File.open(css, 'w') {|file| file.write(f)}
puts "Minified #{css}"
end
Dir.glob("#{File.dirname(__FILE__)}/../../public/sprockets.js").each do |js|
f = ""
File.open(js, 'r') {|file| f << JSMin.minify(file)}
File.open(js, 'w') {|file| file.write(f)}
puts "Minified #{js}"
end
end
desc "Remove compiled and concatenated assets"
task :cleanup do
Dir.glob("#{File.dirname(__FILE__)}/../../public/stylesheets/compiled/*.css").each do |css|
FileUtils.rm_rf(css)
system "git rm #{css}"
end
puts 'Removed compiled stylesheets'
Dir.glob("#{File.dirname(__FILE__)}/../../public/sprockets.js").each do |js|
FileUtils.rm_rf(js)
system "git rm #{js}"
end
puts 'Removed compiled javascripts'
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment