Skip to content

automatically create nondigest non versioned files on asset precompile #26

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 22 additions & 7 deletions lib/tasks/webshims.rake
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
require 'fileutils'

desc "Copy the webshims to public/webshims so dynamic features will work."
task "webshims:update_public" do
shim_root = Webshims::Rails::Engine.root.join('lib', 'assets', 'javascripts', 'webshims')
FileUtils.cp_r(shim_root, Rails.root.join('public'))
desc 'Add a nondigest copy of assets so dynamic features will work.'
task 'webshims:update_public' do
fingerprint = /\-[0-9a-f]{32,64}\./
path = File.join Rails.root.to_s, 'public', 'assets', 'webshims', '**/*'
files = Dir[path]

puts "Updated webshims files in /public/webshims"
end
files.each do |file|
next unless file =~ fingerprint
nondigest = file.sub fingerprint, '.'

if !File.exist?(nondigest) || File.mtime(file) > File.mtime(nondigest)
FileUtils.cp file, nondigest, verbose: true, preserve: true
end
end

puts 'Added nondigest files in /public/assets/webshims'
end

desc "Copy the webshims to public/webshims/[version] for cache-busting."
task "webshims:update_public_versioned" do
Expand All @@ -20,4 +29,10 @@ task "webshims:update_public_versioned" do
puts "\nBe sure your webshims options are set as follows:"
puts %Q{ $.webshims.setOptions('basePath', '/webshims/#{Webshims::Rails::WEBSHIMS_VERSION}/shims/')}
puts "\nYou can use ERB to dynamically set this path; See README for more information."
end
end

if Rake::Task.task_defined?('assets:precompile')
Rake::Task['assets:precompile'].enhance do
Rake::Task['webshims:update_public'].invoke if defined?(Webshims)
end
end