Skip to content

Commit b002c58

Browse files
committed
fix: routes and other stuff published
1 parent 48df360 commit b002c58

File tree

1 file changed

+59
-28
lines changed

1 file changed

+59
-28
lines changed

src/AdminLTEPreset.php

Lines changed: 59 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,18 @@
33
namespace InfyOm\AdminLTEPreset;
44

55
use Illuminate\Console\Command;
6+
use Illuminate\Container\Container;
7+
use Illuminate\Filesystem\Filesystem;
8+
use Illuminate\Support\Str;
69
use InfyOm\GeneratorHelpers\LaravelUtils;
710
use Laravel\Ui\Presets\Preset;
11+
use Symfony\Component\Finder\SplFileInfo;
812

913
class AdminLTEPreset extends Preset
1014
{
1115
/** @var Command */
1216
protected $command;
1317

14-
protected $views = [
15-
'auth/login.stub' => 'auth/login.blade.php',
16-
'auth/passwords/confirm.stub' => 'auth/passwords/confirm.blade.php',
17-
'auth/passwords/email.stub' => 'auth/passwords/email.blade.php',
18-
'auth/passwords/reset.stub' => 'auth/passwords/reset.blade.php',
19-
'auth/register.stub' => 'auth/register.blade.php',
20-
'auth/verify.stub' => 'auth/verify.blade.php',
21-
'home.stub' => 'home.blade.php',
22-
'layouts/app.stub' => 'layouts/app.blade.php',
23-
'layouts/menu.stub' => 'layouts/menu.blade.php',
24-
'layouts/sidebar.stub' => 'layouts/sidebar.blade.php',
25-
];
26-
2718
public function __construct(Command $command)
2819
{
2920
$this->command = $command;
@@ -79,22 +70,10 @@ public function installAuth()
7970
{
8071
$viewsPath = LaravelUtils::getViewPath();
8172

82-
$this->ensureDirectoriesExist($viewsPath);;
83-
84-
foreach ($this->views as $key => $value) {
85-
if (file_exists($view = LaravelUtils::getViewPath($value))) {
86-
if (!$this->command->confirm("The [{$value}] view already exists. Do you want to replace it?")) {
87-
continue;
88-
}
89-
}
73+
$this->ensureDirectoriesExist($viewsPath);
9074

91-
copy(
92-
__DIR__.'/../adminlte-stubs/'.$key,
93-
$view
94-
);
95-
96-
$this->command->info("{$view} copied");
97-
}
75+
$this->scaffoldAuth();
76+
$this->scaffoldController();
9877
}
9978

10079
protected function ensureDirectoriesExist($viewsPath)
@@ -111,4 +90,56 @@ protected function ensureDirectoriesExist($viewsPath)
11190
mkdir($viewsPath.'auth/passwords', 0755, true);
11291
}
11392
}
93+
94+
protected function scaffoldController()
95+
{
96+
if (!is_dir($directory = app_path('Http/Controllers/Auth'))) {
97+
mkdir($directory, 0755, true);
98+
}
99+
100+
$filesystem = new Filesystem;
101+
102+
collect($filesystem->allFiles(base_path('vendor/laravel/ui/stubs/Auth')))
103+
->each(function (SplFileInfo $file) use ($filesystem) {
104+
$filesystem->copy(
105+
$file->getPathname(),
106+
app_path('Http/Controllers/Auth/'.Str::replaceLast('.stub', '.php', $file->getFilename()))
107+
);
108+
});
109+
}
110+
111+
protected function scaffoldAuth()
112+
{
113+
file_put_contents(app_path('Http/Controllers/HomeController.php'), $this->compileHomeControllerStub());
114+
115+
file_put_contents(
116+
base_path('routes/web.php'),
117+
"Auth::routes();\n\nRoute::get('/home', 'HomeController@index')->name('home');\n\n",
118+
FILE_APPEND
119+
);
120+
121+
tap(new Filesystem, function ($filesystem) {
122+
123+
$filesystem->copyDirectory(__DIR__.'/../adminlte-stubs/auth', resource_path('views/auth'));
124+
$filesystem->copyDirectory(__DIR__.'/../adminlte-stubs/layouts', resource_path('views/layouts'));
125+
$filesystem->copy(__DIR__.'/../adminlte-stubs/home.stub', resource_path('views/home.blade.php'));
126+
127+
collect($filesystem->allFiles(base_path('vendor/laravel/ui/stubs/migrations')))
128+
->each(function (SplFileInfo $file) use ($filesystem) {
129+
$filesystem->copy(
130+
$file->getPathname(),
131+
database_path('migrations/'.$file->getFilename())
132+
);
133+
});
134+
});
135+
}
136+
137+
protected function compileHomeControllerStub()
138+
{
139+
return str_replace(
140+
'{{namespace}}',
141+
Container::getInstance()->getNamespace(),
142+
file_get_contents(base_path('vendor/laravel/ui/src/Auth/stubs/controllers/HomeController.stub'))
143+
);
144+
}
114145
}

0 commit comments

Comments
 (0)