From 0a6765c511ef62df1dd4b6f45ec05e6641f4a323 Mon Sep 17 00:00:00 2001 From: Evan Mattson Date: Sun, 2 Oct 2016 12:19:29 +0400 Subject: [PATCH 1/4] create project root if it not exists for composer installs --- src/Installer/BedrockInstaller.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Installer/BedrockInstaller.php b/src/Installer/BedrockInstaller.php index 17e7ad4..2d032fd 100644 --- a/src/Installer/BedrockInstaller.php +++ b/src/Installer/BedrockInstaller.php @@ -18,6 +18,10 @@ public function download() { Command::debug('Installing Bedrock via Composer'); + if (! is_dir($full_path = $this->props->projectRoot())) { + mkdir($full_path, 0755, true); + } + Composer::createProject('roots/bedrock', $this->props->site_name, [ 'working-dir' => $this->props->parentDirectory(), 'no-interaction' => true, From f8d6f577132145f279d57a62db981612faf72f4d Mon Sep 17 00:00:00 2001 From: Evan Mattson Date: Sun, 2 Oct 2016 12:19:58 +0400 Subject: [PATCH 2/4] use consistent method in WordPress installer --- src/Installer/WordPressInstaller.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Installer/WordPressInstaller.php b/src/Installer/WordPressInstaller.php index 04af468..f5621d2 100644 --- a/src/Installer/WordPressInstaller.php +++ b/src/Installer/WordPressInstaller.php @@ -47,7 +47,7 @@ public function download() 'locale' => $this->props->option('locale'), ]); - if (! is_dir($full_path = $this->props->fullPath())) { + if (! is_dir($full_path = $this->props->projectRoot())) { mkdir($full_path, 0755, true); } From 2b0f89f4dd12914d41d3402d6f90a4d8684f57f0 Mon Sep 17 00:00:00 2001 From: Evan Mattson Date: Sun, 2 Oct 2016 12:21:31 +0400 Subject: [PATCH 3/4] =?UTF-8?q?use=20new=20=E2=80=98in=E2=80=99=20flag=20i?= =?UTF-8?q?nstead=20of=20trying=20to=20use=20global=20=E2=80=98path?= =?UTF-8?q?=E2=80=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit wp-cli strips global options from `$assoc_args` so it’s better to use our own for this. --- src/Props.php | 2 +- src/ValetCommand.php | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Props.php b/src/Props.php index 3b2a54b..9b7853e 100644 --- a/src/Props.php +++ b/src/Props.php @@ -96,7 +96,7 @@ public function parentDirectory() public function fullPath($relative = '') { $parts = array_filter([ - $this->option('path', getcwd()), + $this->option('in', getcwd()), $this->site_name, $relative ]); diff --git a/src/ValetCommand.php b/src/ValetCommand.php index 72ac63c..2210527 100644 --- a/src/ValetCommand.php +++ b/src/ValetCommand.php @@ -74,6 +74,10 @@ public static function boot() * - bedrock * --- * + * [--in=] + * : Specify the path to the parent directory to create the install in. + * Defaults to the current working directory. + * * [--version=] * : WordPress version to install. * --- From 6b92f58e488cda3a76445d82426196d3ac3901cd Mon Sep 17 00:00:00 2001 From: Evan Mattson Date: Sun, 2 Oct 2016 12:21:45 +0400 Subject: [PATCH 4/4] add feature tests to cover new option --- features/valet-new-project-bedrock.feature | 9 +++++++++ features/valet-new.feature | 11 +++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/features/valet-new-project-bedrock.feature b/features/valet-new-project-bedrock.feature index d3e4bbf..07abb16 100644 --- a/features/valet-new-project-bedrock.feature +++ b/features/valet-new-project-bedrock.feature @@ -32,3 +32,12 @@ Feature: It can create new installs for Valet-supported WordPress projects. When I run `wp valet destroy {PROJECT} --yes` Then the {PROJECT} directory should not exist + + @issue-10 + Scenario: It can create a new Bedrock install using the given path to the parent dir. + Given an empty directory + And a random project name as {PROJECT} + And a random string as {PATH} + + When I run `wp valet new {PROJECT} --project=bedrock --in={PATH} --debug` + Then the {PATH}/{PROJECT}/.env file should exist diff --git a/features/valet-new.feature b/features/valet-new.feature index 14befd1..58cee2d 100644 --- a/features/valet-new.feature +++ b/features/valet-new.feature @@ -20,27 +20,30 @@ Feature: Create a new install. Success: {PROJECT} ready! http://{PROJECT}.dev """ + @issue-10 Scenario: It accepts options for configuring the new install. Given an empty directory And a random project name as {PROJECT} And a random string as {ADMIN} + And a random string as {PATH} - When I run `wp valet new {PROJECT} --admin_user={ADMIN} --admin_email=hello@{PROJECT}.dev --version=4.5 --dbname=wp_cli_test --dbprefix={ADMIN}_ --dbuser=wp_cli_test --dbpass=password1` + When I run `wp valet new {PROJECT} --in={PATH} --admin_user={ADMIN} --admin_email=hello@{PROJECT}.dev --version=4.5 --dbname=wp_cli_test --dbprefix={ADMIN}_ --dbuser=wp_cli_test --dbpass=password1` + Then the {PATH}/{PROJECT}/wp-config.php file should exist Then the wp_cli_test database should exist - When I run `wp db tables --path={PROJECT}` + When I run `wp db tables --path={PATH}/{PROJECT}` Then STDOUT should contain: """ {ADMIN}_users """ - When I run `wp core version --path={PROJECT}` + When I run `wp core version --path={PATH}/{PROJECT}` Then STDOUT should be: """ 4.5 """ - When I run `wp user list --fields=ID,user_login,user_email --path={PROJECT}` + When I run `wp user list --fields=ID,user_login,user_email --path={PATH}/{PROJECT}` Then STDOUT should be a table containing rows: | ID | user_login | user_email | | 1 | {ADMIN} | hello@{PROJECT}.dev |