Skip to content
This repository was archived by the owner on Dec 11, 2021. It is now read-only.

Commit 9c842be

Browse files
committed
Restruct folders & scaffold migrations
1 parent fd38aa9 commit 9c842be

File tree

6 files changed

+93
-99
lines changed

6 files changed

+93
-99
lines changed

src/LaravelPresetDark.php

Lines changed: 0 additions & 43 deletions
This file was deleted.

src/LaravelPresetLight.php

Lines changed: 0 additions & 43 deletions
This file was deleted.

src/LaravelPresetServiceProvider.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,20 @@
55
use Laravel\Ui\UiCommand;
66
use Illuminate\Pagination\Paginator;
77
use Illuminate\Support\ServiceProvider;
8+
use TailwindComponents\LaravelPreset\Presets\Dark;
9+
use TailwindComponents\LaravelPreset\Presets\Light;
810

911
class LaravelPresetServiceProvider extends ServiceProvider
1012
{
1113
public function boot()
1214
{
1315
UiCommand::macro('tailwindcss', function ($command) {
14-
LaravelPresetLight::install();
16+
Light::install();
1517

1618
$command->info('Tailwind CSS scaffolding installed successfully.');
1719

1820
if ($command->option('auth')) {
19-
LaravelPresetLight::installAuth();
21+
Light::installAuth();
2022

2123
$command->info('Tailwind CSS auth scaffolding installed successfully.');
2224
}
@@ -25,12 +27,12 @@ public function boot()
2527
});
2628

2729
UiCommand::macro('tailwindcss:dark', function ($command) {
28-
LaravelPresetDark::install();
30+
Dark::install();
2931

3032
$command->info('Tailwind CSS scaffolding installed successfully.');
3133

3234
if ($command->option('auth')) {
33-
LaravelPresetDark::installAuth();
35+
Dark::installAuth();
3436

3537
$command->info('Tailwind CSS auth scaffolding installed successfully.');
3638
}

src/Presets/Dark.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
namespace TailwindComponents\LaravelPreset\Presets;
4+
5+
use Illuminate\Filesystem\Filesystem;
6+
7+
class Dark extends Preset
8+
{
9+
public static function install()
10+
{
11+
parent::install();
12+
static::updatePagination();
13+
}
14+
15+
public static function installAuth()
16+
{
17+
parent::installAuth();
18+
static::scaffoldAuthViews();
19+
}
20+
21+
protected static function updatePagination()
22+
{
23+
(new Filesystem)->delete(resource_path('views/vendor/paginate'));
24+
25+
(new Filesystem)->copyDirectory(__DIR__.'/../../stubs/resources/dark/views/vendor/pagination', resource_path('views/vendor/pagination'));
26+
}
27+
28+
protected static function scaffoldAuthViews()
29+
{
30+
(new Filesystem)->copyDirectory(__DIR__.'/../../stubs/resources/dark/views', resource_path('views'));
31+
}
32+
}

src/Presets/Light.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
namespace TailwindComponents\LaravelPreset\Presets;
4+
5+
use Illuminate\Filesystem\Filesystem;
6+
7+
class Light extends Preset
8+
{
9+
public static function install()
10+
{
11+
parent::install();
12+
static::updatePagination();
13+
}
14+
15+
public static function installAuth()
16+
{
17+
parent::installAuth();
18+
static::scaffoldAuthViews();
19+
}
20+
21+
protected static function updatePagination()
22+
{
23+
(new Filesystem)->delete(resource_path('views/vendor/paginate'));
24+
25+
(new Filesystem)->copyDirectory(__DIR__.'/../../stubs/resources/light/views/vendor/pagination', resource_path('views/vendor/pagination'));
26+
}
27+
28+
protected static function scaffoldAuthViews()
29+
{
30+
(new Filesystem)->copyDirectory(__DIR__.'/../../stubs/resources/light/views', resource_path('views'));
31+
}
32+
}

src/Preset.php renamed to src/Presets/Preset.php

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace TailwindComponents\LaravelPreset;
3+
namespace TailwindComponents\LaravelPreset\Presets;
44

55
use Illuminate\Support\Arr;
66
use Illuminate\Support\Str;
@@ -43,10 +43,11 @@ public static function install()
4343
public static function installAuth()
4444
{
4545
static::scaffoldController();
46+
static::scaffoldMigrations();
4647
static::scaffoldAuth();
4748
}
4849

49-
protected static function updatePackageArray(array $packages)
50+
protected static function updatePackageArray($packages)
5051
{
5152
return array_merge(
5253
static::NPM_PACKAGES_TO_ADD,
@@ -66,20 +67,20 @@ protected static function updateStyles()
6667
}
6768
});
6869

69-
copy(__DIR__.'/../stubs/resources/css/app.css', resource_path('css/app.css'));
70+
copy(__DIR__.'/../../stubs/resources/css/app.css', resource_path('css/app.css'));
7071
}
7172

7273
protected static function updateBootstrapping()
7374
{
74-
copy(__DIR__.'/../stubs/tailwind.config.js', base_path('tailwind.config.js'));
75+
copy(__DIR__.'/../../stubs/tailwind.config.js', base_path('tailwind.config.js'));
7576

76-
copy(__DIR__.'/../stubs/webpack.mix.js', base_path('webpack.mix.js'));
77+
copy(__DIR__.'/../../stubs/webpack.mix.js', base_path('webpack.mix.js'));
7778

78-
copy(__DIR__.'/../stubs/resources/js/app.js', resource_path('js/app.js'));
79+
copy(__DIR__.'/../../stubs/resources/js/app.js', resource_path('js/app.js'));
7980

80-
copy(__DIR__.'/../stubs/resources/js/bootstrap.js', resource_path('js/bootstrap.js'));
81+
copy(__DIR__.'/../../stubs/resources/js/bootstrap.js', resource_path('js/bootstrap.js'));
8182

82-
(new Filesystem)->copyDirectory(__DIR__.'/../stubs/resources/js/components', resource_path('js/components'));
83+
(new Filesystem)->copyDirectory(__DIR__.'/../../stubs/resources/js/components', resource_path('js/components'));
8384
}
8485

8586

@@ -100,6 +101,19 @@ protected static function scaffoldController()
100101
});
101102
}
102103

104+
protected static function scaffoldMigrations()
105+
{
106+
$filesystem = new Filesystem;
107+
108+
collect($filesystem->allFiles(base_path('vendor/laravel/ui/stubs/migrations')))
109+
->each(function (SplFileInfo $file) use ($filesystem) {
110+
$filesystem->copy(
111+
$file->getPathname(),
112+
database_path('migrations/'.$file->getFilename())
113+
);
114+
});
115+
}
116+
103117
protected static function scaffoldAuth()
104118
{
105119
file_put_contents(app_path('Http/Controllers/HomeController.php'), static::compileControllerStub());
@@ -116,7 +130,7 @@ protected static function compileControllerStub()
116130
return str_replace(
117131
'{{namespace}}',
118132
Container::getInstance()->getNamespace(),
119-
file_get_contents(__DIR__.'/../stubs/controllers/HomeController.stub')
133+
file_get_contents(__DIR__.'/../../stubs/controllers/HomeController.stub')
120134
);
121135
}
122136
}

0 commit comments

Comments
 (0)