@wordpress/env 10.39.0 → 11.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +127 -76
- package/lib/cli.js +67 -10
- package/lib/commands/clean.js +13 -4
- package/lib/commands/cleanup.js +79 -0
- package/lib/commands/destroy.js +30 -18
- package/lib/commands/index.js +6 -2
- package/lib/commands/logs.js +17 -8
- package/lib/commands/reset.js +46 -0
- package/lib/commands/run.js +13 -9
- package/lib/commands/start.js +54 -14
- package/lib/commands/status.js +160 -0
- package/lib/commands/stop.js +13 -6
- package/lib/config/get-config-from-environment-vars.js +2 -5
- package/lib/config/load-config.js +35 -5
- package/lib/config/parse-config.js +53 -21
- package/lib/config/post-process-config.js +38 -16
- package/lib/config/test/__snapshots__/config-integration.js.snap +16 -0
- package/lib/config/test/parse-config.js +33 -0
- package/lib/config/test/post-process-config.js +52 -0
- package/lib/runtime/docker/build-docker-compose-config.js +164 -125
- package/lib/runtime/docker/download-sources.js +5 -1
- package/lib/runtime/docker/download-wp-phpunit.js +3 -0
- package/lib/runtime/docker/index.js +281 -91
- package/lib/runtime/docker/init-config.js +20 -12
- package/lib/runtime/docker/wordpress.js +0 -15
- package/lib/runtime/errors.js +11 -0
- package/lib/runtime/index.js +40 -18
- package/lib/runtime/playground/blueprint-builder.js +25 -33
- package/lib/runtime/playground/index.js +82 -4
- package/lib/test/build-docker-compose-config.js +147 -0
- package/lib/test/cli.js +49 -13
- package/package.json +2 -2
- package/lib/commands/install-path.js +0 -33
package/README.md
CHANGED
|
@@ -39,7 +39,6 @@ $ wp-env start --runtime=playground
|
|
|
39
39
|
| Feature | Docker | Playground |
|
|
40
40
|
|---------|--------|------------|
|
|
41
41
|
| Requires Docker | Yes | No |
|
|
42
|
-
| Test environment | Yes | No |
|
|
43
42
|
| Xdebug | Yes | Yes |
|
|
44
43
|
| SPX profiling | Yes | No |
|
|
45
44
|
| phpMyAdmin | Yes | No |
|
|
@@ -49,7 +48,7 @@ $ wp-env start --runtime=playground
|
|
|
49
48
|
| Plugin/theme mounting | Yes | Yes |
|
|
50
49
|
| `wp-env run` command | Yes | No |
|
|
51
50
|
|
|
52
|
-
The Playground runtime is ideal for quick testing or environments where Docker is unavailable. However, it lacks some features available in the Docker runtime, such as the
|
|
51
|
+
The Playground runtime is ideal for quick testing or environments where Docker is unavailable. However, it lacks some features available in the Docker runtime, such as the `run` command for executing arbitrary commands.
|
|
53
52
|
|
|
54
53
|
Once started with a runtime, wp-env will automatically detect and use the same runtime for subsequent commands (`stop`, `destroy`, etc.) until the environment is destroyed.
|
|
55
54
|
|
|
@@ -136,7 +135,7 @@ First, check that `wp-env` is running. One way to do this is to have Docker prin
|
|
|
136
135
|
$ docker ps
|
|
137
136
|
```
|
|
138
137
|
|
|
139
|
-
In this table, by default, you should see
|
|
138
|
+
In this table, by default, you should see two entries: `wordpress` with port 8888 and `mariadb`.
|
|
140
139
|
|
|
141
140
|
### 2. Check the port number
|
|
142
141
|
|
|
@@ -186,7 +185,7 @@ To reset the database:
|
|
|
186
185
|
**⚠️ WARNING: This will permanently delete any posts, pages, media, etc. in the local WordPress installation.**
|
|
187
186
|
|
|
188
187
|
```sh
|
|
189
|
-
$ wp-env
|
|
188
|
+
$ wp-env reset all
|
|
190
189
|
$ wp-env start
|
|
191
190
|
```
|
|
192
191
|
|
|
@@ -214,9 +213,9 @@ While we do provide a default `wp-tests-config.php` file within the environment,
|
|
|
214
213
|
|
|
215
214
|
## Using `composer`, `phpunit`, and `wp-cli` tools.
|
|
216
215
|
|
|
217
|
-
For ease of use, Composer, PHPUnit, and wp-cli are available
|
|
216
|
+
For ease of use, Composer, PHPUnit, and wp-cli are available in the environment. To run these executables, use `wp-env run <container> <tool> <command>`. For example, `wp-env run cli composer install`, or `wp-env run cli phpunit`. You can also access various shells like `wp-env run cli bash` or `wp-env run cli wp shell`.
|
|
218
217
|
|
|
219
|
-
|
|
218
|
+
The `cli` and `wordpress` containers share a database and mapped volumes, but more tools are available in the `cli` container. For test isolation, use `--config` with a separate config file to run a parallel environment (see [Running parallel environments](#running-parallel-environments)).
|
|
220
219
|
|
|
221
220
|
By default, the cwd of the run command is the root of the WordPress install. If you're working on a plugin, you likely need to pass `--env-cwd` to make sure composer/phpunit commands are executed relative to the plugin you're working on. For example, `wp-env run cli --env-cwd=wp-content/plugins/gutenberg composer install`.
|
|
222
221
|
|
|
@@ -295,6 +294,45 @@ Here is a summary:
|
|
|
295
294
|
|
|
296
295
|
`wp-env` creates generated files in the `wp-env` home directory. By default, this is `~/.wp-env`. The exception is Linux, where files are placed at `~/wp-env` [for compatibility with Snap Packages](https://github.com/WordPress/gutenberg/issues/20180#issuecomment-587046325). The `wp-env` home directory contains a subdirectory for each project named `/$md5_of_project_path`. To change the `wp-env` home directory, set the `WP_ENV_HOME` environment variable. For example, running `WP_ENV_HOME="something" wp-env start` will download the project files to the directory `./something/$md5_of_project_path` (relative to the current directory).
|
|
297
296
|
|
|
297
|
+
### Global options
|
|
298
|
+
|
|
299
|
+
These options apply to all `wp-env` commands:
|
|
300
|
+
|
|
301
|
+
```
|
|
302
|
+
--debug Enable debug output. [boolean] [default: false]
|
|
303
|
+
--config Path to a custom .wp-env.json configuration file. [string]
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
The `--config` option allows you to use a custom configuration file instead of the default `.wp-env.json`. This is useful for running multiple parallel environments from the same directory. Each config file gets its own isolated set of Docker containers and data.
|
|
307
|
+
|
|
308
|
+
When using a custom config file, the override file is derived from its name by inserting `.override` before the extension. For example:
|
|
309
|
+
- `--config=.wp-env.test.json` will look for `.wp-env.test.override.json`
|
|
310
|
+
- `--config=staging.json` will look for `staging.override.json`
|
|
311
|
+
- `--config=./configs/dev.wp-env.json` will look for `./configs/dev.wp-env.override.json`
|
|
312
|
+
|
|
313
|
+
Override files for custom configs work the same way as `.wp-env.override.json` does for the default config (see [.wp-env.override.json](#wp-envoverridejson)).
|
|
314
|
+
|
|
315
|
+
#### Running parallel environments
|
|
316
|
+
|
|
317
|
+
You can run multiple wp-env environments from the same folder by using different config files and ports:
|
|
318
|
+
|
|
319
|
+
```sh
|
|
320
|
+
# Start first environment with default config
|
|
321
|
+
wp-env start
|
|
322
|
+
|
|
323
|
+
# Start second environment with custom config on different ports
|
|
324
|
+
WP_ENV_PORT=8890 wp-env start --config=./staging.json
|
|
325
|
+
|
|
326
|
+
# Check status of each environment
|
|
327
|
+
wp-env status
|
|
328
|
+
wp-env status --config=./staging.json
|
|
329
|
+
|
|
330
|
+
# Stop specific environment
|
|
331
|
+
wp-env stop --config=./staging.json
|
|
332
|
+
```
|
|
333
|
+
|
|
334
|
+
Each config file gets its own isolated Docker containers and data, so changes in one environment don't affect the other.
|
|
335
|
+
|
|
298
336
|
### `wp-env start`
|
|
299
337
|
|
|
300
338
|
The start command installs and initializes the WordPress environment, which includes downloading any specified remote sources. By default, `wp-env` will not update or re-configure the environment except when the configuration file changes. Tell `wp-env` to update sources and apply the configuration options again with `wp-env start --update`. This will not overwrite any existing content.
|
|
@@ -303,8 +341,7 @@ The start command installs and initializes the WordPress environment, which incl
|
|
|
303
341
|
wp-env start
|
|
304
342
|
|
|
305
343
|
Starts WordPress for development on port 8888 (http://localhost:8888)
|
|
306
|
-
(override with WP_ENV_PORT)
|
|
307
|
-
(override with WP_ENV_TESTS_PORT). The current working directory must be a
|
|
344
|
+
(override with WP_ENV_PORT). The current working directory must be a
|
|
308
345
|
WordPress installation, a plugin, a theme, or contain a .wp-env.json file. After
|
|
309
346
|
first install, use the '--update' flag to download updates to mapped sources and
|
|
310
347
|
to re-apply WordPress configuration options.
|
|
@@ -334,22 +371,22 @@ Options:
|
|
|
334
371
|
```sh
|
|
335
372
|
wp-env stop
|
|
336
373
|
|
|
337
|
-
Stops running WordPress for development and
|
|
374
|
+
Stops running WordPress for development and frees the ports.
|
|
338
375
|
|
|
339
376
|
Options:
|
|
340
377
|
--debug Enable debug output. [boolean] [default: false]
|
|
341
378
|
```
|
|
342
379
|
|
|
343
|
-
### `wp-env
|
|
380
|
+
### `wp-env reset [environment]`
|
|
344
381
|
|
|
345
382
|
```sh
|
|
346
|
-
wp-env
|
|
383
|
+
wp-env reset [environment]
|
|
347
384
|
|
|
348
|
-
|
|
385
|
+
Resets the WordPress databases.
|
|
349
386
|
|
|
350
387
|
Positionals:
|
|
351
|
-
environment Which environments' databases to
|
|
352
|
-
|
|
388
|
+
environment Which environments' databases to reset.
|
|
389
|
+
[string] [choices: "all", "development", "tests"] [default: "development"]
|
|
353
390
|
|
|
354
391
|
Options:
|
|
355
392
|
--debug Enable debug output. [boolean] [default: false]
|
|
@@ -385,8 +422,8 @@ containers.
|
|
|
385
422
|
|
|
386
423
|
Positionals:
|
|
387
424
|
container The Docker service to run the command on.
|
|
388
|
-
|
|
389
|
-
|
|
425
|
+
[string] [required] [choices: "mysql", "wordpress", "cli", "composer",
|
|
426
|
+
"phpmyadmin"]
|
|
390
427
|
command The command to run. [required]
|
|
391
428
|
|
|
392
429
|
Options:
|
|
@@ -410,29 +447,27 @@ ID user_login display_name user_email user_registered roles
|
|
|
410
447
|
✔ Ran `wp user list` in 'cli'. (in 2s 374ms)
|
|
411
448
|
```
|
|
412
449
|
|
|
413
|
-
#### Creating a post on the
|
|
450
|
+
#### Creating a post on the development instance:
|
|
414
451
|
|
|
415
452
|
```sh
|
|
416
|
-
wp-env run
|
|
453
|
+
wp-env run cli "wp post create --post_type=page --post_title='Ready'"
|
|
417
454
|
|
|
418
|
-
ℹ Starting 'wp post create --post_type=page --post_title='Ready'' on the
|
|
455
|
+
ℹ Starting 'wp post create --post_type=page --post_title='Ready'' on the cli container.
|
|
419
456
|
|
|
420
457
|
Success: Created post 5.
|
|
421
|
-
✔ Ran `wp post create --post_type=page --post_title='Ready'` in '
|
|
458
|
+
✔ Ran `wp post create --post_type=page --post_title='Ready'` in 'cli'. (in 3s 293ms)
|
|
422
459
|
```
|
|
423
460
|
|
|
424
|
-
#### Opening the WordPress shell
|
|
461
|
+
#### Opening the WordPress shell and running PHP commands:
|
|
425
462
|
|
|
426
463
|
```sh
|
|
427
|
-
wp-env run
|
|
428
|
-
ℹ Starting 'wp shell' on the
|
|
464
|
+
wp-env run cli wp shell
|
|
465
|
+
ℹ Starting 'wp shell' on the cli container. Exit the WordPress shell with ctrl-c.
|
|
429
466
|
|
|
430
|
-
Starting 31911d623e75f345e9ed328b9f48cff6_mysql_1 ... done
|
|
431
|
-
Starting 31911d623e75f345e9ed328b9f48cff6_tests-wordpress_1 ... done
|
|
432
467
|
wp> echo( 'hello world!' );
|
|
433
468
|
hello world!
|
|
434
469
|
wp> ^C
|
|
435
|
-
✔ Ran `wp shell` in '
|
|
470
|
+
✔ Ran `wp shell` in 'cli'. (in 16s 400ms)
|
|
436
471
|
```
|
|
437
472
|
|
|
438
473
|
#### Installing a plugin or theme on the development instance
|
|
@@ -469,17 +504,32 @@ To set the permalink to the year, month, and post name:
|
|
|
469
504
|
wp-env run cli "wp rewrite structure /%year%/%monthnum%/%postname%/"
|
|
470
505
|
```
|
|
471
506
|
|
|
507
|
+
### `wp-env cleanup`
|
|
508
|
+
|
|
509
|
+
```sh
|
|
510
|
+
wp-env cleanup
|
|
511
|
+
|
|
512
|
+
Cleanup the WordPress environment. Removes docker containers, volumes, networks,
|
|
513
|
+
and local files, but preserves docker images for faster re-starts.
|
|
514
|
+
|
|
515
|
+
Options:
|
|
516
|
+
--debug Enable debug output. [boolean] [default: false]
|
|
517
|
+
--scripts Execute any configured lifecycle scripts. [boolean] [default: true]
|
|
518
|
+
--force Skip the confirmation prompt. [boolean] [default: false]
|
|
519
|
+
```
|
|
520
|
+
|
|
472
521
|
### `wp-env destroy`
|
|
473
522
|
|
|
474
523
|
```sh
|
|
475
524
|
wp-env destroy
|
|
476
525
|
|
|
477
|
-
Destroy the WordPress environment. Deletes docker containers, volumes,
|
|
478
|
-
|
|
526
|
+
Destroy the WordPress environment. Deletes docker containers, volumes, networks,
|
|
527
|
+
and images associated with the WordPress environment and removes local files.
|
|
479
528
|
|
|
480
529
|
Options:
|
|
481
530
|
--debug Enable debug output. [boolean] [default: false]
|
|
482
531
|
--scripts Execute any configured lifecycle scripts. [boolean] [default: true]
|
|
532
|
+
--force Skip the confirmation prompt. [boolean] [default: false]
|
|
483
533
|
```
|
|
484
534
|
|
|
485
535
|
### `wp-env logs [environment]`
|
|
@@ -491,30 +541,49 @@ displays PHP and Docker logs for given WordPress environment.
|
|
|
491
541
|
|
|
492
542
|
Positionals:
|
|
493
543
|
environment Which environment to display the logs from.
|
|
494
|
-
|
|
544
|
+
[string] [choices: "development"] [default: "development"]
|
|
495
545
|
|
|
496
546
|
Options:
|
|
497
547
|
--debug Enable debug output. [boolean] [default: false]
|
|
498
548
|
--watch Watch for logs as they happen. [boolean] [default: true]
|
|
499
549
|
```
|
|
500
550
|
|
|
501
|
-
### `wp-env
|
|
551
|
+
### `wp-env status`
|
|
502
552
|
|
|
503
|
-
Get the
|
|
553
|
+
Get the status of the wp-env environment including whether it's running, URLs, ports, and configuration.
|
|
504
554
|
|
|
505
555
|
Example:
|
|
506
556
|
|
|
507
557
|
```sh
|
|
508
|
-
$ wp-env
|
|
558
|
+
$ wp-env status
|
|
559
|
+
|
|
560
|
+
status: running
|
|
561
|
+
- runtime: docker
|
|
562
|
+
- install path: /home/user/.wp-env/63263e6506becb7b8613b02d42280a49
|
|
563
|
+
- config: /home/user/my-plugin
|
|
509
564
|
|
|
510
|
-
|
|
565
|
+
environment:
|
|
566
|
+
- url: http://localhost:8888
|
|
567
|
+
- multisite: no
|
|
568
|
+
- xdebug: off
|
|
569
|
+
- http port: 8888
|
|
570
|
+
- mysql port: 13306
|
|
571
|
+
```
|
|
572
|
+
|
|
573
|
+
```sh
|
|
574
|
+
$ wp-env status --help
|
|
575
|
+
Get the status of the wp-env environment including URLs, ports, and configuration.
|
|
576
|
+
|
|
577
|
+
Options:
|
|
578
|
+
--debug Enable debug output. [boolean] [default: false]
|
|
579
|
+
--json Output status as JSON. [boolean] [default: false]
|
|
511
580
|
```
|
|
512
581
|
|
|
513
582
|
## .wp-env.json
|
|
514
583
|
|
|
515
584
|
You can customize the WordPress installation, plugins and themes that the development environment will use by specifying a `.wp-env.json` file in the directory that you run `wp-env` from.
|
|
516
585
|
|
|
517
|
-
`.wp-env.json` supports
|
|
586
|
+
`.wp-env.json` supports the following fields:
|
|
518
587
|
|
|
519
588
|
| Field | Type | Default | Description |
|
|
520
589
|
|----------------------|----------------|----------------------------------------|----------------------------------------------------------------------------------------------------------------------------------|
|
|
@@ -522,16 +591,16 @@ You can customize the WordPress installation, plugins and themes that the develo
|
|
|
522
591
|
| `"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. |
|
|
523
592
|
| `"plugins"` | `string[]` | `[]` | A list of plugins to install and activate in the environment. |
|
|
524
593
|
| `"themes"` | `string[]` | `[]` | A list of themes to install in the environment. |
|
|
525
|
-
| `"port"` | `integer` | `8888`
|
|
526
|
-
| `"
|
|
594
|
+
| `"port"` | `integer` | `8888` | The primary port number to use for the installation. You'll access the instance through the port: 'http://localhost:8888'. |
|
|
595
|
+
| `"testsEnvironment"` | `boolean` | `false` | _Deprecated._ Whether to create a separate test environment with its own database and containers. Use `--config` with a separate config file instead. |
|
|
527
596
|
| `"config"` | `Object` | See below. | Mapping of wp-config.php constants to their desired values. |
|
|
528
597
|
| `"mappings"` | `Object` | `"{}"` | Mapping of WordPress directories to local directories to be mounted in the WordPress instance. |
|
|
529
|
-
| `"mysqlPort"` | `integer` | `null` (randomly assigned) | The MySQL port number to expose.
|
|
598
|
+
| `"mysqlPort"` | `integer` | `null` (randomly assigned) | The MySQL port number to expose. |
|
|
530
599
|
| `"phpmyadminPort"` | `integer` | `null` | The port number for phpMyAdmin. If provided, you'll access phpMyAdmin through: http://localhost:<port> |
|
|
531
600
|
| `"multisite"` | `boolean` | `false` | Whether to set up a multisite installation. |
|
|
532
601
|
| `"lifecycleScripts"` | `Object` | `"{}"` | Mapping of commands that should be executed at certain points in the lifecycle. |
|
|
533
602
|
|
|
534
|
-
_Note: the port number environment
|
|
603
|
+
_Note: the port number environment variable (`WP_ENV_PORT`) takes precedence over the .wp-env.json value._
|
|
535
604
|
|
|
536
605
|
Several types of strings can be passed into the `core`, `plugins`, `themes`, and `mappings` fields.
|
|
537
606
|
|
|
@@ -545,7 +614,7 @@ Several types of strings can be passed into the `core`, `plugins`, `themes`, and
|
|
|
545
614
|
|
|
546
615
|
Remote sources will be downloaded into a temporary directory located in `~/.wp-env`.
|
|
547
616
|
|
|
548
|
-
Additionally, the key `env` is available to override any of the above options on
|
|
617
|
+
Additionally, the key `env` is available to override any of the above options on the development environment. For example, take the following `.wp-env.json` file:
|
|
549
618
|
|
|
550
619
|
```json
|
|
551
620
|
{
|
|
@@ -557,29 +626,21 @@ Additionally, the key `env` is available to override any of the above options on
|
|
|
557
626
|
"env": {
|
|
558
627
|
"development": {
|
|
559
628
|
"themes": [ "./one-theme" ]
|
|
560
|
-
},
|
|
561
|
-
"tests": {
|
|
562
|
-
"config": {
|
|
563
|
-
"KEY_1": false
|
|
564
|
-
},
|
|
565
|
-
"port": 3000,
|
|
566
|
-
"mysqlPort": 13306,
|
|
567
|
-
"phpmyadminPort": 9001
|
|
568
629
|
}
|
|
569
630
|
}
|
|
570
631
|
}
|
|
571
632
|
```
|
|
572
633
|
|
|
573
|
-
|
|
634
|
+
Here, `cwd` will be mapped as a plugin, `one-theme` will be mapped as a theme, KEY_1 will be set to true, and KEY_2 will be set to false.
|
|
574
635
|
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
This gives you a lot of power to change the options applicable to each environment.
|
|
636
|
+
For running a separate test environment, use `--config` with a separate config file instead of `env.tests` (see [Running parallel environments](#running-parallel-environments)).
|
|
578
637
|
|
|
579
638
|
## .wp-env.override.json
|
|
580
639
|
|
|
581
640
|
Any fields here will take precedence over .wp-env.json. This file is useful when ignored from version control, to persist local development overrides. Note that options like `plugins` and `themes` are not merged. As a result, if you set `plugins` in your override file, this will override all of the plugins listed in the base-level config. The only keys which are merged are `config` and `mappings`. This means that you can set your own wp-config values without losing any of the default values.
|
|
582
641
|
|
|
642
|
+
When using `--config` with a custom config file, the override file name is derived by inserting `.override` before the extension. For example, `.wp-env.test.json` will look for `.wp-env.test.override.json`.
|
|
643
|
+
|
|
583
644
|
## Default wp-config values.
|
|
584
645
|
|
|
585
646
|
On the development instance, these wp-config values are defined by default:
|
|
@@ -595,11 +656,9 @@ WP_SITEURL: 'http://localhost',
|
|
|
595
656
|
WP_HOME: 'http://localhost',
|
|
596
657
|
```
|
|
597
658
|
|
|
598
|
-
On the test instance, all of the above are still defined, but `WP_DEBUG` and `SCRIPT_DEBUG` are set to false.
|
|
599
|
-
|
|
600
659
|
These can be overridden by setting a value within the `config` configuration. Setting it to `null` will prevent the constant being defined entirely.
|
|
601
660
|
|
|
602
|
-
|
|
661
|
+
The values referencing a URL include the specified port. So if you set `port: 2000`, `WP_HOME` (for example) will be `http://localhost:2000`.
|
|
603
662
|
|
|
604
663
|
## Lifecycle Scripts
|
|
605
664
|
|
|
@@ -609,7 +668,8 @@ example, `WP_ENV_LIFECYCLE_SCRIPT_AFTER_START`. Keep in mind that these will be
|
|
|
609
668
|
build won't break on subsequent executions.
|
|
610
669
|
|
|
611
670
|
* `afterStart`: Runs after `wp-env start` has finished setting up the environment.
|
|
612
|
-
* `
|
|
671
|
+
* `afterReset`: Runs after `wp-env reset` has finished resetting the environment.
|
|
672
|
+
* `afterCleanup`: Runs after `wp-env cleanup` has cleaned up the environment.
|
|
613
673
|
* `afterDestroy`: Runs after `wp-env destroy` has destroyed the environment.
|
|
614
674
|
|
|
615
675
|
## Examples
|
|
@@ -698,21 +758,19 @@ Since all plugins in the `plugins` key are activated by default, you should use
|
|
|
698
758
|
}
|
|
699
759
|
```
|
|
700
760
|
|
|
701
|
-
### Map a plugin only in
|
|
761
|
+
### Map a plugin only in a specific environment
|
|
702
762
|
|
|
703
|
-
If you need a plugin active in one environment but not
|
|
763
|
+
If you need a plugin active in one environment but not another, use `--config` with a separate config file. For example, create a `test.wp-env.json` that includes an extra test plugin:
|
|
704
764
|
|
|
705
765
|
```json
|
|
706
766
|
{
|
|
707
|
-
"plugins": [ "." ],
|
|
708
|
-
"
|
|
709
|
-
"tests": {
|
|
710
|
-
"plugins": [ ".", "path/to/test/plugin" ]
|
|
711
|
-
}
|
|
712
|
-
}
|
|
767
|
+
"plugins": [ ".", "path/to/test/plugin" ],
|
|
768
|
+
"port": 8889
|
|
713
769
|
}
|
|
714
770
|
```
|
|
715
771
|
|
|
772
|
+
Then start it with `wp-env start --config=test.wp-env.json`.
|
|
773
|
+
|
|
716
774
|
### Custom Port Numbers
|
|
717
775
|
|
|
718
776
|
You can tell `wp-env` to use a custom port number so that your instance does not conflict with other `wp-env` instances.
|
|
@@ -720,21 +778,15 @@ You can tell `wp-env` to use a custom port number so that your instance does not
|
|
|
720
778
|
```json
|
|
721
779
|
{
|
|
722
780
|
"plugins": [ "." ],
|
|
723
|
-
"port": 4013
|
|
724
|
-
"env": {
|
|
725
|
-
"tests": {
|
|
726
|
-
"port": 4012
|
|
727
|
-
}
|
|
728
|
-
}
|
|
781
|
+
"port": 4013
|
|
729
782
|
}
|
|
730
783
|
```
|
|
731
784
|
|
|
732
785
|
These can also be set via environment variables:
|
|
733
786
|
|
|
734
|
-
- `WP_ENV_PORT` to override the
|
|
735
|
-
-
|
|
736
|
-
-
|
|
737
|
-
- By default, MySQL aren't exposed to the host, which means no chance of port conflicts. But these can also be overridden for the development and testing environments via `WP_ENV_MYSQL_PORT` and `WP_ENV_TESTS_MYSQL_PORT`, respectively.
|
|
787
|
+
- `WP_ENV_PORT` to override the web server's port.
|
|
788
|
+
- phpMyAdmin is not enabled by default, but its port can also be overridden via `WP_ENV_PHPMYADMIN_PORT`.
|
|
789
|
+
- By default, MySQL isn't exposed to the host, which means no chance of port conflicts. But this can also be overridden via `WP_ENV_MYSQL_PORT`.
|
|
738
790
|
|
|
739
791
|
### Specific PHP Version
|
|
740
792
|
|
|
@@ -749,7 +801,7 @@ You can tell `wp-env` to use a specific PHP version for compatibility and testin
|
|
|
749
801
|
|
|
750
802
|
### Multisite support
|
|
751
803
|
|
|
752
|
-
You can tell `wp-env`
|
|
804
|
+
You can tell `wp-env` if the site should be multisite enabled.
|
|
753
805
|
|
|
754
806
|
```json
|
|
755
807
|
{
|
|
@@ -805,8 +857,7 @@ wp-env start --spx
|
|
|
805
857
|
|
|
806
858
|
Once enabled, you can access the SPX web UI by visiting any page in your WordPress environment with the query parameters `?SPX_KEY=dev&SPX_UI_URI=/`. For example:
|
|
807
859
|
|
|
808
|
-
-
|
|
809
|
-
- Test site: `http://localhost:8889/?SPX_KEY=dev&SPX_UI_URI=/`
|
|
860
|
+
- `http://localhost:8888/?SPX_KEY=dev&SPX_UI_URI=/`
|
|
810
861
|
|
|
811
862
|
From the SPX interface, you can:
|
|
812
863
|
- Enable profiling for subsequent requests
|
package/lib/cli.js
CHANGED
|
@@ -18,6 +18,7 @@ const {
|
|
|
18
18
|
getAvailableRuntimes,
|
|
19
19
|
getRuntime,
|
|
20
20
|
UnsupportedCommandError,
|
|
21
|
+
EnvironmentNotInitializedError,
|
|
21
22
|
} = require( './runtime' );
|
|
22
23
|
|
|
23
24
|
// Colors.
|
|
@@ -45,8 +46,11 @@ const withSpinner =
|
|
|
45
46
|
process.exit( 0 );
|
|
46
47
|
},
|
|
47
48
|
( error ) => {
|
|
48
|
-
if (
|
|
49
|
-
|
|
49
|
+
if (
|
|
50
|
+
error instanceof UnsupportedCommandError ||
|
|
51
|
+
error instanceof EnvironmentNotInitializedError
|
|
52
|
+
) {
|
|
53
|
+
// Error is a known user-facing error.
|
|
50
54
|
spinner.fail( error.message );
|
|
51
55
|
process.exit( 1 );
|
|
52
56
|
} else if (
|
|
@@ -97,6 +101,11 @@ module.exports = function cli() {
|
|
|
97
101
|
describe: 'Enable debug output.',
|
|
98
102
|
default: false,
|
|
99
103
|
} );
|
|
104
|
+
yargs.option( 'config', {
|
|
105
|
+
type: 'string',
|
|
106
|
+
describe: 'Path to a custom .wp-env.json configuration file.',
|
|
107
|
+
requiresArg: true,
|
|
108
|
+
} );
|
|
100
109
|
|
|
101
110
|
yargs.parserConfiguration( {
|
|
102
111
|
// Treats unknown options as arguments for commands to deal with instead of discarding them.
|
|
@@ -162,15 +171,33 @@ module.exports = function cli() {
|
|
|
162
171
|
() => {},
|
|
163
172
|
withSpinner( env.stop )
|
|
164
173
|
);
|
|
174
|
+
yargs.command(
|
|
175
|
+
'reset [environment]',
|
|
176
|
+
wpYellow( 'Resets the WordPress databases.' ),
|
|
177
|
+
( args ) => {
|
|
178
|
+
args.positional( 'environment', {
|
|
179
|
+
type: 'string',
|
|
180
|
+
describe: "Which environments' databases to reset.",
|
|
181
|
+
choices: [ 'all', 'development', 'tests' ],
|
|
182
|
+
default: 'development',
|
|
183
|
+
} );
|
|
184
|
+
args.option( 'scripts', {
|
|
185
|
+
type: 'boolean',
|
|
186
|
+
describe: 'Execute any configured lifecycle scripts.',
|
|
187
|
+
default: true,
|
|
188
|
+
} );
|
|
189
|
+
},
|
|
190
|
+
withSpinner( env.reset )
|
|
191
|
+
);
|
|
165
192
|
yargs.command(
|
|
166
193
|
'clean [environment]',
|
|
167
|
-
|
|
194
|
+
chalk.gray( '[Deprecated: use reset] Resets the WordPress databases.' ),
|
|
168
195
|
( args ) => {
|
|
169
196
|
args.positional( 'environment', {
|
|
170
197
|
type: 'string',
|
|
171
|
-
describe: "Which environments' databases to
|
|
198
|
+
describe: "Which environments' databases to reset.",
|
|
172
199
|
choices: [ 'all', 'development', 'tests' ],
|
|
173
|
-
default: '
|
|
200
|
+
default: 'development',
|
|
174
201
|
} );
|
|
175
202
|
args.option( 'scripts', {
|
|
176
203
|
type: 'boolean',
|
|
@@ -246,7 +273,7 @@ module.exports = function cli() {
|
|
|
246
273
|
yargs.command(
|
|
247
274
|
'destroy',
|
|
248
275
|
wpRed(
|
|
249
|
-
'Destroy the WordPress environment. Deletes docker containers, volumes, and
|
|
276
|
+
'Destroy the WordPress environment. Deletes docker containers, volumes, networks, and images associated with the WordPress environment and removes local files.'
|
|
250
277
|
),
|
|
251
278
|
( args ) => {
|
|
252
279
|
args.option( 'scripts', {
|
|
@@ -254,14 +281,44 @@ module.exports = function cli() {
|
|
|
254
281
|
describe: 'Execute any configured lifecycle scripts.',
|
|
255
282
|
default: true,
|
|
256
283
|
} );
|
|
284
|
+
args.option( 'force', {
|
|
285
|
+
type: 'boolean',
|
|
286
|
+
describe: 'Skip the confirmation prompt.',
|
|
287
|
+
default: false,
|
|
288
|
+
} );
|
|
257
289
|
},
|
|
258
290
|
withSpinner( env.destroy )
|
|
259
291
|
);
|
|
260
292
|
yargs.command(
|
|
261
|
-
'
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
293
|
+
'cleanup',
|
|
294
|
+
wpYellow(
|
|
295
|
+
'Cleanup the WordPress environment. Removes docker containers, volumes, networks, and local files, but preserves docker images for faster re-starts.'
|
|
296
|
+
),
|
|
297
|
+
( args ) => {
|
|
298
|
+
args.option( 'scripts', {
|
|
299
|
+
type: 'boolean',
|
|
300
|
+
describe: 'Execute any configured lifecycle scripts.',
|
|
301
|
+
default: true,
|
|
302
|
+
} );
|
|
303
|
+
args.option( 'force', {
|
|
304
|
+
type: 'boolean',
|
|
305
|
+
describe: 'Skip the confirmation prompt.',
|
|
306
|
+
default: false,
|
|
307
|
+
} );
|
|
308
|
+
},
|
|
309
|
+
withSpinner( env.cleanup )
|
|
310
|
+
);
|
|
311
|
+
yargs.command(
|
|
312
|
+
'status',
|
|
313
|
+
'Get the status of the wp-env environment including URLs, ports, and configuration.',
|
|
314
|
+
( args ) => {
|
|
315
|
+
args.option( 'json', {
|
|
316
|
+
type: 'boolean',
|
|
317
|
+
describe: 'Output status as JSON.',
|
|
318
|
+
default: false,
|
|
319
|
+
} );
|
|
320
|
+
},
|
|
321
|
+
withSpinner( env.status )
|
|
265
322
|
);
|
|
266
323
|
|
|
267
324
|
return yargs;
|
package/lib/commands/clean.js
CHANGED
|
@@ -17,25 +17,34 @@ const { getRuntime, detectRuntime } = require( '../runtime' );
|
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
19
|
/**
|
|
20
|
-
*
|
|
20
|
+
* @deprecated Use `reset` instead.
|
|
21
|
+
*
|
|
22
|
+
* Resets the development server's database, the tests server's database, or both.
|
|
21
23
|
*
|
|
22
24
|
* @param {Object} options
|
|
23
|
-
* @param {WPEnvironmentSelection} options.environment The environment to
|
|
25
|
+
* @param {WPEnvironmentSelection} options.environment The environment to reset. Either 'development', 'tests', or 'all'.
|
|
24
26
|
* @param {Object} options.spinner A CLI spinner which indicates progress.
|
|
25
27
|
* @param {boolean} options.scripts Indicates whether or not lifecycle scripts should be executed.
|
|
26
28
|
* @param {boolean} options.debug True if debug mode is enabled.
|
|
29
|
+
* @param {string|null} options.config Path to a custom .wp-env.json configuration file.
|
|
27
30
|
*/
|
|
28
31
|
module.exports = async function clean( {
|
|
29
32
|
environment,
|
|
30
33
|
spinner,
|
|
31
34
|
scripts,
|
|
32
35
|
debug,
|
|
36
|
+
config: customConfigPath,
|
|
33
37
|
} ) {
|
|
34
|
-
|
|
35
|
-
|
|
38
|
+
spinner.warn( 'The `clean` command is deprecated. Use `reset` instead.' );
|
|
39
|
+
|
|
40
|
+
const config = await loadConfig( path.resolve( '.' ), customConfigPath );
|
|
41
|
+
const runtime = getRuntime(
|
|
42
|
+
await detectRuntime( config.workDirectoryPath )
|
|
43
|
+
);
|
|
36
44
|
|
|
37
45
|
await runtime.clean( config, { environment, spinner, debug } );
|
|
38
46
|
|
|
47
|
+
// Execute afterClean for backwards compatibility.
|
|
39
48
|
if ( scripts ) {
|
|
40
49
|
await executeLifecycleScript( 'afterClean', config, spinner );
|
|
41
50
|
}
|