This repository has been archived by the owner on Jun 8, 2019. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create Kumade::Packager. More one step to close issue #7.
- Loading branch information
Showing
5 changed files
with
415 additions
and
352 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
Oops, something went wrong.