# typed: strict
# frozen_string_literal: true
require "rails_live_reload"

# This is a hack to fix the Listen gem ignoring the .devcontainer folder
original_socket_path = RailsLiveReload.config.socket_path
RailsLiveReload
  .config
  .define_singleton_method(:socket_path) { original_socket_path }

RailsLiveReload.config.instance_variable_set(
  :@root_path,
  Rails.root.join("app"),
)

RailsLiveReload.configure do |config|
  config.url = "/rails/live/reload"

  # "root path" is already set to app/, so don't include that as a prefix
  config.watch %r{views/.+\.(erb|haml|slim)$}

  # app/javscript is not in the reload path. HMR already handles JS hot reloading
  config.watch %r{assets/\w+/(.+\.(css|js|html|png|jpg|ts|jsx)).*},
               reload: :always

  # More examples:
  config.watch %r{helpers/.+\.rb}, reload: :always
  # config.watch %r{config/locales/.+\.yml}, reload: :always

  config.enabled = Rails.env.development? || Rails.env.staging?
end
