Skip to content

Commit ac5c8e4

Browse files
justin808claude
andcommitted
fix: Auto-remove default gem files to prevent installer conflicts
Automatically detect and remove default bin/dev (Rails) and config/shakapacker.yml (Shakapacker) files before running the React on Rails installer. This prevents interactive conflict prompts that would interrupt the installation process. The installer now: - Checks if bin/dev matches the Rails default and removes it if so - Checks if config/shakapacker.yml matches Shakapacker default and removes it - Only removes files that exactly match gem defaults (safe deletion) - Provides user feedback when removing files This ensures a smooth, non-interactive installation experience while preserving any customized versions of these files. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 62d92e1 commit ac5c8e4

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

lib/generators/react_on_rails/install_generator.rb

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class InstallGenerator < Rails::Generators::Base
3838

3939
def run_generators
4040
if installation_prerequisites_met? || options.ignore_warnings?
41+
remove_default_gem_files
4142
invoke_generators
4243
add_bin_scripts
4344
# Only add the post install message if not using Redux
@@ -66,6 +67,53 @@ def print_generator_messages
6667
GeneratorMessages.messages.each { |message| puts message }
6768
end
6869

70+
def remove_default_gem_files
71+
remove_default_bin_dev
72+
remove_default_shakapacker_yml
73+
end
74+
75+
def remove_default_bin_dev
76+
bin_dev_path = File.join(destination_root, "bin/dev")
77+
return unless File.exist?(bin_dev_path)
78+
79+
default_bin_dev = <<~RUBY.strip
80+
#!/usr/bin/env ruby
81+
exec "./bin/rails", "server", *ARGV
82+
RUBY
83+
84+
current_content = File.read(bin_dev_path).strip
85+
return unless current_content == default_bin_dev
86+
87+
puts Rainbow("🗑️ Removing default bin/dev file to avoid conflicts...").yellow
88+
File.delete(bin_dev_path)
89+
end
90+
91+
def remove_default_shakapacker_yml
92+
config_path = File.join(destination_root, "config/shakapacker.yml")
93+
return unless File.exist?(config_path)
94+
return unless shakapacker_yml_matches_default?(config_path)
95+
96+
puts Rainbow("🗑️ Removing default config/shakapacker.yml file to avoid conflicts...").yellow
97+
File.delete(config_path)
98+
end
99+
100+
def shakapacker_yml_matches_default?(config_path)
101+
shakapacker_gem_path = Gem.loaded_specs["shakapacker"]&.full_gem_path
102+
return false unless shakapacker_gem_path
103+
104+
default_config_path = File.join(shakapacker_gem_path, "lib/install/config/shakapacker.yml")
105+
return false unless File.exist?(default_config_path)
106+
107+
default_content = File.read(default_config_path)
108+
current_content = File.read(config_path)
109+
110+
current_content == default_content
111+
rescue StandardError => e
112+
# If we can't compare, don't delete - better safe than sorry
113+
puts Rainbow("⚠️ Could not verify shakapacker.yml: #{e.message}").yellow if options.verbose?
114+
false
115+
end
116+
69117
def invoke_generators
70118
ensure_shakapacker_installed
71119
if options.typescript?

0 commit comments

Comments
 (0)