Skip to content

Instantly share code, notes, and snippets.

@zealot128
Last active Jun 14, 2021
Embed
What would you like to do?
Migrate off rails-assets.org

Migrate Gem-assets by vendoring

inspired: https://www.ramblingcode.dev/posts/bye_rails_assets/

This script + initializer can help you to migrate of the "rails-assets.org" hosted assets. If you can not immediately move to Webpack/NPM, you can just copy the asset content into your vendor directory.

Add to your config/initializers/assets.rb:

Rails.application.configure do
  config.assets.paths += Dir["#{Rails.root}/vendor/assets/rails-assets/*/*"]
end
#!/usr/bin/env ruby
require 'pry'
gems = `bundle list --paths | grep rails-assets`
gems.strip.split.each do |gem_path|
base_path = Dir[gem_path + "/*.gemspec"].first.split('/').last.sub('.gemspec', '')
target = "vendor/assets/rails-assets/#{base_path}"
FileUtils.mkdir_p(target)
puts "copying #{gem_path} -> #{target}"
Dir[gem_path + "/app/assets/*"].each do |source|
FileUtils.cp_r(source, target)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment