Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Benjamin-Dobell/55d1e6f727ec1c8275b19b51045e715d to your computer and use it in GitHub Desktop.
Save Benjamin-Dobell/55d1e6f727ec1c8275b19b51045e715d to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
set -e
BASE_DIR=$(dirname $0)
DISABLE_SAVE=false
EMPTY_GAME=false
RELEASE=false
DISABLE_SAVE_REGEX="^--?(no|disable)-save\$"
EMPTY_GAME_REGEX="^--?(empty|blank)\$"
RELEASE_REGEX="^--?release\$"
for arg in "$@"; do
if [[ "$arg" =~ $DISABLE_SAVE_REGEX ]]; then
DISABLE_SAVE=true
fi
if [[ "$arg" =~ $EMPTY_GAME_REGEX ]]; then
EMPTY_GAME=true
fi
if [[ "$arg" =~ $RELEASE_REGEX ]]; then
RELEASE=true
fi
done
if [ -z "$LUA_COMPILE" ]; then
LUA_COMPILE=lua-compile
fi
if [ ! -d "$BASE_DIR/build" ]; then
mkdir -p "$BASE_DIR/build"
fi
$LUA_COMPILE -s "$BASE_DIR" -s "$BASE_DIR/lib" "$BASE_DIR/scripts/Global.ttslua" > "$BASE_DIR/build/Global.bundle.ttslua"
$LUA_COMPILE -s "$BASE_DIR" -s "$BASE_DIR/lib" "$BASE_DIR/scripts/Card.ttslua" > "$BASE_DIR/build/Card.bundle.ttslua"
if [ "$DISABLE_SAVE" = "true" ]; then
echo "Disabling save."
sed -i -e "s/DISABLE_SAVE=true/DISABLE_SAVE=false/g" "$BASE_DIR/build/Global.bundle.ttslua"
fi
if [ "$EMPTY_GAME" = "true" ]; then
echo "Enabling empty game option."
sed -i -e "s/EMPTY_GAME=false/EMPTY_GAME=true/g" "$BASE_DIR/build/Global.bundle.ttslua"
fi
if [ "$RELEASE" = "true" ]; then
# Hackily disable dev
sed -i -e "s/require('Debug')local m=true/require('Debug')local m=false/g" "$BASE_DIR/build/Global.bundle.ttslua"
sed -i -e "s/require('Debug')local m=true/require('Debug')local m=false/g" "$BASE_DIR/build/Card.bundle.ttslua"
echo "Minifying..."
luamin -f "$BASE_DIR/build/Global.bundle.ttslua" > "$BASE_DIR/build/Global.bundle.min.ttslua"
luamin -f "$BASE_DIR/build/Card.bundle.ttslua" > "$BASE_DIR/build/Card.bundle.min.ttslua"
# Minification produces a single instance of some invalid Lua - we'll just hackily fix it.
sed -i -e "s/a.prepare(\.\.\.)/(a.prepare(...))/g" "$BASE_DIR/build/Global.bundle.min.ttslua"
sed -i -e "s/a.prepare(\.\.\.)/(a.prepare(...))/g" "$BASE_DIR/build/Card.bundle.min.ttslua"
mv "$BASE_DIR/build/Global.bundle.ttslua" "$BASE_DIR/build/Global.bundle.orig.ttslua"
mv "$BASE_DIR/build/Card.bundle.ttslua" "$BASE_DIR/build/Card.bundle.orig.ttslua"
mv "$BASE_DIR/build/Global.bundle.min.ttslua" "$BASE_DIR/build/Global.bundle.ttslua"
mv "$BASE_DIR/build/Card.bundle.min.ttslua" "$BASE_DIR/build/Card.bundle.ttslua"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment