Skip to content

Commit

Permalink
Allow easier customization of the .env file
Browse files Browse the repository at this point in the history
The .env file allows for configuring how the WordPress Local environment should be configured. However, because the file is version controlled, developers must be careful not to commit their modifications.

This commit renames the .env file to be .env.example. During env start, the .env.example file is copied to .env if it does not exist. This allows for contributors to continue using the project without thinking about .env and to make changes when needed. This brings WordPress Core into the dotenv project guidelines.

Props johnbillion, afragen, h71.
Fixes #52668.
  • Loading branch information
TimothyBJacobs committed Sep 17, 2024
1 parent 7dad836 commit 0580ae0
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
File renamed without changes.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# gitignore file for WordPress Core

# Configuration files with possibly sensitive information
.env
wp-config.php
wp-tests-config.php
.htaccess
Expand Down
14 changes: 14 additions & 0 deletions tools/local-env/scripts/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,20 @@ const dotenv = require( 'dotenv' );
const dotenvExpand = require( 'dotenv-expand' );
const { execSync } = require( 'child_process' );

try {
execSync( 'test -f .env', { stdio: 'inherit' } );
} catch ( e ) {
// test exits with a status code of 1 if the test fails.
// Alert the user on any other failure.
if ( e.status !== 1 ) {
throw e;
}

// The file does not exist, copy over the default example file.
execSync( 'cp .env.example .env', { stdio: 'inherit' } );
}


dotenvExpand.expand( dotenv.config() );

// Check if the Docker service is running.
Expand Down

0 comments on commit 0580ae0

Please sign in to comment.