<commit_before>var fs = require('fs');
var _ = require('lodash');
var log = require('winston');

module.exports = function templateFinder(config) {

  if ( !config || !config.rendering || !config.rendering.templatePath || !config.rendering.templateExtension ) {
    throw new Error('Invalid configuration.  You must provide the following config properties:\n' +
      '{\n' +
      '  rendering: {\n' +
      '    templatePath: "...",\n' +
      '    templateExtension: "..."\n' +
      '  }\n' +
      '}');
  } 

  var templateFolder = config.rendering.templatePath;
  var templateExtension = config.rendering.templateExtension;

  log.debug('templateFinder', templateFolder, templateExtension);

  var templateFolderPaths = fs.readdirSync(templateFolder);
  var templateMap = _.indexBy(templateFolderPaths);
        
  return function findTemplate(doc) {
    // Find the template by doc.id, then fall back to by doc.docType
    // e.g. ngAnimate.module.templates.html -> module.templates.html
    return templateMap[doc.id + '.' + doc.docType + '.' + templateExtension] ||
           templateMap[doc.id + '.' + templateExtension] ||
           templateMap[doc.docType + '.' + templateExtension];
  };
};<commit_msg>chore(template-finder): add logging<commit_after>var fs = require('fs');
var _ = require('lodash');
var log = require('winston');

module.exports = function templateFinder(config) {

  if ( !config || !config.rendering || !config.rendering.templatePath || !config.rendering.templateExtension ) {
    throw new Error('Invalid configuration.  You must provide the following config properties:\n' +
      '{\n' +
      '  rendering: {\n' +
      '    templatePath: "...",\n' +
      '    templateExtension: "..."\n' +
      '  }\n' +
      '}');
  }

  var templateFolder = config.rendering.templatePath;
  var templateExtension = config.rendering.templateExtension;

  log.debug('templateFinder', templateFolder, templateExtension);

  var templateFolderPaths = fs.readdirSync(templateFolder);
  var templateMap = _.indexBy(templateFolderPaths);

  log.debug('templates found', templateMap);
        
  return function findTemplate(doc) {
    // Find the template by doc.id, then fall back to by doc.docType
    // e.g. ngAnimate.module.templates.html -> module.templates.html
    var template = templateMap[doc.id + '.' + doc.docType + '.' + templateExtension] ||
           templateMap[doc.id + '.' + templateExtension] ||
           templateMap[doc.docType + '.' + templateExtension];
    if(!template) {
      throw new Error('Unable to find a template for doc:', doc.id, doc.docType);
    }
    log.debug('found template: ', template);
    return template;
  };
};
{'fraction_non_alphanumeric': 0.14599627560521417, 'fraction_numerical': 0.0, 'mean_word_length': 3.27027027027027, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '6712132', 'n_tokens_mistral': 784, 'n_tokens_neox': 771, 'n_words': 173}