<commit_before>PACKS_PATH        = Rails.root.join('public/packs')
PACK_DIGESTS_PATH = PACKS_PATH.join('digests.json')

WEBPACKER_APP_TEMPLATE_PATH = File.expand_path('../install/template.rb', __dir__)

namespace :webpacker do
  desc "Compile javascript packs using webpack for production with digests"
  task :compile do
    webpack_digests_json = JSON.parse(`WEBPACK_ENV=production ./bin/webpack --json`)['assetsByChunkName'].to_json

    FileUtils.mkdir_p(PACKS_PATH)
    File.open(PACK_DIGESTS_PATH, 'w+') { |file| file.write webpack_digests_json }

    puts "Compiled digests for all packs in #{PACK_DIGESTS_PATH}: "
    puts webpack_digests_json
  end

  desc "Install webpacker in this application"
  task :install do
    exec "./bin/rails app:template LOCATION=#{WEBPACKER_APP_TEMPLATE_PATH}"
  end

  namespace :install do
    desc "Install everything needed for react"
    task :react do
      config_path = Rails.root.join('config/webpack/shared.js')
      config = File.read(config_path)<commit_msg>Use config digests path within rake<commit_after>WEBPACKER_APP_TEMPLATE_PATH = File.expand_path('../install/template.rb', __dir__)

namespace :webpacker do
  desc "Compile javascript packs using webpack for production with digests"
  task :compile => :environment do
    webpack_digests_json = JSON.parse(`WEBPACK_ENV=production ./bin/webpack --json`)['assetsByChunkName'].to_json

    digests_path = Rails.application.config.x.webpacker[:digests_path]
    packs_path = File.dirname(digests_path)

    FileUtils.mkdir_p(packs_path)
    File.open(digests_path, 'w+') { |file| file.write webpack_digests_json }

    puts "Compiled digests for all packs in #{digests_path}: "
    puts webpack_digests_json
  end

  desc "Install webpacker in this application"
  task :install do
    exec "./bin/rails app:template LOCATION=#{WEBPACKER_APP_TEMPLATE_PATH}"
  end

  namespace :install do
    desc "Install everything needed for react"
    task :react do
      config_path = Rails.root.join('config/webpack/shared.js')
      config = File.read(config_path)
{'fraction_non_alphanumeric': 0.09995147986414361, 'fraction_numerical': 0.0, 'mean_word_length': 4.498666666666667, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, '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': '6780949', 'n_tokens_mistral': 679, 'n_tokens_neox': 659, 'n_words': 153}