From 03414de9995870109f3f6e0e1c88605a0353aaf3 Mon Sep 17 00:00:00 2001 From: Enrique Piqueras Date: Tue, 22 Oct 2019 13:18:20 -0700 Subject: [PATCH] Env: Add support for custom ports. (#17697) --- packages/env/.npmrc | 1 + packages/env/README.md | 17 +++++++++++------ packages/env/lib/cli.js | 4 ++-- .../env/lib/create-docker-compose-config.js | 6 +++--- packages/env/lib/env.js | 8 +++++--- packages/env/package.json | 2 +- 6 files changed, 23 insertions(+), 15 deletions(-) create mode 100644 packages/env/.npmrc diff --git a/packages/env/.npmrc b/packages/env/.npmrc new file mode 100644 index 0000000000000..43c97e719a5a8 --- /dev/null +++ b/packages/env/.npmrc @@ -0,0 +1 @@ +package-lock=false diff --git a/packages/env/README.md b/packages/env/README.md index 45736ee1fa29b..9be3fe8e36709 100644 --- a/packages/env/README.md +++ b/packages/env/README.md @@ -15,8 +15,10 @@ wp-env Commands: wp-env start [ref] Starts WordPress for development on port 8888 - (​http://localhost:8888​) and tests on port 8889 - (​http://localhost:8889​). If the current working + (​http://localhost:8888​) (override with + WP_ENV_PORT) and tests on port 8889 + (​http://localhost:8889​) (override with + WP_ENV_TESTS_PORT). If the current working directory is a plugin and/or has e2e-tests with plugins and/or mu-plugins, they will be mounted appropiately. @@ -34,10 +36,11 @@ Options: ```sh wp-env start [ref] -Starts WordPress for development on port 8888 (​http://localhost:8888​) and -tests on port 8889 (​http://localhost:8889​). If the current working directory -is a plugin and/or has e2e-tests with plugins and/or mu-plugins, they will be -mounted appropiately. +Starts WordPress for development on port 8888 (​http://localhost:8888​) +(override with WP_ENV_PORT) and tests on port 8889 (​http://localhost:8889​) +(override with WP_ENV_TESTS_PORT). If the current working directory is a plugin +and/or has e2e-tests with plugins and/or mu-plugins, they will be mounted +appropiately. Positionals: ref A `https://github.com/WordPress/WordPress` git repo branch or commit for @@ -63,3 +66,5 @@ Positionals: environment Which environments' databases to clean. [string] [choices: "all", "development", "tests"] [default: "tests"] ``` + +

Code is Poetry.

diff --git a/packages/env/lib/cli.js b/packages/env/lib/cli.js index 6f134afd9ae42..98dc1ecb42ce2 100644 --- a/packages/env/lib/cli.js +++ b/packages/env/lib/cli.js @@ -46,10 +46,10 @@ module.exports = function cli() { chalk`Starts WordPress for development on port {bold.underline ${ terminalLink( '8888', 'http://localhost:8888' - ) }} and tests on port {bold.underline ${ terminalLink( + ) }} (override with WP_ENV_PORT) and tests on port {bold.underline ${ terminalLink( '8889', 'http://localhost:8889' - ) }}. If the current working directory is a plugin and/or has e2e-tests with plugins and/or mu-plugins, they will be mounted appropiately.` + ) }} (override with WP_ENV_TESTS_PORT). If the current working directory is a plugin and/or has e2e-tests with plugins and/or mu-plugins, they will be mounted appropiately.` ), ( args ) => { args.positional( 'ref', { diff --git a/packages/env/lib/create-docker-compose-config.js b/packages/env/lib/create-docker-compose-config.js index 7a3dfc7d33b6a..6cc4b8ddfabf1 100644 --- a/packages/env/lib/create-docker-compose-config.js +++ b/packages/env/lib/create-docker-compose-config.js @@ -11,7 +11,7 @@ module.exports = function createDockerComposeConfig( - ${ pluginPath }/../${ pluginName }-wordpress/:/var/www/html/${ commonVolumes }`; const testsVolumes = ` - tests-wordpress:/var/www/html/${ commonVolumes }`; - return `version: '2' + return `version: '2.1' volumes: tests-wordpress: services: @@ -28,7 +28,7 @@ services: WORDPRESS_DB_PASSWORD: password image: wordpress ports: - - 8888:80 + - \${WP_ENV_PORT:-8888}:80 volumes:${ volumes } wordpress-cli: depends_on: @@ -44,7 +44,7 @@ services: WORDPRESS_DB_PASSWORD: password image: wordpress ports: - - 8889:80 + - \${WP_ENV_TESTS_PORT:-8889}:80 volumes:${ testsVolumes } tests-wordpress-cli: depends_on: diff --git a/packages/env/lib/env.js b/packages/env/lib/env.js index 159bb2ac2fc45..3b982c0e143f5 100644 --- a/packages/env/lib/env.js +++ b/packages/env/lib/env.js @@ -30,9 +30,11 @@ const wpCliRun = ( command, isTests = false ) => ); const setupSite = ( isTests = false ) => wpCliRun( - `wp core install --url=localhost:888${ - isTests ? '9' : '8' - } --title=Gutenberg --admin_user=admin --admin_password=password --admin_email=admin@wordpress.org`, + `wp core install --url=localhost:${ + isTests ? + process.env.WP_ENV_TESTS_PORT || 8889 : + process.env.WP_ENV_PORT || 8888 + } --title=${ pluginName } --admin_user=admin --admin_password=password --admin_email=admin@wordpress.org`, isTests ); const activatePlugin = ( isTests = false ) => diff --git a/packages/env/package.json b/packages/env/package.json index 6be0539b3725c..19f0fe52cdc04 100644 --- a/packages/env/package.json +++ b/packages/env/package.json @@ -1,6 +1,6 @@ { "name": "@wordpress/env", - "version": "1.0.0", + "version": "0.0.0", "description": "A zero-config, self contained local WordPress environment for development and testing.", "author": "The WordPress Contributors", "license": "GPL-2.0-or-later",