#!/bin/bash

VERSION=$1

rm -rf wasm-pack-*.tar.?z cargo-wasm-pack*

echo "Downloading wasm-pack-$VERSION..."

wget --content-disposition "https://github.com/rustwasm/wasm-pack/archive/refs/tags/v$VERSION.tar.gz"

tar xf wasm-pack-$VERSION.tar.gz

tar cf wasm-pack-$VERSION.tar wasm-pack-$VERSION

cd wasm-pack-$VERSION

  # Configure cargo-vendor-filterer
  cat << EOF >> Cargo.toml
[package.metadata.vendor-filter]
platforms = ["x86_64-unknown-linux-gnu", "i686-unknown-linux-gnu"]
all-features = true
EOF


  if ! [ -f /usr/bin/cargo-vendor-filterer ]; then
    echo "WARNING: Creating unfiltered vendor libs tarball!"
    cargo vendor
  else
    cargo vendor-filterer
  fi

  mv vendor ../cargo-wasm-pack-$VERSION
cd ..

tar cf cargo-wasm-pack-$VERSION.tar cargo-wasm-pack-$VERSION

plzip -9 cargo-wasm-pack-$VERSION.tar
plzip -9 wasm-pack-$VERSION.tar

rm -rf wasm-pack-$VERSION
rm -rf cargo-wasm-pack-$VERSION
rm -f wasm-pack-$VERSION.tar.gz
