Merge "Add autocomplete for Special:Redirect subpages"
[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 $TARGET_DIR && git checkout $TARGET_DIR && git fetch origin &&
19 git checkout -B upstream-oojs-ui origin/master || exit 1
20
21 # Fetch upstream version
22 cd $NPM_DIR
23 if [ -n "$1" ]
24 then
25 npm install "oojs-ui@$1" || exit 1
26 else
27 npm install oojs-ui || exit 1
28 fi
29
30 OOJSUI_VERSION=$(node -e 'console.log(require("./node_modules/oojs-ui/package.json").version);')
31 if [ "$OOJSUI_VERSION" == "" ]
32 then
33 echo 'Could not find OOjs UI version'
34 exit 1
35 fi
36
37 # Copy files
38 # - Exclude the minimised distribution files and RTL sheets for non-CSSJanus environments
39 rsync --force --recursive --delete --exclude 'oojs-ui*.min.*' --exclude 'oojs-ui*.rtl.css' ./node_modules/oojs-ui/dist/ "$REPO_DIR/$TARGET_DIR" || exit 1
40
41 # Clean up temporary area
42 rm -rf "$NPM_DIR"
43
44 # Generate commit
45 cd $REPO_DIR || exit 1
46
47 COMMITMSG=$(cat <<END
48 Update OOjs UI to v$OOJSUI_VERSION
49
50 Release notes:
51 https://git.wikimedia.org/blob/oojs%2Fui.git/v$OOJSUI_VERSION/History.md
52 END
53 )
54
55 # Stage deletion, modification and creation of files. Then commit.
56 git add --update $TARGET_DIR && git add $TARGET_DIR && git commit -m "$COMMITMSG" || exit 1