<commit_before>'use strict';

var path = require('path');
var utils = require('./utils');

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

  /**
   * Build variables
   */

  var src = path.resolve.bind(path, __dirname, 'templates');
  var dir = app.options.dest || app.cwd || process.cwd();

  /**
   * Use other generators as plugins
   */

  app.use(require('generate-collections'));
  app.use(require('generate-defaults'));

  /**
   * Create a new package.json file, same as the [raw](#packageraw) task, but also
   * normalizes the result using [normalize-pkg][].
   *
   * ```sh
   * $ gen package:new
   * ```
   * @name package:new
   * @api public
   */

  app.task('new', ['setup'], function() {
    return app.toStream('templates', pickFile(app))
      .pipe(app.renderFile('*'))
      .pipe(utils.normalize())
      .pipe(app.conflicts(dir))
      .pipe(app.dest(dir));
  });

  /**
   * Generate a `package.json` file in the cwd. To use a different template, run
   * the [package:choose](#packagechoose) task, or pass the name on the `-t` or
   * `--template` flag.
   *
   * ```sh
   * $ gen package:raw
   * ```
   * @name package:raw
   * @api public
   */

  app.task('raw', ['setup'], function() {
    return app.toStream('templates', pickFile(app))
      .pipe(app.renderFile('*'))
      .pipe(app.conflicts(dir))
      .pipe(app.dest(dir));
  });

  /**
   * Prompts the user to choose the template to use for generating a `package.json` file to the working directory, or specified `-d` | `--dest`.
   *
   * ```sh
   * $ gen package:choose
   * ```
   * @name package:choose
   * @api public
   */

  app.task('choose', ['setup'], function() {
    return app.toStream('templates')
      .pipe(utils.choose({key: 'stem'}))
      .pipe(app.renderFile('*'))
      .pipe(utils.normalize())
      .pipe(utils.pick())
      .pipe(app.conflicts(dir))
      .pipe(app.dest(dir));
  });

  /**
   * Prepare questions and merge data to be used for prompts from the `base` instance
   * onto the context.
   *
   * ```sh
   * $ gen package:setup
   * ```
   * @name package:setup
   * @api public
   */

  app.task('setup', function(cb) {
    app.data(app.base.cache.data);
    app.use(utils.commonQuestions());
    app.template('*.json', {cwd: src()});
    cb();
  });

  /**
   * Alias for the `package` task to allow running the generator
   * with the following command:
   *
   * ```sh
   * $ gen package
   * ```
   * @name default
   */
<commit_msg>alias task as `package`<commit_after>'use strict';

var path = require('path');
var utils = require('./utils');

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

  /**
   * Build variables
   */

  var src = path.resolve.bind(path, __dirname, 'templates');
  var dir = app.options.dest || app.cwd || process.cwd();

  /**
   * Use other generators as plugins
   */

  app.use(require('generate-collections'));
  app.use(require('generate-defaults'));

  /**
   * Create a new package.json file, same as the [raw](#packageraw) task, but also
   * normalizes the result using [normalize-pkg][].
   *
   * ```sh
   * $ gen package:new
   * ```
   * @name package:new
   * @api public
   */

  app.task('new', ['setup'], function() {
    return app.toStream('templates', pickFile(app))
      .pipe(app.renderFile('*'))
      .pipe(utils.normalize())
      .pipe(app.conflicts(dir))
      .pipe(app.dest(dir));
  });

  /**
   * Generate a `package.json` file in the cwd. To use a different template, run
   * the [package:choose](#packagechoose) task, or pass the name on the `-t` or
   * `--template` flag.
   *
   * ```sh
   * $ gen package:raw
   * ```
   * @name package:raw
   * @api public
   */

  app.task('raw', ['setup'], function() {
    return app.toStream('templates', pickFile(app))
      .pipe(app.renderFile('*'))
      .pipe(app.conflicts(dir))
      .pipe(app.dest(dir));
  });

  /**
   * Prompts the user to choose the template to use for generating a `package.json` file to the working directory, or specified `-d` | `--dest`.
   *
   * ```sh
   * $ gen package:choose
   * ```
   * @name package:choose
   * @api public
   */

  app.task('choose', ['setup'], function() {
    return app.toStream('templates')
      .pipe(utils.choose({key: 'stem'}))
      .pipe(app.renderFile('*'))
      .pipe(utils.normalize())
      .pipe(utils.pick())
      .pipe(app.conflicts(dir))
      .pipe(app.dest(dir));
  });

  /**
   * Prepare questions and merge data to be used for prompts from the `base` instance
   * onto the context.
   *
   * ```sh
   * $ gen package:setup
   * ```
   * @name package:setup
   * @api public
   */

  app.task('setup', function(cb) {
    app.data(app.base.cache.data);
    app.use(utils.commonQuestions());
    app.template('*.json', {cwd: src()});
    cb();
  });

  /**
   * Alias for the `package` task to allow running the generator
   * with the following command:
   *
   * ```sh
   * $ gen package
   * ```
   * @name default
   */

  app.task('package', ['new']);
{'fraction_non_alphanumeric': 0.1855568673750492, 'fraction_numerical': 0.0, 'mean_word_length': 2.740250183958793, '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': '7257720', 'n_tokens_mistral': 1729, 'n_tokens_neox': 1695, 'n_words': 411}