Skip to content

Commit 740a368

Browse files
committed
wip
1 parent e5bd504 commit 740a368

File tree

2 files changed

+249
-245
lines changed

2 files changed

+249
-245
lines changed

packages/core/src/IsComponentInstaller.php

Lines changed: 44 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -7,57 +7,59 @@
77
use function Tempest\root_path;
88
use function Tempest\Support\str;
99

10-
/**
11-
* @phpstan-require-implements \Tempest\Core\Installer
12-
*/
13-
trait IsComponentInstaller
14-
{
15-
use PublishesFiles;
16-
17-
private function installMainNamespace(): void
10+
if (trait_exists(PublishesFiles::class)) {
11+
/**
12+
* @phpstan-require-implements \Tempest\Core\Installer
13+
*/
14+
trait IsComponentInstaller
1815
{
19-
if ($this->composer->mainNamespace !== null) {
20-
return;
21-
}
16+
use PublishesFiles;
2217

23-
if (! $this->confirm('Tempest detected no main project namespace. Do you want to create it?', default: true)) {
24-
return;
25-
}
18+
private function installMainNamespace(): void
19+
{
20+
if ($this->composer->mainNamespace !== null) {
21+
return;
22+
}
2623

27-
$appPath = root_path($this->ask('Which path do you wish to use as your main project directory?', default: 'app/'));
24+
if (! $this->confirm('Tempest detected no main project namespace. Do you want to create it?', default: true)) {
25+
return;
26+
}
2827

29-
$defaultAppNamespace = str($appPath)
30-
->replaceStart(root_path(), '')
31-
->trim('/')
32-
->explode('/')
33-
->map(fn (string $part) => ucfirst($part))
34-
->implode('\\')
35-
->append('\\')
36-
->toString();
28+
$appPath = root_path($this->ask('Which path do you wish to use as your main project directory?', default: 'app/'));
3729

38-
$appNamespace = str($this->ask('Which namespace do you wish to use?', default: $defaultAppNamespace))
39-
->trim('\\')
40-
->append('\\')
41-
->toString();
30+
$defaultAppNamespace = str($appPath)
31+
->replaceStart(root_path(), '')
32+
->trim('/')
33+
->explode('/')
34+
->map(fn (string $part) => ucfirst($part))
35+
->implode('\\')
36+
->append('\\')
37+
->toString();
4238

43-
if (! is_dir($appPath)) {
44-
mkdir($appPath, recursive: true);
45-
}
39+
$appNamespace = str($this->ask('Which namespace do you wish to use?', default: $defaultAppNamespace))
40+
->trim('\\')
41+
->append('\\')
42+
->toString();
4643

47-
$this->composer
48-
->addNamespace(
49-
$appNamespace,
50-
$appPath,
51-
)
52-
->save();
44+
if (! is_dir($appPath)) {
45+
mkdir($appPath, recursive: true);
46+
}
5347

54-
$this->success("Project namespace created: {$appPath}");
55-
}
48+
$this->composer
49+
->addNamespace(
50+
$appNamespace,
51+
$appPath,
52+
)
53+
->save();
5654

57-
private function updateComposer(): void
58-
{
59-
if ($this->confirm(question: 'Run composer update?', default: true)) {
60-
$this->composer->executeUpdate();
55+
$this->success("Project namespace created: {$appPath}");
56+
}
57+
58+
private function updateComposer(): void
59+
{
60+
if ($this->confirm(question: 'Run composer update?', default: true)) {
61+
$this->composer->executeUpdate();
62+
}
6163
}
6264
}
6365
}

0 commit comments

Comments
 (0)