From ad01010232e95a2c08ceb97f0b29b8377dcd197e Mon Sep 17 00:00:00 2001 From: Julien DAUPHANT Date: Mon, 20 Mar 2023 01:10:53 +0100 Subject: [PATCH] Update merge Script --- scripts/merge-patches.sh | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/scripts/merge-patches.sh b/scripts/merge-patches.sh index ecce1a490..3767dbdd3 100644 --- a/scripts/merge-patches.sh +++ b/scripts/merge-patches.sh @@ -22,13 +22,20 @@ function merge_patches() { # Check if the package version exists and if the patch needs to be updated if [ "$PACKAGE_VERSION" == "null" ] || [[ "$PATCH_FILE" =~ "$PACKAGE_NAME+$PACKAGE_VERSION".patch ]]; then echo "Package '$PACKAGE_NAME' not found in package.json or patch already up-to-date. Skipping patch update." + echo "" continue fi # Create a subfolder for the current package inside the temporary directory PACKAGE_TEMP_DIR="$TEMP_DIR/$PATCH_DIR" + if [ -d "$PACKAGE_TEMP_DIR" ]; then + echo "$PACKAGE_TEMP_DIR already exist, skipping patch update. Remove it to regenerate." + echo "" + continue + fi + mkdir -p "$PACKAGE_TEMP_DIR" - LOG_FILE=$PACKAGE_TEMP_DIR/result.log + LOG_FILE="$PACKAGE_TEMP_DIR".log # Install the package in the package subfolder cd "$PACKAGE_TEMP_DIR" @@ -54,7 +61,7 @@ function merge_patches() { yarn patch-package "$PACKAGE_NAME" > $LOG_FILE 2>&1 # Move the new patch file to the old patch file's location - mv patches/"$PACKAGE_NAME"*.patch "$(dirname $PATCH_PATH)" + mv patches/*.patch "$(dirname $PATCH_PATH)" rm $PATCH_PATH # Clean up the package subfolder @@ -78,11 +85,12 @@ function continue_patches() { # Iterate through the package subfolders for PACKAGE_TEMP_DIR in "$TEMP_DIR"/*; do - echo "# Manage $PATCH_PATH" PATCH_DIR="$PATCHES_DIR/$(basename "$PACKAGE_TEMP_DIR")" PATCH_PATH="$PATCH_DIR"/*.patch - PATCH_FILE=$(basename $PATCH_PATH) + PATCH_FILE=$(basename $PATCH_PATH) PACKAGE_NAME=$(echo "$PATCH_FILE" | cut -d'+' -f1) + LOG_FILE="$PACKAGE_TEMP_DIR".log + echo "# Manage $PATCH_PATH" # Check for conflicts CONFLICTS=$(grep -lr "<<<<<<<" "$PACKAGE_TEMP_DIR/node_modules/$PACKAGE_NAME") || true @@ -97,14 +105,16 @@ function continue_patches() { else # If there are no conflicts, generate a new patch file cd "$PACKAGE_TEMP_DIR" - yarn patch-package "$PACKAGE_NAME" + yarn patch-package "$PACKAGE_NAME" 2>&1 > $LOG_FILE || true # Move the new patch file to the old patch file's location - mv patches/"$PACKAGE_NAME"*.patch "$(dirname $PATCH_PATH)" + mv patches/*.patch "$(dirname $PATCH_PATH)" + rm $PATCH_PATH # Clean up the package subfolder cd "$TEMP_DIR" rm -rf "$(basename "$PACKAGE_TEMP_DIR")" + echo "Patch Done and temp file cleaned" fi done