mirror of
https://github.com/filamentphp/plugin-skeleton.git
synced 2025-12-07 05:58:51 +08:00
156 lines
4.0 KiB
PHP
156 lines
4.0 KiB
PHP
<?php
|
|
|
|
namespace VendorName\Skeleton;
|
|
|
|
use Filament\Support\Assets\AlpineComponent;
|
|
use Filament\Support\Assets\Asset;
|
|
use Filament\Support\Assets\Css;
|
|
use Filament\Support\Assets\Js;
|
|
use Filament\Support\Facades\FilamentAsset;
|
|
use Filament\Support\Facades\FilamentIcon;
|
|
use Filament\Support\Icons\Icon;
|
|
use Illuminate\Filesystem\Filesystem;
|
|
use Livewire\Features\SupportTesting\Testable;
|
|
use Spatie\LaravelPackageTools\Commands\InstallCommand;
|
|
use Spatie\LaravelPackageTools\Package;
|
|
use Spatie\LaravelPackageTools\PackageServiceProvider;
|
|
use VendorName\Skeleton\Commands\SkeletonCommand;
|
|
use VendorName\Skeleton\Testing\TestsSkeleton;
|
|
|
|
class SkeletonServiceProvider extends PackageServiceProvider
|
|
{
|
|
public static string $name = 'skeleton';
|
|
|
|
public static string $viewNamespace = 'skeleton';
|
|
|
|
public function configurePackage(Package $package): void
|
|
{
|
|
/*
|
|
* This class is a Package Service Provider
|
|
*
|
|
* More info: https://github.com/spatie/laravel-package-tools
|
|
*/
|
|
$package->name(static::$name)
|
|
->hasCommands($this->getCommands())
|
|
->hasInstallCommand(function (InstallCommand $command) {
|
|
$command
|
|
->publishConfigFile()
|
|
->publishMigrations()
|
|
->askToRunMigrations()
|
|
->askToStarRepoOnGitHub(':vendor_slug/:package_slug');
|
|
});
|
|
|
|
$configFileName = $package->shortName();
|
|
|
|
if (file_exists($package->basePath("/../config/{$configFileName}.php"))) {
|
|
$package->hasConfigFile();
|
|
}
|
|
|
|
if (file_exists($package->basePath('/../database/migrations'))) {
|
|
$package->hasMigrations($this->getMigrations());
|
|
}
|
|
|
|
if (file_exists($package->basePath('/../resources/lang'))) {
|
|
$package->hasTranslations();
|
|
}
|
|
|
|
if (file_exists($package->basePath('/../resources/views'))) {
|
|
$package->hasViews(static::$viewNamespace);
|
|
}
|
|
}
|
|
|
|
public function packageRegistered(): void
|
|
{
|
|
}
|
|
|
|
public function packageBooted(): void
|
|
{
|
|
// Asset Registration
|
|
FilamentAsset::register(
|
|
$this->getAssets(),
|
|
$this->getAssetPackageName()
|
|
);
|
|
|
|
FilamentAsset::registerScriptData(
|
|
$this->getScriptData(),
|
|
$this->getAssetPackageName()
|
|
);
|
|
|
|
// Icon Registration
|
|
FilamentIcon::register($this->getIcons());
|
|
|
|
// Handle Stubs
|
|
if (app()->runningInConsole()) {
|
|
foreach (app(Filesystem::class)->files(__DIR__ . '/../stubs/') as $file) {
|
|
$this->publishes([
|
|
$file->getRealPath() => base_path("stubs/skeleton/{$file->getFilename()}"),
|
|
], 'skeleton-stubs');
|
|
}
|
|
}
|
|
|
|
// Testing
|
|
Testable::mixin(new TestsSkeleton());
|
|
}
|
|
|
|
protected function getAssetPackageName(): ?string
|
|
{
|
|
return ':vendor_slug/:package_slug';
|
|
}
|
|
|
|
/**
|
|
* @return array<Asset>
|
|
*/
|
|
protected function getAssets(): array
|
|
{
|
|
return [
|
|
// AlpineComponent::make('skeleton', __DIR__ . '/../resources/dist/components/skeleton.js'),
|
|
Css::make('skeleton-styles', __DIR__ . '/../resources/dist/skeleton.css'),
|
|
Js::make('skeleton-scripts', __DIR__ . '/../resources/dist/skeleton.js'),
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @return array<class-string>
|
|
*/
|
|
protected function getCommands(): array
|
|
{
|
|
return [
|
|
SkeletonCommand::class,
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @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',
|
|
];
|
|
}
|
|
}
|