<commit_before>'use strict';

var _ = require('lodash');
var chalk = require('chalk');
var RSVP = require('rsvp');
var tmp = require('tmp');
var utils = require('../../utils');
var gcp = require('../../gcp');
var prepareFunctionsUpload = require('../../prepareFunctionsUpload');

var GCP_REGION = 'us-central1';

tmp.setGracefulCleanup();

module.exports = function(context, options, payload) {
  var _uploadSource = function(source) {
    return gcp.cloudfunctions.generateUploadUrl(context.projectId, GCP_REGION).then(function(uploadUrl) {
      _.set(context, 'uploadUrl', uploadUrl);
      uploadUrl = _.replace(uploadUrl, 'https://storage.googleapis.com', '');
      return gcp.storage.upload(source, uploadUrl);
    });
  };
  if (options.config.get('functions')) {
    utils.logBullet(chalk.cyan.bold('functions:') + ' preparing ' + chalk.bold(options.config.get('functions.source')) + ' directory for uploading...');

    return prepareFunctionsUpload(context, options).then(function(result) {
      payload.functions = {
        triggers: options.config.get('functions.triggers')
      };

      if (!result) {
        return undefined;
      }
      return _uploadSource(result).then(function() {
        utils.logSuccess(chalk.green.bold('functions:') + ' ' + chalk.bold(options.config.get('functions.source')) + ' folder uploaded successfully');
      }).catch(function(err) {
        utils.logWarning(chalk.yellow('functions:') + ' Upload Error: ' + err.message);
      });
    });
  }<commit_msg>Stop deployment process if there's error uploading (#712)<commit_after>'use strict';

var _ = require('lodash');
var chalk = require('chalk');
var RSVP = require('rsvp');
var tmp = require('tmp');
var utils = require('../../utils');
var gcp = require('../../gcp');
var prepareFunctionsUpload = require('../../prepareFunctionsUpload');

var GCP_REGION = 'us-central1';

tmp.setGracefulCleanup();

module.exports = function(context, options, payload) {
  var _uploadSource = function(source) {
    return gcp.cloudfunctions.generateUploadUrl(context.projectId, GCP_REGION).then(function(uploadUrl) {
      _.set(context, 'uploadUrl', uploadUrl);
      uploadUrl = _.replace(uploadUrl, 'https://storage.googleapis.com', '');
      return gcp.storage.upload(source, uploadUrl);
    });
  };
  if (options.config.get('functions')) {
    utils.logBullet(chalk.cyan.bold('functions:') + ' preparing ' + chalk.bold(options.config.get('functions.source')) + ' directory for uploading...');

    return prepareFunctionsUpload(context, options).then(function(result) {
      payload.functions = {
        triggers: options.config.get('functions.triggers')
      };

      if (!result) {
        return undefined;
      }
      return _uploadSource(result).then(function() {
        utils.logSuccess(chalk.green.bold('functions:') + ' ' + chalk.bold(options.config.get('functions.source')) + ' folder uploaded successfully');
      }).catch(function(err) {
        utils.logWarning(chalk.yellow('functions:') + ' Upload Error: ' + err.message);
        return RSVP.reject(err);
      });
    });
  }
{'fraction_non_alphanumeric': 0.17307071359380044, 'fraction_numerical': 0.0016144656118824668, 'mean_word_length': 3.878740157480315, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '4867523', 'n_tokens_mistral': 929, 'n_tokens_neox': 902, 'n_words': 159}