Skip to content

Commit

Permalink
Merge pull request #82 from savannabits/4.x-dev
Browse files Browse the repository at this point in the history
4.x dev - Support for nwidart/laravel-modules 11.x
  • Loading branch information
coolsam726 authored Apr 15, 2024
2 parents dc3703a + 6a7c217 commit c01655e
Show file tree
Hide file tree
Showing 13 changed files with 64 additions and 28 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ phpunit.xml
phpstan.neon
testbench.yaml
vendor
.phpunit.cache
29 changes: 23 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@
"require": {
"php": "^8.1",
"filament/filament": "^3.0",
"nwidart/laravel-modules": "^10.0",
"nwidart/laravel-modules": "^11.0",
"spatie/laravel-package-tools": "^1.15.0"
},
"require-dev": {
"laravel/pint": "^1.0",
"nunomaduro/collision": "^7.9|^8.1",
"nunomaduro/collision": "^8.1",
"nunomaduro/larastan": "^2.0.1",
"orchestra/testbench": "^8.0|^9.0",
"orchestra/testbench": "^9.0",
"pestphp/pest": "^2.1",
"pestphp/pest-plugin-arch": "^2.0",
"pestphp/pest-plugin-laravel": "^2.0",
Expand All @@ -51,17 +51,34 @@
}
},
"scripts": {
"post-autoload-dump": "@php ./vendor/bin/testbench package:discover --ansi",
"post-autoload-dump": [
"@clear",
"@prepare",
"@php ./vendor/bin/testbench package:discover --ansi"
],
"analyse": "vendor/bin/phpstan analyse",
"test": "vendor/bin/pest",
"test-coverage": "vendor/bin/pest --coverage",
"format": "vendor/bin/pint"
"format": "vendor/bin/pint",
"clear": "@php vendor/bin/testbench package:purge-skeleton --ansi",
"prepare": "@php vendor/bin/testbench package:discover --ansi",
"build": "@php vendor/bin/testbench workbench:build --ansi",
"serve": [
"Composer\\Config::disableProcessTimeout",
"@build",
"@php vendor/bin/testbench serve"
],
"lint": [
"@php vendor/bin/pint",
"@php vendor/bin/phpstan analyse"
]
},
"config": {
"sort-packages": true,
"allow-plugins": {
"pestphp/pest-plugin": true,
"phpstan/extension-installer": true
"phpstan/extension-installer": true,
"wikimedia/composer-merge-plugin": true
}
},
"extra": {
Expand Down
2 changes: 2 additions & 0 deletions src/Commands/ModuleFilamentInstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,11 @@ private function ensureFilamentDirectoriesExist(): void
}

if ($this->cluster) {
$dir = $this->getModule()->appPath('Filament/Clusters');
if (! is_dir($dir = $this->getModule()->appPath('Filament/Clusters'))) {
$this->makeDirectory($dir);
}

} else {
if (! is_dir($dir = $this->getModule()->appPath('Filament/Pages'))) {
$this->makeDirectory($dir);
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/ModuleMakeFilamentClusterCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class ModuleMakeFilamentClusterCommand extends GeneratorCommand

protected function getRelativeNamespace(): string
{
return 'App\\Filament\\Clusters';
return 'Filament\\Clusters';
}

protected function getStub(): string
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/ModuleMakeFilamentPluginCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class ModuleMakeFilamentPluginCommand extends GeneratorCommand

protected function getRelativeNamespace(): string
{
return 'App\\Filament';
return 'Filament';
}

protected function getStub(): string
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/stubs/filament-cluster.stub
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class {{ class }} extends Cluster

public static function getNavigationLabel(): string
{
return '__({{ navigationLabel }})';
return __('{{ navigationLabel }}');
}

public static function getNavigationIcon(): ?string
Expand Down
2 changes: 1 addition & 1 deletion src/Concerns/GeneratesModularFiles.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ protected function rootNamespace(): string

protected function getPath($name): string
{
$name = Str::replaceFirst($this->rootNamespace(), '', $name);
$name = Str::replaceFirst($this->rootNamespace(), 'app', $name);

return $this->getModule()->getExtraPath(str_replace('\\', '/', $name) . '.php');
}
Expand Down
13 changes: 8 additions & 5 deletions src/Modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,14 @@ public function getModule(string $name): \Nwidart\Modules\Module
public function convertPathToNamespace(string $fullPath): string
{
$base = str(trim(config('modules.paths.modules', base_path('Modules')), '/'));
$relative = str(trim(config('modules.namespace', 'Modules'), '\\'))->replace('\\', DIRECTORY_SEPARATOR)->toString();

return str($fullPath)
->replace($base, $relative)
->replace('.php', '')
$relative = str($fullPath)->afterLast($base)->replaceFirst('/app/', '/');

return str($relative)
->ltrim('/')
->prepend('/')
->prepend(config('modules.namespace', 'Modules'))
->replace(DIRECTORY_SEPARATOR, '\\')
->rtrim('.php')
->explode(DIRECTORY_SEPARATOR)
->map(fn ($piece) => str($piece)->studly()->toString())
->implode('\\');
Expand Down
5 changes: 3 additions & 2 deletions src/ModulesPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ public function register(Panel $panel): void
{
$panel
->topNavigation(config('filament-modules.clusters.enabled', false) && config('filament-modules.clusters.use-top-navigation', false));
foreach ($this->getModulePlugins() as $modulePlugin) {
$plugins = $this->getModulePlugins();
foreach ($plugins as $modulePlugin) {
$panel->plugin($modulePlugin::make());
}
}
Expand Down Expand Up @@ -46,7 +47,7 @@ protected function getModulePlugins(): array
}
// get a glob of all Filament plugins
$basePath = str(config('modules.paths.modules', 'Modules'));
$pattern = $basePath . '/*/App/Filament/*Plugin.php';
$pattern = $basePath . '/*/app/Filament/*Plugin.php';
$pluginPaths = glob($pattern);

return collect($pluginPaths)->map(fn ($path) => FilamentModules::convertPathToNamespace($path))->toArray();
Expand Down
10 changes: 5 additions & 5 deletions src/ModulesServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,18 +170,18 @@ protected function registerModuleMacros(): void
$relativeNamespace = str_replace('App\\', '', $relativeNamespace);
$relativeNamespace = str_replace('App', '', $relativeNamespace);
$relativeNamespace = trim($relativeNamespace, '\\');
$relativeNamespace = 'App\\' . $relativeNamespace;
$relativeNamespace = '\\' . $relativeNamespace;

return $this->namespace($relativeNamespace);
});
Module::macro('appPath', function (string $relativePath = '') {
$appPath = $this->getExtraPath('App');
$appPath = $this->getExtraPath('app');

return $appPath . ($relativePath ? DIRECTORY_SEPARATOR . $relativePath : '');
});

Module::macro('databasePath', function (string $relativePath = '') {
$appPath = $this->getExtraPath('Database');
$appPath = $this->getExtraPath('database');

return $appPath . ($relativePath ? DIRECTORY_SEPARATOR . $relativePath : '');
});
Expand All @@ -199,13 +199,13 @@ protected function registerModuleMacros(): void
});

Module::macro('seedersPath', function (string $relativePath = '') {
$appPath = $this->databasePath('Seeders');
$appPath = $this->databasePath('seeders');

return $appPath . ($relativePath ? DIRECTORY_SEPARATOR . $relativePath : '');
});

Module::macro('factoriesPath', function (string $relativePath = '') {
$appPath = $this->databasePath('Factories');
$appPath = $this->databasePath('factories');

return $appPath . ($relativePath ? DIRECTORY_SEPARATOR . $relativePath : '');
});
Expand Down
5 changes: 0 additions & 5 deletions tests/ExampleTest.php

This file was deleted.

12 changes: 12 additions & 0 deletions tests/ModulesTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

it('can test', function () {
expect(true)->toBeTrue();
});

// test that a module can be generated successfully
it('can generate a module', function () {
$this->artisan('module:make', ['name' => ['Example']])
->expectsOutput('Module created successfully.')
->assertExitCode(0);
});
7 changes: 6 additions & 1 deletion tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,15 @@
use Filament\Widgets\WidgetsServiceProvider;
use Illuminate\Database\Eloquent\Factories\Factory;
use Livewire\LivewireServiceProvider;
use Nwidart\Modules\LaravelModulesServiceProvider;
use Orchestra\Testbench\Concerns\WithWorkbench;
use Orchestra\Testbench\TestCase as Orchestra;
use RyanChandler\BladeCaptureDirective\BladeCaptureDirectiveServiceProvider;

class TestCase extends Orchestra
{
use WithWorkbench;

protected function setUp(): void
{
parent::setUp();
Expand All @@ -29,7 +33,7 @@ protected function setUp(): void
);
}

protected function getPackageProviders($app)
protected function getPackageProviders($app): array
{
return [
ActionsServiceProvider::class,
Expand All @@ -44,6 +48,7 @@ protected function getPackageProviders($app)
SupportServiceProvider::class,
TablesServiceProvider::class,
WidgetsServiceProvider::class,
LaravelModulesServiceProvider::class,
ModulesServiceProvider::class,
];
}
Expand Down

0 comments on commit c01655e

Please sign in to comment.