#!/usr/bin/env bash
set -e

PROJECT_ROOT="$(pwd)"

MANIFEST="$PROJECT_ROOT/src/main/resources/manifest.json"
RESOURCE_DIR="$PROJECT_ROOT/src/main/resources"
DIST_DIR="$PROJECT_ROOT/dist"

mkdir -p "$DIST_DIR"

NAME=$(jq -r '.Name' "$MANIFEST")
VERSION=$(jq -r '.Version' "$MANIFEST")
SERVER=$(jq -r '.ServerVersion' "$MANIFEST")
SERVER=${SERVER//[<>=~^]/}

ZIP_NAME="${NAME}-${VERSION}_${SERVER}.zip"

echo "Building $ZIP_NAME"

cd "$RESOURCE_DIR"
zip -r "$DIST_DIR/$ZIP_NAME" .