Skip to content

Commit

Permalink
fix publishing method
Browse files Browse the repository at this point in the history
  • Loading branch information
pxpm committed Jul 16, 2023
1 parent 7c54479 commit cb40f05
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 16 deletions.
16 changes: 7 additions & 9 deletions src/Console/Commands/Traits/PublishableStubTrait.php
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
<?php

namespace Backpack\Generators\Console\Commands\Traits;
use Illuminate\Support\Str;

trait PublishableStubTrait
{
/**
* Check if the stub exists in the project's stubs folder.
* If it does, return the path to it.
* If it doesn't, return the path to the stub in the package.
*
* @param string $path
* @return string
* Return the path to the stub
*/
public function getStubPath(string $path): string
{
if (file_exists(base_path("stubs/backpack/generators/{$path}.stub"))) {
return base_path("stubs/backpack/generators/{$path}.stub");
$path = Str::finish($path, '.stub');

if (file_exists(base_path("stubs/backpack/generators/{$path}"))) {
return base_path("stubs/backpack/generators/{$path}");
}

return __DIR__."/../../stubs/{$path}.stub";
return __DIR__."/../../stubs/{$path}";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
abstract class PublishOrCreateViewBackpackCommand extends GeneratorCommand
{
use \Backpack\CRUD\app\Console\Commands\Traits\PrettyCommandOutput;
use \Backpack\Generators\Console\Commands\Traits\PublishableStubTrait;

/**
* The source file to copy from.
Expand Down Expand Up @@ -41,12 +42,7 @@ abstract class PublishOrCreateViewBackpackCommand extends GeneratorCommand
*/
protected function getStub()
{
// check if base_path('stubs/backpack/generators/$FILE') exists, and use that
if (file_exists(base_path('stubs/backpack/generators/generators/'.$this->stub))) {
return base_path('stubs/backpack/generators/generators/'.$this->stub);
}

return __DIR__.'/../../stubs/'.$this->stub;
return $this->getStubPath($this->stub);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/GeneratorsServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,6 @@ public function boot(): void

$this->publishes([
__DIR__.'/Console/stubs' => base_path('stubs/backpack/generators'),
], 'stubs');
], 'backpack-generators-stubs');
}
}

0 comments on commit cb40f05

Please sign in to comment.