Remove unused 'XMPGetInfo' and 'XMPGetResults' hooks
[lhc/web/wiklou.git] / maintenance / resources / update-oojs-ui.sh
1 #!/bin/bash -eu
2
3 # This script generates a commit that updates our copy of OOjs UI
4
5 if [ -n "${2:-}" ]
6 then
7 # Too many parameters
8 echo >&2 "Usage: $0 [<version>]"
9 exit 1
10 fi
11
12 REPO_DIR=$(cd "$(dirname $0)/../.."; pwd) # Root dir of the git repo working tree
13 TARGET_DIR="resources/lib/oojs-ui" # Destination relative to the root of the repo
14 NPM_DIR=$(mktemp -d 2>/dev/null || mktemp -d -t 'update-oojs-ui') # e.g. /tmp/update-oojs-ui.rI0I5Vir
15
16 # Prepare working tree
17 cd "$REPO_DIR"
18 git reset composer.json
19 git checkout composer.json
20 git reset -- $TARGET_DIR
21 git checkout -- $TARGET_DIR
22 git fetch origin
23 git checkout -B upstream-oojs-ui origin/master
24
25 # Fetch upstream version
26 cd $NPM_DIR
27 if [ -n "${1:-}" ]
28 then
29 npm install "oojs-ui@$1"
30 else
31 npm install oojs-ui
32 fi
33
34 OOJSUI_VERSION=$(node -e 'console.log(require("./node_modules/oojs-ui/package.json").version);')
35 if [ "$OOJSUI_VERSION" == "" ]
36 then
37 echo 'Could not find OOjs UI version'
38 exit 1
39 fi
40
41 # Copy files, picking the necessary ones from source and distribution
42 rm -r "$REPO_DIR/$TARGET_DIR"
43 mkdir -p "$REPO_DIR/$TARGET_DIR/i18n"
44 mkdir -p "$REPO_DIR/$TARGET_DIR/images"
45 mkdir -p "$REPO_DIR/$TARGET_DIR/themes/mediawiki/images"
46 cp ./node_modules/oojs-ui/dist/{oojs-ui-mediawiki-noimages.css,oojs-ui-mediawiki.js,oojs-ui.js} "$REPO_DIR/$TARGET_DIR"
47 cp -R ./node_modules/oojs-ui/dist/i18n "$REPO_DIR/$TARGET_DIR"
48 cp -R ./node_modules/oojs-ui/dist/images "$REPO_DIR/$TARGET_DIR"
49 cp -R ./node_modules/oojs-ui/dist/themes/mediawiki/images "$REPO_DIR/$TARGET_DIR/themes/mediawiki"
50 cp ./node_modules/oojs-ui/src/themes/mediawiki/*.json "$REPO_DIR/$TARGET_DIR/themes/mediawiki"
51
52 # Clean up temporary area
53 rm -rf "$NPM_DIR"
54
55 # Generate commit
56 cd $REPO_DIR
57
58 COMMITMSG=$(cat <<END
59 Update OOjs UI to v$OOJSUI_VERSION
60
61 Release notes:
62 https://git.wikimedia.org/blob/oojs%2Fui.git/v$OOJSUI_VERSION/History.md
63 END
64 )
65
66 # Update composer.json as well
67 composer require oojs/oojs-ui $OOJSUI_VERSION --no-update
68
69 # Stage deletion, modification and creation of files. Then commit.
70 git add --update $TARGET_DIR
71 git add $TARGET_DIR
72 git add composer.json
73 git commit -m "$COMMITMSG"