<commit_before>'use strict';

var path = require('path');
var debug = require('debug')('generate:mocha');
var opts = {alias: {tmpl: 't'}, default: {tmpl: 'test.js'}};
var argv = require('minimist')(process.argv.slice(2), opts);
var debug = require('debug')('generate:mocha');
var rename = require('./lib/rename');
var utils = require('./lib/utils');

module.exports = function(app, base, env, options) {
  if (!utils.isValid(app, 'generate-mocha')) return;

  /**
   * Config store for user-defined, generator-specific defaults
   */

  var store = new utils.DataStore('generate-mocha');

  /**
   * Paths
   */

  var cwd = path.resolve.bind(path, __dirname);
  function dir(name) {
    return app.option(name) || cwd(name);
  }

  /**
   * Instance plugins
   */

  app.use(require('generate-defaults'))
    .use(require('generate-collections'))
    .use(utils.commonQuestions())
    .use(utils.register())
    .use(rename())
    .use(prompt())

  /**
   * Options
   */

  app.option(base.options)
    .option(argv)
    .option({delims: ['<%', '%>']})
    .option('renameFile', function(file) {
      file.stem = 'test';
      return file;
    });

  /**
   * Helpers
   */

  app.helper('camelcase', require('camel-case'));
  app.helper('strip', function(name, str) {
    return str.replace('^' + new RegExp(str) + '\\W*', '');
  });

  /**
   * Middleware
   */

  app.postRender(/\.js$/, function(view, next) {
    app.union('cache.install', view.data.install);
    next();
  });

  /**
   * Pipeline plugins
   */

  app.plugin('rename', rename);

  /**
   * Sub-generators
   */

  app.register('generators/*/', {cwd: __dirname});

  /**
   * This task is used in unit tests to ensure this generator works in all intended
   * scenarios.
   *
   * ```sh
   * $ gen mocha:unit-test
   * ```
   * @name unit-test
   * @api public
   */

  app.task('unit-test', function(cb) {
    app.base.set('cache.unit-test', true);
    cb();
  });

  /**
   * Pre-load templates. This is called by the [default](#default) task, but if you call
   * this task directly make sure it's called after collections are created.
   *
   * ```sh
   * $ gen mocha:templates
   * ```
   * @name templates
   * @api public
   */

  app.task('templates', {silent: true}, function(cb) {
    debug('loading templates');

    app.includes.option('renameKey', function(key, file) {
      return file ? file.stem : path.basename(key, path.extname(key));
    });

    app.includes('*.js', {cwd: dir('templates/includes')});
    app.layouts('*.js', {cwd: dir('templates/layouts')});
    app.templates('*.js', {
      cwd: dir('templates'),
      renameKey: function(key, file) {
        return file ? file.basename : path.basename(key);
      }
    });

    debug('loaded templates');
    cb();
  });

  /**
   * Loads the `project.name` and `project.alias` questions onto the `question.queue`
   * to be asked when the `.ask` method is called. This is called by the [default]() task.
   *
   * ```sh
   * $ gen mocha:questions
   * ```
   * @name questions
   * @api public
   */

  // app.task('questions', {silent: true}, function(cb) {
  //   debug('loading questions');
  //   app.data(base.cache.data);

  //   app.question('project.name', 'Project name?', {
  //     default: app.data('name') || app.pkg.get('name')
  //   });
  //   app.question('project.alias', 'Project alias?', {
  //     default: app.data('alias')
  //   });

  //   debug('loaded questions');
  //   cb();
  // });

  /**
   * Prompt the user for the `dest` directory to use for the generated test file(s).
   * Called by the [default]() task.
   *
   * ```sh
   * $ gen mocha:dest
   * ```
   * @name dest
   * @api public
   */

  app.task('prompt-save-choices', {silent: true}, function(cb) {
    app.confirm('save-choices', 'Want to automatically install mocha next time?');
    app.ask('save-choices', {save: false}, function(err, answers) {
      if (err) return cb(err);
      if (answers['save-choices']) {
        store.set('install', true);
      }
      cb();
    });
  });

  /**
   * Prompt the user to install any necessary dependencies after generated files
   * are written to the file system.
   *
   * ```sh
   * $ gen mocha:prompt-install
   * ```
   * @name mocha:prompt-install
   * @api public
   */

  app.task('prompt-install', {silent: true}, function(cb) {
    app.npm.askInstall('mocha', function(err) {<commit_msg>clean up<commit_after>'use strict';

var path = require('path');
var debug = require('debug')('generate:mocha');
var opts = {alias: {tmpl: 't'}, default: {tmpl: 'test.js'}};
var argv = require('minimist')(process.argv.slice(2), opts);
var debug = require('debug')('generate:mocha');
var rename = require('./lib/rename');
var utils = require('./lib/utils');

module.exports = function(app, base, env, options) {
  if (!utils.isValid(app, 'generate-mocha')) return;

  /**
   * Config store for user-defined, generator-specific defaults
   */

  var store = new utils.DataStore('generate-mocha');

  /**
   * Paths
   */

  var cwd = path.resolve.bind(path, __dirname);
  function dir(name) {
    return app.option(name) || cwd(name);
  }

  /**
   * Instance plugins
   */

  app.use(require('generate-defaults'))
    .use(require('generate-collections'))
    .use(utils.commonQuestions())
    .use(utils.register())
    .use(rename())
    .use(prompt())

  /**
   * Options
   */

  app.option(base.options)
    .option(argv)
    .option({delims: ['<%', '%>']})
    .option('renameFile', function(file) {
      file.stem = 'test';
      return file;
    });

  /**
   * Helpers
   */

  app.helper('camelcase', require('camel-case'));
  app.helper('strip', function(name, str) {
    return str.replace('^' + new RegExp(str) + '\\W*', '');
  });

  /**
   * Middleware
   */

  app.postRender(/\.js$/, function(view, next) {
    app.union('cache.install', view.data.install);
    next();
  });

  /**
   * Pipeline plugins
   */

  app.plugin('rename', rename);

  /**
   * Sub-generators
   */

  app.register('generators/*/', {cwd: __dirname});

  /**
   * This task is used in unit tests to ensure this generator works in all intended
   * scenarios.
   *
   * ```sh
   * $ gen mocha:unit-test
   * ```
   * @name unit-test
   * @api public
   */

  app.task('unit-test', function(cb) {
    app.base.set('cache.unit-test', true);
    cb();
  });

  /**
   * Pre-load templates. This is called by the [default](#default) task, but if you call
   * this task directly make sure it's called after collections are created.
   *
   * ```sh
   * $ gen mocha:templates
   * ```
   * @name templates
   * @api public
   */

  app.task('templates', {silent: true}, function(cb) {
    debug('loading templates');

    app.includes.option('renameKey', function(key, file) {
      return file ? file.stem : path.basename(key, path.extname(key));
    });

    app.includes('*.js', {cwd: dir('templates/includes')});
    app.layouts('*.js', {cwd: dir('templates/layouts')});
    app.templates('*.js', {
      cwd: dir('templates'),
      renameKey: function(key, file) {
        return file ? file.basename : path.basename(key);
      }
    });

    debug('loaded templates');
    cb();
  });

  /**
   * Prompt the user for the `dest` directory to use for the generated test file(s).
   * Called by the [default]() task.
   *
   * ```sh
   * $ gen mocha:dest
   * ```
   * @name dest
   * @api public
   */

  app.task('prompt-choices', {silent: true}, function(cb) {
    app.confirm('choices', 'Want to automatically install mocha next time?');
    app.ask('choices', {save: false}, function(err, answers) {
      if (err) return cb(err);
      if (answers.choices) {
        store.set('install', true);
      }
      cb();
    });
  });

  /**
   * Prompt the user to install any necessary dependencies after generated files
   * are written to the file system.
   *
   * ```sh
   * $ gen mocha:prompt-install
   * ```
   * @name mocha:prompt-install
   * @api public
   */

  app.task('prompt-install', {silent: true}, function(cb) {
    app.npm.askInstall('mocha', function(err) {
{'fraction_non_alphanumeric': 0.19137332672285573, 'fraction_numerical': 0.00024789291026276647, 'mean_word_length': 2.7953904045155222, 'pattern_counts': {'":': 0, '<': 5, '<?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': '4839401', 'n_tokens_mistral': 2770, 'n_tokens_neox': 2705, 'n_words': 606}