Skip to content
This repository has been archived by the owner on Jun 8, 2019. It is now read-only.

Commit

Permalink
Create Kumade::Packager. More one step to close issue #7.
Browse files Browse the repository at this point in the history
  • Loading branch information
tapajos authored and Gabe Berke-Williams committed Sep 12, 2011
1 parent 4279a2f commit 56b11b3
Show file tree
Hide file tree
Showing 5 changed files with 415 additions and 352 deletions.
1 change: 1 addition & 0 deletions lib/kumade.rb
Expand Up @@ -7,6 +7,7 @@ module Kumade
autoload :DeploymentError, "kumade/deployment_error"
autoload :Configuration, "kumade/configuration"
autoload :Heroku, "kumade/heroku"
autoload :Packager, "kumade/packager"

def self.configuration
@@configuration ||= Configuration.new
Expand Down
97 changes: 9 additions & 88 deletions lib/kumade/deployer.rb
Expand Up @@ -3,13 +3,14 @@

module Kumade
class Deployer < Base
attr_reader :git, :heroku
attr_reader :git, :heroku, :packager

def initialize
super()
@git = Git.new
@heroku = Heroku.new
@branch = @git.current_branch
@git = Git.new
@heroku = Heroku.new
@branch = @git.current_branch
@packager = Packager.new(@git)
end

def deploy
Expand All @@ -30,6 +31,10 @@ def pre_deploy
sync_github
end

def package_assets
packager.run
end

def sync_github
git.push(@branch)
end
Expand All @@ -42,90 +47,6 @@ def ensure_clean_git
git.ensure_clean_git
end

def package_assets
invoke_custom_task if custom_task?
package_with_jammit if jammit_installed?
package_with_more if more_installed?
end

def package_with_jammit
begin
success_message = "Packaged assets with Jammit"

if Kumade.configuration.pretending?
success(success_message)
else
Jammit.package!

success(success_message)
git_add_and_commit_all_assets_in(jammit_assets_path)
end
rescue => jammit_error
error("Error: #{jammit_error.class}: #{jammit_error.message}")
end
end

def package_with_more
success_message = "Packaged assets with More"
if Kumade.configuration.pretending?
success(success_message)
else
begin
run "bundle exec rake more:generate"
if git.dirty?
success(success_message)
git_add_and_commit_all_assets_in(more_assets_path)
end
rescue => more_error
error("Error: #{more_error.class}: #{more_error.message}")
end
end
end

def invoke_custom_task
success("Running kumade:before_asset_compilation task")
Rake::Task["kumade:before_asset_compilation"].invoke unless Kumade.configuration.pretending?
end

def git_add_and_commit_all_assets_in(dir)
git.add_and_commit_all_in(dir, Kumade::Heroku::DEPLOY_BRANCH, 'Compiled assets', "Added and committed all assets", "couldn't commit assets")
end

def jammit_assets_path
File.join(Jammit::PUBLIC_ROOT, Jammit.package_path)
end

def more_assets_path
File.join('public', ::Less::More.destination_path)
end

def jammit_installed?
@jammit_installed ||=
(defined?(Jammit) ||
begin
require 'jammit'
true
rescue LoadError
false
end)
end

def more_installed?
@more_installed ||=
(defined?(Less::More) ||
begin
require 'less/more'
true
rescue LoadError
false
end)
end

def custom_task?
load("Rakefile") if File.exist?("Rakefile")
Rake::Task.task_defined?("kumade:before_asset_compilation")
end

def ensure_heroku_remote_exists
if git.remote_exists?(Kumade.configuration.environment)
if git.heroku_remote?
Expand Down
94 changes: 94 additions & 0 deletions lib/kumade/packager.rb
@@ -0,0 +1,94 @@
module Kumade
class Packager < Base
attr_reader :git

def initialize(git)
super()
@git = git
end

def run
invoke_custom_task if custom_task?
package_with_jammit if jammit_installed?
package_with_more if more_installed?
end

def invoke_custom_task
success "Running kumade:before_asset_compilation task"
Rake::Task["kumade:before_asset_compilation"].invoke unless Kumade.configuration.pretending?
end

def custom_task?
load("Rakefile") if File.exist?("Rakefile")
Rake::Task.task_defined?("kumade:before_asset_compilation")
end

def package_with_jammit
begin
success_message = "Packaged assets with Jammit"

if Kumade.configuration.pretending?
success(success_message)
else
Jammit.package!

success(success_message)
git_add_and_commit_all_assets_in(jammit_assets_path)
end
rescue => jammit_error
error("Error: #{jammit_error.class}: #{jammit_error.message}")
end
end

def package_with_more
success_message = "Packaged assets with More"
if Kumade.configuration.pretending?
success(success_message)
else
begin
run "bundle exec rake more:generate"
if git.dirty?
success(success_message)
git_add_and_commit_all_assets_in(more_assets_path)
end
rescue => more_error
error("Error: #{more_error.class}: #{more_error.message}")
end
end
end

def git_add_and_commit_all_assets_in(dir)
git.add_and_commit_all_in(dir, Kumade::Heroku::DEPLOY_BRANCH, 'Compiled assets', "Added and committed all assets", "couldn't commit assets")
end

def jammit_assets_path
File.join(Jammit::PUBLIC_ROOT, Jammit.package_path)
end

def more_assets_path
File.join('public', ::Less::More.destination_path)
end

def jammit_installed?
@jammit_installed ||=
(defined?(Jammit) ||
begin
require 'jammit'
true
rescue LoadError
false
end)
end

def more_installed?
@more_installed ||=
(defined?(Less::More) ||
begin
require 'less/more'
true
rescue LoadError
false
end)
end
end
end

0 comments on commit 56b11b3

Please sign in to comment.