25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

74 satır
2.1 KiB

3 yıl önce
  1. # minimum required node version
  2. REQUIRED_NODE_MAJOR=10
  3. REQUIRED_NODE_MINOR=13
  4. # minimum required npm version
  5. REQUIRED_NPM_MAJOR=5
  6. REQUIRED_NPM_MINOR=5
  7. pecho() { printf %s\\n "$*"; }
  8. log() { pecho "$@"; }
  9. error() { log "ERROR: $@" >&2; }
  10. fatal() { error "$@"; exit 1; }
  11. is_cmd() { command -v "$@" >/dev/null 2>&1; }
  12. get_program_version() {
  13. PROGRAM="$1"
  14. KIND="${2:-full}"
  15. PROGRAM_VERSION_STRING=$($PROGRAM --version)
  16. PROGRAM_VERSION_STRING=${PROGRAM_VERSION_STRING#"v"}
  17. DETECTED_MAJOR=$(pecho "$PROGRAM_VERSION_STRING" | cut -s -d "." -f 1)
  18. [ -n "$DETECTED_MAJOR" ] || fatal "Cannot extract $PROGRAM major version from version string \"$PROGRAM_VERSION_STRING\""
  19. case "$DETECTED_MAJOR" in
  20. ''|*[!0-9]*)
  21. fatal "$PROGRAM_LABEL major version from \"$VERSION_STRING\" is not a number. Detected: \"$DETECTED_MAJOR\""
  22. ;;
  23. esac
  24. DETECTED_MINOR=$(pecho "$PROGRAM_VERSION_STRING" | cut -s -d "." -f 2)
  25. [ -n "$DETECTED_MINOR" ] || fatal "Cannot extract $PROGRAM minor version from version string \"$PROGRAM_VERSION_STRING\""
  26. case "$DETECTED_MINOR" in
  27. ''|*[!0-9]*)
  28. fatal "$PROGRAM_LABEL minor version from \"$VERSION_STRING\" is not a number. Detected: \"$DETECTED_MINOR\""
  29. esac
  30. case $KIND in
  31. major)
  32. echo $DETECTED_MAJOR
  33. exit;;
  34. minor)
  35. echo $DETECTED_MINOR
  36. exit;;
  37. *)
  38. echo $DETECTED_MAJOR.$DETECTED_MINOR
  39. exit;;
  40. esac
  41. echo $VERSION
  42. }
  43. compute_node_args() {
  44. ARGS=""
  45. NODE_MAJOR=$(get_program_version "node" "major")
  46. [ "$NODE_MAJOR" -eq "10" ] && ARGS="$ARGS --experimental-worker"
  47. echo $ARGS
  48. }
  49. require_minimal_version() {
  50. PROGRAM_LABEL="$1"
  51. VERSION="$2"
  52. REQUIRED_MAJOR="$3"
  53. REQUIRED_MINOR="$4"
  54. VERSION_MAJOR=$(pecho "$VERSION" | cut -s -d "." -f 1)
  55. VERSION_MINOR=$(pecho "$VERSION" | cut -s -d "." -f 2)
  56. [ "$VERSION_MAJOR" -gt "$REQUIRED_MAJOR" ] || ([ "$VERSION_MAJOR" -eq "$REQUIRED_MAJOR" ] && [ "$VERSION_MINOR" -ge "$REQUIRED_MINOR" ]) \
  57. || fatal "Your $PROGRAM_LABEL version \"$VERSION_MAJOR.$VERSION_MINOR\" is too old. $PROGRAM_LABEL $REQUIRED_MAJOR.$REQUIRED_MINOR.x or higher is required."
  58. }