Skip to content
Closed
Show file tree
Hide file tree
Changes from 4 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
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ services:
PHP_FPM_UID: ${PHP_FPM_UID-1000}
PHP_FPM_GID: ${PHP_FPM_GID-1000}
HOST_PATH: ${PWD-}/${LOCAL_DIR-src}
WP_CONFIG_PATH: ${WP_CONFIG_PATH-/var/www/wp-config.php}
Comment thread
westonruter marked this conversation as resolved.
Outdated

volumes:
- ./:/var/www
Expand Down
27 changes: 19 additions & 8 deletions tools/local-env/scripts/install.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
/* jshint node:true */

const dotenv = require( 'dotenv' );
const dotenvExpand = require( 'dotenv-expand' );
const wait_on = require( 'wait-on' );
const { execSync } = require( 'child_process' );
const { renameSync, readFileSync, writeFileSync } = require( 'fs' );
const { readFileSync, writeFileSync } = require( 'fs' );
const local_env_utils = require( './utils' );

dotenvExpand.expand( dotenv.config() );
Expand All @@ -11,7 +13,7 @@ dotenvExpand.expand( dotenv.config() );
local_env_utils.determine_auth_option();

// Create wp-config.php.
wp_cli( 'config create --dbname=wordpress_develop --dbuser=root --dbpass=password --dbhost=mysql --force' );
wp_cli( `config create --dbname=wordpress_develop --dbuser=root --dbpass=password --dbhost=mysql --force --config-file=${process.env.LOCAL_DIR}/../wp-config.php` );

// Add the debug settings to wp-config.php.
// Windows requires this to be done as an additional step, rather than using the --extra-php option in the previous step.
Expand All @@ -22,26 +24,35 @@ wp_cli( `config set SCRIPT_DEBUG ${process.env.LOCAL_SCRIPT_DEBUG} --raw --type=
wp_cli( `config set WP_ENVIRONMENT_TYPE ${process.env.LOCAL_WP_ENVIRONMENT_TYPE} --type=constant` );
wp_cli( `config set WP_DEVELOPMENT_MODE ${process.env.LOCAL_WP_DEVELOPMENT_MODE} --type=constant` );

// Move wp-config.php to the base directory, so it doesn't get mixed up in the src or build directories.
renameSync( `${process.env.LOCAL_DIR}/wp-config.php`, 'wp-config.php' );

// Read in wp-tests-config-sample.php, edit it to work with our config, then write it to wp-tests-config.php.
const testConfig = readFileSync( 'wp-tests-config-sample.php', 'utf8' )
.replace( 'youremptytestdbnamehere', 'wordpress_develop_tests' )
.replace( 'yourusernamehere', 'root' )
.replace( 'yourpasswordhere', 'password' )
.replace( 'localhost', 'mysql' )
.replace( "'WP_TESTS_DOMAIN', 'example.org'", `'WP_TESTS_DOMAIN', '${process.env.LOCAL_WP_TESTS_DOMAIN}'` )
.concat( "\ndefine( 'FS_METHOD', 'direct' );\n" );
.replace( `'WP_TESTS_DOMAIN', 'example.org'`, `'WP_TESTS_DOMAIN', '${process.env.LOCAL_WP_TESTS_DOMAIN}'` )
.concat( `\ndefine( 'FS_METHOD', 'direct' );\n` );

writeFileSync( 'wp-tests-config.php', testConfig );

// Once the site is available, install WordPress!
wait_on( { resources: [ `tcp:localhost:${process.env.LOCAL_PORT}`] } )
wait_on( {
resources: [ `tcp:localhost:${process.env.LOCAL_PORT}`],
timeout: 3000,
} )
.catch( err => {
console.error( `Error: It appears the development environment has not been started. Message: ${ err.message }` );
console.error( `Did you forget to do 'npm run env:start'?` );
process.exit( 1 );
} )
.then( () => {
wp_cli( 'db reset --yes' );
const installCommand = process.env.LOCAL_MULTISITE === 'true' ? 'multisite-install' : 'install';
wp_cli( `core ${ installCommand } --title="WordPress Develop" --admin_user=admin --admin_password=password --admin_email=test@example.com --skip-email --url=http://localhost:${process.env.LOCAL_PORT}` );
} )
.catch( err => {
console.error( `Error: Unable to reset DB and install WordPress. Message: ${ err.message }` );
process.exit( 1 );
} );

/**
Expand Down
Loading