From 55840859439775915954be2b368102f8b3572b90 Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Fri, 24 Nov 2017 10:40:49 -0500 Subject: [PATCH] assets rake task: detect the brotli version on the image as the usage changes --- lib/tasks/assets.rake | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/lib/tasks/assets.rake b/lib/tasks/assets.rake index d27b2242272..4116cd12bbe 100644 --- a/lib/tasks/assets.rake +++ b/lib/tasks/assets.rake @@ -1,6 +1,7 @@ task 'assets:precompile:before' do require 'uglifier' + require 'open3' unless %w{profile production}.include? Rails.env raise "rake assets:precompile should only be run in RAILS_ENV=production, you are risking unminified assets" @@ -114,10 +115,26 @@ def gzip(path) raise "gzip compression failed: exit code #{$?.exitstatus}" if $?.exitstatus != 0 end +# different brotli versions use different parameters +ver_out, ver_err, ver_status = Open3.capture3('brotli --version') +if !ver_status.success? + # old versions of brotli don't respond to --version + def brotli_command(path) + "brotli --quality 11 --input #{path} --output #{path}.br" + end +elsif ver_out >= "brotli 1.0.0" + def brotli_command(path) + "brotli --quality=11 #{path} --output=#{path}.br" + end +else + # not sure what to do here, not expecting this + raise "cannot determine brotli version" +end + def brotli(path) if ENV['COMPRESS_BROTLI']&.to_i == 1 - STDERR.puts "brotli --quality 11 --input #{path} --output #{path}.br" - STDERR.puts `brotli --quality 11 --input #{path} --output #{path}.br` + STDERR.puts brotli_command(path) + STDERR.puts `#{brotli_command(path)}` raise "brotli compression failed: exit code #{$?.exitstatus}" if $?.exitstatus != 0 STDERR.puts `chmod +r #{path}.br` raise "chmod failed: exit code #{$?.exitstatus}" if $?.exitstatus != 0