<commit_before>#!/bin/bash

if [ -z "${NPM_EMAIL}" ]; then
  fail 'Please specify email'
  exit 1
fi

if [ -z "${NPM_AUTH_TOKEN}" ]; then
  fail 'Please specify auth token'
  exit 1
fi

if [ ! -f ./package.json ]; then
  fail 'Project must contain a package.json'
  exit 1
fi

if [ -n "${WERCKER_CACHE_DIR}" ]; then
  npm config set cache "$WERCKER_CACHE_DIR/wercker/npm"
fi

if [ -z "${NPM_ACCESS}" ]; then
  NPM_ACCESS=''
else
  info "Setting npm --access ${NPM_ACCESS}"
  NPM_ACCESS="--access=${NPM_ACCESS}"
fi

echo _auth = "${NPM_AUTH_TOKEN}" > ~/.npmrc
echo email = "${NPM_EMAIL}" >> ~/.npmrc

NPM_VERSION=$(
  grep package.json -e 'version' | awk '{print substr($2, 2, length($2)-3)}'
)
NPM_VERSION_PRERELEASE=$(echo "${NPM_VERSION}" | cut -d '-' -f 2 -s)

info NPM_VERSION="${NPM_VERSION}"
info NPM_VERSION_PRERELEASE="${NPM_VERSION_PRERELEASE}"

retries=3

for try in $(seq "$retries"); do
  info "try: ${try}"

  if [ -n "${NPM_VERSION_TAG}" ]; then
    info "npm publish . --tag ${NPM_VERSION_TAG} ${NPM_ACCESS}"
    npm publish . --tag "${NPM_VERSION_TAG}" "${NPM_ACCESS}" && break

  elif [ -n "${NPM_VERSION_PRERELEASE}" ]; then
    info "npm publish . --tag ${WERCKER_GIT_BRANCH} ${NPM_ACCESS}"
    npm publish . --tag "${WERCKER_GIT_BRANCH}" "${NPM_ACCESS}" && break

  else
    info "npm publish . ${NPM_ACCESS}"
    npm publish . "${NPM_ACCESS}" && break

  fi
done

if [ $? -eq 0 ]; then
  success "Package published to NPM"
else
  fail "npm publish failed with status code $?"
fi<commit_msg>Add --tag latest to default npm publish command<commit_after>#!/bin/bash

if [ -z "${NPM_EMAIL}" ]; then
  fail 'Please specify email'
  exit 1
fi

if [ -z "${NPM_AUTH_TOKEN}" ]; then
  fail 'Please specify auth token'
  exit 1
fi

if [ ! -f ./package.json ]; then
  fail 'Project must contain a package.json'
  exit 1
fi

if [ -n "${WERCKER_CACHE_DIR}" ]; then
  npm config set cache "$WERCKER_CACHE_DIR/wercker/npm"
fi

if [ -z "${NPM_ACCESS}" ]; then
  NPM_ACCESS=''
else
  info "Setting npm --access ${NPM_ACCESS}"
  NPM_ACCESS="--access=${NPM_ACCESS}"
fi

echo _auth = "${NPM_AUTH_TOKEN}" > ~/.npmrc
echo email = "${NPM_EMAIL}" >> ~/.npmrc

NPM_VERSION=$(
  grep package.json -e 'version' | awk '{print substr($2, 2, length($2)-3)}'
)
NPM_VERSION_PRERELEASE=$(echo "${NPM_VERSION}" | cut -d '-' -f 2 -s)

info NPM_VERSION="${NPM_VERSION}"
info NPM_VERSION_PRERELEASE="${NPM_VERSION_PRERELEASE}"

retries=3

for try in $(seq "$retries"); do
  info "try: ${try}"

  if [ -n "${NPM_VERSION_TAG}" ]; then
    info "npm publish . --tag ${NPM_VERSION_TAG} ${NPM_ACCESS}"
    npm publish . --tag "${NPM_VERSION_TAG}" "${NPM_ACCESS}" && break

  elif [ -n "${NPM_VERSION_PRERELEASE}" ]; then
    info "npm publish . --tag ${WERCKER_GIT_BRANCH} ${NPM_ACCESS}"
    npm publish . --tag "${WERCKER_GIT_BRANCH}" "${NPM_ACCESS}" && break

  else
    info "npm publish . ${NPM_ACCESS}"
    npm publish . --tag latest "${NPM_ACCESS}" && break

  fi
done

if [ $? -eq 0 ]; then
  success "Package published to NPM"
else
  fail "npm publish failed with status code $?"
fi
{'fraction_non_alphanumeric': 0.17269468882372108, 'fraction_numerical': 0.006516780710329097, 'mean_word_length': 3.767080745341615, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '1573011', 'n_tokens_mistral': 1191, 'n_tokens_neox': 1153, 'n_words': 328}