<commit_before>'use strict';
/* jshint multistr:true */


var chalk = require('chalk');
var path = require('path');
var BBPromise = require('bluebird');
var configPath = path.resolve(__filename, '../../', 'config');
process.env.NODE_CONFIG_DIR = configPath;
var config = require('config');
var dnode = require('dnode');
var logger = require('hoist-logger');
var _ = require('lodash');
logger.streams = _.reject(logger.streams, function (stream) {
  return stream.name === 'console';
});

BBPromise.try(function () {
  console.log(chalk.magenta("hoist.json found \n\nDeploying Hoist Application"));
  console.log(chalk.white("\n\
 __    __   ______   ______   ______   ________\n\
|  \\  |  \\ /      \\ |      \\ /      \\ |        \\\n\
| $$  | $$|  $$$$$$\\ \\$$$$$$|  $$$$$$\\\\$$$$$$$$\n\
| $$__| $$| $$  | $$  | $$  | $$___\\$$  | $$\n\
| $$    $$| $$  | $$  | $$   \\$$    \\   | $$\n\
| $$$$$$$$| $$  | $$  | $$   _\\$$$$$$\\  | $$\n\
| $$  | $$| $$__/ $$ _| $$_ |  \\__| $$  | $$\n\
| $$  | $$ \\$$    $$|   $$ \\ \\$$    $$  | $$\n\
 \\$$   \\$$  \\$$$$$$  \\$$$$$$  \\$$$$$$    \\$$"));
  console.log("==============================================");
  console.log('');
}).then(function () {
  console.log('starting deployment');
  console.log('connecting to worker');
  var jobData = {
    path: process.cwd()
  };
  var client = dnode.connect(config.get('Hoist.dnode.port'));

  client.on('remote', function (remote) {
    remote.deploy(jobData, function (message) {
      console.log(message);
    }, function (message) {
      process.stdout.write(message);
    }, function (err) {
      client.end();
      if (!err) {
        console.log(chalk.green('splines reticulated'));
        process.exit(0);
      } else {
        logger.error(err.message);
        console.error('error during deploy');
        process.exit(1);
      }
    });<commit_msg>adds logs for the deploy process<commit_after>'use strict';
/* jshint multistr:true */


var chalk = require('chalk');
var path = require('path');
var BBPromise = require('bluebird');
var configPath = path.resolve(__filename, '../../', 'config');
process.env.NODE_CONFIG_DIR = configPath;
var config = require('config');
var dnode = require('dnode');
var logger = require('hoist-logger');
var _ = require('lodash');
var Application = require('hoist-model').Application;
logger.streams = _.reject(logger.streams, function (stream) {
  return stream.name === 'console';
});


function logEvent(message, applicationId) {
  var logEventObject = new Model.ExecutionLogEvent({
    application: applicationId,
    environment: 'live',
    type: 'LOG',
    message: message
  });
  logEventObject.saveAsync();
};

function findApplication(gitRepoPath, callback) {

  var parts = gitRepoPath.split(path.sep);

  return BBPromise.resolve({
    repoName: parts[parts.length - 1].replace('.git', ''),
    folderName: parts[parts.length - 2]
  })
  .then(function(details) {
    return Application.findOneAsync({
      slug: details.repoName
    });
  })
  .nodeify(callback);

};

BBPromise.try(function () {
  findApplication(process.cwd()).then(function(application) {
    logEvent("Deploy starting", application._id);
  });
  console.log(chalk.magenta("hoist.json found \n\nDeploying Hoist Application"));
  console.log(chalk.white("\n\
 __    __   ______   ______   ______   ________\n\
|  \\  |  \\ /      \\ |      \\ /      \\ |        \\\n\
| $$  | $$|  $$$$$$\\ \\$$$$$$|  $$$$$$\\\\$$$$$$$$\n\
| $$__| $$| $$  | $$  | $$  | $$___\\$$  | $$\n\
| $$    $$| $$  | $$  | $$   \\$$    \\   | $$\n\
| $$$$$$$$| $$  | $$  | $$   _\\$$$$$$\\  | $$\n\
| $$  | $$| $$__/ $$ _| $$_ |  \\__| $$  | $$\n\
| $$  | $$ \\$$    $$|   $$ \\ \\$$    $$  | $$\n\
 \\$$   \\$$  \\$$$$$$  \\$$$$$$  \\$$$$$$    \\$$"));
  console.log("==============================================");
  console.log('');
}).then(function () {
  console.log('starting deployment');
  console.log('connecting to worker');
  var jobData = {
    path: process.cwd()
  };
  var client = dnode.connect(config.get('Hoist.dnode.port'));

  client.on('remote', function (remote) {
    //Find the application that this deploy is associated with
    remote.deploy(jobData, function (message) {
      console.log(message);
    }, function (message) {
      process.stdout.write(message);
    }, function (err) {
      client.end();
      if (!err) {
        console.log(chalk.green('splines reticulated'));
        findApplication(jobData.path).then(function(application) {
          logEvent("Deploy complete", application._id);
        });
        process.exit(0);
      } else {
        logger.error(err.message);
        console.error('error during deploy');
        findApplication(jobData.path).then(function(application) {
          logEvent("Error during deploy: " + err.message, application._id);
        });
        process.exit(1);
      }
    });
{'fraction_non_alphanumeric': 0.251129363449692, 'fraction_numerical': 0.0012320328542094457, 'mean_word_length': 2.724006116207951, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, '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': '6131445', 'n_tokens_mistral': 1635, 'n_tokens_neox': 1608, 'n_words': 249}