|
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 InstallTailwindFrontendPreset |
|
13
|
|
|
{ |
|
14
|
|
|
public function __construct() |
|
15
|
|
|
{ |
|
16
|
|
|
} |
|
17
|
|
|
|
|
18
|
|
|
public function __invoke(string $name, InputInterface $input, OutputInterface $output) |
|
19
|
|
|
{ |
|
20
|
|
|
$output->writeln('<info># Installing Tailwindcss frontend preset...</info>'); |
|
21
|
|
|
|
|
22
|
|
|
$directory = getcwd() . '/' . $name; |
|
23
|
|
|
|
|
24
|
|
|
$composer = $this->findComposer(); |
|
25
|
|
|
|
|
26
|
|
|
$commands = [ |
|
27
|
|
|
$composer . ' require --dev laravel-frontend-presets/tailwindcss', |
|
28
|
|
|
'php artisan ui tailwindcss --auth', |
|
29
|
|
|
'yarn add tailwindcss --dev', |
|
30
|
|
|
'yarn add vue-template-compiler --dev', |
|
31
|
|
|
'yarn', |
|
32
|
|
|
'yarn dev', |
|
33
|
|
|
]; |
|
34
|
|
|
|
|
35
|
|
|
$runner = new CommandRunner($output, $directory); |
|
36
|
|
|
$isSuccessful = $runner->run($commands); |
|
37
|
|
|
|
|
38
|
|
|
$filesystem = new ProjectFilesystem(getcwd() . '/' . $name); |
|
39
|
|
|
|
|
40
|
|
|
$output->writeln('<info>Update file: resources/lang/en/pagination.php</info>'); |
|
41
|
|
|
$filesystem->updateFile('resources/lang/en/pagination.php', function (string $content) { |
|
42
|
|
|
$patterns = [ |
|
43
|
|
|
'/(\'next\' => \'Next »\',\n)/', |
|
44
|
|
|
]; |
|
45
|
|
|
$replace = [ |
|
46
|
|
|
"\${1} 'goto_page' => 'Goto page #:page',\n", |
|
47
|
|
|
]; |
|
48
|
|
|
|
|
49
|
|
|
return preg_replace($patterns, $replace, $content); |
|
50
|
|
|
}); |
|
51
|
|
|
|
|
52
|
|
|
$output->writeln('<info>Update file: .gitignore</info>'); |
|
53
|
|
|
$filesystem->updateFile('.gitignore', function (string $content) { |
|
54
|
|
|
$patterns = [ |
|
55
|
|
|
'/(\/public\/storage\n)/', |
|
56
|
|
|
]; |
|
57
|
|
|
$replace = [ |
|
58
|
|
|
"\${1}/public/css\n/public/js\n/public/mix-manifest.json\n", |
|
59
|
|
|
]; |
|
60
|
|
|
|
|
61
|
|
|
return preg_replace($patterns, $replace, $content); |
|
62
|
|
|
}); |
|
63
|
|
|
|
|
64
|
|
|
if ($isSuccessful) { |
|
65
|
|
|
$output->writeln('<comment>Tailwindcss preset installed.</comment>'); |
|
66
|
|
|
} |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* Get the composer command for the environment. |
|
71
|
|
|
* |
|
72
|
|
|
* @return string |
|
73
|
|
|
*/ |
|
74
|
|
|
protected function findComposer(): string |
|
75
|
|
|
{ |
|
76
|
|
|
$composerPath = getcwd() . '/composer.phar'; |
|
77
|
|
|
|
|
78
|
|
|
if (file_exists($composerPath)) { |
|
79
|
|
|
return '"' . PHP_BINARY . '" ' . $composerPath; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
return 'composer'; |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
|