<commit_before>#!/bin/bash

error() {
  local line_lo="$1"
  local message="$2"
  local code="${3:-1}"
  if [[ -n "$message" ]] ; then
    echo "build.sh experienced an error on line ${line_lo}: ${message}; exiting with status ${code}"
  else
    echo "build.sh experienced an error on line ${line_lo}; exiting with status ${code}"
  fi
  
  exit 1
}

# Stops the execution of the script if any command, including pipes, fail.
set -e
set -o pipefail
trap 'error ${LINENO}' ERR

# Copy server settings file into the build directory.
# The SERVER_SETTINGS_FILE environment variable should be defined in Jenkins
# after uploading the settings file using the Config File Provider plugin:
# https://wiki.jenkins-ci.org/display/JENKINS/Config+File+Provider+Plugin
echo "Copy server settings  from $SERVER_SETTINGS_PATH to `pwd`/HadithHouseWebsite/server_settings.py ..."
cp "${SERVER_SETTINGS_PATH}" "HadithHouseWebsite/server_settings.py"

# Install NodeJS modules.
echo "Install NodeJS modules..."
npm install

# MomentJS does not have a @types module which is required by TypeScript, because the definition file
# is included with the package itself, so we create a folder for moment under @types and copy
# the definitions file to it, after renaming it to index.d.ts.
mkdir node_modules/@types/moment
cp node_modules/moment/moment.d.ts node_modules/@types/moment/index.d.ts

# Run grunt
echo "Run Grunt..."
./node_modules/.bin/grunt

# Remove Node modules and delete TypeScript cache (.tscache)
echo "Remove NodeJS modules and delete TypeScript cache (.tscache)..."
rm -rf node_modules/
rm -rf .tscache/

# Install and activate a Python virtual environment.
echo "Install and activate a Python virtual environment..."
virtualenv --python=python3.6 venv
source venv/bin/activate

echo "Install Python packages in requirements.txt..."
pip install -r requirements.txt

# Collect Django's static files.
echo "Running 'manage.py collectstatic' to collect static files."
python manage.py collectstatic --noinput

# Running tests...
echo "Running tests..."
python manage.py test

echo "Deactivate Python's virtual environment and delete it..."
deactivate
rm -rf venv<commit_msg>feat(@types) Improvement to build.sh<commit_after>#!/bin/bash

log_error() {
  local msg=$1
  RED='\033[0;31m'
  NC='\033[0m' # No Color
  echo -e "${RED}${msg}${NC}"
}

log() {
  local msg=$1
  echo "${msg}"
}

on_error() {
  local line_lo="$1"
  local message="$2"
  local code="${3:-1}"
  if [[ -n "${message}" ]] ; then
    log_error "build.sh experienced an error on line ${line_lo}: ${message}; exiting with status ${code}"
  else
    log_error "build.sh experienced an error on line ${line_lo}; exiting with status ${code}"
  fi

  exit 1
}

# Stops the execution of the script if any command, including pipes, fail.
set -e
set -o pipefail
trap 'on_error ${LINENO}' ERR

# Copy server settings file into the build directory.
# The SERVER_SETTINGS_FILE environment variable should be defined in Jenkins
# after uploading the settings file using the Config File Provider plugin:
# https://wiki.jenkins-ci.org/display/JENKINS/Config+File+Provider+Plugin
if [[ -z ${SERVER_SETTINGS_PATH} ]]; then
  log_error 'Environment variable SERVER_SETTINGS_PATH is not defined.'
  exit 1
fi

log "Copy server settings from ${SERVER_SETTINGS_PATH} to `pwd`/HadithHouseWebsite/server_settings.py ..."
cp "${SERVER_SETTINGS_PATH}" "HadithHouseWebsite/server_settings.py"

# Install NodeJS modules.
log "Install NodeJS modules..."
npm install

# MomentJS does not have a @types module which is required by TypeScript, because the definition file
# is included with the package itself, so we create a folder for moment under @types and copy
# the definitions file to it, after renaming it to index.d.ts.
mkdir node_modules/@types/moment
cp node_modules/moment/moment.d.ts node_modules/@types/moment/index.d.ts

# Run grunt
log "Run Grunt..."
./node_modules/.bin/grunt

# Remove Node modules and delete TypeScript cache (.tscache)
log "Remove NodeJS modules and delete TypeScript cache (.tscache)..."
rm -rf node_modules/
rm -rf .tscache/

# Install and activate a Python virtual environment.
log "Install and activate a Python virtual environment..."
virtualenv --python=python3.6 venv
source venv/bin/activate

log "Install Python packages in requirements.txt..."
pip install -r requirements.txt

# Collect Django's static files.
log "Running 'manage.py collectstatic' to collect static files."
python manage.py collectstatic --noinput

# Running tests...
log "Running tests..."
python manage.py test

log "Deactivate Python's virtual environment and delete it..."
deactivate
rm -rf venv
{'fraction_non_alphanumeric': 0.1069967707212056, 'fraction_numerical': 0.00581270182992465, 'mean_word_length': 4.327981651376147, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '7559134', 'n_tokens_mistral': 1417, 'n_tokens_neox': 1359, 'n_words': 539}