Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
ahangarha committed Jan 21, 2024
1 parent 2083f06 commit dbbc7ff
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
24 changes: 10 additions & 14 deletions lib/react_on_rails/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def adjust_precompile_task

return if skip_react_on_rails_precompile || build_production_command.blank?

raise(ReactOnRails::Error, shakapacker_precompile_true_message) if shakapacker_precompile?
raise(ReactOnRails::Error, compile_command_conflict_message) if shakapacker_precompile?

precompile_tasks = lambda {
Rake::Task["react_on_rails:generate_packs"].invoke
Expand All @@ -152,10 +152,8 @@ def adjust_precompile_task
# removes files older than 1 hour.
versions = 100_000

clean_task = using_shakapacker_6? ? "webpacker:clean" : "shakapacker:clean"

puts "Invoking task #{clean_task} from React on Rails"
Rake::Task[clean_task].invoke(versions)
puts "Invoking task #{shakapacker_clean_task} from React on Rails"
Rake::Task[shakapacker_clean_task].invoke(versions)
}

if Rake::Task.task_defined?("assets:precompile")
Expand Down Expand Up @@ -257,20 +255,18 @@ def raise_missing_components_subdirectory
raise ReactOnRails::Error, msg
end

def using_shakapacker_6?
shakapacker_major_version = ReactOnRails::WebpackerUtils.shakapacker_version_as_array[0]

shakapacker_major_version == 6
end

def shakapacker_precompile?
return Webpacker.config.webpacker_precompile? if using_shakapacker_6?
return Webpacker.config.webpacker_precompile? if ReactOnRails::WebpackerUtils.using_shakapacker_6?

Webpacker.config.shakapacker_precompile?
end

def shakapacker_precompile_true_message
packer = using_shakapacker_6? ? "webpacker" : "shakapacker"
def shakapacker_clean_task
ReactOnRails::WebpackerUtils.using_shakapacker_6? ? "webpacker:clean" : "shakapacker:clean"
end

def compile_command_conflict_message
packer = ReactOnRails::WebpackerUtils.using_shakapacker_6? ? "webpacker" : "shakapacker"

<<~MSG
Expand Down
6 changes: 6 additions & 0 deletions lib/react_on_rails/webpacker_utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -141,5 +141,11 @@ def self.raise_shakapacker_not_installed
def self.semver_to_string(ary)
"#{ary[0]}.#{ary[1]}.#{ary[2]}"
end

def self.using_shakapacker_6?
shakapacker_major_version = shakapacker_version_as_array[0]

shakapacker_major_version == 6
end
end
end

0 comments on commit dbbc7ff

Please sign in to comment.