build_mp_common_bundle.sh 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #!/usr/bin/env bash
  2. set -euo pipefail
  3. repo_root=$(cd "$(dirname "$0")/.." && pwd)
  4. output_dir="$repo_root/web/js/mp_bundle"
  5. output_file="$output_dir/mp-common.bundle.min.js"
  6. tmp_dir=$(mktemp -d "${TMPDIR:-/tmp}/pms-mp-bundle.XXXXXX")
  7. source_bundle="$tmp_dir/mp-common.bundle.js"
  8. cleanup() {
  9. rm -rf "$tmp_dir"
  10. }
  11. trap cleanup EXIT
  12. sources=(
  13. "web/js/mp_common/common.js"
  14. "web/js/mp_toast/toast.js"
  15. "web/js/mp_request/request.js"
  16. "web/js/mp_user_api/user-api.js"
  17. "web/js/mp_validator/validator-rules.js"
  18. "web/js/mp_validation/validation-manager.js"
  19. "web/js/mp_utils/field-formatter.js"
  20. "web/js/mp_bridge/bridge.js"
  21. "web/js/mp_utils/navigation.js"
  22. "web/js/mp_ss_components/mp-ss-components.js"
  23. )
  24. : > "$source_bundle"
  25. for source in "${sources[@]}"; do
  26. if [[ ! -f "$repo_root/$source" ]]; then
  27. echo "Missing bundle source: $source" >&2
  28. exit 1
  29. fi
  30. printf '\n/* source: %s */\n' "$source" >> "$source_bundle"
  31. cat "$repo_root/$source" >> "$source_bundle"
  32. printf '\n;\n' >> "$source_bundle"
  33. done
  34. mkdir -p "$output_dir"
  35. npx --yes terser@5.51.4 "$source_bundle" \
  36. --compress \
  37. --mangle \
  38. --ecma 2020 \
  39. --comments false \
  40. --output "$output_file"
  41. node --check "$output_file"
  42. printf 'Built %s (%s bytes)\n' "$output_file" "$(wc -c < "$output_file" | tr -d ' ')"