Skip to content

Commit 680b816

Browse files
committed
feat: add a task to copy the built assets from the Maglev engine to the main app
1 parent ecd07b0 commit 680b816

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

lib/tasks/maglev/vite.rake

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,17 @@ namespace :maglev do
5858
Maglev::Engine.vite_ruby.commands.print_info
5959
end
6060
end
61+
62+
desc "Copy the ViteRuby's public directory to the app's public directory"
63+
task copy_public_dir: :environment do
64+
within_engine_folder do
65+
output_dir_name = Maglev::Engine.vite_ruby.config.public_output_dir
66+
source_path = Maglev::Engine.root.join('public', output_dir_name)
67+
target_path = Rails.root.join('public', output_dir_name)
68+
FileUtils.rm_rf(target_path)
69+
FileUtils.mkdir_p(target_path)
70+
FileUtils.cp_r(source_path, target_path)
71+
end
72+
end
6173
end
6274
end

lib/tasks/maglev_tasks.rake

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,6 @@ def within_engine_folder(&block)
66
Dir.chdir(File.join(__dir__, '..', '..'), &block)
77
end
88

9-
# Load all task files only if they haven't been loaded before
10-
Dir[File.join(__dir__, 'maglev', '*.rake')].each do |file|
11-
# Create a unique task loaded flag
12-
task_name = File.basename(file, '.rake')
13-
next if Rake::Task.task_defined?("maglev:#{task_name}:loaded")
14-
15-
load file
16-
# Create a dummy task to mark this file as loaded
17-
Rake::Task.define_task("maglev:#{task_name}:loaded")
18-
end
19-
209
unless ENV['VITE_RUBY_SKIP_ASSETS_PRECOMPILE_EXTENSION'] == 'true'
2110
if Rake::Task.task_defined?('assets:precompile')
2211
Rake::Task['assets:precompile'].enhance do |_task|

0 commit comments

Comments
 (0)