Open2
wp-env と timber/starter-theme を試す

mkdir wp-env-demo
cd wp-env-demo
git init
# 適当に .gitignore を用意
asdf local nodejs 16.20.2
npm i @wordpress/env --save-dev
以下を追加。
package.json
"scripts": {
"wp-env": "wp-env"
},
npm run wp-env start -- --update
> wp-env
> wp-env start --update
⚠ Warning: could not find a .wp-env.json configuration file and could not determine if '/Users/ydan/Documents/chiyoda/wp-env-demo' is a WordPress installation, a plugin, or a theme.
WordPress development site started at http://localhost:8888
WordPress test site started at http://localhost:8889
MySQL is listening on port 64506
MySQL for automated testing is listening on port 64606
✔ Done! (in 158s 846ms)
http://localhost:8888 で以下のようなページが表示される。
http://localhost:8888/wp-admin/ で管理画面にログイン。 (admin/password が初期アカウント)
Troubleshooting common problems
-
wp-env start
での起動と Docker の操作がメイン -
wp-env clean
とwp-env destroy
のコマンドもある- 前者は DB のクリーンアップで、後者は Docker のコンテナやイメージ等も掃除する
ちなみに Docker の Containers は以下のように動いている。tests-
prefix がついているものは、テスト用途だろうか。
cli-1
のように cli が別コンテナで動作しているのがわかる。。
続いて Volumes を見ると、mysql
と user-home
という Volume が test
のあるなしで存在している。
In Use のタブを見ると、 user-home
は wordpress
と cli
のコンテナが両方マウントしており、共有していることがわかった。おそらく、操作は cli のコンテナからやるという意図なのだろう。
Using composer, phpunit, and wp-cli tools.
-
wp-env run
について書かれている - ここでは
wp-env run <env> <tool> <command>
のように説明されており<env>
ってなんぞな?という感じではあるが、後に出てくるコマンドリファレンスではwp-env run <container> [command...]
となっているので、コンテナ名と考えればよさそう。 -
--env-cwd
のオプションで、プラグインごとのディレクトリで composer のようなコマンドを適切に実行できるようだ
この公式ページはしっかり読んでおく必要がありそうだが、一通り読むのは後回しにして次に進む。

local
npx wp-env run cli --env-cwd=wp-content composer require timber/timber:"1.22.*"
cli
/var/www/html/wp-content$ cat composer.json
{
"require": {
"timber/timber": "1.22.*"
},
"config": {
"allow-plugins": {
"composer/installers": true
}
}
}