2021-05-12 05:32:45 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
# Development helper which prints a warning when you edit a non-autoloaded ruby file.
|
|
|
|
# These include initializers, middleware, plugin.rb files, and more.
|
|
|
|
# Launch the server with AUTO_RESTART=0 to disable automatic restarts.
|
2021-05-14 12:19:22 -04:00
|
|
|
if Rails.env.development? && !Rails.configuration.cache_classes && Discourse.running_in_rack?
|
2021-05-12 05:32:45 -04:00
|
|
|
paths = [
|
|
|
|
*Dir["#{Rails.root}/app/*"].reject { |path| path.end_with? "/assets" },
|
|
|
|
"#{Rails.root}/config",
|
|
|
|
"#{Rails.root}/lib",
|
|
|
|
"#{Rails.root}/plugins",
|
|
|
|
]
|
|
|
|
|
|
|
|
Listen
|
|
|
|
.to(*paths, only: /\.rb$/) do |modified, added, removed|
|
2022-01-08 17:39:46 -05:00
|
|
|
supervisor_pid = UNICORN_DEV_SUPERVISOR_PID
|
2021-05-14 13:17:31 -04:00
|
|
|
auto_restart = supervisor_pid && ENV["AUTO_RESTART"] != "0"
|
2021-05-12 05:32:45 -04:00
|
|
|
|
|
|
|
files = modified + added + removed
|
|
|
|
|
|
|
|
not_autoloaded =
|
|
|
|
files.filter_map do |file|
|
2023-02-13 01:26:40 -05:00
|
|
|
autoloaded = Rails.autoloaders.main.__autoloads.key? file
|
2023-06-16 04:15:15 -04:00
|
|
|
|
|
|
|
if !autoloaded && !file.match(%r{/spec/})
|
2023-06-15 02:34:30 -04:00
|
|
|
Pathname.new(file).relative_path_from(Rails.root)
|
|
|
|
end
|
2021-05-12 05:32:45 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
if not_autoloaded.length > 0
|
|
|
|
message =
|
2023-01-07 06:59:28 -05:00
|
|
|
(
|
2021-05-12 05:32:45 -04:00
|
|
|
if auto_restart
|
|
|
|
"Restarting server..."
|
2023-01-07 06:59:28 -05:00
|
|
|
else
|
2021-05-12 05:32:45 -04:00
|
|
|
"Server restart required. Automate this by setting AUTO_RESTART=1."
|
2023-01-07 06:59:28 -05:00
|
|
|
end
|
|
|
|
)
|
2021-05-12 05:32:45 -04:00
|
|
|
STDERR.puts "[DEV]: Edited files which are not autoloaded. #{message}"
|
|
|
|
STDERR.puts not_autoloaded.map { |path| "- #{path}".indent(7) }.join("\n")
|
2021-05-14 13:17:31 -04:00
|
|
|
Process.kill("USR2", supervisor_pid) if auto_restart
|
2023-01-07 06:59:28 -05:00
|
|
|
end
|
2021-05-12 05:32:45 -04:00
|
|
|
end
|
|
|
|
.start
|
|
|
|
end
|