<commit_before>import ms from 'ms';
import bytes from 'bytes';
import { write as copy } from 'clipboardy';
import chalk from 'chalk';
import title from 'title';
import Progress from 'progress';
import Client from '../../util/client';
import eraseLines from '../../util/output/erase-lines';
import wait from '../../util/output/wait';
import { handleError } from '../../util/error';
import getArgs from '../../util/get-args';
import toHumanPath from '../../util/humanize-path';
import Now from '../../util';
import stamp from '../../util/output/stamp.ts';
import { isReady, isDone, isFailed } from '../../util/build-state';
import createDeploy from '../../util/deploy/create-deploy';
import getDeploymentByIdOrHost from '../../util/deploy/get-deployment-by-id-or-host';
import dnsTable from '../../util/format-dns-table.ts';
import sleep from '../../util/sleep';
import parseMeta from '../../util/parse-meta';
import code from '../../util/output/code';
import param from '../../util/output/param';
import highlight from '../../util/output/highlight';
import getProjectName from '../../util/get-project-name';
import {
  BuildsRateLimited,
  CertConfigurationError,
  CertError,
  DeploymentNotFound,
  DeploymentPermissionDenied,
  InvalidDeploymentId,
  DomainNotFound,
  DomainNotVerified,
  DomainPermissionDenied,
  DomainVerificationFailed,
  InvalidDomain,
  TooManyRequests,
  UserAborted,
  DeploymentsRateLimited,
  AliasDomainConfigured,
  MissingBuildScript,
  ConflictingFilePath,
  ConflictingPathSegment
} from '../../util/errors-ts';
import { SchemaValidationFailed } from '../../util/errors';
import purchaseDomainIfAvailable from '../../util/domains/purchase-domain-if-available';
import handleCertError from '../../util/certs/handle-cert-error';

const addProcessEnv = async (log, env) => {
  let val;

  for (const key of Object.keys(env)) {
    if (typeof env[key] !== 'undefined') {
      continue;
    }

    val = process.env[key];

    if (typeof val === 'string') {
      log(
        `Reading ${chalk.bold(
          `"${chalk.bold(key)}"`
        )} from your env (as no value was specified)`
      );
      // Escape value if it begins with @
      env[key] = val.replace(/^@/, '\\@');
    } else {
      throw new Error(
        `No value specified for env ${chalk.bold(
          `"${chalk.bold(key)}"`
        )} and it was not found in your env.`
      );
    }
  }
};

const deploymentErrorMsg = `Your deployment failed. Please retry later. More: https://err.sh/now-cli/deployment-error`;
const prepareAlias = input => `https://${input}`;

const printDeploymentStatus = async (
  output,
  { url, readyState, alias: aliasList },
  deployStamp,
  clipboardEnabled,
  localConfig,
  builds
) => {
  if (readyState === 'READY') {
    if (Array.isArray(aliasList) && aliasList.length > 0) {
      if (aliasList.length === 1) {
        if (clipboardEnabled) {
          const firstAlias = aliasList[0];
          const preparedAlias = prepareAlias(firstAlias);
          try {
            await copy(`https://${firstAlias}`);
            output.ready(`Deployed to ${chalk.bold(chalk.cyan(preparedAlias))} ${chalk.gray('[in clipboard]')} ${deployStamp()}`);
          } catch (err) {
            output.debug(`Error copying to clipboard: ${err}`);
            output.ready(`Deployed to ${chalk.bold(chalk.cyan(preparedAlias))} ${deployStamp()}`);
          }
        }
      } else {
        output.ready(`Deployment complete ${deployStamp()}`);

        // If `alias` is defined in the config, we need to
        // copy the first one to the clipboard.
        const matching = (localConfig.alias || [])[0];

        for (const alias of aliasList) {
          const index = aliasList.indexOf(alias);
          const isLast = index === (aliasList.length - 1);
          const shouldCopy = matching ? alias === matching : isLast;

          if (shouldCopy && clipboardEnabled) {
            try {
              await copy(`https://${alias}`);
              output.print(`- ${chalk.bold(chalk.cyan(prepareAlias(alias)))} ${chalk.gray('[in clipboard]')}\n`);

              continue;
            } catch (err) {
              output.debug(`Error copying to clipboard: ${err}`);
            }
          }

          output.print(`- ${chalk.bold(chalk.cyan(prepareAlias(alias)))}\n`);
        }
      }
    } else {
      output.ready(`Deployment complete ${deployStamp()}`);
    }

    return 0;
  }

  if (!builds) {
    output.error(deploymentErrorMsg);
    return 1;
  }

  const failedBuils = builds.filter(isFailed);
  const amount = failedBuils.length;

  if (amount > 0) {
    output.error('Build failed');
    output.error(
      `Check your logs at https://${url}/_logs or run ${code(
        `now logs ${url}`
      )}`
    );

    return 1;
  }

  output.error(deploymentErrorMsg);<commit_msg>[now deploy] Fix variable name typo (#2649)<commit_after>import ms from 'ms';
import bytes from 'bytes';
import { write as copy } from 'clipboardy';
import chalk from 'chalk';
import title from 'title';
import Progress from 'progress';
import Client from '../../util/client';
import eraseLines from '../../util/output/erase-lines';
import wait from '../../util/output/wait';
import { handleError } from '../../util/error';
import getArgs from '../../util/get-args';
import toHumanPath from '../../util/humanize-path';
import Now from '../../util';
import stamp from '../../util/output/stamp.ts';
import { isReady, isDone, isFailed } from '../../util/build-state';
import createDeploy from '../../util/deploy/create-deploy';
import getDeploymentByIdOrHost from '../../util/deploy/get-deployment-by-id-or-host';
import dnsTable from '../../util/format-dns-table.ts';
import sleep from '../../util/sleep';
import parseMeta from '../../util/parse-meta';
import code from '../../util/output/code';
import param from '../../util/output/param';
import highlight from '../../util/output/highlight';
import getProjectName from '../../util/get-project-name';
import {
  BuildsRateLimited,
  CertConfigurationError,
  CertError,
  DeploymentNotFound,
  DeploymentPermissionDenied,
  InvalidDeploymentId,
  DomainNotFound,
  DomainNotVerified,
  DomainPermissionDenied,
  DomainVerificationFailed,
  InvalidDomain,
  TooManyRequests,
  UserAborted,
  DeploymentsRateLimited,
  AliasDomainConfigured,
  MissingBuildScript,
  ConflictingFilePath,
  ConflictingPathSegment
} from '../../util/errors-ts';
import { SchemaValidationFailed } from '../../util/errors';
import purchaseDomainIfAvailable from '../../util/domains/purchase-domain-if-available';
import handleCertError from '../../util/certs/handle-cert-error';

const addProcessEnv = async (log, env) => {
  let val;

  for (const key of Object.keys(env)) {
    if (typeof env[key] !== 'undefined') {
      continue;
    }

    val = process.env[key];

    if (typeof val === 'string') {
      log(
        `Reading ${chalk.bold(
          `"${chalk.bold(key)}"`
        )} from your env (as no value was specified)`
      );
      // Escape value if it begins with @
      env[key] = val.replace(/^@/, '\\@');
    } else {
      throw new Error(
        `No value specified for env ${chalk.bold(
          `"${chalk.bold(key)}"`
        )} and it was not found in your env.`
      );
    }
  }
};

const deploymentErrorMsg = `Your deployment failed. Please retry later. More: https://err.sh/now-cli/deployment-error`;
const prepareAlias = input => `https://${input}`;

const printDeploymentStatus = async (
  output,
  { url, readyState, alias: aliasList },
  deployStamp,
  clipboardEnabled,
  localConfig,
  builds
) => {
  if (readyState === 'READY') {
    if (Array.isArray(aliasList) && aliasList.length > 0) {
      if (aliasList.length === 1) {
        if (clipboardEnabled) {
          const firstAlias = aliasList[0];
          const preparedAlias = prepareAlias(firstAlias);
          try {
            await copy(`https://${firstAlias}`);
            output.ready(`Deployed to ${chalk.bold(chalk.cyan(preparedAlias))} ${chalk.gray('[in clipboard]')} ${deployStamp()}`);
          } catch (err) {
            output.debug(`Error copying to clipboard: ${err}`);
            output.ready(`Deployed to ${chalk.bold(chalk.cyan(preparedAlias))} ${deployStamp()}`);
          }
        }
      } else {
        output.ready(`Deployment complete ${deployStamp()}`);

        // If `alias` is defined in the config, we need to
        // copy the first one to the clipboard.
        const matching = (localConfig.alias || [])[0];

        for (const alias of aliasList) {
          const index = aliasList.indexOf(alias);
          const isLast = index === (aliasList.length - 1);
          const shouldCopy = matching ? alias === matching : isLast;

          if (shouldCopy && clipboardEnabled) {
            try {
              await copy(`https://${alias}`);
              output.print(`- ${chalk.bold(chalk.cyan(prepareAlias(alias)))} ${chalk.gray('[in clipboard]')}\n`);

              continue;
            } catch (err) {
              output.debug(`Error copying to clipboard: ${err}`);
            }
          }

          output.print(`- ${chalk.bold(chalk.cyan(prepareAlias(alias)))}\n`);
        }
      }
    } else {
      output.ready(`Deployment complete ${deployStamp()}`);
    }

    return 0;
  }

  if (!builds) {
    output.error(deploymentErrorMsg);
    return 1;
  }

  const failedBuilds = builds.filter(isFailed);
  const amount = failedBuilds.length;

  if (amount > 0) {
    output.error('Build failed');
    output.error(
      `Check your logs at https://${url}/_logs or run ${code(
        `now logs ${url}`
      )}`
    );

    return 1;
  }

  output.error(deploymentErrorMsg);
{'fraction_non_alphanumeric': 0.16205329477380706, 'fraction_numerical': 0.002272257797975625, 'mean_word_length': 2.6664142370314274, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 10, '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': '98329', 'n_tokens_mistral': 2918, 'n_tokens_neox': 2902, 'n_words': 725}