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

Commit b8bfe2b

Browse files
committed
Refactor classes
1 parent dd45ad5 commit b8bfe2b

30 files changed

+130
-182
lines changed

src/LaravelPresetDark.php

Lines changed: 4 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -2,73 +2,21 @@
22

33
namespace TailwindComponents\LaravelPreset;
44

5-
use Illuminate\Support\Arr;
6-
use Illuminate\Support\Str;
7-
use Illuminate\Container\Container;
85
use Illuminate\Filesystem\Filesystem;
9-
use Laravel\Ui\Presets\Preset;
106
use Symfony\Component\Finder\SplFileInfo;
117

128
class LaravelPresetDark extends Preset
139
{
1410
public static function install()
1511
{
16-
static::updatePackages();
17-
static::updateStyles();
18-
static::updateBootstrapping();
12+
parent::install();
1913
static::updatePagination();
20-
static::removeNodeModules();
2114
}
2215

2316
public static function installAuth()
2417
{
25-
static::scaffoldController();
26-
static::scaffoldAuth();
27-
}
28-
29-
protected static function updatePackageArray(array $packages)
30-
{
31-
return array_merge([
32-
'vue' => '^2.6.11',
33-
'vue-template-compiler' => '^2.6.11',
34-
'laravel-mix' => '^5.0.1',
35-
'tailwindcss' => '^1.4',
36-
'@tailwindcss/custom-forms' => '^0.2',
37-
], Arr::except($packages, [
38-
'bootstrap',
39-
'bootstrap-sass',
40-
'popper.js',
41-
'laravel-mix',
42-
'jquery',
43-
]));
44-
}
45-
46-
protected static function updateStyles()
47-
{
48-
tap(new Filesystem, function ($filesystem) {
49-
$filesystem->deleteDirectory(resource_path('sass'));
50-
$filesystem->delete(public_path('js/app.js'));
51-
$filesystem->delete(public_path('css/app.css'));
52-
53-
if (! $filesystem->isDirectory($directory = resource_path('css'))) {
54-
$filesystem->makeDirectory($directory, 0755, true);
55-
}
56-
});
57-
58-
copy(__DIR__.'/stubs/resources/css/app.css', resource_path('css/app.css'));
59-
}
60-
61-
protected static function updateBootstrapping()
62-
{
63-
copy(__DIR__.'/stubs/tailwind.config.js', base_path('tailwind.config.js'));
64-
65-
copy(__DIR__.'/stubs/webpack.mix.js', base_path('webpack.mix.js'));
66-
67-
copy(__DIR__.'/stubs/resources/js/app.js', resource_path('js/app.js'));
68-
69-
copy(__DIR__.'/stubs/resources/js/bootstrap.js', resource_path('js/bootstrap.js'));
70-
71-
(new Filesystem)->copyDirectory(__DIR__.'/stubs/resources/js/components', resource_path('js/components'));
18+
parent::installAuth();
19+
static::scaffoldAuthViews();
7220
}
7321

7422
protected static function updatePagination()
@@ -78,33 +26,8 @@ protected static function updatePagination()
7826
(new Filesystem)->copyDirectory(__DIR__.'/stubs/resources/dark/views/vendor/pagination', resource_path('views/vendor/pagination'));
7927
}
8028

81-
protected static function scaffoldController()
29+
protected static function scaffoldAuthViews()
8230
{
83-
if (! is_dir($directory = app_path('Http/Controllers/Auth'))) {
84-
mkdir($directory, 0755, true);
85-
}
86-
87-
$filesystem = new Filesystem;
88-
89-
collect($filesystem->allFiles(base_path('vendor/laravel/ui/stubs/Auth')))
90-
->each(function (SplFileInfo $file) use ($filesystem) {
91-
$filesystem->copy(
92-
$file->getPathname(),
93-
app_path('Http/Controllers/Auth/'.Str::replaceLast('.stub', '.php', $file->getFilename()))
94-
);
95-
});
96-
}
97-
98-
protected static function scaffoldAuth()
99-
{
100-
file_put_contents(app_path('Http/Controllers/HomeController.php'), static::compileControllerStub());
101-
102-
file_put_contents(
103-
base_path('routes/web.php'),
104-
"Auth::routes();\n\nRoute::get('/home', 'HomeController@index')->name('home');\n\n",
105-
FILE_APPEND
106-
);
107-
10831
tap(new Filesystem, function ($filesystem) {
10932
$filesystem->copyDirectory(__DIR__.'/stubs/resources/dark/views', resource_path('views'));
11033

@@ -117,13 +40,4 @@ protected static function scaffoldAuth()
11740
});
11841
});
11942
}
120-
121-
protected static function compileControllerStub()
122-
{
123-
return str_replace(
124-
'{{namespace}}',
125-
Container::getInstance()->getNamespace(),
126-
file_get_contents(__DIR__.'/stubs/controllers/HomeController.stub')
127-
);
128-
}
12943
}

src/LaravelPresetLight.php

Lines changed: 6 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -2,111 +2,34 @@
22

33
namespace TailwindComponents\LaravelPreset;
44

5-
use Illuminate\Support\Arr;
6-
use Illuminate\Support\Str;
7-
use Illuminate\Container\Container;
85
use Illuminate\Filesystem\Filesystem;
9-
use Laravel\Ui\Presets\Preset;
106
use Symfony\Component\Finder\SplFileInfo;
117

128
class LaravelPresetLight extends Preset
139
{
1410
public static function install()
1511
{
16-
static::updatePackages();
17-
static::updateStyles();
18-
static::updateBootstrapping();
12+
parent::install();
1913
static::updatePagination();
20-
static::removeNodeModules();
2114
}
2215

2316
public static function installAuth()
2417
{
25-
static::scaffoldController();
26-
static::scaffoldAuth();
27-
}
28-
29-
protected static function updatePackageArray(array $packages)
30-
{
31-
return array_merge([
32-
'vue' => '^2.6.11',
33-
'vue-template-compiler' => '^2.6.11',
34-
'laravel-mix' => '^5.0.1',
35-
'tailwindcss' => '^1.4',
36-
'@tailwindcss/custom-forms' => '^0.2',
37-
], Arr::except($packages, [
38-
'bootstrap',
39-
'bootstrap-sass',
40-
'popper.js',
41-
'laravel-mix',
42-
'jquery',
43-
]));
44-
}
45-
46-
protected static function updateStyles()
47-
{
48-
tap(new Filesystem, function ($filesystem) {
49-
$filesystem->deleteDirectory(resource_path('sass'));
50-
$filesystem->delete(public_path('js/app.js'));
51-
$filesystem->delete(public_path('css/app.css'));
52-
53-
if (! $filesystem->isDirectory($directory = resource_path('css'))) {
54-
$filesystem->makeDirectory($directory, 0755, true);
55-
}
56-
});
57-
58-
copy(__DIR__.'/stubs/resources/css/app.css', resource_path('css/app.css'));
59-
}
60-
61-
protected static function updateBootstrapping()
62-
{
63-
copy(__DIR__.'/stubs/tailwind.config.js', base_path('tailwind.config.js'));
64-
65-
copy(__DIR__.'/stubs/webpack.mix.js', base_path('webpack.mix.js'));
66-
67-
copy(__DIR__.'/stubs/resources/js/app.js', resource_path('js/app.js'));
68-
69-
copy(__DIR__.'/stubs/resources/js/bootstrap.js', resource_path('js/bootstrap.js'));
70-
71-
(new Filesystem)->copyDirectory(__DIR__.'/stubs/resources/js/components', resource_path('js/components'));
18+
parent::installAuth();
19+
static::scaffoldAuthViews();
7220
}
7321

7422
protected static function updatePagination()
7523
{
7624
(new Filesystem)->delete(resource_path('views/vendor/paginate'));
7725

78-
(new Filesystem)->copyDirectory(__DIR__.'/stubs/resources/light/views/vendor/pagination', resource_path('views/vendor/pagination'));
26+
(new Filesystem)->copyDirectory(__DIR__.'/../stubs/resources/light/views/vendor/pagination', resource_path('views/vendor/pagination'));
7927
}
8028

81-
protected static function scaffoldController()
29+
protected static function scaffoldAuthViews()
8230
{
83-
if (! is_dir($directory = app_path('Http/Controllers/Auth'))) {
84-
mkdir($directory, 0755, true);
85-
}
86-
87-
$filesystem = new Filesystem;
88-
89-
collect($filesystem->allFiles(base_path('vendor/laravel/ui/stubs/Auth')))
90-
->each(function (SplFileInfo $file) use ($filesystem) {
91-
$filesystem->copy(
92-
$file->getPathname(),
93-
app_path('Http/Controllers/Auth/'.Str::replaceLast('.stub', '.php', $file->getFilename()))
94-
);
95-
});
96-
}
97-
98-
protected static function scaffoldAuth()
99-
{
100-
file_put_contents(app_path('Http/Controllers/HomeController.php'), static::compileControllerStub());
101-
102-
file_put_contents(
103-
base_path('routes/web.php'),
104-
"Auth::routes();\n\nRoute::get('/home', 'HomeController@index')->name('home');\n\n",
105-
FILE_APPEND
106-
);
107-
10831
tap(new Filesystem, function ($filesystem) {
109-
$filesystem->copyDirectory(__DIR__.'/stubs/resources/light/views', resource_path('views'));
32+
$filesystem->copyDirectory(__DIR__.'/../stubs/resources/light/views', resource_path('views'));
11033

11134
collect($filesystem->allFiles(base_path('vendor/laravel/ui/stubs/migrations')))
11235
->each(function (SplFileInfo $file) use ($filesystem) {
@@ -117,13 +40,4 @@ protected static function scaffoldAuth()
11740
});
11841
});
11942
}
120-
121-
protected static function compileControllerStub()
122-
{
123-
return str_replace(
124-
'{{namespace}}',
125-
Container::getInstance()->getNamespace(),
126-
file_get_contents(__DIR__.'/stubs/controllers/HomeController.stub')
127-
);
128-
}
12943
}

src/Preset.php

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
<?php
2+
3+
namespace TailwindComponents\LaravelPreset;
4+
5+
use Illuminate\Support\Arr;
6+
use Illuminate\Support\Str;
7+
use Illuminate\Container\Container;
8+
use Illuminate\Filesystem\Filesystem;
9+
use Laravel\Ui\Presets\Preset as LaravelPreset;
10+
use Symfony\Component\Finder\SplFileInfo;
11+
12+
class Preset extends LaravelPreset
13+
{
14+
const NPM_PACKAGES_TO_ADD = [
15+
'@tailwindcss/typography' => '^0.2',
16+
'@tailwindcss/custom-forms' => '^0.2',
17+
'vue' => '^2.6.11',
18+
'vue-template-compiler' => '^2.6.11',
19+
'laravel-mix' => '^5.0.1',
20+
'tailwindcss' => '^1.4',
21+
];
22+
23+
const NPM_PACKAGES_TO_REMOVE = [
24+
'bootstrap',
25+
'bootstrap-sass',
26+
'popper.js',
27+
'laravel-mix',
28+
'jquery',
29+
'sass',
30+
'sass-loader'
31+
];
32+
33+
public static function install()
34+
{
35+
static::updatePackages();
36+
static::updateStyles();
37+
static::updateBootstrapping();
38+
static::removeNodeModules();
39+
}
40+
41+
public static function installAuth()
42+
{
43+
static::scaffoldController();
44+
static::scaffoldAuth();
45+
}
46+
47+
protected static function updatePackageArray(array $packages)
48+
{
49+
return array_merge(
50+
static::NPM_PACKAGES_TO_ADD,
51+
Arr::except($packages, static::NPM_PACKAGES_TO_REMOVE)
52+
);
53+
}
54+
55+
protected static function updateStyles()
56+
{
57+
tap(new Filesystem, function ($filesystem) {
58+
$filesystem->deleteDirectory(resource_path('sass'));
59+
$filesystem->delete(public_path('js/app.js'));
60+
$filesystem->delete(public_path('css/app.css'));
61+
62+
if (! $filesystem->isDirectory($directory = resource_path('css'))) {
63+
$filesystem->makeDirectory($directory, 0755, true);
64+
}
65+
});
66+
67+
copy(__DIR__.'/../stubs/resources/css/app.css', resource_path('css/app.css'));
68+
}
69+
70+
protected static function updateBootstrapping()
71+
{
72+
copy(__DIR__.'/../stubs/tailwind.config.js', base_path('tailwind.config.js'));
73+
74+
copy(__DIR__.'/../stubs/webpack.mix.js', base_path('webpack.mix.js'));
75+
76+
copy(__DIR__.'/../stubs/resources/js/app.js', resource_path('js/app.js'));
77+
78+
copy(__DIR__.'/../stubs/resources/js/bootstrap.js', resource_path('js/bootstrap.js'));
79+
80+
(new Filesystem)->copyDirectory(__DIR__.'/../stubs/resources/js/components', resource_path('js/components'));
81+
}
82+
83+
84+
protected static function scaffoldController()
85+
{
86+
if (! is_dir($directory = app_path('Http/Controllers/Auth'))) {
87+
mkdir($directory, 0755, true);
88+
}
89+
90+
$filesystem = new Filesystem;
91+
92+
collect($filesystem->allFiles(base_path('vendor/laravel/ui/stubs/Auth')))
93+
->each(function (SplFileInfo $file) use ($filesystem) {
94+
$filesystem->copy(
95+
$file->getPathname(),
96+
app_path('Http/Controllers/Auth/'.Str::replaceLast('.stub', '.php', $file->getFilename()))
97+
);
98+
});
99+
}
100+
101+
protected static function scaffoldAuth()
102+
{
103+
file_put_contents(app_path('Http/Controllers/HomeController.php'), static::compileControllerStub());
104+
105+
file_put_contents(
106+
base_path('routes/web.php'),
107+
"Auth::routes();\n\nRoute::get('/home', 'HomeController@index')->name('home');\n\n",
108+
FILE_APPEND
109+
);
110+
}
111+
112+
protected static function compileControllerStub()
113+
{
114+
return str_replace(
115+
'{{namespace}}',
116+
Container::getInstance()->getNamespace(),
117+
file_get_contents(__DIR__.'/../stubs/controllers/HomeController.stub')
118+
);
119+
}
120+
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)