Sha256: 6278c29d78a8456f053290de99deb67b40291838b4f3ec6938326054fee675e7

Contents?: true

Size: 1.38 KB

Versions: 3

Compression:

Stored size: 1.38 KB

Contents

# Some Rails versions use commonJS(require) others use ESM(import).
TURBOLINKS_REGEX = /(import .* from "turbolinks".*\n|require\("turbolinks"\).*\n)/.freeze
ACTIVE_STORAGE_REGEX = /(import.*ActiveStorage|require.*@rails\/activestorage.*)/.freeze
CABLE_CONFIG_PATH = Rails.root.join("config/cable.yml")

abort "❌ Webpacker not found. Exiting." unless defined?(Webpacker::Engine)

say "Install Turbo"
run "yarn add @hotwired/turbo-rails"
insert_into_file "#{Webpacker.config.source_entry_path}/application.js", "import \"@hotwired/turbo-rails\"\n", before: ACTIVE_STORAGE_REGEX

say "Remove Turbolinks"
run "#{RbConfig.ruby} bin/bundle remove turbolinks"
run "#{RbConfig.ruby} bin/bundle", capture: true
run "#{RbConfig.ruby} bin/yarn remove turbolinks"
gsub_file "#{Webpacker.config.source_entry_path}/application.js", TURBOLINKS_REGEX, ''
gsub_file "#{Webpacker.config.source_entry_path}/application.js", /Turbolinks.start.*\n/, ''

if CABLE_CONFIG_PATH.exist?
  say "Enable redis in bundle"
  uncomment_lines "Gemfile", %(gem 'redis')

  say "Switch development cable to use redis"
  gsub_file CABLE_CONFIG_PATH.to_s, /development:\n\s+adapter: async/, "development:\n  adapter: redis\n  url: redis://localhost:6379/1"
else
  say 'ActionCable config file (config/cable.yml) is missing. Uncomment "gem \'redis\'" in your Gemfile and create config/cable.yml to use the Turbo Streams broadcast feature.'
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
turbo-rails-0.7.2 lib/install/turbo_with_webpacker.rb
turbo-rails-0.7.1 lib/install/turbo_with_webpacker.rb
turbo-rails-0.7.0 lib/install/turbo_with_webpacker.rb