<commit_before>path = require 'path'

require 'coffee-script'
proxyquire = require('proxyquire').noCallThru()
glob = require 'glob'

hooks = require './hooks'
logger = require './logger'

addHooks = (runner) ->
    pattern = runner?.configuration?.options?.hookfiles
    return if not pattern

    files = glob.sync pattern

    logger.info 'Found Hookfiles: ' + files

    try
      for file in files
        proxyquire path.resolve(process.cwd(), file), {
          'hooks': hooks
        }
    catch error
      logger.warn 'Skipping hook loading...'
      logger.error 'Error reading hook files (' + files + ')'
      logger.error 'This probably means one or more of your hookfiles is invalid.'
      logger.error 'Message: ' + error.message if error.message?
      logger.error 'Stack: ' + error.stack if error.stack?
      return

    runner.before 'executeTransaction', (transaction, callback)  =>
      if hooks.beforeHooks[transaction.name]?
        hook = hooks.beforeHooks[transaction.name]
        runHook(hook, transaction, callback)
      else
        callback()
    runner.after 'executeTransaction', (transaction, callback) =>
      if hooks.afterHooks[transaction.name]?
        hook = hooks.afterHooks[transaction.name]
        runHook(hook, transaction, callback)
      else
        callback()

  runHook = (hook, transaction, callback) ->
    if hook.length is 1
      # syncronous, no callback
      hook transaction
      callback()
    else if hook.length is 2
      # async
      hook transaction, () =>
        callback()

module.exports = addHooks
<commit_msg>Adds debug info to test hooks<commit_after>path = require 'path'

require 'coffee-script'
proxyquire = require('proxyquire').noCallThru()
glob = require 'glob'

hooks = require './hooks'
logger = require './logger'

addHooks = (runner) ->
    pattern = runner?.configuration?.options?.hookfiles
    return if not pattern

    files = glob.sync pattern

    logger.info 'Found Hookfiles: ' + files

    try
      for file in files
        proxyquire path.resolve(process.cwd(), file), {
          'hooks': hooks
        }
    catch error
      logger.warn 'Skipping hook loading...'
      logger.error 'Error reading hook files (' + files + ')'
      logger.error 'This probably means one or more of your hookfiles is invalid.'
      logger.error 'Message: ' + error.message if error.message?
      logger.error 'Stack: ' + error.stack if error.stack?
      return

    runner.before 'executeTransaction', (transaction, callback)  =>
      if hooks.beforeHooks[transaction.name]?
        logger.debug 'Running before hook'
        hook = hooks.beforeHooks[transaction.name]
        runHook(hook, transaction, callback)
      else
        callback()
    runner.after 'executeTransaction', (transaction, callback) =>
      if hooks.afterHooks[transaction.name]?
        logger.debug 'Running after hook'
        hook = hooks.afterHooks[transaction.name]
        runHook(hook, transaction, callback)
      else
        callback()

  runHook = (hook, transaction, callback) ->
    if hook.length is 1
      # syncronous, no callback
      hook transaction
      callback()
    else if hook.length is 2
      # async
      hook transaction, () =>
        callback()

module.exports = addHooks

{'fraction_non_alphanumeric': 0.10571341277115796, 'fraction_numerical': 0.0012221203788573174, 'mean_word_length': 2.6704035874439462, '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': '5590604', 'n_tokens_mistral': 895, 'n_tokens_neox': 886, 'n_words': 267}