Module: ReactOnRails::Generators::ProSetup

Included in:
InstallGenerator, ProGenerator
Defined in:
lib/generators/react_on_rails/pro_setup.rb

Overview

Provides Pro setup functionality for React on Rails generators.

This module extracts Pro-specific setup methods that can be shared between:

  • InstallGenerator (when –pro or –rsc flags are used)

  • ProGenerator (standalone generator for upgrading existing apps)

Required Dependencies

Including classes must provide (typically via Rails::Generators::Base):

  • destination_root: Path to the target Rails application

  • template, copy_file, append_to_file: Thor file manipulation methods

  • options: Generator options hash

Including classes must also include GeneratorHelper which provides:

  • use_pro?, use_rsc?: Feature flag helpers

  • pro_gem_installed?: Pro gem detection

rubocop:disable Metrics/ModuleLength

Constant Summary collapse

PRO_GEM_NAME =
"react_on_rails_pro"
AUTO_INSTALL_TIMEOUT =

Version is appended dynamically via pro_gem_auto_install_command to ensure the installed version matches the current react_on_rails gem version.

120
TERMINATION_GRACE_PERIOD =
5

Instance Method Summary collapse

Instance Method Details

#missing_pro_gem?(force: false) ⇒ Boolean

Check if Pro gem is missing. Attempts auto-install via bundle add.

Parameters:

  • force (Boolean) (defaults to: false)

    When true, always checks (default: only if use_pro?).

Returns:

  • (Boolean)

    true if Pro gem is missing and could not be installed



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
# File 'lib/generators/react_on_rails/pro_setup.rb', line 58

def missing_pro_gem?(force: false)
  return false unless force || use_pro?
  return false if pro_gem_installed?
  return false if attempt_pro_gem_auto_install

  context_line = if options.key?(:pro) || options.key?(:rsc)
                   flag = options[:rsc] ? "--rsc" : "--pro"
                   "You specified #{flag}, which requires the react_on_rails_pro gem."
                 else
                   "This generator requires the react_on_rails_pro gem."
                 end

  GeneratorMessages.add_error(<<~MSG.strip)
    🚫 Failed to auto-install #{PRO_GEM_NAME} gem.

    #{context_line}

    Please add manually to your Gemfile:
      gem '#{PRO_GEM_NAME}', '~> #{recommended_pro_gem_version}'

    Then run: bundle install

    No license needed for evaluation or non-production use.
    Free or low-cost production licenses available for startups and small companies.
    See the upgrade guide: https://reactonrails.com/docs/pro/upgrading-to-pro/
  MSG
  true
end

#setup_proObject

Note:

NPM dependencies are handled separately by JsDependencyManager

Main entry point for Pro setup. Orchestrates creation of all Pro-related files and configuration.

Creates:

  • config/initializers/react_on_rails_pro.rb

  • client/node-renderer.js

  • Procfile.dev entry for node-renderer



40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/generators/react_on_rails/pro_setup.rb', line 40

def setup_pro
  say "\n#{set_color('=' * 80, :cyan)}"
  say set_color("🚀 REACT ON RAILS PRO SETUP", :cyan, :bold)
  say set_color("=" * 80, :cyan)

  create_pro_initializer
  create_node_renderer
  add_pro_to_procfile
  update_webpack_config_for_pro

  say set_color("=" * 80, :cyan)
  say "✅ React on Rails Pro setup complete!", :green
  say set_color("=" * 80, :cyan)
end