class ReactOnRails::SystemChecker

def check_node_version

def check_node_version
  stdout, stderr, status = Open3.capture3("node", "--version")
  # Use stdout if available, fallback to stderr if stdout is empty
  node_version = stdout.strip
  node_version = stderr.strip if node_version.empty?
  # Return early if node is not found (non-zero status) or no output
  return if !status.success? || node_version.empty?
  # Extract major version number (e.g., "v18.17.0" -> 18)
  major_version = node_version[/v(\d+)/, 1]&.to_i
  return unless major_version
  if major_version < 18
    add_warning(<<~MSG.strip)
      ⚠️  Node.js version #{node_version} detected.
      React on Rails recommends Node.js 18+ for best compatibility.
      You may experience issues with older versions.
      Consider upgrading: https://nodejs.org/en/
    MSG
  else
    add_success("✅ Node.js #{node_version} is installed and compatible")
  end
end