summaryrefslogtreecommitdiff
path: root/maintenance/resources/update-oojs-ui.sh
blob: f6245f2723f78d146339eaab92e6d2c4df4a0df0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/env bash

# This script generates a commit that updates our copy of OOjs UI

if [ -n "$2" ]
then
	# Too many parameters
	echo >&2 "Usage: $0 [<version>]"
	exit 1
fi

REPO_DIR=$(cd "$(dirname $0)/../.."; pwd) # Root dir of the git repo working tree
TARGET_DIR="resources/lib/oojs-ui" # Destination relative to the root of the repo
NPM_DIR=$(mktemp -d 2>/dev/null || mktemp -d -t 'update-oojs-ui') # e.g. /tmp/update-oojs-ui.rI0I5Vir

# Prepare working tree
cd "$REPO_DIR" &&
git reset composer.json && git checkout composer.json &&
git reset $TARGET_DIR && git checkout $TARGET_DIR && git fetch origin &&
git checkout -B upstream-oojs-ui origin/master || exit 1

# Fetch upstream version
cd $NPM_DIR
if [ -n "$1" ]
then
	npm install "oojs-ui@$1" || exit 1
else
	npm install oojs-ui || exit 1
fi

OOJSUI_VERSION=$(node -e 'console.log(require("./node_modules/oojs-ui/package.json").version);')
if [ "$OOJSUI_VERSION" == "" ]
then
	echo 'Could not find OOjs UI version'
	exit 1
fi

# Copy files, excluding:
# * the Apex theme files,
# * the minimised distribution files, and
# * the RTL sheets for non-CSSJanus environments
# * the raster- and vector-only distribution sheets
rsync --force --recursive --delete \
	--exclude '*apex*' \
	--exclude 'oojs-ui*.min.*' \
	--exclude 'oojs-ui*.rtl.css' \
	--exclude 'oojs-ui*.raster.css' \
	--exclude 'oojs-ui*.vector.css' \
	./node_modules/oojs-ui/dist/ "$REPO_DIR/$TARGET_DIR" || exit 1

# Clean up temporary area
rm -rf "$NPM_DIR"

# Generate commit
cd $REPO_DIR || exit 1

COMMITMSG=$(cat <<END
Update OOjs UI to v$OOJSUI_VERSION

Release notes:
 https://git.wikimedia.org/blob/oojs%2Fui.git/v$OOJSUI_VERSION/History.md
END
)

# Update composer.json as well
composer require oojs/oojs-ui $OOJSUI_VERSION --no-update

# Stage deletion, modification and creation of files. Then commit.
git add --update $TARGET_DIR && git add $TARGET_DIR && git add composer.json && git commit -m "$COMMITMSG" || exit 1