From 8f5247e83199a1de9cc9b6d6a864ea8f4dfb12ce Mon Sep 17 00:00:00 2001 From: austenadler Date: Wed, 9 Feb 2022 14:46:49 +0000 Subject: [PATCH] Use shell best practices in build_web.sh (#49) * Quote all shell variables * Use [[ ]]/$() over [ ]/`` Co-authored-by: Austen Adler --- build_web.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/build_web.sh b/build_web.sh index bc9c3d5..0de31a3 100755 --- a/build_web.sh +++ b/build_web.sh @@ -40,29 +40,29 @@ CRATE_NAME_SNAKE_CASE="${CRATE_NAME//-/_}" # for those who name crates with-keba export RUSTFLAGS=--cfg=web_sys_unstable_apis # Clear output from old stuff: -rm -f docs/${CRATE_NAME_SNAKE_CASE}_bg.wasm +rm -f "docs/${CRATE_NAME_SNAKE_CASE}_bg.wasm" echo "Building rust…" BUILD=release -cargo build -p ${CRATE_NAME} --release --lib --target wasm32-unknown-unknown +cargo build -p "${CRATE_NAME}" --release --lib --target wasm32-unknown-unknown # Get the output directory (in the workspace it is in another location) -TARGET=`cargo metadata --format-version=1 | jq --raw-output .target_directory` +TARGET=$(cargo metadata --format-version=1 | jq --raw-output .target_directory) echo "Generating JS bindings for wasm…" TARGET_NAME="${CRATE_NAME_SNAKE_CASE}.wasm" wasm-bindgen "${TARGET}/wasm32-unknown-unknown/${BUILD}/${TARGET_NAME}" \ --out-dir docs --no-modules --no-typescript -if [ "${FAST}" = false ]; then +if [[ "${FAST}" == false ]]; then echo "Optimizing wasm…" # to get wasm-opt: apt/brew/dnf install binaryen - wasm-opt docs/${CRATE_NAME}_bg.wasm -O2 --fast-math -o docs/${CRATE_NAME}_bg.wasm # add -g to get debug symbols + wasm-opt "docs/${CRATE_NAME}_bg.wasm" -O2 --fast-math -o "docs/${CRATE_NAME}_bg.wasm" # add -g to get debug symbols fi echo "Finished: docs/${CRATE_NAME_SNAKE_CASE}.wasm" -if [ "${OPEN}" = true ]; then +if [[ "${OPEN}" == true ]]; then if [[ "$OSTYPE" == "linux-gnu"* ]]; then # Linux, ex: Fedora xdg-open http://localhost:8080/index.html