Skip to content

Commit

Permalink
copy files only of specific environments
Browse files Browse the repository at this point in the history
Signed-off-by: MarioRadu <[email protected]>
  • Loading branch information
MarioRadu committed Dec 10, 2024
1 parent 2e64da5 commit 2c0b76a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
22 changes: 19 additions & 3 deletions bin/composer-post-install-script.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
],
];

Expand Down
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 2c0b76a

Please sign in to comment.