-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStarterKitPostInstall.php
More file actions
72 lines (54 loc) · 1.98 KB
/
Copy pathStarterKitPostInstall.php
File metadata and controls
72 lines (54 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Process;
use function Laravel\Prompts\info;
use function Laravel\Prompts\spin;
class StarterKitPostInstall
{
protected string $env = '';
protected string $config = '';
public function handle($console)
{
$this->exportAndDeleteFile('config/dok.export.php', 'config/dok.php');
info('[✓] Added config/dok.php');
$this->config = app('files')->get(base_path('config/dok.php'));
$this->env = app('files')->get(base_path('.env'));
$this->writeFiles();
$this->finish();
}
protected function runCommand(string $command, bool $spin = true, string $message = ''): void
{
$result = null;
if ($spin) {
spin(
callback: function () use (&$result, $command) {
$result = Process::timeout(120)->run($command);
},
message: $message
);
} else {
$result = Process::timeout(120)->run($command);
}
if ($result->failed()) {
throw new \RuntimeException("Command failed: {$command}\n".$result->errorOutput());
}
echo $result->output();
}
protected function writeFiles(): void
{
app('files')->put(base_path('config/dok.php'), $this->config);
app('files')->put(base_path('.env'), $this->env);
}
protected function exportAndDeleteFile(string $source, string $destination): void
{
$sourcePath = base_path($source);
$destinationPath = base_path($destination);
File::ensureDirectoryExists(dirname($destinationPath));
File::put($destinationPath, File::get($sourcePath));
File::delete($sourcePath);
}
protected function finish(): void
{
info('Thanks for purchasing this starter kit, I hope it helps you. If you have any questions or run into any issues, please create an issue on GitHub. Have a nice day!');
}
}