Skip to content
49 changes: 49 additions & 0 deletions apps/cli/commands/site/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,55 @@ export const registerCommand = ( yargs: StudioArgv ) => {
let adminPassword = argv.adminPassword;
let adminEmail = argv.adminEmail;

// Validate and resolve the WordPress version against available versions before prompting
if ( wpVersion && wpVersion !== 'latest' && wpVersion !== 'nightly' ) {
try {
logger.reportStart( LoggerAction.VALIDATE, __( 'Checking WordPress version…' ) );
const availableVersions = await fetchWordPressVersions();
const matchedVersion = availableVersions.find(
( v ) => v.value === wpVersion || v.value.startsWith( wpVersion + '.' )

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of just validating that a matching version exists, should we resolve wpVersion to the matched full version? For example, --wp 6.7 actually downloads 6.7.2 instead of 6.7.0.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems Playground already handles this and resolves to the latest patch, so feel free to disregard.
The behavior is still somewhat obscure based on Playground behavior, up to you if you feel it makes sense to handle it here or leave as is.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion! I think it's still valuable to add the resolution here, and maybe also add a log message to clarify the resolution if short versions are provided.

);
if ( ! matchedVersion ) {
const versionLabels = availableVersions
.filter( ( v ) => v.value !== 'latest' )
.map( ( v ) => v.label );
logger.reportError(
new LoggerError(
sprintf(
/* translators: %1$s: requested version, %2$s: list of available versions */
__( 'WordPress version "%1$s" is not available. Available versions: %2$s' ),
wpVersion,
versionLabels.join( ', ' )
)
)
);
return;
}
// Resolve short versions to full versions (e.g. "6.7" → "6.7.2")
if ( matchedVersion.value !== wpVersion ) {
logger.reportSuccess(
sprintf(
/* translators: %1$s: requested version, %2$s: resolved version */
__( 'WordPress version: %1$s → %2$s' ),
wpVersion,
matchedVersion.value
)
);
} else {
logger.reportSuccess(
sprintf(
/* translators: %s: WordPress version */
__( 'WordPress version: %s' ),
wpVersion
)
);
}
wpVersion = matchedVersion.value;
} catch {
// If we can't fetch versions (network issue), let it proceed and fail later
}
}

try {
if ( process.stdin.isTTY ) {
if ( ! siteName ) {
Expand Down
Loading