<commit_before>#!/bin/bash

set -e

if [ -z "$DJANGO_STATIC_ROOT" ]; then
    echo "Environment variable not defined DJANGO_STATIC_ROOT"
    exit 1
fi

# Default settings
BIN="./node_modules/.bin"

STATIC_JS_DIR="${DJANGO_STATIC_ROOT}js/"
STATIC_CSS_DIR="${DJANGO_STATIC_ROOT}css/"
STATIC_IMAGES_DIR="${DJANGO_STATIC_ROOT}images/"
STATIC_FONTS_DIR="${DJANGO_STATIC_ROOT}fonts/"

BROWSERIFY="$BIN/browserify"
ENTRY_JS_FILES="./js/src/main.js"
ENTRY_JS_FILES_WATER_BALANCE="./js/src/main_water_balance.js"

NUNJUCKS_TRANSFORM="-t [ nunjucksify --extension='.html' ]"
MINIFY_PLUGIN="-p [ minifyify --no-map ]"

NODE_SASS="$BIN/node-sass"
ENTRY_SASS_DIR="./sass/"
ENTRY_SASS_FILE="${ENTRY_SASS_DIR}main.scss"
VENDOR_CSS_FILE="${STATIC_CSS_DIR}vendor.css"

TEST_FILES="./js/src/**/tests.js"

usage() {
    echo -n "$(basename $0) [OPTION]...

Bundle JS and CSS static assets.

 Options:
  --watch      Listen for file changes
  --debug      Generate source maps
  --minify     Minify bundles (**SLOW**); Disables source maps
  --tests      Generate test bundles
  --list       List browserify dependencies
  --vendor     Generate vendor bundle and copy assets
  -h, --help   Display this help text
"
}

# Handle options
while [[ -n $1 ]]; do
    case $1 in
        --watch) ENABLE_WATCH=1 ;;
        --debug) ENABLE_DEBUG=1 ;;
        --minify) ENABLE_MINIFY=1 ;;
        --tests) ENABLE_TESTS=1 ;;
        --list) LIST_DEPS=1 ;;
        --vendor) BUILD_VENDOR_BUNDLE=1 ;;
        -h|--help|*) usage; exit 1 ;;
    esac
    shift
done

if [ -n "$ENABLE_WATCH" ]; then
    BROWSERIFY="$BIN/watchify"
    # These flags have to appear last or watchify will exit immediately.
    EXTRA_ARGS="--verbose --poll"
    NODE_SASS="$NODE_SASS --watch --recursive"
    # This argument must be a folder in watch mode, but a
    # single file otherwise.
    ENTRY_SASS_FILE="$ENTRY_SASS_DIR"
fi

if [ -n "$ENABLE_DEBUG" ]; then
    BROWSERIFY="$BROWSERIFY --debug"
    NODE_SASS="$NODE_SASS --source-map ${STATIC_CSS_DIR}main.css.map \
        --source-map-contents"
fi

if [ -n "$ENABLE_MINIFY" ]; then
    EXTRA_ARGS="$MINIFY_PLUGIN $EXTRA_ARGS"
fi

if [ -n "$LIST_DEPS" ]; then
    BROWSERIFY="$BROWSERIFY --list"
fi

COPY_IMAGES_COMMAND="cp -r \
    ./node_modules/leaflet/dist/images/* \
    ./node_modules/leaflet-draw/dist/images/* \
    $STATIC_IMAGES_DIR"

COPY_FONTS_COMMAND="cp -r \
    ./node_modules/font-awesome/fonts/* \
    $STATIC_FONTS_DIR"

COPY_ZEROCLIPBOARD_COMMAND="cp \
    ./node_modules/zeroclipboard/dist/ZeroClipboard.swf \
    $STATIC_JS_DIR"

CONCAT_VENDOR_CSS_COMMAND="cat \
    ./node_modules/leaflet/dist/leaflet.css \
    ./node_modules/leaflet-draw/dist/leaflet.draw.css \
    ./node_modules/font-awesome/css/font-awesome.min.css \
    > $VENDOR_CSS_FILE"

JS_DEPS=(jquery backbone backbone.marionette \
         bootstrap bootstrap-select \
         leaflet leaflet-draw lodash underscore \
         d3 nunjucks turf-area)
BROWSERIFY_EXT=""
BROWSERIFY_REQ=""
for DEP in "${JS_DEPS[@]}"
do
    BROWSERIFY_EXT+="-x $DEP "
    BROWSERIFY_REQ+="-r $DEP "
done

JS_TEST_DEPS=(chai sinon)
BROWSERIFY_TEST_EXT=""
BROWSERIFY_TEST_REQ=""
for DEP in "${JS_TEST_DEPS[@]}"
do
    BROWSERIFY_TEST_EXT+="-x $DEP "
    BROWSERIFY_TEST_REQ+="-r $DEP "
done

# TODO: Combine with original vendor bundle.
JS_DEPS_WATER_BALANCE=(jquery bootstrap bootstrap-select retina.js)
BROWSERIFY_EXT_WATER_BALANCE=""
BROWSERIFY_REQ_WATER_BALANCE=""
for DEP in "${JS_DEPS_WATER_BALANCE[@]}"
do
    BROWSERIFY_EXT_WATER_BALANCE+="-x $DEP "<commit_msg>fixup Add ZeroClipboard to vendor bundle<commit_after>#!/bin/bash

set -e

if [ -z "$DJANGO_STATIC_ROOT" ]; then
    echo "Environment variable not defined DJANGO_STATIC_ROOT"
    exit 1
fi

# Default settings
BIN="./node_modules/.bin"

STATIC_JS_DIR="${DJANGO_STATIC_ROOT}js/"
STATIC_CSS_DIR="${DJANGO_STATIC_ROOT}css/"
STATIC_IMAGES_DIR="${DJANGO_STATIC_ROOT}images/"
STATIC_FONTS_DIR="${DJANGO_STATIC_ROOT}fonts/"

BROWSERIFY="$BIN/browserify"
ENTRY_JS_FILES="./js/src/main.js"
ENTRY_JS_FILES_WATER_BALANCE="./js/src/main_water_balance.js"

NUNJUCKS_TRANSFORM="-t [ nunjucksify --extension='.html' ]"
MINIFY_PLUGIN="-p [ minifyify --no-map ]"

NODE_SASS="$BIN/node-sass"
ENTRY_SASS_DIR="./sass/"
ENTRY_SASS_FILE="${ENTRY_SASS_DIR}main.scss"
VENDOR_CSS_FILE="${STATIC_CSS_DIR}vendor.css"

TEST_FILES="./js/src/**/tests.js"

usage() {
    echo -n "$(basename $0) [OPTION]...

Bundle JS and CSS static assets.

 Options:
  --watch      Listen for file changes
  --debug      Generate source maps
  --minify     Minify bundles (**SLOW**); Disables source maps
  --tests      Generate test bundles
  --list       List browserify dependencies
  --vendor     Generate vendor bundle and copy assets
  -h, --help   Display this help text
"
}

# Handle options
while [[ -n $1 ]]; do
    case $1 in
        --watch) ENABLE_WATCH=1 ;;
        --debug) ENABLE_DEBUG=1 ;;
        --minify) ENABLE_MINIFY=1 ;;
        --tests) ENABLE_TESTS=1 ;;
        --list) LIST_DEPS=1 ;;
        --vendor) BUILD_VENDOR_BUNDLE=1 ;;
        -h|--help|*) usage; exit 1 ;;
    esac
    shift
done

if [ -n "$ENABLE_WATCH" ]; then
    BROWSERIFY="$BIN/watchify"
    # These flags have to appear last or watchify will exit immediately.
    EXTRA_ARGS="--verbose --poll"
    NODE_SASS="$NODE_SASS --watch --recursive"
    # This argument must be a folder in watch mode, but a
    # single file otherwise.
    ENTRY_SASS_FILE="$ENTRY_SASS_DIR"
fi

if [ -n "$ENABLE_DEBUG" ]; then
    BROWSERIFY="$BROWSERIFY --debug"
    NODE_SASS="$NODE_SASS --source-map ${STATIC_CSS_DIR}main.css.map \
        --source-map-contents"
fi

if [ -n "$ENABLE_MINIFY" ]; then
    EXTRA_ARGS="$MINIFY_PLUGIN $EXTRA_ARGS"
fi

if [ -n "$LIST_DEPS" ]; then
    BROWSERIFY="$BROWSERIFY --list"
fi

COPY_IMAGES_COMMAND="cp -r \
    ./node_modules/leaflet/dist/images/* \
    ./node_modules/leaflet-draw/dist/images/* \
    $STATIC_IMAGES_DIR"

COPY_FONTS_COMMAND="cp -r \
    ./node_modules/font-awesome/fonts/* \
    $STATIC_FONTS_DIR"

COPY_ZEROCLIPBOARD_COMMAND="cp \
    ./node_modules/zeroclipboard/dist/ZeroClipboard.swf \
    $STATIC_JS_DIR"

CONCAT_VENDOR_CSS_COMMAND="cat \
    ./node_modules/leaflet/dist/leaflet.css \
    ./node_modules/leaflet-draw/dist/leaflet.draw.css \
    ./node_modules/font-awesome/css/font-awesome.min.css \
    > $VENDOR_CSS_FILE"

JS_DEPS=(jquery backbone backbone.marionette \
         bootstrap bootstrap-select \
         leaflet leaflet-draw lodash underscore \
         d3 nunjucks turf-area \
         zeroclipboard)
BROWSERIFY_EXT=""
BROWSERIFY_REQ=""
for DEP in "${JS_DEPS[@]}"
do
    BROWSERIFY_EXT+="-x $DEP "
    BROWSERIFY_REQ+="-r $DEP "
done

JS_TEST_DEPS=(chai sinon)
BROWSERIFY_TEST_EXT=""
BROWSERIFY_TEST_REQ=""
for DEP in "${JS_TEST_DEPS[@]}"
do
    BROWSERIFY_TEST_EXT+="-x $DEP "
    BROWSERIFY_TEST_REQ+="-r $DEP "
done

# TODO: Combine with original vendor bundle.
JS_DEPS_WATER_BALANCE=(jquery bootstrap bootstrap-select retina.js)
BROWSERIFY_EXT_WATER_BALANCE=""
BROWSERIFY_REQ_WATER_BALANCE=""
for DEP in "${JS_DEPS_WATER_BALANCE[@]}"
do
    BROWSERIFY_EXT_WATER_BALANCE+="-x $DEP "
{'fraction_non_alphanumeric': 0.13886548722269026, 'fraction_numerical': 0.003369839932603201, 'mean_word_length': 3.513941698352345, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '185724', 'n_tokens_mistral': 2833, 'n_tokens_neox': 2680, 'n_words': 508}