Merge "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 mkdir -p "$REPO_DIR/$TARGET_DIR/themes/apex/images"
47 cp ./node_modules/oojs-ui/dist/oojs-ui.js "$REPO_DIR/$TARGET_DIR"
48 cp ./node_modules/oojs-ui/dist/{oojs-ui-mediawiki-noimages.css,oojs-ui-mediawiki.js} "$REPO_DIR/$TARGET_DIR"
49 cp ./node_modules/oojs-ui/dist/{oojs-ui-apex-noimages.css,oojs-ui-apex.js} "$REPO_DIR/$TARGET_DIR"
50 cp -R ./node_modules/oojs-ui/dist/i18n "$REPO_DIR/$TARGET_DIR"
51 cp -R ./node_modules/oojs-ui/dist/images "$REPO_DIR/$TARGET_DIR"
52 cp -R ./node_modules/oojs-ui/dist/themes/mediawiki/images "$REPO_DIR/$TARGET_DIR/themes/mediawiki"
53 cp ./node_modules/oojs-ui/src/themes/mediawiki/*.json "$REPO_DIR/$TARGET_DIR/themes/mediawiki"
54 cp -R ./node_modules/oojs-ui/dist/themes/apex/images "$REPO_DIR/$TARGET_DIR/themes/apex"
55 cp ./node_modules/oojs-ui/src/themes/apex/*.json "$REPO_DIR/$TARGET_DIR/themes/apex"
56
57 # Clean up temporary area
58 rm -rf "$NPM_DIR"
59
60 # Generate commit
61 cd $REPO_DIR
62
63 COMMITMSG=$(cat <<END
64 Update OOjs UI to v$OOJSUI_VERSION
65
66 Release notes:
67 https://git.wikimedia.org/blob/oojs%2Fui.git/v$OOJSUI_VERSION/History.md
68 END
69 )
70
71 # Update composer.json as well
72 composer require oojs/oojs-ui $OOJSUI_VERSION --no-update
73
74 # Stage deletion, modification and creation of files. Then commit.
75 git add --update $TARGET_DIR
76 git add $TARGET_DIR
77 git add composer.json
78 git commit -m "$COMMITMSG"