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
|
# File 'lib/generators/katapult/basics/templates/features/support/webpacker.rb', line 3
module_function def compile_once
digest_file = Rails.root.join("tmp/webpacker_#{Rails.env}_digest")
packable_contents = Dir[Webpacker.config.source_path.join('**/*')]
.sort
.map { |filename| File.read(filename) if File.file?(filename) }
.join
digest = Digest::SHA256.hexdigest(packable_contents)
return if digest_file.exist? && digest_file.read == digest
if ENV['TEST_ENV_NUMBER'].to_i < 1
output_path = Webpacker.config.public_output_path
FileUtils.rm_r(output_path) if File.exist?(output_path)
puts "Removed Webpack output directory #{output_path}"
Webpacker.compile or raise 'Compilation failed'
digest_file.write(digest)
else
loop do
break if digest_file.exist? && digest_file.read == digest
sleep 0.1
end
end
end
|