<commit_before>'use strict';
const Generator = require('yeoman-generator');
const path = require('path');
const mkdirp = require('mkdirp');
const fs = require('fs');
const _ = require('lodash');
const yaml = require('js-yaml');

module.exports = class extends Generator {
  initializing() {
    this.serverless = null;
    this.props = {};
    try {
      this.serverless = yaml.safeLoad(fs.readFileSync(this.destinationPath('serverless.yml'), 'utf8'));
      this.log('Project detected, updating the core instead...');
    } catch (ex) {}
  }

  prompting() {
    return this.prompt([
      {
        type: 'input',
        name: 'name',
        message: 'Your project name',
        default: () => {
          if (this.serverless) {
            return this.serverless.service;
          }
          return _.kebabCase(path.basename(process.cwd() + '-api'));
        },
        filter: _.kebabCase
      },
      {
        type: 'input',
        name: 'description',
        default: answers => {
          if (this.serverless) {
            return this.serverless.description;
          }
          return `${answers.name} Restful API`;
        },
        message: 'Your project description'
      },
      {
        type: 'input',
        name: 'region',
        default: () => {
          if (this.serverless) {
            return this.serverless.provider.region;
          }
          return 'us-west-1';
        },
        message: 'AWS API Gateway region'
      }
    ]).then(answers => {
      this.props = answers;
    });
  }

  defaults() {
    // Create new folder if not updating
    if (!this.serverless && path.basename(this.destinationPath()) !== this.props.name) {
      this.log(
        'Your generator must be inside a folder named ' + this.props.name + '\n' +
        'I\'ll automatically create this folder.'
      );<commit_msg>just ask for desc when creating, not updating, using parent name globally<commit_after>'use strict';
const Generator = require('yeoman-generator');
const path = require('path');
const mkdirp = require('mkdirp');
const fs = require('fs');
const _ = require('lodash');
const yaml = require('js-yaml');

module.exports = class extends Generator {
  initializing() {
    this.serverless = null;
    this.parentName = path.basename(process.cwd());
    this.props = {};
    try {
      this.serverless = yaml.safeLoad(fs.readFileSync(this.destinationPath('serverless.yml'), 'utf8'));
      this.log('Project detected, updating the core instead...');
    } catch (ex) {}
  }

  prompting() {
    return this.prompt([
      {
        type: 'input',
        name: 'name',
        message: 'Your project name',
        default: () => {
          if (this.serverless) {
            return this.serverless.service;
          }
          return _.kebabCase(this.parentName + '-api');
        },
        filter: _.kebabCase
      },
      {
        type: 'input',
        name: 'description',
        when: () => {
          return !this.serverless;
        },
        default: () => {
          return `${_.capitalize(this.parentName)} Restful API`;
        },
        message: 'Your project description'
      },
      {
        type: 'input',
        name: 'region',
        default: () => {
          if (this.serverless) {
            return this.serverless.provider.region;
          }
          return 'us-west-1';
        },
        message: 'AWS API Gateway region'
      }
    ]).then(answers => {
      this.props = answers;
    });
  }

  defaults() {
    // Create new folder if not updating
    if (!this.serverless && path.basename(this.destinationPath()) !== this.props.name) {
      this.log(
        'Your generator must be inside a folder named ' + this.props.name + '\n' +
        'I\'ll automatically create this folder.'
      );
{'fraction_non_alphanumeric': 0.14730728616684266, 'fraction_numerical': 0.0010559662090813093, 'mean_word_length': 2.0482703137570395, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 12, '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': '2063330', 'n_tokens_mistral': 1110, 'n_tokens_neox': 1082, 'n_words': 259}