<commit_before># Install Webpacker
copy_file "#{__dir__}/config/webpacker.yml", "config/webpacker.yml"

puts "Copying webpack core config"
directory "#{__dir__}/config/webpack", "config/webpack"

say "Copying .postcssrc.yml to app root directory"
copy_file "#{__dir__}/config/.postcssrc.yml", ".postcssrc.yml"

say "Copying .babelrc to app root directory"
copy_file "#{__dir__}/config/.babelrc", ".babelrc"

say "Creating JavaScript app source directory"
directory "#{__dir__}/javascript", Webpacker.config.source_path

say "Installing binstubs"
run "bundle binstubs webpacker"

say "Adding configurations"

# Verifies that versions and hashed value of the package contents in the project's package.json
inject_into_file "config/environments/development.rb", "  config.webpacker.check_yarn_integrity = true", after: "Rails.application.configure do\n", verbose: false
inject_into_file "config/environments/production.rb", "  config.webpacker.check_yarn_integrity = false", after: "Rails.application.configure do\n", verbose: false

if File.exists?(".gitignore")
  append_to_file ".gitignore", <<-EOS
/public/packs
/public/packs-test
/node_modules
yarn-debug.log*
.yarn-integrity
EOS
end

say "Installing all JavaScript dependencies"
run "yarn add @rails/webpacker"

say "Installing dev server for live reloading"
run "yarn add --dev webpack-dev-server"

if Rails::VERSION::MAJOR == 5 && Rails::VERSION::MINOR > 1
  say "You need to allow webpack-dev-server host as allowed origin for connect-src.", :yellow
  say "This can be done in Rails 5.2+ for development environment in the CSP initializer", :yellow<commit_msg>Add line break after check_yarn_integrity template config<commit_after># Install Webpacker
copy_file "#{__dir__}/config/webpacker.yml", "config/webpacker.yml"

puts "Copying webpack core config"
directory "#{__dir__}/config/webpack", "config/webpack"

say "Copying .postcssrc.yml to app root directory"
copy_file "#{__dir__}/config/.postcssrc.yml", ".postcssrc.yml"

say "Copying .babelrc to app root directory"
copy_file "#{__dir__}/config/.babelrc", ".babelrc"

say "Creating JavaScript app source directory"
directory "#{__dir__}/javascript", Webpacker.config.source_path

say "Installing binstubs"
run "bundle binstubs webpacker"

say "Adding configurations"

check_yarn_integrity_config = ->(value) { <<CONFIG }
# Verifies that versions and hashed value of the package contents in the project's package.json
  config.webpacker.check_yarn_integrity = #{value}
CONFIG

if Rails::VERSION::MAJOR >= 5
  environment check_yarn_integrity_config.call("true"), env: :development
  environment check_yarn_integrity_config.call("false"), env: :production
else
  inject_into_file "config/environments/development.rb", "\n  #{check_yarn_integrity_config.call("true")}", after: "Rails.application.configure do", verbose: false
  inject_into_file "config/environments/production.rb", "\n  #{check_yarn_integrity_config.call("false")}", after: "Rails.application.configure do", verbose: false
end

if File.exists?(".gitignore")
  append_to_file ".gitignore", <<-EOS
/public/packs
/public/packs-test
/node_modules
yarn-debug.log*
.yarn-integrity
EOS
end

say "Installing all JavaScript dependencies"
run "yarn add @rails/webpacker"

say "Installing dev server for live reloading"
run "yarn add --dev webpack-dev-server"

if Rails::VERSION::MAJOR == 5 && Rails::VERSION::MINOR > 1
  say "You need to allow webpack-dev-server host as allowed origin for connect-src.", :yellow
  say "This can be done in Rails 5.2+ for development environment in the CSP initializer", :yellow
{'fraction_non_alphanumeric': 0.11881464914733017, 'fraction_numerical': 0.002516074923119933, 'mean_word_length': 5.7893738140417454, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4297389', 'n_tokens_mistral': 1177, 'n_tokens_neox': 1125, 'n_words': 328}