Build/Test Tools: Change commands used for the copying .env.example file.

This switches from using the `test`/`cp` commands when copying the `.env.example` file to using `node:fs`. `test` and `cp` are not available on Windows machines.

This also adds the `.env` file to the `svn:ignore` list to prevent it from being committed accidentally.

Follow up to [59038].

Props afercia, Clorith, poena.
Fixes #52668.

git-svn-id: https://develop.svn.wordpress.org/trunk@59249 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Jonathan Desrosiers 2024-10-18 12:35:37 +00:00
parent 6bb92c17e1
commit 0dd8843c31

View File

@ -1,20 +1,12 @@
const dotenv = require( 'dotenv' );
const dotenvExpand = require( 'dotenv-expand' );
const { execSync } = require( 'child_process' );
const { constants, copyFile } = require( 'node:fs' );
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' } );
}
// Copy the default .env file when one is not present.
copyFile( '.env.example', '.env', constants.COPYFILE_EXCL, (e) => {
console.log( '.env file already exists. .env.example was not copied.' );
});
dotenvExpand.expand( dotenv.config() );