Skip to content

Commit 833e4ae

Browse files
committed
feat: ask for project type instead of a confirmation message
1 parent 043bfae commit 833e4ae

File tree

1 file changed

+24
-25
lines changed

1 file changed

+24
-25
lines changed

src/Command/Project/InitializeProjectCommand.php

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,8 @@ protected function perform(InputInterface $input, OutputStyle $output)
103103
return;
104104
}
105105

106-
$projectType = $this->getProjectType();
107-
108-
if (empty($projectType)
109-
&& !$output->confirm('No WordPress installation detected in this directory. Do you want to proceed?', false)) {
110-
return;
111-
}
112-
113106
$name = $this->determineName($input, $output);
107+
$projectType = $this->determineProjectType($output);
114108
$providerId = $this->determineCloudProvider($input, $output, 'Enter the ID of the cloud provider that the project will use');
115109
$region = $this->determineRegion($input, $output, $providerId, 'Enter the name of the region that the project will be in');
116110

@@ -138,6 +132,7 @@ private function determineDatabaseName(OutputStyle $output): string
138132
$databases = $this->apiClient->getDatabases($this->cliConfiguration->getActiveTeamId());
139133

140134
if (!$databases->isEmpty() && $output->confirm('Would you like to use an existing database for this project?')) {
135+
// TODO: This looks ugly. Add more info.
141136
$databaseName = (string) $output->choice('Which database would you like to use?', $databases->pluck('name')->all());
142137
} elseif (
143138
(!$databases->isEmpty() && $output->confirm('Would you like to create a new one for this project instead?'))
@@ -166,6 +161,28 @@ private function determineName(InputInterface $input, OutputStyle $output): stri
166161
return (string) $name;
167162
}
168163

164+
/**
165+
* Determine the type of project being initialized.
166+
*/
167+
private function determineProjectType(OutputStyle $output): string
168+
{
169+
$type = '';
170+
171+
if ($this->filesystem->exists($this->projectDirectory.'/wp-config.php')) {
172+
$type = 'wordpress';
173+
} elseif ($this->filesystem->exists(array_map(function (string $path) {
174+
return $this->projectDirectory.$path;
175+
}, ['/web/app/', '/web/wp-config.php', '/config/application.php']))) {
176+
$type = 'bedrock';
177+
}
178+
179+
if (empty($type)) {
180+
$type = strtolower($output->choice('Please select the type of project to initialize', ['Bedrock', 'WordPress']));
181+
}
182+
183+
return $type;
184+
}
185+
169186
/**
170187
* Get the database name from the console input.
171188
*/
@@ -186,24 +203,6 @@ private function getDatabaseName(InputInterface $input): ?string
186203
return $databaseName;
187204
}
188205

189-
/**
190-
* Get the project type that we're initializing.
191-
*/
192-
private function getProjectType(): string
193-
{
194-
$type = '';
195-
196-
if ($this->filesystem->exists($this->projectDirectory.'/wp-config.php')) {
197-
$type = 'wordpress';
198-
} elseif ($this->filesystem->exists($this->projectDirectory.'/composer.json')
199-
&& false !== strpos((string) file_get_contents($this->projectDirectory.'/composer.json'), 'roots/wordpress')
200-
) {
201-
$type = 'bedrock';
202-
}
203-
204-
return $type;
205-
}
206-
207206
/**
208207
* Checks if the plugin is already installed.
209208
*/

0 commit comments

Comments
 (0)