WP-NOW: Add wp-cli integration
- 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
- Run
nvm use && npm install && npx nx build wp-now - Run
npx nx run wp-now:test - Observe the tests pass
- Run
node dist/packages/wp-now/cli.js wp eval-file /./foo.php - Run
node dist/packages/wp-now/cli.js wp cli version - Run other wp-cli commands
- Confirm wp-cli runs as expected
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 what would be a reproduction?
@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 , 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.