diff --git a/.env b/.env.example similarity index 100% rename from .env rename to .env.example diff --git a/.gitignore b/.gitignore index 44c3769ee314d..f35d743ea866f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ # gitignore file for WordPress Core # Configuration files with possibly sensitive information +.env wp-config.php wp-tests-config.php .htaccess diff --git a/tools/local-env/scripts/start.js b/tools/local-env/scripts/start.js index b929dce0b69a8..22bb65ca8426d 100644 --- a/tools/local-env/scripts/start.js +++ b/tools/local-env/scripts/start.js @@ -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.