playground-tools icon indicating copy to clipboard operation
playground-tools copied to clipboard

WP-NOW: Add wp-cli integration

Open sejas opened this issue 1 year ago • 5 comments

  • Closes: https://github.com/WordPress/playground-tools/issues/25

What?

Brings wp-cli execution to wp-now with the current site context. The new command will be wp-now wp ... I'm open to other command names, like cli.

Why?

wp-cli is a handy tool for all WordPress developers opening a wide range of automatizations.

How?

wp-cli was intentionally removed until the Playground was mature enough to support a wide range of operations. I added a new command that calls executeWPCli, which downloads the phar file and mounts the current directory to make easier the execution of local files with eval-file.

Testing Instructions

  1. Run nvm use && npm install && npx nx build wp-now
  2. Run npx nx run wp-now:test
  3. Observe the tests pass
  4. Run node dist/packages/wp-now/cli.js wp eval-file /./foo.php
  5. Run node dist/packages/wp-now/cli.js wp cli version
  6. Run other wp-cli commands
  7. Confirm wp-cli runs as expected

sejas avatar Apr 03 '24 11:04 sejas

wp cli info fails for me too, but it seems to be more of a problem with the PHP wasm implementation than wp-now. (At least I couldn't find a way to get it to successfully trap the exception.

n3f avatar Jul 28 '24 18:07 n3f

@n3f what would be a reproduction?

adamziel avatar Jul 31 '24 13:07 adamziel

@n3f what would be a reproduction?

I just followed the instructions in the PR then as an additional case ran node dist/packages/wp-now/cli.js wp cli info (just like @kozer). I saw the same error, but I looked to see if there was a way to catch it, but it appeared to be caught and handled at the php boundary -- but I might just not understand how it works correctly.

n3f avatar Jul 31 '24 17:07 n3f

@n3f , thanks for testing it. Yeah, not sure why wp cli info fails in php-wasm/node version and it doesn't in the web version https://playground.wordpress.net/demos/wp-cli.html

Maybe it's a matter of using the latest dependencies.

Screenshot 2024-08-01 at 10 37 59

sejas avatar Aug 01 '24 09:08 sejas