Skip to content

Commit a4b4709

Browse files
authored
chore(core): framework installer improvements (#752)
1 parent 3f9bdde commit a4b4709

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

src/Tempest/Console/src/GenericConsole.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,10 @@ public function ask(
179179
bool $asList = false,
180180
array $validation = [],
181181
): null|string|array {
182+
if ($this->isForced && $default) {
183+
return $default;
184+
}
185+
182186
if ($options === null || $options === []) {
183187
$component = new TextBoxComponent($question, $default);
184188
} elseif ($multiple) {

src/Tempest/Framework/Installers/FrameworkInstaller.php

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Tempest\Core\Installer;
88
use Tempest\Core\PublishesFiles;
99
use function Tempest\root_path;
10+
use function Tempest\Support\str;
1011

1112
final class FrameworkInstaller implements Installer
1213
{
@@ -58,15 +59,29 @@ private function installMainNamespace(): void
5859
return;
5960
}
6061

61-
$appPath = root_path('app/');
62+
$appPath = root_path($this->ask('Which path do you wish to use as your main project directory?', default: 'app/'));
63+
64+
$defaultAppNamespace = str($appPath)
65+
->replaceStart(root_path(), '')
66+
->trim('/')
67+
->explode('/')
68+
->map(fn (string $part) => ucfirst($part))
69+
->implode('\\')
70+
->append('\\')
71+
->toString();
72+
73+
$appNamespace = str($this->ask('Which namespace do you wish to use?', default: $defaultAppNamespace))
74+
->trim('\\')
75+
->append('\\')
76+
->toString();
6277

6378
if (! is_dir($appPath)) {
64-
mkdir($appPath);
79+
mkdir($appPath, recursive: true);
6580
}
6681

6782
$this->composer
6883
->addNamespace(
69-
'App\\',
84+
$appNamespace,
7085
$appPath,
7186
)
7287
->save();

0 commit comments

Comments
 (0)