You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Adding runCLI section to the Playground CLI page (#2583)
## Motivation for the change, related issues
This PR enhances the Playground CLI documentation by introducing a new
major section on `Programmatic Usage with JavaScript`. This new content
details how to control the CLI via the `runCLI` function, which is a key
feature for enabling advanced use cases like automated end-to-end
testing.
In addition to this new content, the PR also includes some minor
improvements to the existing documentation to enhance clarity, correct
typos, and address minor inaccuracies.
Overall, these changes make the documentation more complete and
user-friendly, especially for developers looking to integrate the
Playground CLI into their automated workflows.
---------
Co-authored-by: Adam Zieliński <[email protected]>
Copy file name to clipboardExpand all lines: packages/docs/site/docs/developers/05-local-development/04-wp-playground-cli.md
+122-4Lines changed: 122 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -20,15 +20,15 @@ The Playground CLI requires Node.js 20.18 or higher, which is the recommended Lo
20
20
21
21
## Quickstart
22
22
23
-
Running the Playground CLI is as simple as go to a command-line and run:
23
+
To run the Playground CLI, open a commandline and use the following command:
24
24
25
25
```bash
26
26
npx @wp-playground/cli@latest server
27
27
```
28
28
29
29

30
30
31
-
With the previous command, you only get a fresh WordPress instance to test. Most of the developers want to see their work running. If this is your case, test a plugin or a theme. You can run the CLI on your project folder and run the Playground CLI with the `--auto-mount` flag:
31
+
With the previous command, you only get a fresh WordPress instance to test. Most developers will want to test their own work. To test a plugin or a theme, navigate to your project folder and run the CLI with the `--auto-mount` flag:
32
32
33
33
```bash
34
34
cd my-plugin-or-theme-directory
@@ -40,7 +40,7 @@ npx @wp-playground/cli@latest server --auto-mount
40
40
By default, the CLI loads the latest stable version of WordPress and PHP 8.3 due to its improved performance. To specify your preferred versions, you can use the flag `--wp=<version>` and `--php=<version>`:
41
41
42
42
```bash
43
-
npx @wp-playground/cli@latest server --wp=6.8 --php=8.4
43
+
npx @wp-playground/cli@latest server --wp=6.8 --php=8.3
44
44
```
45
45
46
46
### Loading Blueprints
@@ -117,8 +117,126 @@ The `server` command supports the following optional arguments:
117
117
118
118
## Need some help with the CLI?
119
119
120
-
With the Playground CLI, you can use the `--help` to get some support about the available commands.
120
+
With the Playground CLI, you can use the `--help`flag to get the full list of available commands and arguments.
121
121
122
122
```bash
123
123
npx @wp-playground/cli@latest --help
124
124
```
125
+
126
+
## Programmatic Usage with JavaScript
127
+
128
+
The Playground CLI can also be controlled programmatically from your JavaScript/TypeScript code using the `runCLI` function. This gives you direct access to all CLI functionalities within your code, which is useful for automating end-to-end tests. Let's cover the basics of using `runCLI`.
129
+
130
+
### Running a WordPress instance with a specific version
131
+
132
+
Using the `runCLI` function, you can specify options like the PHP and WordPress versions. In the example below, we request PHP 8.3, the latest version of WordPress, and to be automatically logged in. All supported arguments are defined in the `RunCLIArgs` type.
To execute the code above, the developer can set their preferred method. A simple way to execute this code is to save it as a `.ts` file and run it with a tool like `tsx`. For example: `tsx my-script.ts`
148
+
149
+
### Setting a Blueprint
150
+
151
+
You can provide a blueprint in two ways: either as an object literal directly passed to the `blueprint` property, or as a string containing the path to an external `.json` file.
For full type-safety when defining your blueprint object, you can import and use the `BlueprintDeclaration` type from the `@wp-playground/blueprints` package:
It is possible to mount local directories programmatically using `runCLI`. The options `mount` and `mount-before-install` are available. The `hostPath` property expects a path to a directory on your local machine. This path should be relative to where your script is being executed.
0 commit comments