<commit_before>require 'rake-tasks/crazy_fun/mappings/common'

# Example:
# folder(
#  name = "mytask",
#  srcs = [
#    "file1.txt",
#    "file2.png",
#  ],
#  deps = [
#    "//some/depdendency:target",
#  ],
#  out = "outputfolder")


class FolderMappings
  def add_all(fun)
    fun.add_mapping("folder", Folder::CheckPreconditions.new)
    fun.add_mapping("folder", Folder::CreateTask.new)
    fun.add_mapping("folder", Folder::AddDependencies.new)
  end
end

module Folder

  class CheckPreconditions < Tasks
    def handle(fun, dir, args)
      raise StandardError, ":name must be set" if args[:name].nil?
      raise StandardError, ":srcs must be set" if args[:srcs].nil?
    end
  end

  class CreateTask < Tasks
    def handle(fun, dir, args)
      def dest_name(dir, args, filename)
	"build/#{dir}/#{args[:out] || args[:name]}/#{File.basename(filename)}"
      end

      task task_name(dir, args[:name]) do
	(args[:srcs] || []).each do |src|
          to_export = "#{dir}/#{src}"
          src = Platform.path_for to_export
          dest = dest_name(dir, args, src)
          mkdir_p File.dirname(dest)
	  cp_r src, dest
        end

	(args[:deps] || []).each do |dep|
	  file = Rake::Task[dep].out
	  cp_r file, dest_name(dir, args, file)
	end
      end
    end
  end

  class AddDependencies < Tasks
    def handle(fun, dir, args)
      name = task_name(dir, args[:name])
      task = Rake::Task[name]
      add_dependencies(task, dir, args[:deps])
      add_dependencies(task, dir, args[:srcs])
    end
  end<commit_msg>JasonLeyba: Update the folder command to support arbitrary folder layouts.<commit_after>require 'rake-tasks/crazy_fun/mappings/common'

# Example:
# folder(
#  name = "mytask",
#  srcs = [
#    "file1.txt",
#    "file2.png",
#  ],
#  deps = [
#    "//some/depdendency:target",
#  ],
#  out = "outputfolder")


class FolderMappings
  def add_all(fun)
    fun.add_mapping("folder", Folder::CheckPreconditions.new)
    fun.add_mapping("folder", Folder::CreateTask.new)
    fun.add_mapping("folder", Folder::AddDependencies.new)
  end
end

module Folder

  class CheckPreconditions < Tasks
    def handle(fun, dir, args)
      raise StandardError, ":name must be set" if args[:name].nil?
      raise StandardError, ":srcs must be set" if args[:srcs].nil?
    end
  end

  class CreateTask < Tasks
    def dest_dir(dir, args)
      path_for "build/#{dir}/#{args[:out] || args[:name]}"
    end

    def handle(fun, dir, args)
      folder = dest_dir(dir, args)

      task task_name(dir, args[:name]) do
        puts "Preparing: #{task_name(dir, args[:name])} as #{folder}"
        mkdir_p folder
        copy_resources(dir, args[:srcs], folder)
        copy_resources(dir, args[:deps], folder) unless args[:deps].nil?
      end
    end
  end

  class AddDependencies < Tasks
    def handle(fun, dir, args)
      name = task_name(dir, args[:name])
      task = Rake::Task[name]
      add_dependencies(task, dir, args[:deps]) unless args[:deps].nil?
      add_dependencies(task, dir, args[:srcs])
    end
  end
{'fraction_non_alphanumeric': 0.1465261771485018, 'fraction_numerical': 0.0013170892327955218, 'mean_word_length': 3.1903448275862067, 'pattern_counts': {'":': 4, '<': 9, '<?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': '3210757', 'n_tokens_mistral': 1082, 'n_tokens_neox': 1060, 'n_words': 246}