From d687c0c919338fce802d2051e43eb7dc8dfc26d7 Mon Sep 17 00:00:00 2001 From: Nestor Soriano Date: Fri, 25 Sep 2020 11:15:12 +0200 Subject: [PATCH] Improvements on prefix-vendor-namespaces.sh - Prefix also Container's composer.json - Use one single variant for sed, creating a backup file and later deleting it --- bin/output.sh | 7 ++++++- bin/package-update.sh | 1 + bin/prefix-vendor-namespaces.sh | 14 ++++++++------ 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/bin/output.sh b/bin/output.sh index a225de4164c..e550105f6a5 100644 --- a/bin/output.sh +++ b/bin/output.sh @@ -1,6 +1,11 @@ #!/bin/sh -# Output colorized strings +# Output colorized strings. +# +# Usage: +# +# . $(dirname "$0")/output.sh +# output "Foobar" # # Color codes: # 0 - black diff --git a/bin/package-update.sh b/bin/package-update.sh index 616d16ea330..00cd1dc635d 100755 --- a/bin/package-update.sh +++ b/bin/package-update.sh @@ -1,5 +1,6 @@ #!/bin/sh +# See output.sh for an explanation of the available color codes. . $(dirname "$0")/output.sh if [ ! -d "packages/" ]; then diff --git a/bin/prefix-vendor-namespaces.sh b/bin/prefix-vendor-namespaces.sh index 0360e08bd04..ef47652c4b3 100755 --- a/bin/prefix-vendor-namespaces.sh +++ b/bin/prefix-vendor-namespaces.sh @@ -1,5 +1,6 @@ #!/bin/sh +# See output.sh for an explanation of available the color codes. . $(dirname "$0")/output.sh output 6 "Prefixing the appropriate vendor namespaces with Automattic\WooCommerce\Vendor" @@ -7,9 +8,10 @@ output 6 "Prefixing the appropriate vendor namespaces with Automattic\WooCommerc # Replace "League\Container" in "use" and "namespace" with "Automattic\WooCommerce\Vendor\League\Container". REGEX='s/^[[:space:]]*(use|namespace)[[:space:]]*(League\\Container)/\1 Automattic\\WooCommerce\\Vendor\\\2/g' -# macOS and Linux have a slightly different syntax for 'sed -i' so we need two versions. -if [[ "$OSTYPE" == "darwin"* ]]; then - find ./vendor/league/container -type f -name '*.php' -print0 | xargs -0 sed -i '' -E -e "$REGEX" -else - find ./vendor/league/container -type f -name '*.php' -print0 | xargs -0 sed -i -E -e "$REGEX" -fi +find ./vendor/league/container -iname '*.php' -exec sed -i '.bak' -E -e "$REGEX" {} \; +find ./vendor/league/container -name "*.php.bak" -type f -delete + +# Replace too in the composer.json file for the package. +sed -i '.bak' -E -e "s/\"(League\\\\\\\Container)/\"Automattic\\\\\\\WooCommerce\\\\\\\Vendor\\\\\\\\\1/g" vendor/league/container/composer.json +rm -f vendor/league/container/composer.json.bak +