From 5965d80d4c7bd7632caaa96dbab097e789b4f625 Mon Sep 17 00:00:00 2001 From: aaronskiba Date: Tue, 25 Mar 2025 09:51:27 -0600 Subject: [PATCH 1/2] Move asset copying to precompile task - Moved the code for copying Bootstrap glyphicons and TinyMCE skins from the initializer to a custom Rake task. - Created a new Rake task `assets:copy` to handle the copying of necessary files. - Ensured that the `assets:copy` task runs before `assets:precompile` by setting it as a prerequisite. - This change prevents the files from being copied every time the Rails application initializes (e.g., when starting the server or console), and only copies them during the asset precompilation process. --- config/initializers/assets.rb | 13 ------------- lib/tasks/assets.rake | 20 ++++++++++++++++++++ 2 files changed, 20 insertions(+), 13 deletions(-) create mode 100644 lib/tasks/assets.rake diff --git a/config/initializers/assets.rb b/config/initializers/assets.rb index ed78d115f4..bd4c6cb22a 100644 --- a/config/initializers/assets.rb +++ b/config/initializers/assets.rb @@ -14,16 +14,3 @@ # application.js, application.css, and all non-JS/CSS in the app/assets # folder are already added. # Rails.application.config.assets.precompile += %w( admin.js admin.css ) - -# Bootstrap and TinyMCE expect their files to live in a specific place, so copy them over -puts "Copying Bootstrap glyphicons to the public directory ..." -source_dir = Dir.glob(Rails.root.join('node_modules', 'bootstrap', 'fonts', 'glyphicons-halflings-regular.*')) -destination_dir = Rails.root.join('public', 'fonts', 'bootstrap') -FileUtils.mkdir_p(destination_dir) -FileUtils.cp_r(source_dir, destination_dir) - -puts "Copying TinyMCE skins to the public directory ..." -source_dir = Dir.glob(Rails.root.join('node_modules', 'tinymce', 'skins', 'ui', 'oxide')) -destination_dir = Rails.root.join('public', 'tinymce', 'skins') -FileUtils.mkdir_p(destination_dir) -FileUtils.cp_r(source_dir, destination_dir) diff --git a/lib/tasks/assets.rake b/lib/tasks/assets.rake new file mode 100644 index 0000000000..80f7828f93 --- /dev/null +++ b/lib/tasks/assets.rake @@ -0,0 +1,20 @@ +namespace :assets do + desc 'Copy Bootstrap glyphicons and TinyMCE skins to the public directory' + task :copy do + # Bootstrap and TinyMCE expect their files to live in a specific place, so copy them over + puts 'Copying Bootstrap glyphicons to the public directory ...' + source_dir = Dir.glob(Rails.root.join('node_modules', 'bootstrap', 'fonts', 'glyphicons-halflings-regular.*')) + destination_dir = Rails.root.join('public', 'fonts', 'bootstrap') + FileUtils.mkdir_p(destination_dir) + FileUtils.cp_r(source_dir, destination_dir) + + puts 'Copying TinyMCE skins to the public directory ...' + source_dir = Dir.glob(Rails.root.join('node_modules', 'tinymce', 'skins', 'ui', 'oxide')) + destination_dir = Rails.root.join('public', 'tinymce', 'skins') + FileUtils.mkdir_p(destination_dir) + FileUtils.cp_r(source_dir, destination_dir) + end + + # Run the copy task before precompiling assets + task precompile: :copy +end From 8e65c7a6c4dc33a531b1f85785f285e45b0bf90e Mon Sep 17 00:00:00 2001 From: aaronskiba Date: Tue, 25 Mar 2025 09:54:27 -0600 Subject: [PATCH 2/2] rubocop -A --- lib/tasks/assets.rake | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/tasks/assets.rake b/lib/tasks/assets.rake index 80f7828f93..8d612920fa 100644 --- a/lib/tasks/assets.rake +++ b/lib/tasks/assets.rake @@ -1,3 +1,5 @@ +# frozen_string_literal: true + namespace :assets do desc 'Copy Bootstrap glyphicons and TinyMCE skins to the public directory' task :copy do