<commit_before>#!/bin/bash

set -e

# Make sure we're in the image-cli directory
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
cd "$SCRIPT_DIR" && cd ../

PLATFORM=$(node -e 'console.log(require("os").platform())')
VERSION=$(node -e 'console.log(require("./package.json").version)')

PLATFORM_FILE=""
if [[ "$PLATFORM" == "darwin" ]]; then
  PLATFORM_FILE="node8-mac.tar.gz"
elif [[ "$PLATFORM" == "linux" ]]; then
  PLATFORM_FILE="node8-linux.tar.gz"
elif [[ "$PLATFORM" == "win32" ]]; then
  echo "Windows not yet supported"
  exit 1
else
  echo "Unsupported platform $PLATFORM"
  exit 1
fi

mkdir -p bin/prebuilt/
FILE_TO_DOWNLOAD="image-cli-$PLATFORM_FILE"
echo "Downloading $FILE_TO_DOWNLOAD for version $VERSION..."
curl -L -o "bin/prebuilt/$FILE_TO_DOWNLOAD" "https://github.com/ErisVentures/js-image/releases/download/v${VERSION}/$FILE_TO_DOWNLOAD"

cd bin/prebuilt

if [[ "$FILE_TO_DOWNLOAD" = *.tar.gz ]]; then
  tar -xzf "$FILE_TO_DOWNLOAD"
fi<commit_msg>fix(image-cli): do not download prebuilt if already there<commit_after>#!/bin/bash

set -e

# Make sure we're in the image-cli directory
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
cd "$SCRIPT_DIR" && cd ../

PLATFORM=$(node -e 'console.log(require("os").platform())')
VERSION=$(node -e 'console.log(require("./package.json").version)')

PLATFORM_FILE=""
if [[ "$PLATFORM" == "darwin" ]]; then
  PLATFORM_FILE="node8-mac.tar.gz"
elif [[ "$PLATFORM" == "linux" ]]; then
  PLATFORM_FILE="node8-linux.tar.gz"
elif [[ "$PLATFORM" == "win32" ]]; then
  echo "Windows not yet supported"
  exit 1
else
  echo "Unsupported platform $PLATFORM"
  exit 1
fi

mkdir -p bin/prebuilt/
EXISTING_VERSION=$(cat bin/prebuilt/version.txt || echo 'None')

if [[ "$EXISTING_VERSION" == "$VERSION" ]]; then
  echo "Already has latest version!"
  exit 0
fi

FILE_TO_DOWNLOAD="image-cli-$PLATFORM_FILE"
echo "Downloading $FILE_TO_DOWNLOAD for version $VERSION..."
curl -L -o "bin/prebuilt/$FILE_TO_DOWNLOAD" "https://github.com/ErisVentures/js-image/releases/download/v${VERSION}/$FILE_TO_DOWNLOAD"

cd bin/prebuilt

echo "$VERSION" > version.txt

if [[ "$FILE_TO_DOWNLOAD" = *.tar.gz ]]; then
  tar -xzf "$FILE_TO_DOWNLOAD"
fi
{'fraction_non_alphanumeric': 0.1867983834755276, 'fraction_numerical': 0.00673551863493489, 'mean_word_length': 4.832460732984293, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 5, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3010245', 'n_tokens_mistral': 869, 'n_tokens_neox': 830, 'n_words': 185}