<commit_before>'use strict';

var chalk = require('chalk');


module.exports = {
    askForInsightOptIn,
    askForApplicationType,
    askForModuleName,
    askFori18n,
    askForTestOpts,
    askForClient,
    askForMoreModules
};

function askForInsightOptIn() {
    if (this.existingProject) return;

    var done = this.async();
    var insight = this.insight();

    this.prompt({
        when: function () {
            return insight.optOut === undefined;
        },
        type: 'confirm',
        name: 'insight',
        message: 'May ' + chalk.cyan('JHipster') + ' anonymously report usage statistics to improve the tool over time?',
        default: true
    }).then(function (prompt) {
        if (prompt.insight !== undefined) {
            insight.optOut = !prompt.insight;
        }
        done();
    }.bind(this));
}

function askForApplicationType() {
    if (this.existingProject) return;

    const DEFAULT_APPTYPE = 'monolith';
    if (this.skipServer) {
        this.applicationType = this.configOptions.applicationType = DEFAULT_APPTYPE;
        return;
    }

    var done = this.async();
    var getNumberedQuestion = this.getNumberedQuestion.bind(this);

    this.prompt({
        type: 'list',
        name: 'applicationType',
        message: function (response) {
            return getNumberedQuestion('Which *type* of application would you like to create?', true);
        },
        choices: [
            {
                value: DEFAULT_APPTYPE,
                name: 'Monolithic application (recommended for simple projects)'
            },
            {
                value: 'microservice',
                name: 'Microservice application'
            },
            {
                value: 'gateway',
                name: 'Microservice gateway'
            },
            {
                value: 'uaa',
                name: '[BETA] JHipster UAA server (for microservice OAuth2 authentication)'
            }
        ],
        default: DEFAULT_APPTYPE
    }).then(function (prompt) {
        this.applicationType = this.configOptions.applicationType = prompt.applicationType;
        done();
    }.bind(this));
}

function askForModuleName() {
    if (this.existingProject) return;

    this.askModuleName(this);
    this.configOptions.lastQuestion = this.currentQuestion;
    this.configOptions.totalQuestions = this.totalQuestions;
}

function askFori18n() {
    this.currentQuestion = this.configOptions.lastQuestion;
    this.totalQuestions = this.configOptions.totalQuestions;
    if (this.skipI18n || this.existingProject) return;
    this.aski18n(this);
}

function askForTestOpts() {
    if (this.existingProject) return;

    var getNumberedQuestion = this.getNumberedQuestion.bind(this);
    var choices = [];
    var defaultChoice = [];
    if (!this.skipServer) {
        // all server side test frameworks should be added here
        choices.push(
            {name: 'Gatling', value: 'gatling'},
            {name: 'Cucumber', value: 'cucumber'}
        );
        defaultChoice = ['gatling'];
    }
    if (!this.skipClient) {
        // all client side test frameworks should be added here
        choices.push(
            {name: 'Protractor', value: 'protractor'}
        );
    }
    var done = this.async();

    this.prompt({
        type: 'checkbox',
        name: 'testFrameworks',
        message: function (response) {
            return getNumberedQuestion('Which testing frameworks would you like to use?', true);
        },
        choices: choices,
        default: defaultChoice
    }).then(function (prompt) {
        this.testFrameworks = prompt.testFrameworks;
        done();
    }.bind(this));
}

function askForClient() {
    if (this.existingProject) return;

    var done = this.async();
    var getNumberedQuestion = this.getNumberedQuestion.bind(this);
    var applicationType = this.applicationType;

    this.prompt({
        type: 'list',
        name: 'clientFramework',
        when: function (response) {
            return (applicationType !== 'microservice');
        },
        message: function (response) {
            return getNumberedQuestion('Which *Framework* would you like to use for the client?', applicationType !== 'microservice');
        },
        choices: [
            {
                value: 'angular1',
                name: 'Angular 1.x'
            },
            {
                value: 'angular2',
                name: '[BETA] Angular 2.x'
            }
        ],
        default: 'angular1'
    }).then(function (prompt) {
        this.clientFramework = this.configOptions.clientFramework = prompt.clientFramework;
        done();
    }.bind(this));
}


function askForMoreModules() {
    if (this.existingProject) {
        return;
    }

    var done = this.async();
    var generator = this;
    this.prompt({
        type: 'confirm',
        name: 'installModules',
        message: function(response) {
            return generator.getNumberedQuestion('Would you like to install other generators from the JHipster Market Place?', true);
        },
        default: false
    }).then(function (prompt) {
        if (prompt.installModules) {
            askModulesToBeInstalled(done, generator);
        } else {
            done();
        }
    }.bind(this));
}

function askModulesToBeInstalled(done, generator) {
    generator.httpGet('http://npmsearch.com/query?fields=name,description,author,version&q=keywords:jhipster-module&start=0&size=50',
        function(body) {
            var moduleResponse = JSON.parse(body);
            var choices = [];
            moduleResponse.results.forEach(function (modDef) {
                choices.push({
                    value: { name:modDef.name, version:modDef.version},
                    name: `(${modDef.name}-${modDef.version}) ${modDef.description} [${modDef.author}]`
                });
            });
            if (choices.length > 0) {
                generator.prompt({
                    type: 'checkbox',
                    name: 'otherModules',
                    message: 'Which other modules would you like to use?',
                    choices: choices,
                    default: []
                }).then(function (prompt) {
                    // [ {name: [moduleName], version:[version]}, ...]
                    generator.otherModules = [];
                    prompt.otherModules.forEach(function(module) {
                        generator.otherModules.push({name:module.name[0], version:module.version[0]});
                    });
                    generator.configOptions.otherModules = this.otherModules;
                    done();
                }.bind(generator));
            } else {
                done();
            }
        },
        function (error) {
            generator.warning(`Unable to contact server to fetch additional modules: ${ error.message }`);
            done();
        });
}
<commit_msg>Wording<commit_after>'use strict';

var chalk = require('chalk');


module.exports = {
    askForInsightOptIn,
    askForApplicationType,
    askForModuleName,
    askFori18n,
    askForTestOpts,
    askForClient,
    askForMoreModules
};

function askForInsightOptIn() {
    if (this.existingProject) return;

    var done = this.async();
    var insight = this.insight();

    this.prompt({
        when: function () {
            return insight.optOut === undefined;
        },
        type: 'confirm',
        name: 'insight',
        message: 'May ' + chalk.cyan('JHipster') + ' anonymously report usage statistics to improve the tool over time?',
        default: true
    }).then(function (prompt) {
        if (prompt.insight !== undefined) {
            insight.optOut = !prompt.insight;
        }
        done();
    }.bind(this));
}

function askForApplicationType() {
    if (this.existingProject) return;

    const DEFAULT_APPTYPE = 'monolith';
    if (this.skipServer) {
        this.applicationType = this.configOptions.applicationType = DEFAULT_APPTYPE;
        return;
    }

    var done = this.async();
    var getNumberedQuestion = this.getNumberedQuestion.bind(this);

    this.prompt({
        type: 'list',
        name: 'applicationType',
        message: function (response) {
            return getNumberedQuestion('Which *type* of application would you like to create?', true);
        },
        choices: [
            {
                value: DEFAULT_APPTYPE,
                name: 'Monolithic application (recommended for simple projects)'
            },
            {
                value: 'microservice',
                name: 'Microservice application'
            },
            {
                value: 'gateway',
                name: 'Microservice gateway'
            },
            {
                value: 'uaa',
                name: '[BETA] JHipster UAA server (for microservice OAuth2 authentication)'
            }
        ],
        default: DEFAULT_APPTYPE
    }).then(function (prompt) {
        this.applicationType = this.configOptions.applicationType = prompt.applicationType;
        done();
    }.bind(this));
}

function askForModuleName() {
    if (this.existingProject) return;

    this.askModuleName(this);
    this.configOptions.lastQuestion = this.currentQuestion;
    this.configOptions.totalQuestions = this.totalQuestions;
}

function askFori18n() {
    this.currentQuestion = this.configOptions.lastQuestion;
    this.totalQuestions = this.configOptions.totalQuestions;
    if (this.skipI18n || this.existingProject) return;
    this.aski18n(this);
}

function askForTestOpts() {
    if (this.existingProject) return;

    var getNumberedQuestion = this.getNumberedQuestion.bind(this);
    var choices = [];
    var defaultChoice = [];
    if (!this.skipServer) {
        // all server side test frameworks should be added here
        choices.push(
            {name: 'Gatling', value: 'gatling'},
            {name: 'Cucumber', value: 'cucumber'}
        );
        defaultChoice = ['gatling'];
    }
    if (!this.skipClient) {
        // all client side test frameworks should be added here
        choices.push(
            {name: 'Protractor', value: 'protractor'}
        );
    }
    var done = this.async();

    this.prompt({
        type: 'checkbox',
        name: 'testFrameworks',
        message: function (response) {
            return getNumberedQuestion('Which testing frameworks would you like to use?', true);
        },
        choices: choices,
        default: defaultChoice
    }).then(function (prompt) {
        this.testFrameworks = prompt.testFrameworks;
        done();
    }.bind(this));
}

function askForClient() {
    if (this.existingProject) return;

    var done = this.async();
    var getNumberedQuestion = this.getNumberedQuestion.bind(this);
    var applicationType = this.applicationType;

    this.prompt({
        type: 'list',
        name: 'clientFramework',
        when: function (response) {
            return (applicationType !== 'microservice');
        },
        message: function (response) {
            return getNumberedQuestion('Which *Framework* would you like to use for the client?', applicationType !== 'microservice');
        },
        choices: [
            {
                value: 'angular1',
                name: 'Angular 1.x'
            },
            {
                value: 'angular2',
                name: '[BETA] Angular 2.x'
            }
        ],
        default: 'angular1'
    }).then(function (prompt) {
        this.clientFramework = this.configOptions.clientFramework = prompt.clientFramework;
        done();
    }.bind(this));
}


function askForMoreModules() {
    if (this.existingProject) {
        return;
    }

    var done = this.async();
    var generator = this;
    this.prompt({
        type: 'confirm',
        name: 'installModules',
        message: function(response) {
            return generator.getNumberedQuestion('Would you like to install other generators from the JHipster Marketplace?', true);
        },
        default: false
    }).then(function (prompt) {
        if (prompt.installModules) {
            askModulesToBeInstalled(done, generator);
        } else {
            done();
        }
    }.bind(this));
}

function askModulesToBeInstalled(done, generator) {
    generator.httpGet('http://npmsearch.com/query?fields=name,description,author,version&q=keywords:jhipster-module&start=0&size=50',
        function(body) {
            var moduleResponse = JSON.parse(body);
            var choices = [];
            moduleResponse.results.forEach(function (modDef) {
                choices.push({
                    value: { name:modDef.name, version:modDef.version},
                    name: `(${modDef.name}-${modDef.version}) ${modDef.description} [${modDef.author}]`
                });
            });
            if (choices.length > 0) {
                generator.prompt({
                    type: 'checkbox',
                    name: 'otherModules',
                    message: 'Which other modules would you like to use?',
                    choices: choices,
                    default: []
                }).then(function (prompt) {
                    // [ {name: [moduleName], version:[version]}, ...]
                    generator.otherModules = [];
                    prompt.otherModules.forEach(function(module) {
                        generator.otherModules.push({name:module.name[0], version:module.version[0]});
                    });
                    generator.configOptions.otherModules = this.otherModules;
                    done();
                }.bind(generator));
            } else {
                done();
            }
        },
        function (error) {
            generator.warning(`Unable to contact server to fetch additional modules: ${ error.message }`);
            done();
        });
}

{'fraction_non_alphanumeric': 0.11794391175834475, 'fraction_numerical': 0.0028837142239204095, 'mean_word_length': 1.9389830508474577, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2818284', 'n_tokens_mistral': 3802, 'n_tokens_neox': 3653, 'n_words': 821}