Skip to content

Commit

Permalink
wp-env: start: refactor computation of command output
Browse files Browse the repository at this point in the history
- Refactor repeating logic into getPublicDockerPort
- Remove trailing newlines from dockerCompose output
- Refactor evaluation of spinner.prefixText so as to clearly reveal
  newlines.
  • Loading branch information
mcsf committed Dec 4, 2024
1 parent 720fdfe commit 54bbfcd
Showing 1 changed file with 31 additions and 31 deletions.
62 changes: 31 additions & 31 deletions packages/env/lib/commands/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,50 +236,50 @@ module.exports = async function start( {
const siteUrl = config.env.development.config.WP_SITEURL;
const testsSiteUrl = config.env.tests.config.WP_SITEURL;

const { out: mySQLAddress } = await dockerCompose.port(
const mySQLPort = await getPublicDockerPort(
'mysql',
3306,
dockerComposeConfig
);
const mySQLPort = mySQLAddress.split( ':' ).pop();

const { out: testsMySQLAddress } = await dockerCompose.port(
const testsMySQLPort = await getPublicDockerPort(
'tests-mysql',
3306,
dockerComposeConfig
);
const testsMySQLPort = testsMySQLAddress.split( ':' ).pop();

let phpmyadminPort;
if ( phpmyadmin ) {
const { out: phpmyadminAddress } = await dockerCompose.port(
'phpmyadmin',
80,
dockerComposeConfig
);
phpmyadminPort = phpmyadminAddress.split( ':' ).pop();
}

spinner.prefixText = 'WordPress development site started'
.concat( siteUrl ? ` at ${ siteUrl }` : '.' )
.concat( '\n' )
.concat( 'WordPress test site started' )
.concat( testsSiteUrl ? ` at ${ testsSiteUrl }` : '.' )
.concat( '\n' )
.concat( `MySQL is listening on port ${ mySQLPort }` )
.concat(
`MySQL for automated testing is listening on port ${ testsMySQLPort }`
)
.concat(
phpmyadminPort
? `phpMyAdmin is listening on port ${ phpmyadminPort }`
: ''
)
.concat( '\n' );

const phpmyadminPort = phpmyadmin
? await getPublicDockerPort( 'phpmyadmin', 80, dockerComposeConfig )
: null;

spinner.prefixText = [
'WordPress development site started' +
( siteUrl ? ` at ${ siteUrl }` : '.' ),
'WordPress test site started' +
( testsSiteUrl ? ` at ${ testsSiteUrl }` : '.' ),
`MySQL is listening on port ${ mySQLPort }`,
`MySQL for automated testing is listening on port ${ testsMySQLPort }`,
phpmyadminPort && `phpMyAdmin is listening on port ${ phpmyadminPort }`,
]
.filter( Boolean )
.join( '\n' );
spinner.prefixText += '\n\n';
spinner.text = 'Done!';
};

async function getPublicDockerPort(
service,
containerPort,
dockerComposeConfig
) {
const { out: address } = await dockerCompose.port(
service,
containerPort,
dockerComposeConfig
);
return address.split( ':' ).pop().trim();
}

/**
* Checks for legacy installs and provides
* the user the option to delete them.
Expand Down

0 comments on commit 54bbfcd

Please sign in to comment.