Skip to content

Instantly share code, notes, and snippets.

@msuzoagu
Forked from guilleiguaran/custom_compiler.rb
Created August 24, 2019 00:08
Show Gist options
  • Save msuzoagu/e66dbe838b2b873a6272db3504fa0c2e to your computer and use it in GitHub Desktop.
Save msuzoagu/e66dbe838b2b873a6272db3504fa0c2e to your computer and use it in GitHub Desktop.
Compile assets and push them automatically when run rake assets:precompile
class AssetsCompiler < Sprockets::StaticCompiler
def precompile(paths)
ensure_clean_git
Rake::Task["assets:clean"].invoke
super
commit_compiled_assets
push
end
def ensure_clean_git
raise "Can't deploy without a clean git status." if git_dirty?
end
def commit_compiled_assets
run "git add -u && git add . && git commit -am 'Compiled assets'"
end
def push
run "git push"
end
private
def run(command)
puts "+ Running: #{command}"
puts "-- #{system command}"
end
def git_dirty?
`[[ $(git diff --shortstat 2> /dev/null | tail -n1) != "" ]]`
dirty = $?.success?
end
end
Rails.application.config.assets.compiler = AssetsCompiler
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment