<commit_before>var yeoman = require('yeoman-generator');
var chalk = require('chalk');
var yosay = require('yosay');
var _ = require('lodash');
var path = require('path');
var helpers = require('../../helpers');

module.exports = yeoman.generators.Base.extend({
  prompting: function () {
    var done = this.async();

    this.log(yosay(
      'Welcome to the awesome ' + chalk.red('slack-slash') + ' app generator!'
    ));

    this.log('This generator will create a new ' + chalk.red('slack-slash') + ' app.');
    this.log('To create a new slack-slash handler instead, run ' + chalk.yellow('yo slack-slash:handler') + '.\n');

    var prompts = [{
      type: 'input',
      name: 'appName',
      message: 'Name your app:',
      default: 'slack-slash'
    }, {
      type: 'confirm',
      name: 'initialHandlers',
      message: 'Set up inital handlers?',
      default: false
    }, {
      type: 'input',
      name: 'handlers',
      message: 'List handlers to use (comma separated):',
      validate: helpers.stringNotEmpty,
      filter: helpers.filterHandlers,
      when: function (answers) {
        return answers.initialHandlers;
      }
    }];

    this.prompt(prompts, function (props) {
      this.props = props;
      done();
    }.bind(this));
  },

  handlersSetup: function () {
    if (this.props.handlers && this.props.handlers.length) {
      var done = this.async();
      var prompts = [];
      _.each(this.props.handlers, function (handler) {
        var commandPrompt = {
          type: 'input',
          name: handler + '_command',
          message: 'What is the /:command for ' + handler + '?',
          filter: helpers.cleanSlashCmd,
          default: handler
        };
        var tokenVarPrompt = {
          type: 'input',
          name: handler + '_token',
          message: 'Environment variable for your slack token:',
          default: helpers.pkgToTokenVar(handler)
        };
        prompts.push(commandPrompt, tokenVarPrompt);
      });

      this.prompt(prompts, function (props) {
        _.assign(this.props, props);
        done();
      }.bind(this));
    }
  },

  createHandlersObj: function () {
    var self = this;
    this.props.h = [];
    _.each(this.props.handlers, function (handler) {
      self.props.h.push({
        pkgName: handler,
        command: self.props[handler + '_command'],
        token: self.props[handler + '_token']
      });
    });
  },

  writing: {
    app: function () {
      var self = this;
      var basePath = path.join(__dirname, '..', '..');
      var ssPath = path.join(basePath, 'node_modules', 'slack-slash');
      var ssFiles = ['.npmignore', 'LICENSE.md', 'README.md', 'server.js'];

      _.each(ssFiles, function (file) {
        self.fs.copy(
          path.join(ssPath, file),
          self.destinationPath(file)
        );
      });

      this.fs.copyTpl(
        this.templatePath('www'),
        this.destinationPath('bin', '/www'),
        this.props
      );

      this.fs.copy(
        path.join(ssPath, 'routes', '*'),
        this.destinationPath('routes')<commit_msg>create app into directory with app name<commit_after>var yeoman = require('yeoman-generator');
var chalk = require('chalk');
var yosay = require('yosay');
var _ = require('lodash');
var path = require('path');
var helpers = require('../../helpers');

module.exports = yeoman.generators.Base.extend({
  prompting: function () {
    var done = this.async();

    this.log(yosay(
      'Welcome to the awesome ' + chalk.red('slack-slash') + ' app generator!'
    ));

    this.log('This generator will create a new ' + chalk.red('slack-slash') + ' app.');
    this.log('To create a new slack-slash handler instead, run ' + chalk.yellow('yo slack-slash:handler') + '.\n');

    var prompts = [{
      type: 'input',
      name: 'appName',
      message: 'Name your app:',
      default: 'slack-slash'
    }, {
      type: 'confirm',
      name: 'initialHandlers',
      message: 'Set up inital handlers?',
      default: false
    }, {
      type: 'input',
      name: 'handlers',
      message: 'List handlers to use (comma separated):',
      validate: helpers.stringNotEmpty,
      filter: helpers.filterHandlers,
      when: function (answers) {
        return answers.initialHandlers;
      }
    }];

    this.prompt(prompts, function (props) {
      this.props = props;
      done();
    }.bind(this));
  },

  handlersSetup: function () {
    if (this.props.handlers && this.props.handlers.length) {
      var done = this.async();
      var prompts = [];
      _.each(this.props.handlers, function (handler) {
        var commandPrompt = {
          type: 'input',
          name: handler + '_command',
          message: 'What is the /:command for ' + handler + '?',
          filter: helpers.cleanSlashCmd,
          default: handler
        };
        var tokenVarPrompt = {
          type: 'input',
          name: handler + '_token',
          message: 'Environment variable for your slack token:',
          default: helpers.pkgToTokenVar(handler)
        };
        prompts.push(commandPrompt, tokenVarPrompt);
      });

      this.prompt(prompts, function (props) {
        _.assign(this.props, props);
        done();
      }.bind(this));
    }
  },

  createHandlersObj: function () {
    var self = this;
    this.props.h = [];
    _.each(this.props.handlers, function (handler) {
      self.props.h.push({
        pkgName: handler,
        command: self.props[handler + '_command'],
        token: self.props[handler + '_token']
      });
    });
  },

  paths: function () {
    // Save app into directory with app name
    this.destinationRoot(this.props.appName + '/');
  },

  writing: {
    app: function () {
      var self = this;
      var basePath = path.join(__dirname, '..', '..');
      var ssPath = path.join(basePath, 'node_modules', 'slack-slash');
      var ssFiles = ['.npmignore', 'LICENSE.md', 'README.md', 'server.js'];

      _.each(ssFiles, function (file) {
        self.fs.copy(
          path.join(ssPath, file),
          self.destinationPath(file)
        );
      });

      this.fs.copyTpl(
        this.templatePath('www'),
        this.destinationPath('bin', '/www'),
        this.props
      );

      this.fs.copy(
        path.join(ssPath, 'routes', '*'),
        this.destinationPath('routes')
{'fraction_non_alphanumeric': 0.15746292205743137, 'fraction_numerical': 0.0, 'mean_word_length': 2.294698544698545, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, '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': '2096094', 'n_tokens_mistral': 1980, 'n_tokens_neox': 1920, 'n_words': 437}