Skip to content
This repository was archived by the owner on May 9, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/commands/create/inquirer.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ function marshalWordPress( original, answers ) {
wp.type = answers.wordpressType;
}

if ( answers.wordpressVersion ) {
wp.version = answers.wordpressVersion;
}

if ( answers.emptyContent ) {
wp.purify = true;
}
Expand All @@ -79,6 +83,7 @@ module.exports = function makeInquirer( { prompt } ) {

const {
type: wordpressType,
version: wordpressVersion,
title: wordpressTitle,
username: wordpressUsername,
password: wordpressPassword,
Expand Down Expand Up @@ -149,6 +154,17 @@ module.exports = function makeInquirer( { prompt } ) {
return installWp || wrongType;
},
},
{
name: 'wordpressVersion',
type: 'input',
message: 'What version of WordPress would you like to install?',
default: 'latest',
when( answers ) {
const installWp = answers.wordpress === true;
const nonDevType = answers.wordpressType !== 'dev';
return ( installWp && nonDevType ) || ( wordpressType && wordpressType !== 'dev' && ! wordpressVersion );
},
},
{
name: 'title',
type: 'input',
Expand Down
32 changes: 25 additions & 7 deletions src/commands/create/install-wordpress.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,38 @@
const envUtils = require( '../../env-utils' );
const compose = require( '../../utils/docker-compose' );

async function downloadWordPress( wordpressType, cwd, spinner ) {
const chalk = require( 'chalk' );

/**
* Downloads the given version of WordPress. Falls back to latest in case of an error.
*
* @returns {Promise<string>} The downloaded WP version, or the last one tried.
*/
async function downloadWordPress( wordpressType, cwd, spinner, version = 'latest' ) {
if ( spinner ) {
spinner.start( 'Downloading WordPress...' );
spinner.start( `Downloading WordPress ${ chalk.cyan( version ) }...` );
} else {
console.log( 'Downloading WordPress:' );
console.log( `Downloading WordPress ${ chalk.cyan( version ) }:` );
}

await compose.exec( 'phpfpm', 'wp core download --version=latest --force', { cwd, log: ! spinner } );
try {
await compose.exec( 'phpfpm', `wp core download --version=${ version } --force`, { cwd, log: ! spinner } );
} catch ( err ) {
if( version !== 'latest' ) {
console.warn( chalk.red( `Failed to download WP version '${ chalk.italic.cyanBright( version ) }'. Falling back to '${ chalk.italic.cyanBright( 'latest' ) }'.` ) );

return await downloadWordPress( wordpressType, cwd, spinner, 'latest' );
} else {
throw err;
}
}

if ( spinner ) {
spinner.succeed( 'WordPress is downloaded...' );
spinner.succeed( `WordPress ${ chalk.cyan( version ) } is downloaded...` );
} else {
console.log( ' - Done' );
}

return version;
}

async function configure( envSlug, cwd, spinner ) {
Expand Down Expand Up @@ -129,7 +147,7 @@ module.exports = function makeInstallWordPress( spinner ) {
try {
const cwd = await envUtils.envPath( envSlug );

await downloadWordPress( wordpress.type, cwd, spinner );
await downloadWordPress( wordpress.type, cwd, spinner, wordpress.version );
await configure( envSlug, cwd, spinner );
await install( hostname, wordpress, certs, cwd, spinner );
await setRewrites( cwd, spinner );
Expand Down