From 484ace368102a773548a035691673f1a617b252f Mon Sep 17 00:00:00 2001 From: Sean Fisher Date: Thu, 6 Feb 2025 01:32:16 -0500 Subject: [PATCH] wp-env: Add lifecycleScripts to the schema (#68724) * Add lifecycleScripts to the README * Add lifecycleScripts to the schema/README for @wordpress/env * Adjust from code review feedback Co-authored-by: srtfisher Co-authored-by: t-hamano --- packages/env/README.md | 27 ++++++++++++++------------- schemas/json/wp-env.json | 21 ++++++++++++++++++++- 2 files changed, 34 insertions(+), 14 deletions(-) diff --git a/packages/env/README.md b/packages/env/README.md index 16bba5cba20c07..fe3e5dea3bf2b2 100644 --- a/packages/env/README.md +++ b/packages/env/README.md @@ -479,19 +479,20 @@ You can customize the WordPress installation, plugins and themes that the develo `.wp-env.json` supports fields for options applicable to both the tests and development instances. -| Field | Type | Default | Description | -|--------------------|----------------|----------------------------------------|----------------------------------------------------------------------------------------------------------------------------------| -| `"core"` | `string\|null` | `null` | The WordPress installation to use. If `null` is specified, `wp-env` will use the latest production release of WordPress. | -| `"phpVersion"` | `string\|null` | `null` | The PHP version to use. If `null` is specified, `wp-env` will use the default version used with production release of WordPress. | -| `"plugins"` | `string[]` | `[]` | A list of plugins to install and activate in the environment. | -| `"themes"` | `string[]` | `[]` | A list of themes to install in the environment. | -| `"port"` | `integer` | `8888` (`8889` for the tests instance) | The primary port number to use for the installation. You'll access the instance through the port: 'http://localhost:8888'. | -| `"testsPort"` | `integer` | `8889` | The port number for the test site. You'll access the instance through the port: 'http://localhost:8889'. | -| `"config"` | `Object` | See below. | Mapping of wp-config.php constants to their desired values. | -| `"mappings"` | `Object` | `"{}"` | Mapping of WordPress directories to local directories to be mounted in the WordPress instance. | -| `"mysqlPort"` | `integer` | `null` (randomly assigned) | The MySQL port number to expose. The setting is only available in the `env.development` and `env.tests` objects. | -| `"phpmyadminPort"` | `integer` | `null` | The port number for phpMyAdmin. If provided, you'll access phpMyAdmin through: http://localhost: | -| `"multisite"` | `boolean` | `false` | Whether to set up a multisite installation. | +| Field | Type | Default | Description | +|----------------------|----------------|----------------------------------------|----------------------------------------------------------------------------------------------------------------------------------| +| `"core"` | `string\|null` | `null` | The WordPress installation to use. If `null` is specified, `wp-env` will use the latest production release of WordPress. | +| `"phpVersion"` | `string\|null` | `null` | The PHP version to use. If `null` is specified, `wp-env` will use the default version used with production release of WordPress. | +| `"plugins"` | `string[]` | `[]` | A list of plugins to install and activate in the environment. | +| `"themes"` | `string[]` | `[]` | A list of themes to install in the environment. | +| `"port"` | `integer` | `8888` (`8889` for the tests instance) | The primary port number to use for the installation. You'll access the instance through the port: 'http://localhost:8888'. | +| `"testsPort"` | `integer` | `8889` | The port number for the test site. You'll access the instance through the port: 'http://localhost:8889'. | +| `"config"` | `Object` | See below. | Mapping of wp-config.php constants to their desired values. | +| `"mappings"` | `Object` | `"{}"` | Mapping of WordPress directories to local directories to be mounted in the WordPress instance. | +| `"mysqlPort"` | `integer` | `null` (randomly assigned) | The MySQL port number to expose. The setting is only available in the `env.development` and `env.tests` objects. | +| `"phpmyadminPort"` | `integer` | `null` | The port number for phpMyAdmin. If provided, you'll access phpMyAdmin through: http://localhost: | +| `"multisite"` | `boolean` | `false` | Whether to set up a multisite installation. | +| `"lifecycleScripts"` | `Object` | `"{}"` | Mapping of commands that should be executed at certain points in the lifecycle. | _Note: the port number environment variables (`WP_ENV_PORT` and `WP_ENV_TESTS_PORT`) take precedent over the .wp-env.json values._ diff --git a/schemas/json/wp-env.json b/schemas/json/wp-env.json index 5761fb3d877116..2a98cb3d0d2635 100644 --- a/schemas/json/wp-env.json +++ b/schemas/json/wp-env.json @@ -119,6 +119,25 @@ "description": "The port number for the test site. You'll access the instance through the port: http://localhost:8889", "type": "integer", "default": 8889 + }, + "lifecycleScripts": { + "description": "Mapping of commands that should be executed at certain points in the lifecycle.", + "type": "object", + "default": {}, + "properties": { + "afterStart": { + "description": "Runs after wp-env start has finished setting up the environment.", + "type": "string" + }, + "afterClean": { + "description": "Runs after wp-env clean has finished cleaning the environment.", + "type": "string" + }, + "afterDestroy": { + "description": "Runs after wp-env destroy has destroyed the environment.", + "type": "string" + } + } } } }, @@ -130,7 +149,7 @@ "$ref": "#/definitions/wpEnvPropertyNames" }, { - "enum": [ "$schema", "env", "testsPort" ] + "enum": [ "$schema", "env", "testsPort", "lifecycleScripts" ] } ] }