From 8ecdbb82b00f48110c9812904bb0da110d8a32b6 Mon Sep 17 00:00:00 2001 From: su-ex Date: Tue, 28 Sep 2021 12:46:07 +0200 Subject: [PATCH] Add helpers for overlaying package.json --- merge_helpers.sh | 53 +++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 50 insertions(+), 3 deletions(-) diff --git a/merge_helpers.sh b/merge_helpers.sh index d9562af..7900720 100755 --- a/merge_helpers.sh +++ b/merge_helpers.sh @@ -90,15 +90,15 @@ automatic_i18n_reversion() { local skip_commit="$1" pushd "$SCHILDI_ROOT/matrix-react-sdk" > /dev/null - revert_i18n_changes "$i18n_path" $skip_commit + revert_i18n_changes "$i18n_path" "$skip_commit" popd > /dev/null pushd "$SCHILDI_ROOT/element-web" > /dev/null - revert_i18n_changes "$i18n_path" $skip_commit + revert_i18n_changes "$i18n_path" "$skip_commit" popd > /dev/null pushd "$SCHILDI_ROOT/element-desktop" > /dev/null - revert_i18n_changes "$i18n_path" $skip_commit + revert_i18n_changes "$i18n_path" "$skip_commit" popd > /dev/null } @@ -124,3 +124,50 @@ automatic_i18n_adjustment() { apply_i18n_changes "$i18n_path" popd > /dev/null } + +revert_packagejson_changes() { + local path="$1" + local skip_commit="$2" + + git checkout upstream/master -- "$path" + + if [[ "$skip_commit" != [Yy]* ]]; then + git commit -m "Automatic package.json reversion" || true + fi +} + +apply_packagejson_overlay() { + local orig_path="$1" + local overlay_path="$2" + + # see: https://stackoverflow.com/a/24904276 + new_content=`jq -s '.[0] * .[1]' "$orig_path" "$overlay_path"` + + echo "$new_content" > "$orig_path" + git add "$orig_path" + git commit -m "Automatic package.json adjustment" || true +} + +automatic_packagejson_reversion() { + local skip_commit="$1" + + pushd "$SCHILDI_ROOT/element-web" > /dev/null + revert_packagejson_changes "package.json" "$skip_commit" + popd > /dev/null + + pushd "$SCHILDI_ROOT/element-desktop" > /dev/null + revert_packagejson_changes "package.json" "$skip_commit" + popd > /dev/null +} + +automatic_packagejson_adjustment() { + # element-web + pushd "$SCHILDI_ROOT/element-web" > /dev/null + apply_packagejson_overlay "package.json" "overlay-package.json" + popd > /dev/null + + # element-desktop + pushd "$SCHILDI_ROOT/element-desktop" > /dev/null + apply_packagejson_overlay "package.json" "overlay-package.json" + popd > /dev/null +}