@@ -118,71 +118,12 @@ def check_node_version
118118 end
119119
120120 def ensure_shakapacker_installed
121- return if File . exist? ( "bin/shakapacker" ) && File . exist? ( "bin/shakapacker-dev-server" )
121+ return if shakapacker_binaries_exist?
122122
123- puts Rainbow ( "\n #{ '=' * 80 } " ) . cyan
124- puts Rainbow ( "🔧 SHAKAPACKER SETUP" ) . cyan . bold
125- puts Rainbow ( "=" * 80 ) . cyan
126-
127- # Add Shakapacker to Gemfile if not present
128- unless shakapacker_in_gemfile?
129- puts Rainbow ( "📝 Adding Shakapacker to Gemfile..." ) . yellow
130- success = system ( "bundle add shakapacker --strict" )
131- unless success
132- error = <<~MSG . strip
133- 🚫 Failed to add Shakapacker to your Gemfile.
134-
135- This could be due to:
136- • Bundle installation issues
137- • Network connectivity problems
138- • Gemfile permissions
139-
140- Please try manually:
141- bundle add shakapacker --strict
142-
143- Then re-run: rails generate react_on_rails:install
144- MSG
145- GeneratorMessages . add_error ( error )
146- raise Thor ::Error , error unless options . ignore_warnings?
147- return
148- end
149- puts Rainbow ( "✅ Shakapacker added to Gemfile successfully!" ) . green
150- end
151-
152- # Install Shakapacker
153- puts Rainbow ( "⚙️ Installing Shakapacker (required for webpack integration)..." ) . yellow
154- success = system ( "./bin/rails shakapacker:install" )
155-
156- unless success
157- error = <<~MSG . strip
158- 🚫 Failed to install Shakapacker automatically.
159-
160- This could be due to:
161- • Missing Node.js or npm/yarn
162- • Network connectivity issues
163- • Incomplete bundle installation
164- • Missing write permissions
165-
166- Troubleshooting steps:
167- 1. Ensure Node.js is installed: node --version
168- 2. Try manually: ./bin/rails shakapacker:install
169- 3. Check for error output above
170- 4. Re-run: rails generate react_on_rails:install
171-
172- Need help? Visit: https://github.com/shakacode/shakapacker/blob/main/docs/installation.md
173- MSG
174- GeneratorMessages . add_error ( error )
175- raise Thor ::Error , error unless options . ignore_warnings?
176- return
177- end
178-
179- puts Rainbow ( "✅ Shakapacker installed successfully!" ) . green
180- puts Rainbow ( "=" * 80 ) . cyan
181- puts Rainbow ( "🚀 CONTINUING WITH REACT ON RAILS SETUP" ) . cyan . bold
182- puts "#{ Rainbow ( '=' * 80 ) . cyan } \n "
183-
184- # Create marker file so base generator can avoid copying shakapacker.yml
185- File . write ( ".shakapacker_just_installed" , "" )
123+ print_shakapacker_setup_banner
124+ ensure_shakapacker_in_gemfile
125+ install_shakapacker
126+ finalize_shakapacker_setup
186127 end
187128
188129 # Checks whether "shakapacker" is present in the *current bundle*,
@@ -245,6 +186,88 @@ def cli_exists?(command)
245186 system ( "which #{ command } > /dev/null 2>&1" )
246187 end
247188
189+ def shakapacker_binaries_exist?
190+ File . exist? ( "bin/shakapacker" ) && File . exist? ( "bin/shakapacker-dev-server" )
191+ end
192+
193+ def print_shakapacker_setup_banner
194+ puts Rainbow ( "\n #{ '=' * 80 } " ) . cyan
195+ puts Rainbow ( "🔧 SHAKAPACKER SETUP" ) . cyan . bold
196+ puts Rainbow ( "=" * 80 ) . cyan
197+ end
198+
199+ def ensure_shakapacker_in_gemfile
200+ return if shakapacker_in_gemfile?
201+
202+ puts Rainbow ( "📝 Adding Shakapacker to Gemfile..." ) . yellow
203+ success = system ( "bundle add shakapacker --strict" )
204+ return if success
205+
206+ handle_shakapacker_gemfile_error
207+ end
208+
209+ def install_shakapacker
210+ puts Rainbow ( "⚙️ Installing Shakapacker (required for webpack integration)..." ) . yellow
211+ success = system ( "./bin/rails shakapacker:install" )
212+ return if success
213+
214+ handle_shakapacker_install_error
215+ end
216+
217+ def finalize_shakapacker_setup
218+ puts Rainbow ( "✅ Shakapacker installed successfully!" ) . green
219+ puts Rainbow ( "=" * 80 ) . cyan
220+ puts Rainbow ( "🚀 CONTINUING WITH REACT ON RAILS SETUP" ) . cyan . bold
221+ puts "#{ Rainbow ( '=' * 80 ) . cyan } \n "
222+
223+ # Create marker file so base generator can avoid copying shakapacker.yml
224+ File . write ( ".shakapacker_just_installed" , "" )
225+ end
226+
227+ def handle_shakapacker_gemfile_error
228+ error = <<~MSG . strip
229+ 🚫 Failed to add Shakapacker to your Gemfile.
230+
231+ This could be due to:
232+ • Bundle installation issues
233+ • Network connectivity problems
234+ • Gemfile permissions
235+
236+ Please try manually:
237+ bundle add shakapacker --strict
238+
239+ Then re-run: rails generate react_on_rails:install
240+ MSG
241+ GeneratorMessages . add_error ( error )
242+ raise Thor ::Error , error unless options . ignore_warnings?
243+
244+ return
245+ end
246+
247+ def handle_shakapacker_install_error
248+ error = <<~MSG . strip
249+ 🚫 Failed to install Shakapacker automatically.
250+
251+ This could be due to:
252+ • Missing Node.js or npm/yarn
253+ • Network connectivity issues
254+ • Incomplete bundle installation
255+ • Missing write permissions
256+
257+ Troubleshooting steps:
258+ 1. Ensure Node.js is installed: node --version
259+ 2. Try manually: ./bin/rails shakapacker:install
260+ 3. Check for error output above
261+ 4. Re-run: rails generate react_on_rails:install
262+
263+ Need help? Visit: https://github.com/shakacode/shakapacker/blob/main/docs/installation.md
264+ MSG
265+ GeneratorMessages . add_error ( error )
266+ raise Thor ::Error , error unless options . ignore_warnings?
267+
268+ return
269+ end
270+
248271 def missing_package_manager?
249272 package_managers = %w[ npm pnpm yarn bun ]
250273 missing = package_managers . none? { |pm | cli_exists? ( pm ) }
0 commit comments