<commit_before>const fs = require('fs');
module.exports = plop => {
  // Check whether the given component exist in either components or containers directory
  const componentExists = comp => {
    const pageComponents = fs.readdirSync('app/components');
    const pageContainers = fs.readdirSync('app/containers');
    const components = pageComponents.concat(pageContainers);

    return components.indexOf(comp) >= 0;
  };

  // Stateless component generator
  plop.setGenerator('component', {
    description: 'Generate a Component either using ES6 class or Stateless Function',
    prompts: [{
      type: 'list',
      name: 'type',
      message: 'Select the type of component',
      choices: () => ['ES6 Class', 'Stateless Function']
    }, {
      type: 'input',
      name: 'name',
      message: 'What should it be called?',
      validate: value => {
        if ((/.+/).test(value)) {
          return true;
        }
        return 'name is required';
      }
    }, {
      type: 'input',
      name: 'description',
      message: 'Describe what the component does?',
      validate: value => {
        if ((/.+/).test(value)) {
          return true;
        }
        return 'description is required';
      }
    }, {
      type: 'confirm',
      name: 'wantCSS',
      message: 'Do you want to create corresponding CSS file?'
    }],
    actions: data => {
      const actions = [{
        type: 'add',
        path: 'app/components/{{properCase name}}/index.js',
        templateFile: data.type === 'ES6 Class' ? './webpack/templates/component/es6.js.hbs' : './webpack/templates/component/stateless.js.hbs',
        abortOnFail: true
      }, {
        type: 'add',
        path: 'app/components/{{properCase name}}/{{properCase name}}.test.js',
        templateFile: './webpack/templates/component/component.test.js.hbs',
        abortOnFail: true
      }];

      if (data.wantCSS) {
        actions.push({
          type: 'add',
          path: 'app/components/{{properCase name}}/styles.css',
          templateFile: './webpack/templates/component/styles.css.hbs',
          abortOnFail: true
        });
      }

      return actions;
    }
  });

  // Container Component Generator
  plop.setGenerator('container', {
    description: 'Generate a Container Component',
    prompts: [{
      type: 'input',
      name: 'name',
      message: 'What should it be called?',
      validate: value => {
        if ((/.+/).test(value)) {
          return true;
        }
        return 'name is required';
      }
    }, {
      type: 'input',
      name: 'description',
      message: 'Describe what the container component does?',
      validate: value => {
        if ((/.+/).test(value)) {
          return true;
        }
        return 'description is required';
      }
    }, {
      type: 'confirm',
      name: 'wantCSS',
      message: 'Do you want to create corresponding CSS file?'
    }, {
      type: 'confirm',
      name: 'wantActionsAndReducer',
      message: 'Do you want to generate corresponding actions/reducer files for the container?'
    }, {
      type: 'confirm',
      name: 'wantSelector',
      message: 'Do you want to add selectors to the connect method?'
    }, {
      type: 'list',
      name: 'selectorType',
      message: 'Select one option',
      choices: [
        { name: 'Select from already available selectors', value: 'old' },
        { name: 'Generate new one', value: 'new' }
      ],
      when: answers => answers.wantSelector
    }, {
      type: 'checkbox',
      name: 'selectors',
      message: 'Do you want to add selectors to the connect method?',
      choices: fs.readdirSync('app/selectors').map(dir => ({ name: dir.slice(0, -3), value: dir.slice(0, -3) })),
      when: answers => answers.selectorType === 'old'
    }, {
      type: 'input',
      name: 'selectorName',
      message: 'What the selector should it be called?',
      validate: value => {
        if ((/.+saga/i).test(value)) {
          return 'name should not end with selector, it will be automatically added';
        }
        if ((/.+/).test(value)) {
          return true;
        }
        return 'selector name is required';
      },
      when: answers => answers.selectorType === 'new'
    }],
    actions: data => {
      console.log(data.selectors);
      const actions = [{
        type: 'add',
        path: 'app/containers/{{properCase name}}/index.js',
        templateFile: './webpack/templates/container/index.js.hbs',
        abortOnFail: true
      }, {
        type: 'add',
        path: 'app/containers/{{properCase name}}/{{properCase name}}.test.js',
        templateFile: './webpack/templates/container/container.test.js.hbs',
        abortOnFail: true
      }];

      if (data.wantCSS) {
        actions.push({
          type: 'add',
          path: 'app/containers/{{properCase name}}/styles.css',
          templateFile: './webpack/templates/container/styles.css.hbs',
          abortOnFail: true
        });
      }
<commit_msg>Add validation for selector selection while generating a container<commit_after>const fs = require('fs');
module.exports = plop => {
  // Check whether the given component exist in either components or containers directory
  const componentExists = comp => {
    const pageComponents = fs.readdirSync('app/components');
    const pageContainers = fs.readdirSync('app/containers');
    const components = pageComponents.concat(pageContainers);

    return components.indexOf(comp) >= 0;
  };

  // Stateless component generator
  plop.setGenerator('component', {
    description: 'Generate a Component either using ES6 class or Stateless Function',
    prompts: [{
      type: 'list',
      name: 'type',
      message: 'Select the type of component',
      choices: () => ['ES6 Class', 'Stateless Function']
    }, {
      type: 'input',
      name: 'name',
      message: 'What should it be called?',
      validate: value => {
        if ((/.+/).test(value)) {
          return true;
        }
        return 'name is required';
      }
    }, {
      type: 'input',
      name: 'description',
      message: 'Describe what the component does?',
      validate: value => {
        if ((/.+/).test(value)) {
          return true;
        }
        return 'description is required';
      }
    }, {
      type: 'confirm',
      name: 'wantCSS',
      message: 'Do you want to create corresponding CSS file?'
    }],
    actions: data => {
      const actions = [{
        type: 'add',
        path: 'app/components/{{properCase name}}/index.js',
        templateFile: data.type === 'ES6 Class' ? './webpack/templates/component/es6.js.hbs' : './webpack/templates/component/stateless.js.hbs',
        abortOnFail: true
      }, {
        type: 'add',
        path: 'app/components/{{properCase name}}/{{properCase name}}.test.js',
        templateFile: './webpack/templates/component/component.test.js.hbs',
        abortOnFail: true
      }];

      if (data.wantCSS) {
        actions.push({
          type: 'add',
          path: 'app/components/{{properCase name}}/styles.css',
          templateFile: './webpack/templates/component/styles.css.hbs',
          abortOnFail: true
        });
      }

      return actions;
    }
  });

  // Container Component Generator
  plop.setGenerator('container', {
    description: 'Generate a Container Component',
    prompts: [{
      type: 'input',
      name: 'name',
      message: 'What should it be called?',
      validate: value => {
        if ((/.+/).test(value)) {
          return true;
        }
        return 'name is required';
      }
    }, {
      type: 'input',
      name: 'description',
      message: 'Describe what the container component does?',
      validate: value => {
        if ((/.+/).test(value)) {
          return true;
        }
        return 'description is required';
      }
    }, {
      type: 'confirm',
      name: 'wantCSS',
      message: 'Do you want to create corresponding CSS file?'
    }, {
      type: 'confirm',
      name: 'wantActionsAndReducer',
      message: 'Do you want to generate corresponding actions/reducer files for the container?'
    }, {
      type: 'confirm',
      name: 'wantSelector',
      message: 'Do you want to add selectors to the connect method?'
    }, {
      type: 'list',
      name: 'selectorType',
      message: 'Select one option',
      choices: [
        { name: 'Select from already available selectors', value: 'old' },
        { name: 'Generate new one', value: 'new' }
      ],
      when: answers => answers.wantSelector
    }, {
      type: 'checkbox',
      name: 'selectors',
      message: 'Choose the selectors which has to be added (select/deselect selectors by pressing space)',
      choices: fs.readdirSync('app/selectors').map(dir => ({ name: dir.slice(0, -3), value: dir.slice(0, -3) })),
      validate: value => {
        if (value.length > 0) {
          return true;
        }
        return 'atleast one selector must be selector';
      },
      when: answers => answers.selectorType === 'old'
    }, {
      type: 'input',
      name: 'selectorName',
      message: 'What the selector should it be called?',
      validate: value => {
        if ((/.+saga/i).test(value)) {
          return 'name should not end with selector, it will be automatically added';
        }
        if ((/.+/).test(value)) {
          return true;
        }
        return 'selector name is required';
      },
      when: answers => answers.selectorType === 'new'
    }],
    actions: data => {
      const actions = [{
        type: 'add',
        path: 'app/containers/{{properCase name}}/index.js',
        templateFile: './webpack/templates/container/index.js.hbs',
        abortOnFail: true
      }, {
        type: 'add',
        path: 'app/containers/{{properCase name}}/{{properCase name}}.test.js',
        templateFile: './webpack/templates/container/container.test.js.hbs',
        abortOnFail: true
      }];

      if (data.wantCSS) {
        actions.push({
          type: 'add',
          path: 'app/containers/{{properCase name}}/styles.css',
          templateFile: './webpack/templates/container/styles.css.hbs',
          abortOnFail: true
        });
      }

{'fraction_non_alphanumeric': 0.14527489728037565, 'fraction_numerical': 0.0018587360594795538, 'mean_word_length': 2.162078564800495, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 35, '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': '5161913', 'n_tokens_mistral': 2919, 'n_tokens_neox': 2879, 'n_words': 788}