<commit_before>require 'fileutils'

desc 'Copy and undigest govuk-frontend assets'

namespace :assets do
  def copy_govuk_dependencies
    source = 'lib/node_modules/govuk-frontend/govuk/assets/'
    destination = 'public/assets/govuk-frontend/govuk/assets/'
    dirname = File.dirname(destination)
    FileUtils.mkdir_p(dirname)
    FileUtils.copy_entry source, destination
  end

  def undigest_font_and_image_assets
    build_number_file = File.expand_path('../../.build-number', __dir__)
    build = if File.exist?(build_number_file)
              "#{File.read(build_number_file).chomp}/"
            else
              ''
            end
    assets = Dir.glob(File.join(Rails.root, "./public/assets/#{build}govuk-frontend/govuk/assets/**/*"))

    regex = /(-{1}[a-z0-9]{32}*\.{1}){1}/
    fonts_and_images = ['.png', '.svg', '.woff', '.woff2']
    assets.each do |file|
      next if File.directory?(file) || (fonts_and_images.include?(File.extname(file)) && file !~ regex)

      source = file.split('/')
      source.push(source.pop.gsub(regex, '.'))
      non_digested = File.join(source)
      FileUtils.copy_file(file, non_digested)
    end<commit_msg>BUGFIX added extra logging to new rake tasks<commit_after>require 'fileutils'

desc 'Copy and undigest govuk-frontend assets'

namespace :assets do
  def copy_govuk_dependencies
    puts "INFO - Copying govuk-frontend assets"
    source = 'lib/node_modules/govuk-frontend/govuk/assets/'
    destination = 'public/assets/govuk-frontend/govuk/assets/'
    dirname = File.dirname(destination)
    FileUtils.mkdir_p(dirname)
    FileUtils.copy_entry source, destination
  end

  def undigest_font_and_image_assets
    puts 'INFO - undigesting govuk-frontend image and font assets'
    build_number_file = File.expand_path('../../.build-number', __dir__)
    build = if File.exist?(build_number_file)
              "#{File.read(build_number_file).chomp}/"
            else
              ''
            end
    path = File.join(Rails.root, "./public/assets/#{build}govuk-frontend/govuk/assets/**/*")
    assets = Dir.glob(path)
    puts "INFO - Found #{assets.length} assets to examine from #{path}"
    regex = /(-{1}[a-z0-9]{32}*\.{1}){1}/
    fonts_and_images = ['.png', '.svg', '.woff', '.woff2']
    assets.each do |file|
      next if File.directory?(file) || (fonts_and_images.include?(File.extname(file)) && file !~ regex)

      puts "INFO - Undigesting asset #{file}"
      source = file.split('/')
      source.push(source.pop.gsub(regex, '.'))
      non_digested = File.join(source)
      FileUtils.copy_file(file, non_digested)
      puts "INFO - Undigested asset at #{non_digested}"
    end
{'fraction_non_alphanumeric': 0.14768883878241262, 'fraction_numerical': 0.006012777151446824, 'mean_word_length': 3.1207430340557276, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4923910', 'n_tokens_mistral': 900, 'n_tokens_neox': 894, 'n_words': 165}