#/bin/bash
echo "Using directory: $(pwd)"
current_dir=$(pwd)

echo "Build complete. Packing service packs..."

APP_VERSION=$(grep -o 'APP_VERSION *= *"[^"]*' "$current_dir/app/version.ts" | sed 's/APP_VERSION *= *"//')
CORE_MIN_REQUIRED_VERSION=$(grep -o 'CORE_MIN_REQUIRED_VERSION *= *"[^"]*' "$current_dir/app/version.ts" | sed 's/CORE_MIN_REQUIRED_VERSION *= *"//')

echo "App version: $APP_VERSION"
echo "Kernel target version: $CORE_MIN_REQUIRED_VERSION"

mkdir -p "${current_dir}/packs"
rm -rf "${current_dir}/packs"/*
for PLATFORM in darwin linux win32; do
    for ARCH in arm64 x64; do
        ZIP_NAME="sp-${PLATFORM}-${ARCH}-${APP_VERSION}-${CORE_MIN_REQUIRED_VERSION}.zip"
        SRC_DIR="${current_dir}/out/renderer/assets"
        if [ -d "$SRC_DIR" ]; then
            (cd "$SRC_DIR" && zip -j "${current_dir}/packs/${ZIP_NAME}" *)
            echo "Packed $SRC_DIR to /packs/${ZIP_NAME}"
        else
            echo "Warning: $SRC_DIR does not exist, skipping."
        fi
    done
done


