<commit_before>#!/bin/bash
set -e
set -o pipefail

# ---------------------------------------------------------------------
# A script to publish an NPM package from the current directory, only
# if its current version does not already exist on the NPM registry.
# ---------------------------------------------------------------------

# Googlers can get the npm token from http://go/npm-publish
# Uncomment for testing purposes:
#NPM_TOKEN=YOUR_TOKEN_HERE

# -------------------
#      Functions
# -------------------

# Returns 0/1 if a NPM package & version already exists on the npm registry.
#   ARGS:
#     1: NPM package name
#     2: NPM package version
npm_package_version_exists() {
  local response
  # e.g. http://registry.npmjs.org/@firebaseextensions/fs-bq-import-collection/0.1.10
  local npm_registry_url=http://registry.npmjs.org/$1/$2

  response=$(curl --request GET \
    --url "$npm_registry_url" \
    --header 'Content-Type: application/json' \
    -s)

  if [[ $response == *"version not found: $2"* ]]; then
    return 1
  fi

  # Checks the version field exists and matches current version from the returned json response.
  if [[ $response == *"\"version\":\"$2\""* ]]; then
    return 0
  fi

  echo "Error whilst parsing NPM registry response for package $1 and version $2 at url $npm_registry_url"
  exit 1
}

# -------------------
#    Main Script
# -------------------
pwd

# Confirm the current directory is actually an NPM package with a package.json file.
if ! [ -f "./package.json" ]; then
  echo "A package.json file could not be found in the current working directory."
  exit 1
fi
NPM_PACKAGE_NAME="$(node -e "console.log(require('./package.json')['name'])")"
NPM_PACKAGE_VERSION="$(node -e "console.log(require('./package.json')['version'])")"<commit_msg>Use HTTPS to fetch from NPM registry.<commit_after>#!/bin/bash
set -e
set -o pipefail

# ---------------------------------------------------------------------
# A script to publish an NPM package from the current directory, only
# if its current version does not already exist on the NPM registry.
# ---------------------------------------------------------------------

# Googlers can get the npm token from http://go/npm-publish
# Uncomment for testing purposes:
#NPM_TOKEN=YOUR_TOKEN_HERE

# -------------------
#      Functions
# -------------------

# Returns 0/1 if a NPM package & version already exists on the npm registry.
#   ARGS:
#     1: NPM package name
#     2: NPM package version
npm_package_version_exists() {
  local response
  # e.g. http://registry.npmjs.org/@firebaseextensions/fs-bq-import-collection/0.1.10
  local npm_registry_url=https://registry.npmjs.org/$1/$2

  response=$(curl --request GET \
    --url "$npm_registry_url" \
    --header 'Content-Type: application/json' \
    -s)

  if [[ $response == *"version not found: $2"* ]]; then
    return 1
  fi

  # Checks the version field exists and matches current version from the returned json response.
  if [[ $response == *"\"version\":\"$2\""* ]]; then
    return 0
  fi

  echo "Error whilst parsing NPM registry response for package $1 and version $2 at url $npm_registry_url"
  exit 1
}

# -------------------
#    Main Script
# -------------------
pwd

# Confirm the current directory is actually an NPM package with a package.json file.
if ! [ -f "./package.json" ]; then
  echo "A package.json file could not be found in the current working directory."
  exit 1
fi
NPM_PACKAGE_NAME="$(node -e "console.log(require('./package.json')['name'])")"
NPM_PACKAGE_VERSION="$(node -e "console.log(require('./package.json')['version'])")"
{'fraction_non_alphanumeric': 0.22944921118184333, 'fraction_numerical': 0.00996401882092444, 'mean_word_length': 2.170175438596491, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 1, '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': '4655767', 'n_tokens_mistral': 1071, 'n_tokens_neox': 1014, 'n_words': 351}