<commit_before>'use strict';

var fs = require('fs-extra'),
    config = require('../../config/'),
    path = require('path'),
    pckgPath = path.resolve('mo-app.json'),
    pckgFallbackPath = path.resolve('app.json'),
    ZipFile = require('../helpers/zipfile'),
    requests = require('../helpers/requests'),
    chalk = require('chalk'),
    info = chalk.bgYellow,
    error = chalk.bold.red;


module.exports = function(options) {
  var distFolder = options.dist || config.distFolder || 'build';

  try {
        let fileExists = fs.statSync(pckgPath);
    } catch (e) {
        try {
            let fallbackFileExists = fs.statSync(pckgFallbackPath);
            fs.rename(pckgFallbackPath, pckgPath, function(renameErr) {
                if ( renameErr ) console.log('ERROR: ' + renameErr);
                console.log(info('fallback file , app.json found , renaming the file to mo-app.json'));
            });
        } catch (err) {
            return console.log(error('Error in Reading File. ' + err));
        }
    }

  fs.readJSON(pckgPath, function(err, json) {
  	if(err) {
  		console.log(error(err.message))
  		return
  	}

  	return requests.postPackageData(json, options)
  			.then(function(data) {
          console.log(data)
  				return new ZipFile(distFolder, json.name, json.version).zip()
  			})
  			.then(function(data) {
  				return requests.putPackageData(json.name, json.version, options)
  			})
  			.then(function(data) {
          console.log(data)
  				return
  			})
  			.catch(function(err) {
  				console.log(error(err.message))
  				return
  			})

  })
}<commit_msg>feat(cli): deploy workflow is now transaction safe<commit_after>'use strict';

var fs = require('fs-extra'),
    config = require('../../config/'),
    path = require('path'),
    pckgPath = path.resolve('mo-app.json'),
    pckgFallbackPath = path.resolve('app.json'),
    ZipFile = require('../helpers/zipfile'),
    requests = require('../helpers/requests'),
    chalk = require('chalk'),
    info = chalk.yellow,
    error = chalk.bold.red,
    success = chalk.bold.green;


module.exports = function(options) {
  var distFolder = options.dist || config.distFolder || 'build';

  try {
        let fileExists = fs.statSync(pckgPath);
    } catch (e) {
        try {
            let fallbackFileExists = fs.statSync(pckgFallbackPath);
            fs.rename(pckgFallbackPath, pckgPath, function(renameErr) {
                if ( renameErr ) console.log('ERROR: ' + renameErr);
                console.log(info('fallback file , app.json found , renaming the file to mo-app.json'));
            });
        } catch (err) {
            return console.error(error('Error in Reading File. ' + err));
        }
    }

  fs.readJSON(pckgPath, function(err, json) {
  	if(err) {
  		console.error(error(err.message))
  		return
  	}

    let zipper = new ZipFile(distFolder, json.name, json.version)
    let created = false

    return zipper.zip()
      .then((data) => {
        console.log(info('Zipped package file'))
        return requests.postPackageData(json, options)
      })
      .then((data) => {
        console.log(info('Created package on server with following:'))
        console.log(data)
        created = true
        return requests.putPackageData(json.name, json.version, options)

      })
      .then((data) => {
        console.log(success('All done'))
        return
      })
      .catch((err) => {
        if (created) {
          console.info(info('Removing app from server'))
          requests.deletePackage(json, options)
        }
        console.info(info('Could not deploy:'))
        console.error(error(err.message || err))
      })

  })
}
{'fraction_non_alphanumeric': 0.14812805208898536, 'fraction_numerical': 0.0, 'mean_word_length': 2.3919043238270468, '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': '816005', 'n_tokens_mistral': 1203, 'n_tokens_neox': 1160, 'n_words': 219}