Skip to content

Commit 52f2928

Browse files
authored
Merge pull request #500 from BeAPI/feat/wp-env
feat(env): add .wp-env.json configuration for local development envir…
2 parents b5a38e0 + cd1fe30 commit 52f2928

7 files changed

Lines changed: 149 additions & 3499 deletions

File tree

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,9 @@ assets/conf-img/*.json
8888
### theme.json
8989
src/scss/01-abstract/_theme-json.scss
9090
theme.json
91+
92+
### wp-env
93+
.wp-env/
94+
95+
### Composer
96+
composer.lock

.wp-env.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"$schema": "https://schemas.wp.org/trunk/wp-env.json",
3+
"core": null,
4+
"phpVersion": "8.3",
5+
"testsEnvironment": false,
6+
"themes": [
7+
"."
8+
],
9+
"plugins": [
10+
".wp-env/plugins/advanced-custom-fields"
11+
],
12+
"config": {
13+
"WP_DEBUG": true,
14+
"WP_DEBUG_LOG": true,
15+
"WP_DEBUG_DISPLAY": false,
16+
"SCRIPT_DEBUG": true,
17+
"WP_ENVIRONMENT_TYPE": "local",
18+
"WP_DEVELOPMENT_MODE": "theme"
19+
},
20+
"lifecycleScripts": {
21+
"afterStart": "wp-env run cli wp theme activate beapi-frontend-framework && wp-env run cli wp plugin activate advanced-custom-fields"
22+
}
23+
}

README.md

Lines changed: 80 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,85 @@ Alternatively, you can use NPM.
6767
npm install
6868
```
6969

70+
## Local development with wp-env
71+
72+
BFF ships with a [wp-env](https://developer.wordpress.org/block-editor/reference-guides/packages/packages-env/) configuration (`.wp-env.json`) to run a local WordPress instance with Docker.
73+
74+
### Requirements
75+
76+
- [Docker Desktop](https://www.docker.com/products/docker-desktop/) (or a compatible Docker runtime)
77+
- Node.js (see [Requirements](#nodejs))
78+
79+
### Installing wp-env
80+
81+
You can run wp-env without a global install via `npx @wordpress/env`, or install the CLI once and use the `wp-env` command:
82+
83+
```bash
84+
# Global install (npm or yarn)
85+
npm install -g @wordpress/env
86+
# or
87+
yarn global add @wordpress/env
88+
```
89+
90+
After installation, replace `npx @wordpress/env` with `wp-env` in the commands below.
91+
92+
### Getting started
93+
94+
From the theme root:
95+
96+
```bash
97+
yarn
98+
npx @wordpress/env start
99+
# or, if wp-env is installed globally:
100+
wp-env start
101+
```
102+
103+
On first start, wp-env will:
104+
105+
- Spin up WordPress (PHP 8.3)
106+
- Mount this theme from the current directory
107+
- Install and activate the [Advanced Custom Fields](https://wordpress.org/plugins/advanced-custom-fields/) plugin
108+
109+
### URLs and credentials
110+
111+
| | |
112+
|---|---|
113+
| Site | http://localhost:8888 |
114+
| Admin | http://localhost:8888/wp-admin |
115+
| Username | `admin` |
116+
| Password | `password` |
117+
118+
### Common commands
119+
120+
```bash
121+
# Start the environment
122+
npx @wordpress/env start # or: wp-env start
123+
124+
# Stop containers (data is preserved)
125+
npx @wordpress/env stop # or: wp-env stop
126+
127+
# Remove containers and volumes
128+
npx @wordpress/env destroy # or: wp-env destroy
129+
130+
# Run WP-CLI inside the environment
131+
npx @wordpress/env run cli wp plugin list
132+
# or: wp-env run cli wp plugin list
133+
134+
# Run a command in the theme directory
135+
npx @wordpress/env run cli --env-cwd=wp-content/themes/beapi-frontend-framework composer install
136+
# or: wp-env run cli --env-cwd=wp-content/themes/beapi-frontend-framework composer install
137+
```
138+
139+
### Development workflow
140+
141+
With wp-env running, start the Webpack watcher in a second terminal:
142+
143+
```bash
144+
yarn start
145+
```
146+
147+
Changes to PHP, SCSS, and JavaScript assets are reflected after Webpack rebuilds. Theme PHP changes are picked up immediately thanks to the mounted volume.
148+
70149
## Configuration
71150

72151
The configurations files are in `config` directory.
@@ -130,4 +209,4 @@ function customize_editor_settings( $settings ) {
130209

131210
return $settings;
132211
}
133-
```
212+
```

composer.json

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,32 @@
11
{
22
"name": "beapi/beapi-frontend-framework",
33
"description": "Frontend Framework theme for WordPress",
4-
"type": "metapackage",
4+
"type": "wordpress-theme",
5+
"extra": {
6+
"installer-paths": {
7+
".wp-env/plugins/{$name}/": [
8+
"type:wordpress-plugin"
9+
]
10+
}
11+
},
12+
"repositories": [
13+
{
14+
"name": "wp-packages",
15+
"type": "composer",
16+
"url": "https://repo.wp-packages.org"
17+
}
18+
],
519
"require-dev": {
620
"dealerdirect/phpcodesniffer-composer-installer": "^1.0",
721
"overtrue/phplint": "^9.0",
822
"php-parallel-lint/php-parallel-lint": "^1.4",
923
"phpcompatibility/phpcompatibility-wp": "^2.1",
1024
"phpro/grumphp-shim": "^2.6",
1125
"roave/security-advisories": "dev-latest",
12-
"wp-coding-standards/wpcs": "^3.1"
26+
"wp-coding-standards/wpcs": "3.3.0",
27+
"wp-plugin/advanced-custom-fields": "6.8.4"
1328
},
14-
"scripts": {
29+
"scripts": {
1530
"cs": [
1631
"./vendor/bin/phpcs ."
1732
],
@@ -27,7 +42,11 @@
2742
"config": {
2843
"allow-plugins": {
2944
"dealerdirect/phpcodesniffer-composer-installer": true,
30-
"phpro/grumphp-shim": true
45+
"phpro/grumphp-shim": true,
46+
"composer/installers": true
47+
},
48+
"platform": {
49+
"php": "8.3.0"
3150
}
3251
}
3352
}

0 commit comments

Comments
 (0)