update-oojs-ui.sh 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #!/bin/bash -eu
  2. # This script generates a commit that updates our copy of OOjs UI
  3. if [ -n "${2:-}" ]
  4. then
  5. # Too many parameters
  6. echo >&2 "Usage: $0 [<version>]"
  7. exit 1
  8. fi
  9. REPO_DIR=$(cd "$(dirname $0)/.."; pwd) # Root dir of the git repo working tree
  10. TARGET_DIR="lib/oojs-ui" # Destination relative to the root of the repo
  11. NPM_DIR=$(mktemp -d 2>/dev/null || mktemp -d -t 'update-oojs-ui') # e.g. /tmp/update-oojs-ui.rI0I5Vir
  12. # Prepare working tree
  13. cd "$REPO_DIR"
  14. git reset -- $TARGET_DIR
  15. git checkout -- $TARGET_DIR
  16. git fetch origin
  17. git checkout -B upstream-oojs-ui origin/master
  18. # Fetch upstream version
  19. cd $NPM_DIR
  20. if [ -n "${1:-}" ]
  21. then
  22. npm install "oojs-ui@$1"
  23. else
  24. npm install oojs-ui
  25. fi
  26. OOJSUI_VERSION=$(node -e 'console.log(require("./node_modules/oojs-ui/package.json").version);')
  27. if [ "$OOJSUI_VERSION" == "" ]
  28. then
  29. echo 'Could not find OOjs UI version'
  30. exit 1
  31. fi
  32. # Copy files
  33. # - Exclude the minimised distribution files
  34. # - Support: IE9
  35. # VE requires SVG support, but IE9 doesn't support the CSS background fallback
  36. # so ends up using the PNGs. Otherwise they would not be required.
  37. rsync --force --recursive --delete --exclude 'oojs-ui*.min.*' --exclude 'oojs-ui.js' ./node_modules/oojs-ui/dist/ "$REPO_DIR/$TARGET_DIR"
  38. # Clean up temporary area
  39. rm -rf "$NPM_DIR"
  40. # Generate commit
  41. cd $REPO_DIR
  42. COMMITMSG=$(cat <<END
  43. Update OOjs UI to v$OOJSUI_VERSION
  44. Release notes:
  45. https://git.wikimedia.org/blob/oojs%2Fui.git/v$OOJSUI_VERSION/History.md
  46. END
  47. )
  48. # Stage deletion, modification and creation of files. Then commit.
  49. git add --update $TARGET_DIR
  50. git add $TARGET_DIR
  51. git commit -m "$COMMITMSG"