-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStarterKitPostInstall.php
More file actions
95 lines (74 loc) · 2.61 KB
/
StarterKitPostInstall.php
File metadata and controls
95 lines (74 loc) · 2.61 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<?php
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Process;
use function Laravel\Prompts\info;
use function Laravel\Prompts\select;
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->chooseCodeHighligher();
$this->writeFiles();
$this->finish();
}
protected function chooseCodeHighligher(): void
{
$selected = select(
required: true,
label: 'Which code highligher do you want to use?',
options: [
'torchlight-engine' => 'Torchlight Engine/Phiki (Recommended)',
'none' => 'None',
]
);
if ($selected === 'torchlight-engine') {
$this->runCommand(
command: 'composer require torchlight/engine',
message: 'Installing Torchlight Engine...'
);
return;
}
}
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('I hope this starterkit helps you! If you have any questions or run into any issues, please create an issue on GitHub. Have a nice day!');
}
}