<commit_before>'use strict';

const j = require('../../lib/transform');

const Generator = require('../../lib/generator');
// const randomstring = require('randomstring');
// authentication: {
//   secret: randomstring.generate(),
//   strategies: []
// }

module.exports = class AuthGenerator extends Generator {
  prompting() {
    const prompts = [{
      type: 'checkbox',
      name: 'strategies',
      message: 'What authentication providers do you want to use (other PassportJS strategies not in this list can still be configured manually)?',
      default: 'providers',
      choices: [{
        name: 'Username + Password (Local)',
        value: 'local'
      }, {
        name: 'Google',
        value: 'google'
      }, {
        name: 'Facebook',
        value: 'facebook'
      }, {
        name: 'GitHub',
        value: 'facebook'
      }],
      when: !this.props.type
    }];

    return this.prompt(prompts).then(props => {
      this.props = Object.assign(this.props, props);
    });
  }

  _transformCode(code) {
    const ast = j(code);
    const appDeclaration = ast.findDeclaration('app');
    const configureHooks = ast.findConfigure('hooks');
    const requireCall = `const authentication = require('./authentication');`;

    if (appDeclaration.length === 0) {
      throw new Error('Could not find \'app\' variable declaration in app.js to insert database configuration. Did you modify app.js?');
    }

    if (configureHooks.length === 0) {
      throw new Error('Could not find .configure(hooks()) call in app.js after which to insert database configuration. Did you modify app.js?');
    }

    appDeclaration.insertBefore(requireCall);
    configureHooks.insertAfter(`app.configure(authentication());`);

    return ast.toSource();
  }

  writing() {
    const context = Object.assign({<commit_msg>Linting<commit_after>'use strict';

const j = require('../../lib/transform');

const Generator = require('../../lib/generator');
// const randomstring = require('randomstring');
// authentication: {
//   secret: randomstring.generate(),
//   strategies: []
// }

module.exports = class AuthGenerator extends Generator {
  prompting() {
    const prompts = [{
      type: 'checkbox',
      name: 'strategies',
      message: 'What authentication providers do you want to use (other PassportJS strategies not in this list can still be configured manually)?',
      default: 'providers',
      choices: [{
        name: 'Username + Password (Local)',
        value: 'local'
      }, {
        name: 'Google',
        value: 'google'
      }, {
        name: 'Facebook',
        value: 'facebook'
      }, {
        name: 'GitHub',
        value: 'facebook'
      }],
      when: !this.props.type
    }];

    return this.prompt(prompts).then(props => {
      this.props = Object.assign(this.props, props);
    });
  }

  _transformCode(code) {
    const ast = j(code);
    const appDeclaration = ast.findDeclaration('app');
    const configureHooks = ast.findConfigure('hooks');
    const requireCall = 'const authentication = require(\'./authentication\');';

    if (appDeclaration.length === 0) {
      throw new Error('Could not find \'app\' variable declaration in app.js to insert database configuration. Did you modify app.js?');
    }

    if (configureHooks.length === 0) {
      throw new Error('Could not find .configure(hooks()) call in app.js after which to insert database configuration. Did you modify app.js?');
    }

    appDeclaration.insertBefore(requireCall);
    configureHooks.insertAfter('app.configure(authentication());');

    return ast.toSource();
  }

  writing() {
    const context = Object.assign({
{'fraction_non_alphanumeric': 0.1448087431693989, 'fraction_numerical': 0.001092896174863388, 'mean_word_length': 2.8822905620360553, 'pattern_counts': {'":': 0, '<': 3, '<?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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1667296', 'n_tokens_mistral': 1025, 'n_tokens_neox': 1005, 'n_words': 283}