-
Notifications
You must be signed in to change notification settings - Fork 275
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
wp-now: Add executeWPCli()
function to download and execute WP-CLI
#395
Changes from 14 commits
b5173cb
e101433
af6a0ad
d5ba677
f53d520
8fcff51
ad3513d
de46790
877cfe7
5741ae8
244ee69
7f1f9ce
863b338
96ae2cf
cc86a62
1766aa1
da7699d
99174cc
acfbe6f
471b353
ca269c6
e0395e6
a241c2d
5e8e97c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
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'; | ||
|
||
export async function executeWPCli(args: string[], emscriptenOptions = {}) { | ||
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, | ||
}, | ||
emscriptenOptions | ||
); | ||
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; | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import path from 'path'; | ||
import getWpNowPath from './get-wp-now-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 path.resolve('./wp-cli.phar'); | ||
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. Should this be a temp directory? 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. I found that using a temporal directory on my laptop, the 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. 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. @danielbachhuber , with the temp folder, it seems to pass ok in CI. But it is still failing on my local computer. 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. Is it getting mounted correctly @sejas? What do you see when you list files? 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. @sejas It failed locally for me too. 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.
Yes, the file is accessible in VFS and the file size is correct. It must be something related to MacOs and the tmp path. 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. @sejas would you start a new issue for this? I'd like to make sure this works on MacOs 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. Fixing it with WordPress/playground-tools#42 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. There was a conflict mounting |
||
} |
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.