rector/bin/build-prefixed-rector.sh

40 lines
1.4 KiB
Bash
Raw Normal View History

#!/usr/bin/env bash
# print each statement before run (https://stackoverflow.com/a/9966150/1348344)
set -x
# install php-scoper if missing
# broken due to php-parser 3, see: https://github.com/humbug/php-scoper/pull/203
# if [ ! -d vendor/bin ]; then composer bin php-scoper require humbug/php-scoper; fi
# cleanup build
2018-05-13 13:08:27 +02:00
rm -rf build/
# prefix current code to /build directory (see "scoper.inc.php" for settings)
2018-05-13 13:08:27 +02:00
php php-scoper.phar add-prefix --no-interaction --prefix='RectorPrefixed'
2018-05-13 13:08:27 +02:00
# prefix namespace in *.yml files
(find build/ -type f -name '*.yml' | xargs perl -pi -e 's/((?:\\{1,2}\w+|\w+\\{1,2})(?:\w+\\{0,2})+)/RectorPrefixed\\\1/g')
# un-prefix Rector files, so it's public API, in configs etc.
2018-05-13 03:28:39 +02:00
(find build/ -type f | xargs sed -i 's/RectorPrefixed\\Rector/Rector/g')
(find build/ -type f | xargs sed -i 's/RectorPrefixed\\\\Rector/Rector/g')
# unprefix container dump - see https://github.com/symfony/symfony/blob/226e2f3949c5843b67826aca4839c2c6b95743cf/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php#L897
2018-05-13 03:28:39 +02:00
(find build/ -type f | xargs sed -i 's/use Symfony/use RectorPrefixed\\\\Symfony/g')
# ?todo
cp composer.json build/composer.json
# rebuild composer dump
composer dump-autoload -d build --no-dev
# make bin executable
chmod +x build/bin/rector
# clear kernel cache to make use of this new one, maybe prefix this cache as well?
rm -rf /tmp/_rector_cache
# run it to test it
2018-05-13 13:08:27 +02:00
build/bin/rector