-
Notifications
You must be signed in to change notification settings - Fork 139
/
Copy pathTailwindCssPreset.php
125 lines (104 loc) · 4.06 KB
/
TailwindCssPreset.php
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<?php
namespace LaravelFrontendPresets\TailwindCssPreset;
use Illuminate\Container\Container;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
use Laravel\Ui\Presets\Preset;
use Symfony\Component\Finder\SplFileInfo;
class TailwindCssPreset extends Preset
{
public static function install()
{
static::updatePackages();
static::updateStyles();
static::updateBootstrapping();
static::updateWelcomePage();
static::removeNodeModules();
}
public static function installAuth()
{
static::scaffoldController();
static::scaffoldAuth();
}
protected static function updatePackageArray(array $packages)
{
return array_merge([
'@tailwindcss/forms' => '^0.5',
'autoprefixer' => '^10.4.4',
'laravel-mix' => '^6.0.6',
'postcss' => '^8.4.14',
'tailwindcss' => '^3.0.23',
], Arr::except($packages, [
'bootstrap',
'bootstrap-sass',
'popper.js',
'laravel-mix',
'jquery',
]));
}
protected static function updateStyles()
{
tap(new Filesystem, function ($filesystem) {
$filesystem->deleteDirectory(resource_path('sass'));
$filesystem->delete(public_path('js/app.js'));
$filesystem->delete(public_path('css/app.css'));
if (! $filesystem->isDirectory($directory = resource_path('css'))) {
$filesystem->makeDirectory($directory, 0755, true);
}
});
copy(__DIR__.'/tailwindcss-stubs/resources/css/app.css', resource_path('css/app.css'));
}
protected static function updateBootstrapping()
{
copy(__DIR__.'/tailwindcss-stubs/tailwind.config.js', base_path('tailwind.config.js'));
copy(__DIR__.'/tailwindcss-stubs/webpack.mix.js', base_path('webpack.mix.js'));
copy(__DIR__.'/tailwindcss-stubs/resources/js/bootstrap.js', resource_path('js/bootstrap.js'));
}
protected static function updateWelcomePage()
{
(new Filesystem)->delete(resource_path('views/welcome.blade.php'));
copy(__DIR__.'/tailwindcss-stubs/resources/views/welcome.blade.php', resource_path('views/welcome.blade.php'));
}
protected static function scaffoldController()
{
if (! is_dir($directory = app_path('Http/Controllers/Auth'))) {
mkdir($directory, 0755, true);
}
$filesystem = new Filesystem;
collect($filesystem->allFiles(base_path('vendor/laravel/ui/stubs/Auth')))
->each(function (SplFileInfo $file) use ($filesystem) {
$filesystem->copy(
$file->getPathname(),
app_path('Http/Controllers/Auth/'.Str::replaceLast('.stub', '.php', $file->getFilename()))
);
});
}
protected static function scaffoldAuth()
{
file_put_contents(app_path('Http/Controllers/HomeController.php'), static::compileControllerStub());
file_put_contents(
base_path('routes/web.php'),
"Auth::routes();\n\nRoute::get('/home', [\App\Http\Controllers\HomeController::class, 'index'])->name('home');\n\n",
FILE_APPEND
);
tap(new Filesystem, function ($filesystem) {
$filesystem->copyDirectory(__DIR__.'/tailwindcss-stubs/resources/views', resource_path('views'));
collect($filesystem->allFiles(base_path('vendor/laravel/ui/stubs/migrations')))
->each(function (SplFileInfo $file) use ($filesystem) {
$filesystem->copy(
$file->getPathname(),
database_path('migrations/'.$file->getFilename())
);
});
});
}
protected static function compileControllerStub()
{
return str_replace(
'{{namespace}}',
Container::getInstance()->getNamespace(),
file_get_contents(__DIR__.'/tailwindcss-stubs/controllers/HomeController.stub')
);
}
}