remove PluginServiceProvider and configure updates

This commit is contained in:
Adam Weston
2022-12-09 11:41:26 -05:00
parent 81ee508b06
commit 848c2783b8
10 changed files with 218 additions and 42 deletions

View File

@@ -2,44 +2,109 @@
namespace VendorName\Skeleton;
//use Filament\Support\Assets\Js;
//use Filament\Support\Assets\Css;
use Filament\Facades\Filament;
use Filament\Context;
use Filament\PluginServiceProvider;
use Filament\Support\Assets\AssetManager;
use Filament\Support\Assets\Js;
use Filament\Support\Assets\Css;
use Filament\Support\Assets\Asset;
use Filament\Support\Facades\FilamentAsset;
use Filament\Support\Facades\FilamentIcon;
use Filament\Support\Icons\Icon;
use Filament\Support\Icons\IconManager;
use Filament\Support\Assets\AlpineComponent;
use Illuminate\Filesystem\Filesystem;
use Spatie\LaravelPackageTools\Package;
//use Filament\Support\Assets\AlpineComponent;
use Spatie\LaravelPackageTools\PackageServiceProvider;
use Spatie\LaravelPackageTools\Commands\InstallCommand;
use Livewire\Testing\TestableLivewire;
use VendorName\Skeleton\Commands\SkeletonCommand;
use VendorName\Skeleton\Testing\TestsSkeleton;
class SkeletonServiceProvider extends PluginServiceProvider
class SkeletonServiceProvider extends PackageServiceProvider
{
public static string $name = 'skeleton';
public static string $viewNamespace = 'skeleton';
public function configurePackage(Package $package): void
{
$package->name(static::$name)
->hasConfigFile()
->hasViews()
->hasMigration('create_skeleton_table')
->hasCommand(SkeletonCommand::class);
->hasCommands($this->getCommands())
->hasInstallCommand(function(InstallCommand $command) {
$command
->publishConfigFile()
->publishMigrations()
->askToRunMigrations()
->askToStarRepoOnGitHub(':vendor_slug/:package_slug');
});
$configFileName = $package->shortName();
if (file_exists($this->package->basePath("/../config/{$configFileName}.php"))) {
$package->hasConfigFile();
}
if (file_exists($this->package->basePath('/../database/migrations'))) {
$package->hasMigrations($this->getMigrations());
}
if (file_exists($this->package->basePath('/../resources/lang'))) {
$package->hasTranslations();
}
if (file_exists($this->package->basePath('/../resources/views'))) {
$package->hasViews(static::$viewNamespace);
}
}
public function packageRegistered(): void
{
parent::packageRegistered();
// Facade Registration
$this->app->bind('skeleton', function (): Skeleton {
return new Skeleton();
});
// Context Registration
$this->app->resolving('skeleton', function () {
foreach ($this->getContexts() as $context) {
Filament::registerContext($context);
}
});
// Asset Registration
$this->app->resolving(AssetManager::class, function () {
FilamentAsset::register($this->getAssets(), $this->getAssetPackage());
FilamentAsset::registerScriptData($this->getScriptData(), $this->getAssetPackage());
});
// Icon Registration
$this->app->resolving(IconManager::class, function () {
FilamentIcon::register($this->getIcons());
});
}
public function packageBooted(): void
{
parent::packageBooted();
$this->registerMacros();
// Handle Stubs
if ($this->app->runningInConsole()) {
foreach (app(Filesystem::class)->files(__DIR__ . '/../stubs/') as $file) {
$this->publishes([
$file->getRealPath() => base_path("stubs/skeleton/{$file->getFilename()}"),
], 'forms-stubs');
}
}
// Testing
TestableLivewire::mixin(new TestsSkeleton());
}
protected function getAssetPackage(): ?string
{
return 'skeleton';
return static::$name ?? null;
}
/**
@@ -48,9 +113,65 @@ class SkeletonServiceProvider extends PluginServiceProvider
protected function getAssets(): array
{
return [
// AlpineComponent::make('skeleton', __DIR__ . '/../resources/dist/components/skeleton.js'),
// Css::make('echo', __DIR__ . '/../resources/dist/skeleton.js'),
// Js::make('echo', __DIR__ . '/../resources/dist/skeleton.js'),
// AlpineComponent::make('skeleton', __DIR__ . '/../resources/dist/components/skeleton.js'),
Css::make('skeleton-styles', __DIR__ . '/../resources/dist/skeleton.js'),
Js::make('skeleton-scripts', __DIR__ . '/../resources/dist/skeleton.js'),
];
}
/**
* @return array<class-string>
*/
protected function getCommands(): array
{
return [
SkeletonCommand::class
];
}
/**
* @return array<Context>
*/
protected function getContexts(): array
{
return [];
}
/**
* @return array<string, Icon>
*/
protected function getIcons(): array
{
return [];
}
/**
* @return array<string>
*/
protected function getRoutes(): array
{
return [];
}
/**
* @return array<string, mixed>
*/
protected function getScriptData(): array
{
return [];
}
/**
* @return array<string>
*/
protected function getMigrations(): array
{
return [
'create_skeleton_table'
];
}
protected function registerMacros(): void
{
}
}

View File

@@ -5,6 +5,7 @@ namespace Filament;
use Filament\Contracts\Plugin;
use Filament\Support\Assets\Theme;
use Filament\Support\Facades\FilamentAsset;
use Filament\Support\Color;
class SkeletonTheme implements Plugin
{
@@ -20,6 +21,15 @@ class SkeletonTheme implements Plugin
]);
$context
->font('DM Sans')
->primaryColor(Color::Amber)
->secondaryColor(Color::Gray)
->warningColor(Color::Amber)
->dangerColor(Color::Rose)
->successColor(Color::Green)
->grayColor(Color::Slate)
->sidebarWidth('20rem')
->collapsedSidebarWidth('5.4rem')
->theme('skeleton');
}

View File

@@ -0,0 +1,14 @@
<?php
namespace VendorName\Skeleton\Testing;
use Illuminate\Testing\Assert;
use Livewire\Testing\TestableLivewire;
/**
* @mixin TestableLivewire
*/
class TestsSkeleton
{
//
}