Forked from joerichsen/parallel_assets_compiler.gemspec
Last active
December 18, 2015 10:49
-
-
Save juno/5771290 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# -*- encoding: utf-8 -*- | |
Gem::Specification.new do |s| | |
s.name = 'parallel_assets_compiler' | |
s.version = '0.2.0' | |
s.platform = Gem::Platform::RUBY | |
s.author = 'Jørgen Orehøj Erichsen' | |
s.email = '[email protected]' | |
s.summary = 'Compile assets in parallel' | |
s.description = 'Compile assets in parallel to speed up deployment' | |
s.files = ['parallel_assets_compiler.rb'] | |
s.require_path = '.' | |
s.add_dependency('parallel') | |
s.add_dependency('actionpack') | |
end |
This file contains hidden or 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
# Compile assets in parallel to speed up deployment | |
# | |
# Works by monkey patching to sprockets-rails 2.0.0 (for Rails 4.0.0) | |
# | |
# Use it by adding this to your Gemfile and run bundle install | |
# | |
# gem 'parallel_assets_compiler', :git => 'git://gist.github.com/2873091.git' | |
# | |
# Inspired by | |
# https://gist.github.com/joerichsen/2873091 | |
# https://github.com/steel/sprockets/commit/6327afc3341e34efd1dfdcfad08e3b9d85f7fd4a | |
# https://github.com/hornairs/sprockets-rails-parallel | |
require 'sprockets/manifest' | |
require 'parallel' | |
module Sprockets | |
class Manifest | |
def compile(*args) | |
raise Error, "manifest requires environment for compilation" unless environment | |
paths = environment.each_logical_path(*args).to_a + | |
args.flatten.select { |fn| Pathname.new(fn).absolute? if fn.is_a?(String)} | |
local_assets = [] | |
paths.each do |path| | |
if asset = find_asset(path) | |
files[asset.digest_path] = { | |
'logical_path' => asset.logical_path, | |
'mtime' => asset.mtime.iso8601, | |
'size' => asset.bytesize, | |
'digest' => asset.digest | |
} | |
assets[asset.logical_path] = asset.digest_path | |
local_assets << asset | |
end | |
end | |
Parallel.each(local_assets) do |asset| | |
target = File.join(dir, asset.digest_path) | |
if File.exist?(target) | |
logger.debug "Skipping #{target}, already exists" | |
else | |
logger.info "Writing #{target}" | |
asset.write_to target | |
asset.write_to "#{target}.gz" if asset.is_a?(BundledAsset) | |
end | |
save | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment