Skip to content

Commit

Permalink
Add optional beta suffix to build.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
Rexagon committed May 31, 2024
1 parent 1e377ed commit 16e1eb3
Showing 1 changed file with 43 additions and 7 deletions.
50 changes: 43 additions & 7 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,35 @@

set -e

function print_help() {
echo 'Usage: build.sh [OPTIONS]'
echo ''
echo 'Options:'
echo ' -h,--help Print this help message and exit'
echo ' --beta Build as `-beta` version.'
}

beta=false
while [[ $# -gt 0 ]]; do
key="$1"
case $key in
-h|--help)
print_help
exit 0
;;
--beta)
beta="true"
shift # past argument
;;
*) # unknown option
echo 'ERROR: Unknown option'
echo ''
print_help
exit 1
;;
esac
done

# Check if jq is installed
if ! [ -x "$(command -v jq)" ]; then
echo "jq is not installed" >& 2
Expand All @@ -22,16 +51,23 @@ wasm-pack build --release -t nodejs -d pkg-node
wasm-pack build --release -t web -d pkg

# Get the package name
PKG_NAME=$(jq -r .name pkg/package.json | sed 's/\-/_/g')
BASE_NAME=$(jq -r .name pkg/package.json | sed 's/\-/_/g')

PKG_NAME=$(jq -r .name pkg/package.json)
if [[ "$beta" == "true" ]]; then
PKG_NAME="$PKG_NAME-beta"
fi

# Merge nodejs & browser packages
cp "pkg-node/${PKG_NAME}.js" "pkg/${PKG_NAME}_main.js"
cp "pkg-node/${PKG_NAME}.d.ts" "pkg/${PKG_NAME}_main.d.ts"
cp "pkg-node/${BASE_NAME}.js" "pkg/${BASE_NAME}_main.js"
cp "pkg-node/${BASE_NAME}.d.ts" "pkg/${BASE_NAME}_main.d.ts"

sed -i "s/__wbindgen_placeholder__/wbg/g" "pkg/${PKG_NAME}_main.js"
sed -i "s/__wbindgen_placeholder__/wbg/g" "pkg/${BASE_NAME}_main.js"

jq ".main = \"${PKG_NAME}_main.js\"" pkg/package.json |
jq ".browser = \"${PKG_NAME}.js\"" > pkg/temp.json
mv pkg/temp.json pkg/package.json
PACKAGE_JSON=$(
jq ".name = \"$PKG_NAME\" | .main = \"${BASE_NAME}_main.js\" | .browser = \"${BASE_NAME}.js\"" \
pkg/package.json
)
echo "$PACKAGE_JSON" > pkg/package.json

rm -rf pkg-node

0 comments on commit 16e1eb3

Please sign in to comment.