Build Tools: Allow easier customization of the .env file.

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, desrosj.
Fixes #52668.


git-svn-id: https://develop.svn.wordpress.org/trunk@59038 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Timothy Jacobs 2024-09-17 22:25:03 +00:00
parent 98a9f6481a
commit 3cd3a00c76
3 changed files with 15 additions and 0 deletions

View File

1
.gitignore vendored
View File

@ -1,6 +1,7 @@
# gitignore file for WordPress Core
# Configuration files with possibly sensitive information
.env
wp-config.php
wp-tests-config.php
.htaccess

View File

@ -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.