--- /dev/null
+#!/usr/bin/env bash
+
+if [ "$2" != "" ]
+then
+ echo >&2 "Usage: $0 [<version>]"
+ exit 1
+fi
+
+MW_DIR=$(cd $(dirname $0)/../..; pwd) # e.g. mediawiki-core/
+NPM_DIR=`mktemp -d 2>/dev/null || mktemp -d -t 'mw-update-oojs'` # e.g. /tmp/mw-update-oojs.rI0I5Vir
+
+# Prepare MediaWiki working copy
+cd $MW_DIR
+git reset resources/lib/oojs/ && git checkout resources/lib/oojs/ && git fetch origin || exit 1
+
+git checkout -B upstream-oojs origin/master || exit 1
+
+# Fetch upstream version
+cd $NPM_DIR
+if [ "$1" != "" ]
+then
+ npm install oojs@$1 || exit 1
+else
+ npm install oojs || exit 1
+fi
+
+OOJS_VERSION=$(node -e 'console.log(JSON.parse(require("fs").readFileSync("./node_modules/oojs/package.json")).version);')
+if [ "$OOJS_VERSION" == "" ]
+then
+ echo 'Could not find OOjs version'
+ exit 1
+fi
+
+# Copy file(s)
+mv ./node_modules/oojs/dist/* $MW_DIR/resources/lib/oojs/ || exit 1
+
+# Generate commit
+cd $MW_DIR || exit 1
+
+# Clean up temporary area
+rm -rf $NPM_DIR
+
+COMMITMSG=$(cat <<END
+Update OOjs to v$OOJS_VERSION
+
+Release notes:
+ https://git.wikimedia.org/blob/oojs%2Fcore.git/v$OOJS_VERSION/History.md
+END
+)
+
+git commit resources/lib/oojs/ -m "$COMMITMSG" || exit 1
+++ /dev/null
-#!/usr/bin/env bash
-
-# FIXME this script is duplicated from update-oojs-ui.sh - factor this out
-
-# This script generates a commit that updates the oojs distribution
-# ./bin/update-oojs.sh path/to/repo/for/oojs
-
-function oojshash() {
- grep "OOjs v" resources/oojs/oojs.js \
- | head -n 1 \
- | grep -Eo '\([a-z0-9]+\)' \
- | sed 's/^(//' \
- | sed 's/)$//'
-}
-
-function oojstag() {
- grep "OOjs v" resources/oojs/oojs.js \
- | head -n 1 \
- | grep -Eo '\bv[0-9a-z.-]+\b'
-}
-
-function oojsversion() {
- grep "OOjs v" resources/oojs/oojs.js \
- | head -n 1 \
- | grep -Eo '\bv[0-9a-z.-]+\b.*$'
-}
-
-# cd to the MW directory
-cd $(cd $(dirname $0)/../..; pwd)
-
-if [ "x$1" == "x" ]
-then
- echo >&2 "Usage: update-oojs.sh path/to/repo/for/oojs"
- exit 1
-fi
-
-# Undo any changes in the oojs directory
-git reset resources/oojs/
-git checkout resources/oojs/
-
-git fetch origin
-# Create a branch of MW if needed, and reset it to master
-git checkout -B update-oojs origin/master
-
-# Get the old oojs version
-OLDVERSION=$(oojshash)
-if [ "x$OLDVERSION" == "x" ]
-then
- TAG=$(oojstag)
-fi
-
-# cd to the oojs directory
-cd $1 || exit 1
-if [ "x$OLDVERSION" == "x" ]
-then
- # Try the tag
- OLDVERSION=$(git rev-parse $TAG)
- if [ $? != 0 ]
- then
- echo Could not find OOjs version
- cd -
- exit 1
- fi
-fi
-if [ "$(git rev-parse $OLDVERSION)" == "$(git rev-parse HEAD)" ]
-then
- echo "No changes (already at $OLDVERSION)"
- cd -
- exit 0
-fi
-# Build the distribution
-npm install || exit 1
-grunt || exit 1
-# Get the list of changes
-NEWCHANGES=$(git log $OLDVERSION.. --oneline --no-merges --reverse --color=never)
-NEWCHANGESDISPLAY=$(git log $OLDVERSION.. --oneline --no-merges --reverse --color=always)
-# cd back to the VisualEditor directory
-cd -
-
-# Copy files from dist/ to resources/oojs/
-cp -a $1/dist/* resources/oojs/
-# Figure out what the new version is
-NEWVERSION=$(oojsversion)
-# Generate commit summary
-COMMITMSG=$(cat <<END
-Update OOjs to $NEWVERSION
-
-New changes:
-$NEWCHANGES
-END
-)
-# Commit
-git commit resources/oojs/ -m "$COMMITMSG"
-cat >&2 <<END
-
-
-Created commit with changes:
-$NEWCHANGESDISPLAY
-END