<commit_before>/* eslint-disable no-console */
import path from 'path'
import fs from 'fs-extra'
import chalk from 'chalk'
import isObject from 'is-plain-object'

function isProbablyFile(filePath) {
  return path.extname(filePath).length > 1
}

function processArrayOfTargets(targets, outputFolder) {
  return targets.map(target => ({
    from: target,
    to: path.join(outputFolder, path.basename(target))
  }))
}

function processObjectOfTargets(targets, outputFolder = '') {
  return Object.entries(targets).map(([from, to]) => {
    const dest = (isProbablyFile(from) && !isProbablyFile(to))
      ? path.join(outputFolder, to, path.basename(from))
      : path.join(outputFolder, to)

    return { from, to: dest }
  })
}

export default function copy(options = { verbose: false }) {
  const { outputFolder, targets, verbose } = options

  return {
    name: 'copy',
    async generateBundle(outputOptions) {
      let processedTargets = []

      if (Array.isArray(targets) && targets.length) {
        const destFolder = outputFolder || outputOptions.dir || path.dirname(outputOptions.file)

        processedTargets = processArrayOfTargets(targets, destFolder)
      }

      if (isObject(targets) && Object.entries(options).length) {
        processedTargets = processObjectOfTargets(targets, outputFolder)
      }

      if (processedTargets.length) {
        if (verbose) {
          console.log('Copied files and folders:')
        }

        await Promise.all(processedTargets.map(async ({ from, to }) => {
          try {
            await fs.copy(from, to)

            if (verbose) {
              console.log(`${chalk.green(`${from} -> ${to}`)}`)
            }
          } catch (e) {
            this.error(e)
          }
        }))
      }
    }
  }
}<commit_msg>Fix targets as an object length<commit_after>/* eslint-disable no-console */
import path from 'path'
import fs from 'fs-extra'
import chalk from 'chalk'
import isObject from 'is-plain-object'

function isProbablyFile(filePath) {
  return path.extname(filePath).length > 1
}

function processArrayOfTargets(targets, outputFolder) {
  return targets.map(target => ({
    from: target,
    to: path.join(outputFolder, path.basename(target))
  }))
}

function processObjectOfTargets(targets, outputFolder = '') {
  return Object.entries(targets).map(([from, to]) => {
    const dest = (isProbablyFile(from) && !isProbablyFile(to))
      ? path.join(outputFolder, to, path.basename(from))
      : path.join(outputFolder, to)

    return { from, to: dest }
  })
}

export default function copy(options = { verbose: false }) {
  const { outputFolder, targets, verbose } = options

  return {
    name: 'copy',
    async generateBundle(outputOptions) {
      let processedTargets = []

      if (Array.isArray(targets) && targets.length) {
        const destFolder = outputFolder || outputOptions.dir || path.dirname(outputOptions.file)

        processedTargets = processArrayOfTargets(targets, destFolder)
      }

      if (isObject(targets) && Object.entries(targets).length) {
        processedTargets = processObjectOfTargets(targets, outputFolder)
      }

      if (processedTargets.length) {
        if (verbose) {
          console.log('Copied files and folders:')
        }

        await Promise.all(processedTargets.map(async ({ from, to }) => {
          try {
            await fs.copy(from, to)

            if (verbose) {
              console.log(`${chalk.green(`${from} -> ${to}`)}`)
            }
          } catch (e) {
            this.error(e)
          }
        }))
      }
    }
  }
}
{'fraction_non_alphanumeric': 0.13273842721695484, 'fraction_numerical': 0.0005577244841048522, 'mean_word_length': 2.759958071278826, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '6833878', 'n_tokens_mistral': 1107, 'n_tokens_neox': 1058, 'n_words': 227}