Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,12 @@ vendor/
.DS_store?

############
## Config overrides for CS tools
## Config overrides for tools
############
phpcs.xml
phpunit.xml
phpstan.neon
wp-cli.local.yml

############
## Misc
Expand Down
3 changes: 3 additions & 0 deletions .wp-env.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
"./plugins/web-worker-offloading",
"./plugins/webp-uploads"
],
"lifecycleScripts": {
"afterStart": "bin/update-wp-cli-local-ssh.sh"
},
"env": {
"tests": {
"config": {
Expand Down
22 changes: 22 additions & 0 deletions bin/update-wp-cli-local-ssh.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash
# This script is intended to be run as the lifecycleScripts.afterStart script.

set -e

cd "$(dirname "$0")/.."

wp_cli_config_file="wp-cli.local.yml"

if [ ! -e "$wp_cli_config_file" ]; then
echo "path: /var/www/html" >> "$wp_cli_config_file"
fi

hash=$(basename "$(npm run --silent wp-env install-path 2>/dev/null)")
container_id=$(docker ps --format "{{.ID}} {{.Names}}" | grep "$hash-cli" | awk '{print $1}')

grep -v 'ssh:' < "$wp_cli_config_file" > "$wp_cli_config_file-next"

echo "ssh: docker:$container_id" >> "$wp_cli_config_file-next"
mv "$wp_cli_config_file-next" "$wp_cli_config_file"

echo "Container ID for cli: $container_id"