Use ResourceLoaderImageModule to serve icons for OOjs UI
[lhc/web/wiklou.git] / maintenance / resources / update-oojs-ui.sh
1 #!/usr/bin/env bash
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 && git checkout composer.json &&
19 git reset $TARGET_DIR && git checkout $TARGET_DIR && git fetch origin &&
20 git checkout -B upstream-oojs-ui origin/master || exit 1
21
22 # Fetch upstream version
23 cd $NPM_DIR
24 if [ -n "$1" ]
25 then
26 npm install "oojs-ui@$1" || exit 1
27 else
28 npm install oojs-ui || exit 1
29 fi
30
31 OOJSUI_VERSION=$(node -e 'console.log(require("./node_modules/oojs-ui/package.json").version);')
32 if [ "$OOJSUI_VERSION" == "" ]
33 then
34 echo 'Could not find OOjs UI version'
35 exit 1
36 fi
37
38 # Copy files, picking the necessary ones from source and distribution
39 rm -r "$REPO_DIR/$TARGET_DIR" || exit 1
40 mkdir -p "$REPO_DIR/$TARGET_DIR/i18n" || exit 1
41 mkdir -p "$REPO_DIR/$TARGET_DIR/images" || exit 1
42 mkdir -p "$REPO_DIR/$TARGET_DIR/themes/mediawiki/images" || exit 1
43 cp ./node_modules/oojs-ui/dist/{oojs-ui-mediawiki-noimages.css,oojs-ui-mediawiki.js,oojs-ui.js} "$REPO_DIR/$TARGET_DIR" || exit 1
44 cp -R ./node_modules/oojs-ui/dist/i18n "$REPO_DIR/$TARGET_DIR" || exit 1
45 cp -R ./node_modules/oojs-ui/dist/images "$REPO_DIR/$TARGET_DIR" || exit 1
46 cp -R ./node_modules/oojs-ui/dist/themes/mediawiki/images "$REPO_DIR/$TARGET_DIR/themes/mediawiki" || exit 1
47 cp ./node_modules/oojs-ui/src/themes/mediawiki/*.json "$REPO_DIR/$TARGET_DIR/themes/mediawiki" || exit 1
48
49 # Clean up temporary area
50 rm -rf "$NPM_DIR"
51
52 # Generate commit
53 cd $REPO_DIR || exit 1
54
55 COMMITMSG=$(cat <<END
56 Update OOjs UI to v$OOJSUI_VERSION
57
58 Release notes:
59 https://git.wikimedia.org/blob/oojs%2Fui.git/v$OOJSUI_VERSION/History.md
60 END
61 )
62
63 # Update composer.json as well
64 composer require oojs/oojs-ui $OOJSUI_VERSION --no-update
65
66 # Stage deletion, modification and creation of files. Then commit.
67 git add --update $TARGET_DIR && git add $TARGET_DIR && git add composer.json && git commit -m "$COMMITMSG" || exit 1