forked from shakacode/shakapacker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
configuration.rb
136 lines (112 loc) · 3.07 KB
/
configuration.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
require "yaml"
require "active_support/core_ext/hash/keys"
require "active_support/core_ext/hash/indifferent_access"
class Webpacker::Configuration
class << self
attr_accessor :installing
end
attr_reader :root_path, :config_path, :env
def initialize(root_path:, config_path:, env:)
@root_path = root_path
@config_path = config_path
@env = env
end
def dev_server
fetch(:dev_server)
end
def compile?
fetch(:compile)
end
def ensure_consistent_versioning?
fetch(:ensure_consistent_versioning)
end
def webpacker_precompile?
# ENV of false takes precedence
return false if %w(no false n f).include?(ENV["WEBPACKER_PRECOMPILE"])
return true if %w(yes true t).include?(ENV["WEBPACKER_PRECOMPILE"])
return false unless config_path.exist?
fetch(:webpacker_precompile)
end
def source_path
root_path.join(fetch(:source_path))
end
def additional_paths
fetch(:additional_paths)
end
def source_entry_path
source_path.join(fetch(:source_entry_path))
end
def manifest_path
if data.has_key?(:manifest_path)
root_path.join(fetch(:manifest_path))
else
public_output_path.join("manifest.json")
end
end
def public_manifest_path
manifest_path
end
def public_path
root_path.join(fetch(:public_root_path))
end
def public_output_path
public_path.join(fetch(:public_output_path))
end
def cache_manifest?
fetch(:cache_manifest)
end
def cache_path
root_path.join(fetch(:cache_path))
end
def check_yarn_integrity=(value)
warn <<~EOS
Webpacker::Configuration#check_yarn_integrity=(value) is obsolete. The integrity
check has been removed from Webpacker (https://github.com/rails/webpacker/pull/2518)
so changing this setting will have no effect.
EOS
end
def webpack_compile_output?
fetch(:webpack_compile_output)
end
def compiler_strategy
fetch(:compiler_strategy)
end
def fetch(key)
data.fetch(key, defaults[key])
end
private
def data
@data ||= load
end
def load
config = begin
YAML.load_file(config_path.to_s, aliases: true)
rescue ArgumentError
YAML.load_file(config_path.to_s)
end
config[env].deep_symbolize_keys
rescue Errno::ENOENT => e
if self.class.installing
{}
else
raise "Webpacker configuration file not found #{config_path}. " \
"Please run rails webpacker:install " \
"Error: #{e.message}"
end
rescue Psych::SyntaxError => e
raise "YAML syntax error occurred while parsing #{config_path}. " \
"Please note that YAML must be consistently indented using spaces. Tabs are not allowed. " \
"Error: #{e.message}"
end
def defaults
@defaults ||= begin
path = File.expand_path("../../install/config/webpacker.yml", __FILE__)
config = begin
YAML.load_file(path, aliases: true)
rescue ArgumentError
YAML.load_file(path)
end
HashWithIndifferentAccess.new(config[env])
end
end
end