game-algorithms/tools/wasm-pack-plugin/plugin.sh

56 lines
1.5 KiB
Bash
Executable File

#!/bin/sh
# Properties: actions
# username, token, registry=https://registry.npmjs.org, scope, folder=.
# profile=release, target=bundler, make, browser
# publish: username, token
# test:
# build:
echo wasm-pack plugin
pwd
echo actions: ${PLUGIN_ACTIONS}
echo username: ${PLUGIN_USERNAME}
echo registry: ${PLUGIN_REGISTRY:-https://registry.npmjs.org/}
echo scope: ${PLUGIN_SCOPE}
echo folder: ${PLUGIN_FOLDER:-.}
echo profile: ${PLUGIN_PROFILE:-release}
echo target: ${PLUGIN_TARGET:-bundler}
echo make: ${PLUGIN_MAKE}
set -eu
cd ${PLUGIN_FOLDER:-.}
if [[ "${PLUGIN_ACTIONS}" =~ '(^|,)build(,|$)' ]]; then
if [ "${PLUGIN_SCOPE:-}" = "" ]; then
wasm-pack build --${PLUGIN_PROFILE:-release} --target ${PLUGIN_TARGET:-bundler}
else
wasm-pack build --${PLUGIN_PROFILE:-release} --target ${PLUGIN_TARGET:-bundler} --scope ${PLUGIN_SCOPE}
fi
if [ "${PLUGIN_MAKE:-}" != "" ]; then
make ${PLUGIN_MAKE}
fi
fi
if [[ "${PLUGIN_ACTIONS}" =~ '(^|,)test(,|$)' ]]; then
wasm-pack test --node
fi
if [[ "${PLUGIN_ACTIONS}" =~ '(^|,)publish(,|$)' ]]; then
cd pkg
npm pkg set type=module
REGISTRY=${PLUGIN_REGISTRY:-https://registry.npmjs.org/}
if [ "${PLUGIN_SCOPE:-}" = "" ]; then
npm config set registry ${REGISTRY}
else
npm config set @${PLUGIN_SCOPE}:registry ${REGISTRY}
fi
npm config set -- $(echo ${REGISTRY} | sed -Ee "s/^https?://"):_authToken "${PLUGIN_TOKEN}"
npm publish
fi