# frozen_string_literal: true require "generators/anycable/with_os_helpers" module AnyCableRailsGenerators # Entry point for interactive installation class SetupGenerator < ::Rails::Generators::Base namespace "anycable:setup" source_root File.expand_path("templates", __dir__) DOCS_ROOT = "https://docs.anycable.io/v1/#" DEVELOPMENT_METHODS = %w[skip local docker].freeze SERVER_SOURCES = %w[skip brew binary].freeze class_option :devenv, type: :string, desc: "Select your development environment (options: #{DEVELOPMENT_METHODS.join(", ")})" class_option :source, type: :string, desc: "Choose a way of installing AnyCable-Go server (options: #{SERVER_SOURCES.join(", ")})" class_option :skip_heroku, type: :boolean, desc: "Do not copy Heroku configs" class_option :skip_procfile_dev, type: :boolean, desc: "Do not create Procfile.dev" include WithOSHelpers class_option :bin_path, type: :string, desc: "Where to download AnyCable-Go server binary (default: #{DEFAULT_BIN_PATH})" class_option :version, type: :string, desc: "Specify the AnyCable-Go version (defaults to latest release)" def welcome say "👋 Welcome to AnyCable interactive installer." end def configs inside("config") do template "cable.yml" template "anycable.yml" end end def cable_url environment(nil, env: :development) do <<~SNIPPET # Specify AnyCable WebSocket server URL to use by JS client config.after_initialize do config.action_cable.url = ActionCable.server.config.url = ENV.fetch("CABLE_URL", "ws://localhost:8080/cable") if AnyCable::Rails.enabled? end SNIPPET end environment(nil, env: :production) do <<~SNIPPET # Specify AnyCable WebSocket server URL to use by JS client config.after_initialize do config.action_cable.url = ActionCable.server.config.url = ENV.fetch("CABLE_URL") if AnyCable::Rails.enabled? end SNIPPET end say_status :info, "✅ 'config.action_cable.url' has been configured" say_status :help, "⚠️ If you're using JS client make sure you have " \ "`action_cable_meta_tag` included before any