if [ "$#" -lt 1 ] || [ "$#" -gt 2 ]; then
echo "Error: Invalid number of arguments. Usage: $0 <build|pack|publish> [release|debug]"
exit 1
fi
command=$1
mode=${2:-"debug"}
if [[ "$command" != "build" && "$command" != "pack" && "$command" != "publish" ]]; then
echo "Error: First argument must be one of 'build', 'pack', or 'publish'."
exit 1
fi
if [[ "$mode" != "release" && "$mode" != "debug" ]]; then
echo "Error: Second argument must be either 'release' or 'debug'. Defaulting to 'debug'."
mode="debug"
fi
if ! command -v wasm-pack &> /dev/null; then
read -p "wasm-pack could not be found. Do you want to install it? (y/n): " install_wasm_pack
if [[ "$install_wasm_pack" == [Yy]* ]]; then
cargo install wasm-pack --force
else
echo "Error: wasm-pack is required for this script."
exit 1
fi
fi
wasm-pack $command --$mode --no-default-features --features=wasm,reqwest,serde,types,_wasm_bindgen