<commit_before>'use strict';

var Generator = require('yeoman-generator');
var chalk     = require('chalk');
var yosay     = require('yosay');
var copyTpl   = require('../app/utils').copyTpl;

var commandLineOptions = {
    defaults: {
        type: Boolean,
        desc: 'Scaffold server with defaults settings and no user interaction',
        defaults: false
    },
    http: {
        type: String,
        desc: 'HTTP server port'
    },
    https: {
        type: String,
        desc: 'HTTPS server port'
    },
    ws: {
        type: String,
        desc: 'WebSocket server port'
    }
};
var prompts = [
    {
        type: 'input',
        name: 'httpPort',
        message: 'HTTP server port?',
        default: '8111'
    },
    {
        type: 'input',
        name: 'httpsPort',
        message: 'HTTPS server port?',
        default: '8443'
    },
    {
        type: 'input',
        name: 'websocketPort',
        message: 'WebSocket server port?',
        default: '13337'
    },
    {
        type: 'confirm',
        name: 'markdownSupport',
        message: 'Add support for rendering Markdown files?',
        default: false
    }
];

module.exports = Generator.extend({
    constructor: function() {
        Generator.apply(this, arguments);
        var generator = this;
        Object.keys(commandLineOptions).forEach(function(option) {
            generator.option(option, commandLineOptions[option]);
        });
    },
    prompting: function() {
        var options = this.options;
        var customPortSelected = (options.http || options.https || options.ws);
        if (options.defaults || customPortSelected) {
            var done = this.async();
            var defaultHttpPort = prompts[0].default;
            var defaultHttpsPort = prompts[1].default;
            var defaultWebsocketPort = prompts[2].default;
            this.httpPort = options.http || defaultHttpPort;
            this.httpsPort = options.https || defaultHttpsPort;
            this.websocketPort = options.ws || defaultWebsocketPort;
            this.markdownSupport = prompts[3].default;
            done();
        } else {
            return this.prompt(prompts).then(function(answers) {
                this.httpPort = answers.httpPort;
                this.httpsPort = answers.httpsPort;
                this.websocketPort = answers.websocketPort;
                this.markdownSupport = answers.markdownSupport;
            }.bind(this));
        }
    },
    configuring: {
        projectfiles: function() {
            if (this.markdownSupport) {
                this.log(yosay('Place Markdown files in ' + chalk.blue('./web/client/')));
            }
            copyTpl('_package.json', 'package.json', this);
            copyTpl('config/_gitignore', '.gitignore', this);
            copyTpl('config/_env', '.env', this);
            copyTpl('config/_default.js', 'config/default.js', this);
        }
    },
    writing: {
        serverFiles: function() {<commit_msg>Cleared complexity lint warnings in server sub-generator<commit_after>'use strict';

var _         = require('lodash');
var Generator = require('yeoman-generator');
var chalk     = require('chalk');
var yosay     = require('yosay');
var copyTpl   = require('../app/utils').copyTpl;

var commandLineOptions = {
    defaults: {
        type: Boolean,
        desc: 'Scaffold server with defaults settings and no user interaction',
        defaults: false
    },
    http: {
        type: String,
        desc: 'HTTP server port'
    },
    https: {
        type: String,
        desc: 'HTTPS server port'
    },
    ws: {
        type: String,
        desc: 'WebSocket server port'
    }
};
var prompts = [
    {
        type: 'input',
        name: 'httpPort',
        message: 'HTTP server port?',
        default: '8111'
    },
    {
        type: 'input',
        name: 'httpsPort',
        message: 'HTTPS server port?',
        default: '8443'
    },
    {
        type: 'input',
        name: 'websocketPort',
        message: 'WebSocket server port?',
        default: '13337'
    },
    {
        type: 'confirm',
        name: 'markdownSupport',
        message: 'Add support for rendering Markdown files?',
        default: false
    }
];

module.exports = Generator.extend({
    constructor: function() {
        Generator.apply(this, arguments);
        var generator = this;
        Object.keys(commandLineOptions).forEach(function(option) {
            generator.option(option, commandLineOptions[option]);
        });
    },
    prompting: function() {
        var options = this.options;
        var customPortSelected = (options.http || options.https || options.ws);
        if (options.defaults || customPortSelected) {
            var done = this.async();
            this.httpPort = _.defaultTo(options.http, prompts[0].default);
            this.httpsPort = _.defaultTo(options.https, prompts[1].default);
            this.websocketPort = _.defaultTo(options.ws, prompts[2].default);
            this.markdownSupport = prompts[3].default;
            done();
        } else {
            return this.prompt(prompts).then(function(answers) {
                _.extend(this, _.pick(answers, [
                    'httpPort',
                    'httpsPort',
                    'websocketPort',
                    'markdownSupport'
                ]));
            }.bind(this));
        }
    },
    configuring: {
        projectfiles: function() {
            if (this.markdownSupport) {
                this.log(yosay('Place Markdown files in ' + chalk.blue('./web/client/')));
            }
            copyTpl('_package.json', 'package.json', this);
            copyTpl('config/_gitignore', '.gitignore', this);
            copyTpl('config/_env', '.env', this);
            copyTpl('config/_default.js', 'config/default.js', this);
        }
    },
    writing: {
        serverFiles: function() {
{'fraction_non_alphanumeric': 0.1307510148849797, 'fraction_numerical': 0.005751014884979702, 'mean_word_length': 1.9272277227722772, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4090487', 'n_tokens_mistral': 1690, 'n_tokens_neox': 1624, 'n_words': 363}