<commit_before>/*
 * patternlab-node - v0.10.1 - 2015
 *
 * <NAME>, <NAME>, and the web community.
 * Licensed under the MIT license.
 *
 * Many thanks to <NAME> and <NAME> for inspiration, encouragement, and advice.
 *
 */


(function () {
  'use strict';

  var path = require('path');
  var diveSync = require('diveSync');
  var engineMatcher = /^engine_(.*)\.js/;
  var enginesDirectory = __dirname;

  var PatternEngines; // the main export object
  var engineNameForExtension; // generated mapping of extension to engine name


  // free "private" functions, for internal setup only

  function findSupportedPatternEngineNames() {
    var foundPatternEngineNames = [];

    // find
    diveSync(enginesDirectory, {
      recursive: false,
      filter: function (filePath, dir) {
        var baseName = path.basename(filePath),
            engineMatch = baseName.match(engineMatcher);

        if (dir || engineMatch !== null) { return true; }
        return false;
      }
    }, function (err, filePath) {
      if (err) { throw err; }
      var baseName = path.basename(filePath),
          engineMatch = baseName.match(engineMatcher),
          foundEngineName = engineMatch[1];

      foundPatternEngineNames.push(foundEngineName);
    });

    return foundPatternEngineNames;
  }

  // try to load all supported engines
  function loadAllEngines(enginesObject) {
    console.log('\nLoading engines...');

    enginesObject.supportedPatternEngineNames.forEach(function (engineName) {
      var notLoaded = false;

      try {
        enginesObject[engineName] = require('./engine_' + engineName);
      } catch (err) {
        // Handle errors loading each pattern engine. This will usually be
        // because the engine's renderer hasn't been installed by the end user
        // -- we don't include any of them (except mustache) by default as
        // depedencies in package.json.
        notLoaded = (err.code === 'MODULE_NOT_FOUND');
      } finally {
        console.log('-', engineName, 'engine:',
                    notLoaded ? 'renderer not installed; engine disabled' : 'good to go');
      }
    });
    console.log('Done loading engines.\n');
  }

  // produce a mapping between file extension and engine name for each of the
  // loaded engines
  function createFileExtensionToEngineNameMap(enginesObject) {
    var mapping = {};

    Object.keys(enginesObject).forEach(function (engineName) {
      var extensionForEngine = enginesObject[engineName].engineFileExtension;
      mapping[extensionForEngine] = engineName;
    });

    return mapping;
  }


  //
  // PatternEngines: the main export of this module<commit_msg>slight polish to engine loader console output<commit_after>/*
 * patternlab-node - v0.10.1 - 2015
 *
 * <NAME>, <NAME>, and the web community.
 * Licensed under the MIT license.
 *
 * Many thanks to <NAME> and <NAME> for inspiration, encouragement, and advice.
 *
 */


(function () {
  'use strict';

  var path = require('path');
  var diveSync = require('diveSync');
  var engineMatcher = /^engine_(.*)\.js/;
  var enginesDirectory = __dirname;

  var PatternEngines; // the main export object
  var engineNameForExtension; // generated mapping of extension to engine name


  // free "private" functions, for internal setup only

  function findSupportedPatternEngineNames() {
    var foundPatternEngineNames = [];

    // find
    diveSync(enginesDirectory, {
      recursive: false,
      filter: function (filePath, dir) {
        var baseName = path.basename(filePath),
            engineMatch = baseName.match(engineMatcher);

        if (dir || engineMatch !== null) { return true; }
        return false;
      }
    }, function (err, filePath) {
      if (err) { throw err; }
      var baseName = path.basename(filePath),
          engineMatch = baseName.match(engineMatcher),
          foundEngineName = engineMatch[1];

      foundPatternEngineNames.push(foundEngineName);
    });

    return foundPatternEngineNames;
  }

  // try to load all supported engines
  function loadAllEngines(enginesObject) {
    console.log('\nLoading engines...');

    enginesObject.supportedPatternEngineNames.forEach(function (engineName) {
      var notLoaded = false;

      try {
        enginesObject[engineName] = require('./engine_' + engineName);
      } catch (err) {
        // Handle errors loading each pattern engine. This will usually be
        // because the engine's renderer hasn't been installed by the end user
        // -- we don't include any of them (except mustache) by default as
        // depedencies in package.json.
        notLoaded = (err.code === 'MODULE_NOT_FOUND');
      } finally {
        console.log('-', engineName, 'engine:',
                    notLoaded ? 'renderer not installed; engine disabled' : 'good to go');
      }
    });
    console.log('...done loading engines.\n');
  }

  // produce a mapping between file extension and engine name for each of the
  // loaded engines
  function createFileExtensionToEngineNameMap(enginesObject) {
    var mapping = {};

    Object.keys(enginesObject).forEach(function (engineName) {
      var extensionForEngine = enginesObject[engineName].engineFileExtension;
      mapping[extensionForEngine] = engineName;
    });

    return mapping;
  }


  //
  // PatternEngines: the main export of this module
{'fraction_non_alphanumeric': 0.10994568271211838, 'fraction_numerical': 0.003371417868514703, 'mean_word_length': 2.841726618705036, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '3213644', 'n_tokens_mistral': 1482, 'n_tokens_neox': 1432, 'n_words': 435}