Last active
August 29, 2015 14:06
-
-
Save eduardojmatos/a5c124c0ae1eafba1ba2 to your computer and use it in GitHub Desktop.
Fix temporarily a sprockets bug with files that contains "." in their filenames
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
desc "Fix asset names with .min at end of filename" | |
task :fixassets => :environment do | |
puts "\n\n" | |
manifest_file = "" | |
manifest_json = "" | |
Dir.glob(File.join(Rails.root, 'public/assets/manifest*.json')) do |file| | |
manifest_file = file | |
manifest_json = File.read(file) | |
end | |
Dir.glob(File.join(Rails.root, 'public/assets/**/*.{amd,maskedinput,maskMoney,min,validate}')) do |file| | |
ext = File.extname(file) | |
search, replace = %r(#{ext}$), "#{ext}.js" | |
new_name = file.gsub(search, replace) | |
manifest_json.gsub!(%Q[#{ext}"], %Q[#{ext}.js"]) | |
manifest_json.gsub!(%Q[#{ext}.gz"], %Q[#{ext}.js.gz"]) | |
puts "Renaming #{file}..." | |
%x(mv '#{file}' '#{new_name}') | |
%x(mv '#{file}.gz' '#{new_name}.gz') | |
puts "#{new_name} renamed!\n" | |
end | |
puts "\nChanging manifest.json..." | |
File.open(manifest_file, "w") { |f| f.write(manifest_json) } | |
puts "manifest.json changed!\n" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment