<commit_before>'use strict';
var _ = require('lodash');
var path = require('path');
var chalk = require('chalk');
var bar = require('progress-bar');
var mcaprc = require('mcaprc');
var mctCore = require('mct-core');

/**
 * return the default server from the json file
 * @returns {*}
 */
var getServer = function (args) {
  if ( args.length > 1 ) {
    return mcaprc.get(args[ 1 ]);
  } else {
    return mcaprc.get(mcaprc.default_server);
  }
};

/*
 *
 * @returns {process.stdout}
 */
var getProcessBar = function () {
  var _bar = bar.create(process.stdout);
  _bar.format = '$bar; $percentage,2:0;% uploaded.';
  _bar.symbols.loaded = chalk.cyan('#');
  _bar.symbols.notLoaded = chalk.red('-');
  _bar.width = 50;
  return _bar;
};

/**
 *
 * @returns {{
 *  name: string,
 *  value: string
 * }[]}
 */
var getChoice = function () {
  var choices = [
    {
      name : 'Deploy Default',
      value: 'default_server'
    }
  ];
  var servers = mcaprc.list();
  _.each(servers.server, function (server, key) {
    if ( key !== servers.default_server ) {
      choices.push(
        {
          name : 'Deploy ' + key,
          value: key
        }
      );
    }
  });
  return choices;
};

var validationErrorPrinter = function(err) {
  _.each(err.details, function(info) {
    console.log('\n' + chalk.underline(info.file));
    console.log(chalk.red(info.message));
  })
}

/**
 * deploy application
 */
var deploy = function (args) {
  var _bar = getProcessBar();
  var config = getServer(args);
  config.rootPath = process.cwd();
  config.progress = function (percent) {
    _bar.update(percent / 100);
    if ( percent >= 100 ) {
      console.log('\nInitialize application...');
    }
  };
  mctCore.deploy(config, function(err, data) {
    if (err) {
      if (err.name === 'LintError' || err.name === 'ValidateError') {
        return validationErrorPrinter(err);
      }
      return console.log(chalk.red(err.message || err));
    }
    console.log(chalk.green('Your application is now available!'));
    console.log(chalk.gray('Client:'), chalk.underline(data.client));
    console.log(chalk.gray('API:'), chalk.underline(data.server));<commit_msg>fix code styles<commit_after>'use strict';
var _ = require('lodash');
var chalk = require('chalk');
var bar = require('progress-bar');
var mcaprc = require('mcaprc');
var mctCore = require('mct-core');

/**
 * return the default server from the json file
 * @returns {*}
 */
var getServer = function (args) {
  if ( args.length > 1 ) {
    return mcaprc.get(args[ 1 ]);
  } else {
    return mcaprc.get(mcaprc.default_server);
  }
};

/*
 *
 * @returns {process.stdout}
 */
var getProcessBar = function () {
  var _bar = bar.create(process.stdout);
  _bar.format = '$bar; $percentage,2:0;% uploaded.';
  _bar.symbols.loaded = chalk.cyan('#');
  _bar.symbols.notLoaded = chalk.red('-');
  _bar.width = 50;
  return _bar;
};

/**
 *
 * @returns {{
 *  name: string,
 *  value: string
 * }[]}
 */
var getChoice = function () {
  var choices = [
    {
      name : 'Deploy Default',
      value: 'default_server'
    }
  ];
  var servers = mcaprc.list();
  _.each(servers.server, function (server, key) {
    if ( key !== servers.default_server ) {
      choices.push(
        {
          name : 'Deploy ' + key,
          value: key
        }
      );
    }
  });
  return choices;
};

var validationErrorPrinter = function(err) {
  _.each(err.details, function(info) {
    console.log('\n' + chalk.underline(info.file));
    console.log(chalk.red(info.message));
  });
};

/**
 * deploy application
 */
var deploy = function (args) {
  var _bar = getProcessBar();
  var config = getServer(args);
  config.rootPath = process.cwd();
  config.progress = function (percent) {
    _bar.update(percent / 100);
    if ( percent >= 100 ) {
      console.log('\nInitialize application...');
    }
  };
  var deploy = mctCore.deploy(config);
  deploy.on('data', console.log);
  deploy.on('error', function(err) {
    if (err.name === 'LintError' || err.name === 'ValidateError') {
      return validationErrorPrinter(err);
    }
    console.log(chalk.red(err.message || err));
  });
  deploy.on('complete', function(data) {
    console.log(chalk.green('Your application is now available!'));
    console.log(chalk.gray('Client:'), chalk.underline(data.client));
    console.log(chalk.gray('API:'), chalk.underline(data.server));
{'fraction_non_alphanumeric': 0.1786855317206755, 'fraction_numerical': 0.005476951163852123, 'mean_word_length': 3.0620945319740502, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '2617784', 'n_tokens_mistral': 1511, 'n_tokens_neox': 1484, 'n_words': 301}