-
Notifications
You must be signed in to change notification settings - Fork 295
wp-now: Add executeWPCli()
function to download and execute WP-CLI
#395
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
adamziel
merged 24 commits into
WordPress:trunk
from
Automattic:add/wp-now-command-wp-cli
May 30, 2023
Merged
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
b5173cb
wp-now: add basic wp-cli command
sejas e101433
Merge branch 'trunk' of github.com:Automattic/wordpress-playground in…
sejas af6a0ad
wp-now: remove wp command until we fix pthreads
sejas d5ba677
wp-now: remove unnecessary flags for wp-cli
sejas f53d520
Merge branch 'trunk' of github.com:Automattic/wordpress-playground in…
sejas 8fcff51
wp-now: force creating an empty file for downloadFile
sejas ad3513d
wp-now: add tests for executeWPCli
sejas de46790
wp-now: optimize tests and download files in parallel
sejas 877cfe7
wp-now: accept path as second argument on executeWPCli
sejas 5741ae8
wp-now: improve download file
sejas 244ee69
wp-now: add emscriptenOptions to startWPNow
sejas 7f1f9ce
wp-now: change wp-cli option to get its version
sejas 863b338
wp-now: download wp-cli only for that test collection
sejas 96ae2cf
wp-now: move downloadWithTimer to another PR
sejas cc86a62
Merge branch 'trunk' of github.com:Automattic/wordpress-playground in…
sejas 1766aa1
wp-now: use downloadWithTimer for wp-cli
sejas da7699d
wp-now: change wp-cli test version
sejas 99174cc
wp-now: avoid exposing emscriptenOptions and just onStdout
sejas acfbe6f
wp-now: remove unused import
sejas 471b353
wp-now: mock console.log for wp-cli tests
sejas ca269c6
wp-now: remove the stdout and emscriptenOptions unnecessary
sejas e0395e6
wp-now: add comment on executeWPCli marking it as unstable
sejas a241c2d
Merge branch 'trunk' into add/wp-now-command-wp-cli
danielbachhuber 5e8e97c
Use a tmp directory for WP-CLI tests
danielbachhuber File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import startWPNow from './wp-now'; | ||
import { downloadWPCLI } from './download'; | ||
import { disableOutput } from './output'; | ||
import getWpCliPath from './get-wp-cli-path'; | ||
import getWpNowConfig from './config'; | ||
import { DEFAULT_PHP_VERSION, DEFAULT_WORDPRESS_VERSION } from './constants'; | ||
|
||
/** | ||
* This is an unstable API. Multiple wp-cli commands may not work due to a current limitation on php-wasm and pthreads. | ||
* @param args The arguments to pass to wp-cli. | ||
*/ | ||
export async function executeWPCli(args: string[]) { | ||
await downloadWPCLI(); | ||
disableOutput(); | ||
const options = await getWpNowConfig({ | ||
php: DEFAULT_PHP_VERSION, | ||
wp: DEFAULT_WORDPRESS_VERSION, | ||
path: process.env.WP_NOW_PROJECT_PATH || process.cwd(), | ||
}); | ||
const { phpInstances, options: wpNowOptions } = await startWPNow({ | ||
...options, | ||
numberOfPhpInstances: 2, | ||
}); | ||
const [, php] = phpInstances; | ||
|
||
try { | ||
php.useHostFilesystem(); | ||
await php.cli([ | ||
'php', | ||
getWpCliPath(), | ||
`--path=${wpNowOptions.documentRoot}`, | ||
...args, | ||
]); | ||
} catch (resultOrError) { | ||
const success = | ||
resultOrError.name === 'ExitStatus' && resultOrError.status === 0; | ||
if (!success) { | ||
throw resultOrError; | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import path from 'path'; | ||
import getWpNowPath from './get-wp-now-path'; | ||
import getWpCliTmpPath from './get-wp-cli-tmp-path'; | ||
|
||
/** | ||
* The path for wp-cli phar file within the WP Now folder. | ||
*/ | ||
export default function getWpCliPath() { | ||
if (process.env.NODE_ENV !== 'test') { | ||
return path.join(getWpNowPath(), 'wp-cli.phar'); | ||
} | ||
return getWpCliTmpPath(); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import path from 'path'; | ||
import os from 'os'; | ||
|
||
/** | ||
* The full path to the hidden WP-CLI folder in the user's tmp directory. | ||
*/ | ||
export default function getWpCliTmpPath() { | ||
const tmpDirectory = os.tmpdir(); | ||
|
||
return path.join(tmpDirectory, `wp-now-tests-wp-cli-hidden-folder`); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
"extends": "./tsconfig.json", | ||
"compilerOptions": { | ||
"outDir": "../../dist/out-tsc", | ||
"types": ["jest", "node"] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nice |
||
"types": ["vitest/globals", "vitest/importMeta", "vite/client", "node"] | ||
}, | ||
"include": [ | ||
"jest.config.ts", | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI I merged this change: https://github.com/WordPress/wordpress-playground/pull/470/files#diff-3652c54df4b8d0d8e367481121e32f08cc409cfc4236fdb3172d69dcbf6ca8b0
It shouldn't matter here at all and this check still passes, but I wanted to flag it here just in case.