1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Scriptura\QuickStart\Tasks; |
6
|
|
|
|
7
|
|
|
use Scriptura\QuickStart\CommandRunner; |
8
|
|
|
use Scriptura\QuickStart\ProjectFilesystem; |
9
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
10
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
11
|
|
|
|
12
|
|
|
class InstallTelescope |
13
|
|
|
{ |
14
|
|
|
public function __construct() |
15
|
|
|
{ |
16
|
|
|
} |
17
|
|
|
|
18
|
|
|
public function __invoke(string $name, InputInterface $input, OutputInterface $output) |
19
|
|
|
{ |
20
|
|
|
$output->writeln('<info># Installing Telescope...</info>'); |
21
|
|
|
|
22
|
|
|
$directory = getcwd() . '/' . $name; |
23
|
|
|
|
24
|
|
|
$composer = $this->findComposer(); |
25
|
|
|
|
26
|
|
|
$commands = [ |
27
|
|
|
$composer . ' require laravel/telescope', |
28
|
|
|
'php artisan telescope:install', |
29
|
|
|
]; |
30
|
|
|
|
31
|
|
|
$runner = new CommandRunner($output, $directory); |
32
|
|
|
$isSuccessful = $runner->run($commands); |
33
|
|
|
|
34
|
|
|
$filesystem = new ProjectFilesystem(getcwd() . '/' . $name); |
35
|
|
|
|
36
|
|
|
$output->writeln('<info>Update file: app/Console/Kernel.php</info>'); |
37
|
|
|
$filesystem->updateFile('app/Console/Kernel.php', function (string $content) { |
38
|
|
|
$patterns = [ |
39
|
|
|
'/\/\/ \$schedule/', |
40
|
|
|
'/inspire/', |
41
|
|
|
'/hourly/', |
42
|
|
|
]; |
43
|
|
|
$replace = [ |
44
|
|
|
'$schedule', |
45
|
|
|
'telescope:prune --hours=24', |
46
|
|
|
'daily', |
47
|
|
|
]; |
48
|
|
|
|
49
|
|
|
return preg_replace($patterns, $replace, $content); |
50
|
|
|
}); |
51
|
|
|
|
52
|
|
|
if ($isSuccessful) { |
53
|
|
|
$output->writeln('<comment>Telescope installed.</comment>'); |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Get the composer command for the environment. |
59
|
|
|
* |
60
|
|
|
* @return string |
61
|
|
|
*/ |
62
|
|
|
protected function findComposer(): string |
63
|
|
|
{ |
64
|
|
|
$composerPath = getcwd() . '/composer.phar'; |
65
|
|
|
|
66
|
|
|
if (file_exists($composerPath)) { |
67
|
|
|
return '"' . PHP_BINARY . '" ' . $composerPath; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
return 'composer'; |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|