Module: GeneratorMessages
- Defined in:
- lib/generators/react_on_rails/generator_messages.rb
Constant Summary collapse
- PRO_UPGRADE_HINT =
"\n\n 💎 For RSC, streaming SSR, and 10-100x faster SSR, try React on Rails Pro:" \ "\n #{Rainbow('https://reactonrails.com/docs/pro/upgrading-to-pro/').cyan.underline}".freeze
Class Method Summary collapse
- .add_error(message) ⇒ Object
- .add_info(message) ⇒ Object
- .add_warning(message) ⇒ Object
- .clear ⇒ Object
-
.detect_package_manager ⇒ Object
Uses relative lockfile paths resolved against Dir.pwd, so callers must invoke this while the current working directory is the target Rails app root.
- .format_error(msg) ⇒ Object
- .format_info(msg) ⇒ Object
- .format_warning(msg) ⇒ Object
- .helpful_message_after_installation(component_name: "HelloWorld", route: "hello_world", pro: false, rsc: false, shakapacker_just_installed: false) ⇒ Object
- .messages ⇒ Object
- .output ⇒ Object
Class Method Details
.add_error(message) ⇒ Object
14 15 16 |
# File 'lib/generators/react_on_rails/generator_messages.rb', line 14 def add_error() output << format_error() end |
.add_info(message) ⇒ Object
22 23 24 |
# File 'lib/generators/react_on_rails/generator_messages.rb', line 22 def add_info() output << format_info() end |
.add_warning(message) ⇒ Object
18 19 20 |
# File 'lib/generators/react_on_rails/generator_messages.rb', line 18 def add_warning() output << format_warning() end |
.clear ⇒ Object
42 43 44 |
# File 'lib/generators/react_on_rails/generator_messages.rb', line 42 def clear @output = [] end |
.detect_package_manager ⇒ Object
Uses relative lockfile paths resolved against Dir.pwd, so callers must invoke this while the current working directory is the target Rails app root.
99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/generators/react_on_rails/generator_messages.rb', line 99 def detect_package_manager env_package_manager = ENV.fetch("REACT_ON_RAILS_PACKAGE_MANAGER", nil)&.strip&.downcase return env_package_manager if %w[npm pnpm yarn bun].include?(env_package_manager) # Check for lock files to determine package manager return "yarn" if File.exist?("yarn.lock") return "pnpm" if File.exist?("pnpm-lock.yaml") return "bun" if File.exist?("bun.lock") || File.exist?("bun.lockb") # Default to npm (Shakapacker 8.x default) - covers package-lock.json and no lockfile "npm" end |
.format_error(msg) ⇒ Object
30 31 32 |
# File 'lib/generators/react_on_rails/generator_messages.rb', line 30 def format_error(msg) Rainbow("ERROR: #{msg}").red end |
.format_info(msg) ⇒ Object
38 39 40 |
# File 'lib/generators/react_on_rails/generator_messages.rb', line 38 def format_info(msg) Rainbow(msg.to_s).green end |
.format_warning(msg) ⇒ Object
34 35 36 |
# File 'lib/generators/react_on_rails/generator_messages.rb', line 34 def format_warning(msg) Rainbow("WARNING: #{msg}").orange end |
.helpful_message_after_installation(component_name: "HelloWorld", route: "hello_world", pro: false, rsc: false, shakapacker_just_installed: false) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 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 89 90 91 92 93 94 95 |
# File 'lib/generators/react_on_rails/generator_messages.rb', line 46 def (component_name: "HelloWorld", route: "hello_world", pro: false, rsc: false, shakapacker_just_installed: false) process_manager_section = build_process_manager_section testing_section = build_testing_section package_manager = detect_package_manager shakapacker_status = build_shakapacker_status_section(shakapacker_just_installed: shakapacker_just_installed) render_example = build_render_example(component_name: component_name, route: route, rsc: rsc) render_label = build_render_label(route: route, rsc: rsc) # rsc guard is defensive; callers via install_generator already pass pro: true when rsc is set pro_hint = pro || rsc ? "" : PRO_UPGRADE_HINT <<~MSG ╔════════════════════════════════════════════════════════════════════════╗ ║ 🎉 React on Rails Successfully Installed! ║ ╚════════════════════════════════════════════════════════════════════════╝ #{process_manager_section}#{shakapacker_status} 📋 QUICK START: ───────────────────────────────────────────────────────────────────────── 1. Install dependencies: #{Rainbow("bundle && #{package_manager} install").cyan} 2. Prepare database: #{Rainbow('bin/rails db:prepare').cyan} 3. Start the app: ./bin/dev # HMR (Hot Module Replacement) mode ./bin/dev static # Static bundles (no HMR, faster initial load) ./bin/dev prod # Production-like mode for testing ./bin/dev help # See all available options 4. Visit: #{Rainbow(route ? "http://localhost:3000/#{route}" : 'http://localhost:3000').cyan.underline} ✨ KEY FEATURES: ───────────────────────────────────────────────────────────────────────── • Auto-registration enabled - Your layout only needs: <%= javascript_pack_tag %> <%= stylesheet_pack_tag %> #{render_label} #{render_example} 📚 LEARN MORE: ───────────────────────────────────────────────────────────────────────── • Documentation: #{Rainbow('https://reactonrails.com/docs/').cyan.underline} • Webpack customization: #{Rainbow('https://github.com/shakacode/shakapacker#webpack-configuration').cyan.underline} 💡 TIP: Run 'bin/dev help' for development server options and troubleshooting#{testing_section}#{pro_hint} MSG end |
.messages ⇒ Object
26 27 28 |
# File 'lib/generators/react_on_rails/generator_messages.rb', line 26 def output end |
.output ⇒ Object
10 11 12 |
# File 'lib/generators/react_on_rails/generator_messages.rb', line 10 def output @output ||= [] end |