mirror of
https://github.com/filamentphp/plugin-skeleton.git
synced 2025-12-06 21:48:53 +08:00
remove PluginServiceProvider and configure updates
This commit is contained in:
@@ -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
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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');
|
||||
}
|
||||
|
||||
|
||||
14
src/Testing/TestsSkeleton.php
Normal file
14
src/Testing/TestsSkeleton.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace VendorName\Skeleton\Testing;
|
||||
|
||||
use Illuminate\Testing\Assert;
|
||||
use Livewire\Testing\TestableLivewire;
|
||||
|
||||
/**
|
||||
* @mixin TestableLivewire
|
||||
*/
|
||||
class TestsSkeleton
|
||||
{
|
||||
//
|
||||
}
|
||||
Reference in New Issue
Block a user