Class: ReactOnRails::Generators::InstallGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- ReactOnRails::Generators::InstallGenerator
- Includes:
- GeneratorHelper
- Defined in:
- lib/generators/react_on_rails/install_generator.rb
Overview
rubocop:disable Metrics/ClassLength
Instance Method Summary collapse
-
#run_generators ⇒ Object
Main generator entry point.
Methods included from GeneratorHelper
#add_documentation_reference, #add_npm_dependencies, #component_extension, #copy_file_and_missing_parent_directories, #dest_dir_exists?, #dest_file_exists?, #empty_directory_with_keep_file, #keep_file, #package_json, #setup_file_error, #symlink_dest_file_to_dest_file
Instance Method Details
#run_generators ⇒ Object
Validation Skipping: Sets ENV to prevent version validation from running during generator execution. The npm package isn’t installed until midway through the generator, so validation would fail if run during Rails initialization. The ensure block guarantees cleanup even if the generator fails.
Main generator entry point
Sets up React on Rails in a Rails application by:
-
Validating prerequisites
-
Installing required packages
-
Generating configuration files
-
Setting up example components
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/generators/react_on_rails/install_generator.rb', line 58 def run_generators # Set environment variable to skip validation during generator run # This is inherited by all invoked generators and persists through Rails initialization # See lib/react_on_rails/engine.rb for the validation skip logic ENV["REACT_ON_RAILS_SKIP_VALIDATION"] = "true" if installation_prerequisites_met? || .ignore_warnings? invoke_generators add_bin_scripts # Only add the post install message if not using Redux # Redux generator handles its own messages unless .redux? else error = <<~MSG.strip 🚫 React on Rails generator prerequisites not met! Please resolve the issues listed above before continuing. All prerequisites must be satisfied for a successful installation. Use --ignore-warnings to bypass checks (not recommended). MSG GeneratorMessages.add_error(error) end ensure # Always clean up ENV variable, even if generator fails # CRITICAL: ENV cleanup must come first to ensure it executes even if # print_generator_messages raises an exception. This prevents ENV pollution # that could affect subsequent processes. ENV.delete("REACT_ON_RAILS_SKIP_VALIDATION") end |