Skip to content

Commit

Permalink
fix: publish templates command removed and use vendor views
Browse files Browse the repository at this point in the history
  • Loading branch information
mitulgolakiya committed Jul 25, 2022
1 parent a899872 commit fbc1772
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 136 deletions.
2 changes: 0 additions & 2 deletions config/laravel_generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@

'schema_files' => resource_path('model_schemas/'),

'templates_dir' => resource_path('infyom/infyom-generator-templates/'),

'seeder' => database_path('seeders/'),

'database_seeder' => database_path('seeders/DatabaseSeeder.php'),
Expand Down
22 changes: 11 additions & 11 deletions src/Commands/Publish/PublishTablesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ public function publishLivewireTableViews()
$viewsPath = config('laravel_generator.path.views', resource_path('views/'));
$templateType = config('infyom.laravel_generator.templates', 'adminlte-templates');
$files = [
'views/templates/scaffold/table/livewire/actions.blade.php' => 'common/livewire-tables/actions.blade.php',
'scaffold.table.livewire.actions' => 'common/livewire-tables/actions.blade.php',
];

g_filesystem()->createDirectoryIfNotExist($viewsPath.'common/livewire-tables');

foreach ($files as $stub => $blade) {
$sourceFile = get_templates_package_path($templateType).'/'.$stub;
$destinationFile = $viewsPath.$blade;
$this->publishFile($sourceFile, $destinationFile, $blade);
foreach ($files as $templateView => $destinationView) {
$content = view($templateType.'::'.$templateView);
$destinationFile = $viewsPath.$destinationView;
g_filesystem()->createFile($destinationFile, $content);
}
}

Expand All @@ -62,14 +62,14 @@ protected function publishDataTableViews()
$viewsPath = config('laravel_generator.path.views', resource_path('views/'));

$files = [
'layouts/datatables_css' => 'layouts/datatables_css.blade.php',
'layouts/datatables_js' => 'layouts/datatables_js.blade.php',
'layouts.datatables_css' => 'layouts/datatables_css.blade.php',
'layouts.datatables_js' => 'layouts/datatables_js.blade.php',
];

foreach ($files as $stub => $blade) {
$sourceFile = get_template_file_path('views/scaffold/'.$stub, 'laravel-generator');
$destinationFile = $viewsPath.$blade;
$this->publishFile($sourceFile, $destinationFile, $blade);
foreach ($files as $templateView => $destinationView) {
$content = view('laravel-generator::scaffold.'.$templateView)->render();
$destinationFile = $viewsPath.$destinationView;
g_filesystem()->createFile($destinationFile, $content);
}
}

Expand Down
78 changes: 0 additions & 78 deletions src/Commands/Publish/PublishTemplatesCommand.php

This file was deleted.

26 changes: 13 additions & 13 deletions src/Commands/Publish/PublishUserCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ private function copyViews()

$files = $this->getViews();

foreach ($files as $stub => $blade) {
$sourceFile = get_template_file_path('views/templates/'.$stub, $templateType);
$destinationFile = $viewsPath.$blade;
$this->publishFile($sourceFile, $destinationFile, $blade);
foreach ($files as $templateView => $destinationView) {
$content = view($templateType.'::'.$templateView);
$destinationFile = $viewsPath.$destinationView;
g_filesystem()->createFile($destinationFile, $content);
}
}

Expand All @@ -55,13 +55,13 @@ private function createDirectories($dir)
private function getViews(): array
{
return [
'users/create' => 'users/create.blade.php',
'users/edit' => 'users/edit.blade.php',
'users/fields' => 'users/fields.blade.php',
'users/index' => 'users/index.blade.php',
'users/show' => 'users/show.blade.php',
'users/show_fields' => 'users/show_fields.blade.php',
'users/table' => 'users/table.blade.php',
'users.create' => 'users/create.blade.php',
'users.edit' => 'users/edit.blade.php',
'users.fields' => 'users/fields.blade.php',
'users.index' => 'users/index.blade.php',
'users.show' => 'users/show.blade.php',
'users.show_fields' => 'users/show_fields.blade.php',
'users.table' => 'users/table.blade.php',
];
}

Expand All @@ -83,8 +83,8 @@ private function updateMenu()
$templateType = config('laravel_generator.templates', 'adminlte-templates');
$path = $viewsPath.'layouts/menu.blade.php';
$menuContents = g_filesystem()->getFile($path);
$sourceFile = g_filesystem()->getFile(get_template_file_path('views/templates/users/menu', $templateType));
$menuContents .= infy_nl().$sourceFile;
$usersMenuContent = view($templateType.'::templates.users.menu')->render();
$menuContents .= infy_nl().$usersMenuContent;

g_filesystem()->createFile($path, $menuContents);
$this->comment("\nUser Menu added");
Expand Down
6 changes: 5 additions & 1 deletion src/InfyOmGeneratorServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@ public function boot()
$configPath = __DIR__.'/../config/laravel_generator.php';
$this->publishes([
$configPath => config_path('laravel_generator.php'),
]);
], 'laravel-generator-config');

$this->publishes([
__DIR__.'/../views' => resource_path('vendor/laravel-generator'),
], 'laravel-generator-templates');
}

$this->registerCommands();
Expand Down
31 changes: 0 additions & 31 deletions src/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,37 +48,6 @@ function infy_nl_tab(int $lns = 1, int $tabs = 1): string
}
}

if (!function_exists('get_template_file_path')) {
function get_template_file_path(string $templateName, string $templateType): string
{
$templateName = str_replace('.', '/', $templateName);

$templatesPath = config(
'laravel_generator.path.templates_dir',
resource_path('infyom/infyom-generator-templates/')
);

$path = $templatesPath.$templateName.'.blade.php';

if (file_exists($path)) {
return $path;
}

return get_templates_package_path($templateType).'/'.$templateName.'.blade.php';
}
}

if (!function_exists('get_templates_package_path')) {
function get_templates_package_path(string $templateType): string
{
if (!str_contains($templateType, '/')) {
$templateType = base_path('vendor/infyomlabs/').$templateType;
}

return $templateType;
}
}

if (!function_exists('model_name_from_table_name')) {
function model_name_from_table_name(string $tableName): string
{
Expand Down

0 comments on commit fbc1772

Please sign in to comment.