<commit_before>(function() {
  'use strict';

  var mustache = require('mustache');
  var fs = require('fs');
  var Q = require('q');
  var mkdirp = require('mkdirp');
  // create promise versions of read and write files
  var read = Q.denodeify(fs.readFile);
  var write = Q.denodeify(fs.writeFile);

  module.exports = {
    generate: function(answers) {

      // create promise versions of chmod and mkdirp
      var chmod = Q.denodeify(fs.chmod);
      var mkdir = Q.denodeify(mkdirp);

      // Kick off a promise chain
      mkdir('ansible/inventory', '0755')
        .then(getReader('ansible.cfg.mustache')).then(render).then(getWriter('ansible/ansible.cfg'))
        .then(getReader('aws_keys.mustache')).then(render).then(getWriter('ansible/inventory/aws_keys'))
        .then(getReader('destroy-old-nodes.yaml.mustache')).then(render)
          .then(getWriter('ansible/destroy-old-nodes.yaml'))
        .then(getReader('ec2.ini.mustache')).then(render).then(getWriter('ansible/inventory/ec2.ini'))
        .then(getReader('ec2.py')).then(render).then(getWriter('ansible/inventory/ec2.py'))
        .then(getReader('immutable.yaml.mustache')).then(render).then(getWriter('ansible/immutable.yaml'))
        .then(getReader('provision.sh.mustache')).then(render).then(getWriter('ansible/provision.sh'))
          .then(chmod('ansible/provision.sh', '0744'))
        .then(getReader('tag-old-nodes.yaml.mustache')).then(render).then(getWriter('ansible/tag-old-nodes.yaml'))
        .then(mkdir('ansible/roles/' + answers.appName + '/tasks'))
        .then(getReader('roles/appName/tasks/main.yaml.mustache')).then(render).then(getWriter('ansible/roles/' +
          answers.appName + '/tasks/main.yaml'))
        .then(getReader('myApp.pem.mustache')).then(render).then(getWriter('ansible/' + answers.appPem))
        .finally(function() {
          fs.chmod('ansible/provision.sh', '0744');
          fs.chmod('ansible/inventory/ec2.py', '0755');
        })
        .catch(handler);

      /**
       * Render a template by injecting answers into it
       *
       * @param {String} template
       * @returns {String} rendered template
       */
      function render(template) {
        return mustache.render(template, answers);
      }
    }
  };

  /**
   * Partial application - creates a function which allows reading and returns a promise
   *
   * @param {String} template
   * @returns {Function} Promise
   */
  function getReader(template) {
    return function() {
      return read(__dirname + '/templates/' + template, 'utf8');
    };
  }

  /**
   * Partial application - creates a function which allows file writing and returns a promise
   *
   * @param {String} outputPath e.g. 'out.txt'
   * @returns {Function} Promise with parameter "compiledTemplate", which is ready to write to outputPath
   */
  function getWriter(outputPath) {
    return function(compiledTemplate) {
      return write(outputPath, compiledTemplate);
    };
  }

  /**
   * Generic error handler. Simply logs to the console.
   *
   * @param {Error} err
   */
  function handler(err) {
    console.log(('Something went wrong'));
    console.log(err);
  }

}());
<commit_msg>aws_keys and appName.pem added to .gitignore<commit_after>(function() {
  'use strict';

  var mustache = require('mustache');
  var fs = require('fs');
  var Q = require('q');
  var mkdirp = require('mkdirp');
  // create promise versions of read and write files
  var read = Q.denodeify(fs.readFile);
  var write = Q.denodeify(fs.writeFile);

  module.exports = {
    generate: function(answers) {

      // create promise versions of chmod and mkdirp
      var chmod = Q.denodeify(fs.chmod);
      var mkdir = Q.denodeify(mkdirp);

      //function that handles .gitignore
      function gitignore(path){
        return function(){
          return fs.appendFile('.gitignore', "\n" + path, function(err){
            if(err) return Promise.reject(err);
            return Promise.resolve();
          });
        };
      }

      // Kick off a promise chain
      mkdir('ansible/inventory', '0755')
        .then(getReader('ansible.cfg.mustache')).then(render).then(getWriter('ansible/ansible.cfg'))
        .then(getReader('aws_keys.mustache')).then(render).then(getWriter('ansible/inventory/aws_keys'))
        .then(gitignore('ansible/inventory/aws_keys'))
        .then(getReader('destroy-old-nodes.yaml.mustache')).then(render)
          .then(getWriter('ansible/destroy-old-nodes.yaml'))
        .then(getReader('ec2.ini.mustache')).then(render).then(getWriter('ansible/inventory/ec2.ini'))
        .then(getReader('ec2.py')).then(render).then(getWriter('ansible/inventory/ec2.py'))
        .then(getReader('immutable.yaml.mustache')).then(render).then(getWriter('ansible/immutable.yaml'))
        .then(getReader('provision.sh.mustache')).then(render).then(getWriter('ansible/provision.sh'))
          .then(chmod('ansible/provision.sh', '0744'))
        .then(getReader('tag-old-nodes.yaml.mustache')).then(render).then(getWriter('ansible/tag-old-nodes.yaml'))
        .then(mkdir('ansible/roles/' + answers.appName + '/tasks'))
        .then(getReader('roles/appName/tasks/main.yaml.mustache')).then(render).then(getWriter('ansible/roles/' +
          answers.appName + '/tasks/main.yaml'))
        .then(getReader('myApp.pem.mustache')).then(render).then(getWriter('ansible/' + answers.appPem))
        .then(gitignore('ansible/' + answers.appPem))
        .finally(function() {
          fs.chmod('ansible/provision.sh', '0744');
          fs.chmod('ansible/inventory/ec2.py', '0755');
        })
        .catch(handler);

      /**
       * Render a template by injecting answers into it
       *
       * @param {String} template
       * @returns {String} rendered template
       */
      function render(template) {
        return mustache.render(template, answers);
      }
    }
  };

  /**
   * Partial application - creates a function which allows reading and returns a promise
   *
   * @param {String} template
   * @returns {Function} Promise
   */
  function getReader(template) {
    return function() {
      return read(__dirname + '/templates/' + template, 'utf8');
    };
  }

  /**
   * Partial application - creates a function which allows file writing and returns a promise
   *
   * @param {String} outputPath e.g. 'out.txt'
   * @returns {Function} Promise with parameter "compiledTemplate", which is ready to write to outputPath
   */
  function getWriter(outputPath) {
    return function(compiledTemplate) {
      return write(outputPath, compiledTemplate);
    };
  }

  /**
   * Generic error handler. Simply logs to the console.
   *
   * @param {Error} err
   */
  function handler(err) {
    console.log(('Something went wrong'));
    console.log(err);
  }

}());
{'fraction_non_alphanumeric': 0.15738284703801944, 'fraction_numerical': 0.006483937518420277, 'mean_word_length': 3.0543608124253288, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4178528', 'n_tokens_mistral': 2128, 'n_tokens_neox': 2104, 'n_words': 384}