#!/usr/bin/env bash set -euo pipefail repo_root=$(cd "$(dirname "$0")/.." && pwd) output_dir="$repo_root/web/js/mp_bundle" output_file="$output_dir/mp-common.bundle.min.js" tmp_dir=$(mktemp -d "${TMPDIR:-/tmp}/pms-mp-bundle.XXXXXX") source_bundle="$tmp_dir/mp-common.bundle.js" cleanup() { rm -rf "$tmp_dir" } trap cleanup EXIT sources=( "web/js/mp_common/common.js" "web/js/mp_toast/toast.js" "web/js/mp_request/request.js" "web/js/mp_user_api/user-api.js" "web/js/mp_validator/validator-rules.js" "web/js/mp_validation/validation-manager.js" "web/js/mp_utils/field-formatter.js" "web/js/mp_bridge/bridge.js" "web/js/mp_utils/navigation.js" "web/js/mp_ss_components/mp-ss-components.js" ) : > "$source_bundle" for source in "${sources[@]}"; do if [[ ! -f "$repo_root/$source" ]]; then echo "Missing bundle source: $source" >&2 exit 1 fi printf '\n/* source: %s */\n' "$source" >> "$source_bundle" cat "$repo_root/$source" >> "$source_bundle" printf '\n;\n' >> "$source_bundle" done mkdir -p "$output_dir" npx --yes terser@5.51.4 "$source_bundle" \ --compress \ --mangle \ --ecma 2020 \ --comments false \ --output "$output_file" node --check "$output_file" printf 'Built %s (%s bytes)\n' "$output_file" "$(wc -c < "$output_file" | tr -d ' ')"