Skip to content

Commit 60fec2b

Browse files
Fix plugin make CRUD command
1 parent 6387fb3 commit 60fec2b

File tree

8 files changed

+25
-26
lines changed

8 files changed

+25
-26
lines changed

src/Commands/Concerns/HasModuleSelector.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public function getModule(): string
5959

6060
public function transformModuleToNamespace(): string
6161
{
62-
return str($this->module)
62+
return str($this->getModule())
6363
->replace(DIRECTORY_SEPARATOR, '\\')
6464
->afterLast('\\')
6565
->studly()

src/Commands/PluginCreateCommand.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,6 @@ protected function removeUnusedFiles(string $location): void
164164

165165
public function getReplacements(string $replaceText): array
166166
{
167-
$namespace = Str::of($this->replaceNamespace($this->argument('namespace')))->append('\\\\');
168-
169167
return [
170168
'{type}' => 'plugin',
171169
'{types}' => 'plugins',
@@ -179,8 +177,8 @@ public function getReplacements(string $replaceText): array
179177
'{Module}' => Str::of(str_replace('\\\\', '\\', $this->argument('namespace'))),
180178
'{PluginId}' => $this->argument('id'),
181179
'{PluginName}' => ucfirst(str_replace('-', ' ', $this->argument('name'))),
182-
'{PluginNamespace}' => $namespace,
183-
'{PluginServiceProvider}' => $namespace . 'Providers\\\\' . $this->argument('provider'),
180+
'{PluginNamespace}' => Str::of($this->replaceNamespace($this->argument('namespace')))->append('\\\\'),
181+
'{PluginServiceProvider}' => Str::of($this->replaceNamespace($this->argument('namespace')))->append('\\\\') . 'Providers\\\\' . $this->argument('provider'),
184182
'{PluginAuthor}' => $this->argument('author'),
185183
'{PluginAuthorURL}' => $this->argument('author_url'),
186184
'{PluginVersion}' => $this->argument('version'),

src/Commands/PluginMakeCrudCommand.php

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Botble\DevTool\Commands;
44

5+
use Botble\Base\Facades\BaseHelper;
56
use Botble\DevTool\Commands\Abstracts\BaseMakeCommand;
67
use Botble\DevTool\Commands\Concerns\HasSubModule;
78
use Botble\DevTool\Helper;
@@ -46,7 +47,6 @@ public function handle(): int
4647

4748
$this->handleReplacements($location, [
4849
Helper::joinPaths(['config', 'permissions.stub']),
49-
Helper::joinPaths(['helpers', 'helpers.stub']),
5050
Helper::joinPaths(['routes', 'web.stub']),
5151
Helper::joinPaths(['src', 'Providers', '{Module}ServiceProvider.stub']),
5252
Helper::joinPaths(['src', 'Plugin.stub']),
@@ -64,20 +64,35 @@ protected function removeUnusedFiles(string $location): void
6464
{
6565
$files = [
6666
Helper::joinPaths(['config', 'permissions.stub']),
67-
Helper::joinPaths(['helpers', 'constants.stub']),
6867
Helper::joinPaths(['routes', 'web.stub']),
68+
Helper::joinPaths(['resources', 'views', '.gitkeep']),
69+
'composer.json',
6970
Helper::joinPaths(['src', 'Providers', '{Module}ServiceProvider.stub']),
71+
Helper::joinPaths(['src', 'Forms', 'Settings', '{Module}Form.stub']),
72+
Helper::joinPaths(['src', 'Http', 'Controllers', 'Settings', '{Module}Controller.stub']),
73+
Helper::joinPaths(['src', 'Http', 'Requests', 'Settings', '{Module}Request.stub']),
74+
Helper::joinPaths(['src', 'PanelSections', '{Module}PanelSection.stub']),
7075
];
7176

7277
foreach ($files as $file) {
7378
File::delete(Helper::joinPaths([$location, $file]));
7479
}
80+
81+
File::deleteDirectory(Helper::joinPaths([$location, 'src', 'PanelSections', '']));
7582
}
7683

7784
public function getReplacements(string $replaceText): array
7885
{
7986
$module = strtolower($this->argument('plugin'));
8087

88+
$pluginContent = BaseHelper::getFileData(BaseHelper::joinPaths([plugin_path($module), 'plugin.json']));
89+
90+
$namespace = $module;
91+
92+
if ($pluginContent) {
93+
$namespace = $pluginContent['namespace'];
94+
}
95+
8196
return [
8297
'{type}' => 'plugin',
8398
'{types}' => 'plugins',
@@ -88,7 +103,7 @@ public function getReplacements(string $replaceText): array
88103
'{Modules}' => ucfirst(Str::plural(Str::snake(str_replace('-', '_', $module)))),
89104
'{-modules}' => Str::plural($module),
90105
'{MODULE}' => strtoupper(Str::snake(str_replace('-', '_', $module))),
91-
'{Module}' => ucfirst(Str::camel($module)),
106+
'{Module}' => rtrim($namespace, '\\'),
92107
];
93108
}
94109

stubs/plugin/src/Providers/{Name}ServiceProvider.stub

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class {Name}ServiceProvider extends ServiceProvider
1414
$this
1515
->setNamespace('{types}/{-name}')
1616
{PluginBootProvider}
17-
{PluginRegisterLanguage}
18-
{PluginRegisterDashboardMenu}
17+
{PluginRegisterLanguage}
18+
{PluginRegisterDashboardMenu}
1919
}
2020
}

stubs/sub-module/helpers/helpers.stub

Lines changed: 0 additions & 3 deletions
This file was deleted.

stubs/sub-module/routes/web.stub

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Add below this line: Route::group(['prefix' => BaseHelper::getAdminPrefix(), 'middleware' => 'auth'], function () {
1+
// Add below this line: AdminHelper::registerRoutes(function () {
22
Route::group(['prefix' => '{-names}', 'as' => '{-name}.'], function () {
33
Route::resource('', '{Name}Controller')->parameters(['' => '{-name}']);
44
});

stubs/sub-module/src/PanelSections/PanelSection.stub

Lines changed: 0 additions & 11 deletions
This file was deleted.

stubs/sub-module/src/Providers/{Module}ServiceProvider.stub

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
'name',
44
]);
55

6-
// Add after this line: Event::listen(RouteMatched::class, function () {
6+
// Add after this line: DashboardMenu::default()->beforeRetrieving(function () {
77
\Botble\Base\Facades\DashboardMenu::registerItem([
88
'id' => 'cms-{types}-{-name}',
99
'priority' => 0,

0 commit comments

Comments
 (0)