Skip to content

Commit cb40f05

Browse files
committed
fix publishing method
1 parent 7c54479 commit cb40f05

File tree

3 files changed

+10
-16
lines changed

3 files changed

+10
-16
lines changed
Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,21 @@
11
<?php
22

33
namespace Backpack\Generators\Console\Commands\Traits;
4+
use Illuminate\Support\Str;
45

56
trait PublishableStubTrait
67
{
78
/**
8-
* Check if the stub exists in the project's stubs folder.
9-
* If it does, return the path to it.
10-
* If it doesn't, return the path to the stub in the package.
11-
*
12-
* @param string $path
13-
* @return string
9+
* Return the path to the stub
1410
*/
1511
public function getStubPath(string $path): string
1612
{
17-
if (file_exists(base_path("stubs/backpack/generators/{$path}.stub"))) {
18-
return base_path("stubs/backpack/generators/{$path}.stub");
13+
$path = Str::finish($path, '.stub');
14+
15+
if (file_exists(base_path("stubs/backpack/generators/{$path}"))) {
16+
return base_path("stubs/backpack/generators/{$path}");
1917
}
2018

21-
return __DIR__."/../../stubs/{$path}.stub";
19+
return __DIR__."/../../stubs/{$path}";
2220
}
2321
}

src/Console/Commands/Views/PublishOrCreateViewBackpackCommand.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
abstract class PublishOrCreateViewBackpackCommand extends GeneratorCommand
1010
{
1111
use \Backpack\CRUD\app\Console\Commands\Traits\PrettyCommandOutput;
12+
use \Backpack\Generators\Console\Commands\Traits\PublishableStubTrait;
1213

1314
/**
1415
* The source file to copy from.
@@ -41,12 +42,7 @@ abstract class PublishOrCreateViewBackpackCommand extends GeneratorCommand
4142
*/
4243
protected function getStub()
4344
{
44-
// check if base_path('stubs/backpack/generators/$FILE') exists, and use that
45-
if (file_exists(base_path('stubs/backpack/generators/generators/'.$this->stub))) {
46-
return base_path('stubs/backpack/generators/generators/'.$this->stub);
47-
}
48-
49-
return __DIR__.'/../../stubs/'.$this->stub;
45+
return $this->getStubPath($this->stub);
5046
}
5147

5248
/**

src/GeneratorsServiceProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,6 @@ public function boot(): void
5555

5656
$this->publishes([
5757
__DIR__.'/Console/stubs' => base_path('stubs/backpack/generators'),
58-
], 'stubs');
58+
], 'backpack-generators-stubs');
5959
}
6060
}

0 commit comments

Comments
 (0)