Class: ReactOnRails::Dev::PackGenerator
- Inherits:
-
Object
- Object
- ReactOnRails::Dev::PackGenerator
- Defined in:
- lib/react_on_rails/dev/pack_generator.rb
Overview
PackGenerator triggers the generation of React on Rails packs
Design decisions:
-
Why trigger via Rake task instead of direct Ruby code?
-
The actual pack generation logic lives in lib/react_on_rails/packs_generator.rb
-
The rake task (lib/tasks/generate_packs.rake) provides a stable, documented interface
-
This allows the implementation to evolve without breaking bin/dev
-
Users can also run the task directly: ‘rake react_on_rails:generate_packs`
-
-
Why two execution strategies (direct vs bundle exec)?
-
Direct Rake execution: Faster when already in Bundler/Rails context (bin/dev)
-
Bundle exec fallback: Required when called outside Rails context
-
This optimization avoids subprocess overhead in the common case
-
-
Why is the class named “PackGenerator” when it delegates?
-
It’s a semantic wrapper around pack generation for the dev workflow
-
Provides a clean API for bin/dev without exposing Rake internals
-
Handles hook detection, error handling, and output formatting
-
Class Method Summary collapse
Class Method Details
.generate(verbose: false) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/react_on_rails/dev/pack_generator.rb', line 29 def generate(verbose: false) # Skip if shakapacker has a precompile hook configured if ReactOnRails::PackerUtils.shakapacker_precompile_hook_configured? if verbose hook_value = ReactOnRails::PackerUtils.shakapacker_precompile_hook_value puts "⏭️ Skipping pack generation (handled by shakapacker precompile hook: #{hook_value})" end return end if verbose puts "📦 Generating React on Rails packs..." success = run_pack_generation else print "📦 Generating packs... " success = run_pack_generation(silent: true) puts success ? "✅" : "❌" end return if success puts "❌ Pack generation failed" exit 1 end |