forked from shakacode/shakapacker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
railtie.rb
70 lines (60 loc) · 2.15 KB
/
railtie.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
require "rails/railtie"
require "shakapacker/helper"
require "shakapacker/dev_server_proxy"
require "shakapacker/version_checker"
class Shakapacker::Engine < ::Rails::Engine
# Allows Shakapacker config values to be set via Rails env config files
config.shakapacker = ActiveSupport::OrderedOptions.new
initializer "shakapacker.version_checker" do
if File.exist?(Shakapacker::VersionChecker::NodePackageVersion.package_json_path)
Shakapacker::VersionChecker.build.raise_if_gem_and_node_package_versions_differ
end
end
initializer "shakapacker.proxy" do |app|
if (Shakapacker.config.dev_server.present? rescue nil)
app.middleware.insert_before 0,
Rails::VERSION::MAJOR >= 5 ?
Shakapacker::DevServerProxy : "Shakapacker::DevServerProxy", ssl_verify_none: true
end
end
initializer "shakapacker.helper" do
ActiveSupport.on_load :action_controller do
ActionController::Base.helper Shakapacker::Helper
end
ActiveSupport.on_load :action_view do
include Shakapacker::Helper
end
end
initializer "shakapacker.logger" do
config.after_initialize do
if ::Rails.logger.respond_to?(:tagged)
Shakapacker.logger = ::Rails.logger
else
Shakapacker.logger = ActiveSupport::TaggedLogging.new(::Rails.logger)
end
end
end
initializer "shakapacker.bootstrap" do
if defined?(Rails::Server) || defined?(Rails::Console)
Shakapacker.bootstrap
if defined?(Spring)
require "spring/watcher"
Spring.after_fork { Shakapacker.bootstrap }
Spring.watch(Shakapacker.config.config_path)
end
end
end
initializer "shakapacker.set_source" do |app|
if Shakapacker.config.config_path.exist?
app.config.javascript_path = Shakapacker.config.source_path.relative_path_from(Rails.root.join("app")).to_s
end
end
initializer "shakapacker.remove_app_packs_from_the_autoload_paths" do
Rails.application.config.before_initialize do
if Shakapacker.config.config_path.exist?
source_path = Shakapacker.config.source_path.to_s
ActiveSupport::Dependencies.autoload_paths.delete(source_path)
end
end
end
end