<commit_before>'use strict';

var walkSync = require('./utilities/walk-sync').walkSync,
    fs = require('fs-extra'),
    chalk = require('chalk'),
    RSVP = require('rsvp'),
    _ = require('lodash-node'),
    path = require('path'),
    Promise = RSVP.Promise,
    stat = RSVP.denodeify(fs.stat),
    outputFile = RSVP.denodeify(fs.outputFile),
    sequence = require('./utilities/sequence'),
    readFile = RSVP.denodeify(fs.readFile),
    keypress = require('./ui/keypress'),
    prompt = require('./ui/prompt'),
    FileInfo = require('./models/file_info'),
    npmInstall = require('./actions/npm_install'),
    ui = require('./ui');

function install(intoDir, name, dryRun, skipNpmInstall) {
  var skeletonDir = path.resolve(path.join(__dirname, '..', 'skeleton'));

  var files = walkSync(skeletonDir),
      file;

  function shouldCommit() {
    return !dryRun;
  }

  function skipPostInstall() {
    return dryRun || skipNpmInstall;
  }

  function templateContext() {
    return {
      namespace: name
    };
  }

  function destPath(file) {
    return path.join(intoDir, file);
  }

  function srcPath(file) {
    return path.join(skeletonDir, file);
  }

  var actions = {
    write: function (info) {
      ui.write('  ' + chalk.green('create') + ' ' +info.displayPath + '\n');

      if (shouldCommit()) {
        return writeFile(info.render(), info.outputPath);
      }
    },

    skip: function (info) {
      var label = 'skip';
      if (info.resolution === 'identical') {
        label = 'identical';
      }

      ui.write('  ' + chalk.yellow(label) + ' ' + info.displayPath + '\n');
    },

    overwrite: function (info) {
      ui.write('  ' + chalk.yellow('overwrite') + info.displayPath + '\n');
      if (shouldCommit()) {
        return writeFile(info.render(), info.outputPath);
      }
    }
  };

  function buildFileInfo(file) {
    return new FileInfo({
      action: 'write',
      outputPath: destPath(file),
      displayPath: file,
      inputPath: srcPath(file),
      namespace: name
    });
  }

  function prepareConfirm(info) {
    return info.checkForConflict().then(function (resolution) {
      info.resolution = resolution;
      return info;
    });
  }

  function commit(result) {
    var action = actions[result.action];

    if (action) {
      return action.call(null, result);
    } else {
      throw new Error('Tried to call action \"' + result.action + '\" but it does not exist');
    }
  }

  function postInstall() {
    if (skipPostInstall()) {
      ui.write(chalk.yellow('Skipping `npm install`..\n'));
      return 0;
    }

    return npmInstall();
  }

  function processFiles(fileList) {
    RSVP.filter(fileList.map(buildFileInfo), isFile).
      map(prepareConfirm).
      then(function (infos) {
        infos.filter(function(info) {
          return info.resolution === 'identical';
        }).forEach(function(info) {
          info.action = 'skip';
        });

        var infosNeedingConfirmation =
          infos.filter(function (info) {
          return info.resolution === 'confirm';
        }).map(function(info) {
          return info.confirmOverwriteTask();
        });

        return sequence(infosNeedingConfirmation).returns(infos);
      }).map(commit).
        then(postInstall).
        then(function (code) {
          process.exit(code);
    });
  }

  ui.write('installing\n');

  if (dryRun) {
    ui.write(chalk.yellow('You specified the dry-run flag, so no changes will be written.\n'));
  }
<commit_msg>small skeleton cleanup<commit_after>'use strict';

var walkSync = require('./utilities/walk-sync').walkSync,
    fs = require('fs-extra'),
    chalk = require('chalk'),
    RSVP = require('rsvp'),
    _ = require('lodash-node'),
    path = require('path'),
    Promise = RSVP.Promise,
    stat = RSVP.denodeify(fs.stat),
    outputFile = RSVP.denodeify(fs.outputFile),
    sequence = require('./utilities/sequence'),
    readFile = RSVP.denodeify(fs.readFile),
    keypress = require('./ui/keypress'),
    prompt = require('./ui/prompt'),
    FileInfo = require('./models/file_info'),
    npmInstall = require('./actions/npm_install'),
    ui = require('./ui');

function install(intoDir, name, dryRun, skipNpmInstall) {
  var skeletonDir = path.resolve(path.join(__dirname, '..', 'skeleton'));

  var files = walkSync(skeletonDir),
      file;

  function shouldCommit() {
    return !dryRun;
  }

  function skipPostInstall() {
    return dryRun || skipNpmInstall;
  }

  function templateContext() {
    return {
      namespace: name
    };
  }

  function destPath(file) {
    return path.join(intoDir, file);
  }

  function srcPath(file) {
    return path.join(skeletonDir, file);
  }

  var actions = {
    write: function (info) {
      ui.write('  ' + chalk.green('create') + ' ' +info.displayPath + '\n');

      if (shouldCommit()) {
        return writeFile(info.render(), info.outputPath);
      }
    },

    skip: function (info) {
      var label = 'skip';
      if (info.resolution === 'identical') {
        label = 'identical';
      }

      ui.write('  ' + chalk.yellow(label) + ' ' + info.displayPath + '\n');
    },

    overwrite: function (info) {
      ui.write('  ' + chalk.yellow('overwrite') + info.displayPath + '\n');
      if (shouldCommit()) {
        return writeFile(info.render(), info.outputPath);
      }
    }
  };

  function buildFileInfo(file) {
    return new FileInfo({
      action: 'write',
      outputPath: destPath(file),
      displayPath: file,
      inputPath: srcPath(file),
      namespace: name
    });
  }

  function prepareConfirm(info) {
    return info.checkForConflict().then(function (resolution) {
      info.resolution = resolution;
      return info;
    });
  }

  function commit(result) {
    var action = actions[result.action];

    if (action) {
      return action.call(null, result);
    } else {
      throw new Error('Tried to call action \"' + result.action + '\" but it does not exist');
    }
  }

  function postInstall() {
    if (skipPostInstall()) {
      ui.write(chalk.yellow('Skipping `npm install`..\n'));
      return 0;
    }

    return npmInstall();
  }

  function markIdenticalToBeSkipped(info) {
    if (info.resolution === 'identical') {
      info.action = 'skip';
    }
  }

  function processFiles(fileList) {

    var fileInfos = fileList.map(buildFileInfo);

    RSVP.filter(fileInfos, isFile).
      map(prepareConfirm).
      then(function (infos) {
        infos.forEach(markIdenticalToBeSkipped);

        var infosNeedingConfirmation =
          infos.filter(function (info) {
            return info.resolution === 'confirm';
        }).map(function(info) {
          return info.confirmOverwriteTask();
        });

        return sequence(infosNeedingConfirmation).returns(infos);
      }).map(commit).
        then(postInstall).
        then(function (code) {
          process.exit(code);
    });
  }

  ui.write('installing\n');

  if (dryRun) {
    ui.write(chalk.yellow('You specified the dry-run flag, so no changes will be written.\n'));
  }

{'fraction_non_alphanumeric': 0.15319269432252583, 'fraction_numerical': 0.0002831657935721365, 'mean_word_length': 2.6356150283067423, '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': '6562932', 'n_tokens_mistral': 2262, 'n_tokens_neox': 2163, 'n_words': 436}