<commit_before>'use strict';

var RSVP = require('rsvp');
var logger = require('../logger');
var api = require('../api');
var chalk = require('chalk');
var _ = require('lodash');
var getProjectId = require('../getProjectId');
var utils = require('../utils');
var FirebaseError = require('../error');
var track = require('../track');

var TARGETS = {
  hosting: require('./hosting'),
  database: require('./database'),
  functions: require('./functions'),
  storage: require('./storage')
};

var _chain = function(fns, context, options, payload) {
  var latest = (fns.shift() || RSVP.resolve)(context, options, payload);
  if (fns.length) {
    return latest.then(function() {
      return _chain(fns, context, options, payload);
    });
  }

  return latest;
};

/**
 * The `deploy()` function runs through a three step deploy process for a listed
 * number of deploy targets. This allows deploys to be done all together or
 * for individual deployable elements to be deployed as such.
 */
var deploy = function(targetNames, options) {
  var projectId = getProjectId(options);
  var payload = {};
  // a shared context object for deploy targets to decorate as needed
  var context = {projectId: projectId};
  var prepares = [];
  var deploys = [];
  var releases = [];

  for (var i = 0; i < targetNames.length; i++) {
    var targetName = targetNames[i];
    var target = TARGETS[targetName];

    if (!target) {
      return RSVP.reject(new FirebaseError(chalk.bold(targetName) + ' is not a valid deploy target', {exit: 1}));
    }

    if (target.prepare) {
      prepares.push(target.prepare);
    }
    if (target.deploy) {
      deploys.push(target.deploy);
    }
    if (target.release) {
      releases.push(target.release);
    }
  }

  logger.info();
  logger.info(chalk.bold(chalk.gray('===') + ' Deploying to \'' + projectId +  '\'...'));
  logger.info();

  var activeTargets = targetNames.filter(function(t) {
    return options.config.has(t);
  });
  utils.logBullet('deploying ' + chalk.bold(activeTargets.join(', ')));

  return _chain(prepares, context, options, payload).then(function() {
    return _chain(deploys, context, options, payload);
  }).then(function() {
    utils.logBullet('starting release process (may take several minutes)...');
    return _chain(releases, context, options, payload);
  }).then(function() {
    return api.request('POST', '/v1/projects/' + encodeURIComponent(projectId) + '/releases', {
      data: payload,
      auth: true,
      origin: api.deployOrigin
    });
  }).then(function(res) {
    if (_.has(options, 'config.notes.databaseRules')) {
      track('Rules Deploy', options.config.notes.databaseRules);
    }

    logger.info();
    utils.logSuccess(chalk.underline.bold('Deploy complete!'));
    logger.info();
    var deployedHosting = _.includes(targetNames, 'hosting');
    if (deployedHosting) {
      logger.info(chalk.bold('Hosting Site:'), utils.addSubdomain(api.hostingOrigin, options.instance));
    }
    logger.info(chalk.bold('Dashboard:'), utils.consoleUrl(options.project, '/overview'));
    if (deployedHosting) {
      logger.info();
      logger.info('Visit the URL above or run', chalk.bold('firebase open'));
    }
    return res.body;
  });
};

deploy.TARGETS = TARGETS;

module.exports = deploy;
<commit_msg>show function URLs after deploying HTTP functions<commit_after>'use strict';

var RSVP = require('rsvp');
var logger = require('../logger');
var api = require('../api');
var chalk = require('chalk');
var _ = require('lodash');
var getProjectId = require('../getProjectId');
var utils = require('../utils');
var FirebaseError = require('../error');
var track = require('../track');

var TARGETS = {
  hosting: require('./hosting'),
  database: require('./database'),
  functions: require('./functions'),
  storage: require('./storage')
};

var _chain = function(fns, context, options, payload) {
  var latest = (fns.shift() || RSVP.resolve)(context, options, payload);
  if (fns.length) {
    return latest.then(function() {
      return _chain(fns, context, options, payload);
    });
  }

  return latest;
};

/**
 * The `deploy()` function runs through a three step deploy process for a listed
 * number of deploy targets. This allows deploys to be done all together or
 * for individual deployable elements to be deployed as such.
 */
var deploy = function(targetNames, options) {
  var projectId = getProjectId(options);
  var payload = {};
  // a shared context object for deploy targets to decorate as needed
  var context = {projectId: projectId};
  var prepares = [];
  var deploys = [];
  var releases = [];

  for (var i = 0; i < targetNames.length; i++) {
    var targetName = targetNames[i];
    var target = TARGETS[targetName];

    if (!target) {
      return RSVP.reject(new FirebaseError(chalk.bold(targetName) + ' is not a valid deploy target', {exit: 1}));
    }

    if (target.prepare) {
      prepares.push(target.prepare);
    }
    if (target.deploy) {
      deploys.push(target.deploy);
    }
    if (target.release) {
      releases.push(target.release);
    }
  }

  logger.info();
  logger.info(chalk.bold(chalk.gray('===') + ' Deploying to \'' + projectId +  '\'...'));
  logger.info();

  var activeTargets = targetNames.filter(function(t) {
    return options.config.has(t);
  });
  utils.logBullet('deploying ' + chalk.bold(activeTargets.join(', ')));

  return _chain(prepares, context, options, payload).then(function() {
    return _chain(deploys, context, options, payload);
  }).then(function() {
    utils.logBullet('starting release process (may take several minutes)...');
    return _chain(releases, context, options, payload);
  }).then(function() {
    return api.request('POST', '/v1/projects/' + encodeURIComponent(projectId) + '/releases', {
      data: payload,
      auth: true,
      origin: api.deployOrigin
    });
  }).then(function(res) {
    if (_.has(options, 'config.notes.databaseRules')) {
      track('Rules Deploy', options.config.notes.databaseRules);
    }

    logger.info();
    utils.logSuccess(chalk.underline.bold('Deploy complete!'));
    logger.info();
    var deployedHosting = _.includes(targetNames, 'hosting');
    logger.info(chalk.bold('Project Console:'), utils.consoleUrl(options.project, '/overview'));
    if (deployedHosting) {
      logger.info(chalk.bold('Hosting URL:'), utils.addSubdomain(api.hostingOrigin, options.instance));
    }
    _.forEach(context.functionUrls, function(elem) {
      logger.info(chalk.bold('Function URL'), '(' + elem.funcName + '):', elem.url);
    });
    return res.body;
  });
};

deploy.TARGETS = TARGETS;

module.exports = deploy;

{'fraction_non_alphanumeric': 0.16508510317818947, 'fraction_numerical': 0.0009037505648441031, 'mean_word_length': 3.662921348314607, 'pattern_counts': {'":': 0, '<': 5, '<?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': '5282479', 'n_tokens_mistral': 2087, 'n_tokens_neox': 2023, 'n_words': 502}