Skip to content

Commit 2c0b76a

Browse files
committed
copy files only of specific environments
Signed-off-by: MarioRadu <magda_marior@yahoo.com>
1 parent 2e64da5 commit 2c0b76a

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

bin/composer-post-install-script.php

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,42 @@ function copyFile(array $file): void
99
if (is_readable($file['destination'])) {
1010
echo "File {$file['destination']} already exists." . PHP_EOL;
1111
} else {
12-
if (! copy($file['source'], $file['destination'])) {
13-
echo "Cannot copy {$file['source']} file to {$file['destination']}" . PHP_EOL;
12+
if (! isDevModeEnabled() && $file['environment'] === 'local') {
13+
echo "Skipping the copy of {$file['source']} due to environment settings." . PHP_EOL;
1414
} else {
15-
echo "File {$file['source']} copied successfully to {$file['destination']}." . PHP_EOL;
15+
if (! copy($file['source'], $file['destination'])) {
16+
echo "Cannot copy {$file['source']} file to {$file['destination']}" . PHP_EOL;
17+
} else {
18+
echo "File {$file['source']} copied successfully to {$file['destination']}." . PHP_EOL;
19+
}
1620
}
1721
}
1822
}
1923

24+
function isDevModeEnabled(): bool
25+
{
26+
return file_exists('config/autoload/development.local.php');
27+
}
28+
29+
// when adding files to the below array the `source` and `destination` must be relative to the project root folder
30+
// the `environment` key will indicate when the file should be copied,
31+
// if the value is `production` the file will be copied on both production and local environments,
32+
// if the value is `local` the file will be copied only on local environments
2033
$files = [
2134
[
2235
'source' => 'config/autoload/local.php.dist',
2336
'destination' => 'config/autoload/local.php',
37+
'environment' => 'production',
2438
],
2539
[
2640
'source' => 'config/autoload/local.test.php.dist',
2741
'destination' => 'config/autoload/local.test.php',
42+
'environment' => 'local',
2843
],
2944
[
3045
'source' => 'vendor/dotkernel/dot-mail/config/mail.global.php.dist',
3146
'destination' => 'config/autoload/mail.global.php',
47+
'environment' => 'production',
3248
],
3349
];
3450

composer.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@
104104
"post-create-project-cmd": [
105105
"@development-enable"
106106
],
107+
"post-update-cmd": [
108+
"php bin/composer-post-install-script.php"
109+
],
107110
"development-disable": "laminas-development-mode disable",
108111
"development-enable": "laminas-development-mode enable",
109112
"development-status": "laminas-development-mode status",

0 commit comments

Comments
 (0)