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
This commit is contained in:
Nestor Soriano 2020-09-25 11:15:12 +02:00
parent fcd9b115ca
commit d687c0c919
3 changed files with 15 additions and 7 deletions

View File

@ -1,6 +1,11 @@
#!/bin/sh
# Output colorized strings
# Output colorized strings.
#
# Usage:
#
# . $(dirname "$0")/output.sh
# output <color> "Foobar"
#
# Color codes:
# 0 - black

View File

@ -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

View File

@ -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