<commit_before>const path = require('path')
const majo = require('majo')
const matcher = require('micromatch')
const { glob, fs } = require('majo')
const isBinaryPath = require('is-binary-path')
const logger = require('./logger')
const getGlobPatterns = require('./utils/getGlobPatterns')

module.exports = async (config, context) => {
  const actions =
    typeof config.actions === 'function'
      ? await config.actions.call(context, context)
      : config.actions

  for (const action of actions) {
    logger.debug('Running action:', action)
    if (action.type === 'add' && action.files) {
      const stream = majo()
      stream.source(['!**/node_modules/**'].concat(action.files), {
        baseDir: path.resolve(
          context.generator.path,
          config.templateDir || 'template'
        )
      })

      if (action.filters) {
        const excludedPatterns = getGlobPatterns(
          action.filters,
          context.answers,
          true
        )

        if (excludedPatterns.length > 0) {
          stream.use(() => {
            const excludedFiles = matcher(stream.fileList, excludedPatterns)
            for (const file of excludedFiles) {
              stream.deleteFile(file)
            }
          })
        }
      }

      const shouldTransform =
        typeof action.transform === 'boolean'
          ? action.transform
          : config.transform !== false
      if (shouldTransform) {
        stream.use(({ files }) => {
          let fileList = Object.keys(stream.files)

          // Exclude binary path
          fileList = fileList.filter(fp => !isBinaryPath(fp))

          if (action.transformInclude) {
            fileList = matcher(fileList, action.transformInclude)
          }
          if (action.transformExclude) {
            fileList = matcher.not(fileList, action.transformExclude)
          }

          fileList.forEach(relativePath => {
            const contents = files[relativePath].contents.toString()
            const transformer = require('jstransformer')(
              require(`jstransformer-${config.transformer || 'ejs'}`)
            )
            stream.writeContents(
              relativePath,
              transformer.render(
                contents,
                config.transformerOptions,
                Object.assign({}, context.answers, {
                  context
                })
              ).body
            )
          })
        })<commit_msg>feat: allow to use custom data for template interpolation<commit_after>const path = require('path')
const majo = require('majo')
const matcher = require('micromatch')
const { glob, fs } = require('majo')
const isBinaryPath = require('is-binary-path')
const logger = require('./logger')
const getGlobPatterns = require('./utils/getGlobPatterns')

module.exports = async (config, context) => {
  const actions =
    typeof config.actions === 'function'
      ? await config.actions.call(context, context)
      : config.actions

  for (const action of actions) {
    logger.debug('Running action:', action)
    if (action.type === 'add' && action.files) {
      const stream = majo()
      stream.source(['!**/node_modules/**'].concat(action.files), {
        baseDir: path.resolve(
          context.generator.path,
          config.templateDir || 'template'
        )
      })

      if (action.filters) {
        const excludedPatterns = getGlobPatterns(
          action.filters,
          context.answers,
          true
        )

        if (excludedPatterns.length > 0) {
          stream.use(() => {
            const excludedFiles = matcher(stream.fileList, excludedPatterns)
            for (const file of excludedFiles) {
              stream.deleteFile(file)
            }
          })
        }
      }

      const shouldTransform =
        typeof action.transform === 'boolean'
          ? action.transform
          : config.transform !== false
      if (shouldTransform) {
        stream.use(({ files }) => {
          let fileList = Object.keys(stream.files)

          // Exclude binary path
          fileList = fileList.filter(fp => !isBinaryPath(fp))

          if (action.transformInclude) {
            fileList = matcher(fileList, action.transformInclude)
          }
          if (action.transformExclude) {
            fileList = matcher.not(fileList, action.transformExclude)
          }

          fileList.forEach(relativePath => {
            const contents = files[relativePath].contents.toString()
            const transformer = require('jstransformer')(
              require(`jstransformer-${config.transformer || 'ejs'}`)
            )
            stream.writeContents(
              relativePath,
              transformer.render(
                contents,
                config.transformerOptions,
                Object.assign(
                  {},
                  context.answers,
                  typeof config.templateData === 'function'
                    ? config.templateData.call(context, context)
                    : config.templateData,
                  {
                    context
                  }
                )
              ).body
            )
          })
        })
{'fraction_non_alphanumeric': 0.11415349016583108, 'fraction_numerical': 0.0003856536829926726, 'mean_word_length': 1.788709677419355, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '6154492', 'n_tokens_mistral': 1346, 'n_tokens_neox': 1303, 'n_words': 268}