From 2c0b76a169a3ff0c93c85991858a099f7a1b0649 Mon Sep 17 00:00:00 2001 From: MarioRadu Date: Tue, 10 Dec 2024 16:30:19 +0200 Subject: [PATCH] copy files only of specific environments Signed-off-by: MarioRadu --- bin/composer-post-install-script.php | 22 +++++++++++++++++++--- composer.json | 3 +++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/bin/composer-post-install-script.php b/bin/composer-post-install-script.php index af2e8a9..23f5011 100644 --- a/bin/composer-post-install-script.php +++ b/bin/composer-post-install-script.php @@ -9,26 +9,42 @@ function copyFile(array $file): void if (is_readable($file['destination'])) { echo "File {$file['destination']} already exists." . PHP_EOL; } else { - if (! copy($file['source'], $file['destination'])) { - echo "Cannot copy {$file['source']} file to {$file['destination']}" . PHP_EOL; + if (! isDevModeEnabled() && $file['environment'] === 'local') { + echo "Skipping the copy of {$file['source']} due to environment settings." . PHP_EOL; } else { - echo "File {$file['source']} copied successfully to {$file['destination']}." . PHP_EOL; + if (! copy($file['source'], $file['destination'])) { + echo "Cannot copy {$file['source']} file to {$file['destination']}" . PHP_EOL; + } else { + echo "File {$file['source']} copied successfully to {$file['destination']}." . PHP_EOL; + } } } } +function isDevModeEnabled(): bool +{ + return file_exists('config/autoload/development.local.php'); +} + +// when adding files to the below array the `source` and `destination` must be relative to the project root folder +// the `environment` key will indicate when the file should be copied, +// if the value is `production` the file will be copied on both production and local environments, +// if the value is `local` the file will be copied only on local environments $files = [ [ 'source' => 'config/autoload/local.php.dist', 'destination' => 'config/autoload/local.php', + 'environment' => 'production', ], [ 'source' => 'config/autoload/local.test.php.dist', 'destination' => 'config/autoload/local.test.php', + 'environment' => 'local', ], [ 'source' => 'vendor/dotkernel/dot-mail/config/mail.global.php.dist', 'destination' => 'config/autoload/mail.global.php', + 'environment' => 'production', ], ]; diff --git a/composer.json b/composer.json index 5e018ac..2b6d264 100644 --- a/composer.json +++ b/composer.json @@ -104,6 +104,9 @@ "post-create-project-cmd": [ "@development-enable" ], + "post-update-cmd": [ + "php bin/composer-post-install-script.php" + ], "development-disable": "laminas-development-mode disable", "development-enable": "laminas-development-mode enable", "development-status": "laminas-development-mode status",