Skip to content

Commit

Permalink
Merge pull request #20 from Setono/env-local
Browse files Browse the repository at this point in the history
Create .env.local if it doesn't exist
  • Loading branch information
loevgaard authored Feb 18, 2022
2 parents 5d05809 + 8058f07 commit 341486d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
24 changes: 14 additions & 10 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "setono/deployer-dotenv",
"type": "library",
"description": "Easily update your .env files when deploying",
"license": "MIT",
"type": "library",
"authors": [
{
"name": "Joachim Løvgaard",
Expand All @@ -20,14 +20,7 @@
"phpunit/phpunit": "^9.5",
"setono/code-quality-pack": "^2.1"
},
"config": {
"sort-packages": true
},
"extra": {
"branch-alias": {
"dev-master": "1.1-dev"
}
},
"prefer-stable": true,
"autoload": {
"psr-4": {
"Setono\\Deployer\\DotEnv\\": "src/"
Expand All @@ -41,7 +34,18 @@
"Setono\\Deployer\\DotEnv\\": "tests/"
}
},
"prefer-stable": true,
"config": {
"allow-plugins": {
"ergebnis/composer-normalize": true,
"dealerdirect/phpcodesniffer-composer-installer": false
},
"sort-packages": true
},
"extra": {
"branch-alias": {
"dev-master": "1.1-dev"
}
},
"scripts": {
"analyse": "psalm",
"check-style": "ecs check",
Expand Down
6 changes: 6 additions & 0 deletions src/task/dotenv.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@
set('stage', 'prod');
}

// this small trick will make sure the environment (i.e. for the console) is set to the expected environment
// when running commands before the generation of the .env.local.php is run
if (!test('[ -f {{release_path}}/.env.local ]')) {
run('echo "APP_ENV={{stage}}" > {{release_path}}/.env.local');
}

if (has('previous_release') && test('[ -f {{previous_release}}/.env.{{stage}}.local ]')) {
run('cp {{previous_release}}/.env.{{stage}}.local {{release_path}}');
} else {
Expand Down

0 comments on commit 341486d

Please sign in to comment.