22
33namespace VendorName \Skeleton ;
44
5- // use Filament\Support\Assets\Js ;
6- // use Filament\Support\Assets\Css ;
5+ use Filament \Facades \ Filament ;
6+ use Filament \Context ;
77use Filament \PluginServiceProvider ;
8+ use Filament \Support \Assets \AssetManager ;
9+ use Filament \Support \Assets \Js ;
10+ use Filament \Support \Assets \Css ;
811use Filament \Support \Assets \Asset ;
12+ use Filament \Support \Facades \FilamentAsset ;
13+ use Filament \Support \Facades \FilamentIcon ;
14+ use Filament \Support \Icons \Icon ;
15+ use Filament \Support \Icons \IconManager ;
16+ use Filament \Support \Assets \AlpineComponent ;
17+ use Illuminate \Filesystem \Filesystem ;
918use Spatie \LaravelPackageTools \Package ;
10- //use Filament\Support\Assets\AlpineComponent;
19+ use Spatie \LaravelPackageTools \PackageServiceProvider ;
20+ use Spatie \LaravelPackageTools \Commands \InstallCommand ;
21+ use Livewire \Testing \TestableLivewire ;
1122use VendorName \Skeleton \Commands \SkeletonCommand ;
23+ use VendorName \Skeleton \Testing \TestsSkeleton ;
1224
13- class SkeletonServiceProvider extends PluginServiceProvider
25+ class SkeletonServiceProvider extends PackageServiceProvider
1426{
1527 public static string $ name = 'skeleton ' ;
1628
29+ public static string $ viewNamespace = 'skeleton ' ;
30+
1731 public function configurePackage (Package $ package ): void
1832 {
1933 $ package ->name (static ::$ name )
20- ->hasConfigFile ()
21- ->hasViews ()
22- ->hasMigration ('create_skeleton_table ' )
23- ->hasCommand (SkeletonCommand::class);
34+ ->hasCommands ($ this ->getCommands ())
35+ ->hasInstallCommand (function (InstallCommand $ command ) {
36+ $ command
37+ ->publishConfigFile ()
38+ ->publishMigrations ()
39+ ->askToRunMigrations ()
40+ ->askToStarRepoOnGitHub (':vendor_slug/:package_slug ' );
41+ });
42+
43+ $ configFileName = $ package ->shortName ();
44+
45+ if (file_exists ($ this ->package ->basePath ("/../config/ {$ configFileName }.php " ))) {
46+ $ package ->hasConfigFile ();
47+ }
48+
49+ if (file_exists ($ this ->package ->basePath ('/../database/migrations ' ))) {
50+ $ package ->hasMigrations ($ this ->getMigrations ());
51+ }
52+
53+ if (file_exists ($ this ->package ->basePath ('/../resources/lang ' ))) {
54+ $ package ->hasTranslations ();
55+ }
56+
57+ if (file_exists ($ this ->package ->basePath ('/../resources/views ' ))) {
58+ $ package ->hasViews (static ::$ viewNamespace );
59+ }
2460 }
2561
2662 public function packageRegistered (): void
2763 {
28- parent ::packageRegistered ();
29-
64+ // Facade Registration
3065 $ this ->app ->bind ('skeleton ' , function (): Skeleton {
3166 return new Skeleton ();
3267 });
68+
69+ // Context Registration
70+ $ this ->app ->resolving ('skeleton ' , function () {
71+ foreach ($ this ->getContexts () as $ context ) {
72+ Filament::registerContext ($ context );
73+ }
74+ });
75+
76+ // Asset Registration
77+ $ this ->app ->resolving (AssetManager::class, function () {
78+ FilamentAsset::register ($ this ->getAssets (), $ this ->getAssetPackage ());
79+ FilamentAsset::registerScriptData ($ this ->getScriptData (), $ this ->getAssetPackage ());
80+ });
81+
82+ // Icon Registration
83+ $ this ->app ->resolving (IconManager::class, function () {
84+ FilamentIcon::register ($ this ->getIcons ());
85+ });
3386 }
3487
3588 public function packageBooted (): void
3689 {
37- parent ::packageBooted ();
90+ $ this ->registerMacros ();
91+
92+ // Handle Stubs
93+ if ($ this ->app ->runningInConsole ()) {
94+ foreach (app (Filesystem::class)->files (__DIR__ . '/../stubs/ ' ) as $ file ) {
95+ $ this ->publishes ([
96+ $ file ->getRealPath () => base_path ("stubs/skeleton/ {$ file ->getFilename ()}" ),
97+ ], 'forms-stubs ' );
98+ }
99+ }
100+
101+ // Testing
102+ TestableLivewire::mixin (new TestsSkeleton ());
38103 }
39104
40105 protected function getAssetPackage (): ?string
41106 {
42- return ' skeleton ' ;
107+ return static :: $ name ?? null ;
43108 }
44109
45110 /**
@@ -48,9 +113,65 @@ protected function getAssetPackage(): ?string
48113 protected function getAssets (): array
49114 {
50115 return [
51- // AlpineComponent::make('skeleton', __DIR__ . '/../resources/dist/components/skeleton.js'),
52- // Css::make('echo', __DIR__ . '/../resources/dist/skeleton.js'),
53- // Js::make('echo', __DIR__ . '/../resources/dist/skeleton.js'),
116+ // AlpineComponent::make('skeleton', __DIR__ . '/../resources/dist/components/skeleton.js'),
117+ Css::make ('skeleton-styles ' , __DIR__ . '/../resources/dist/skeleton.js ' ),
118+ Js::make ('skeleton-scripts ' , __DIR__ . '/../resources/dist/skeleton.js ' ),
119+ ];
120+ }
121+
122+ /**
123+ * @return array<class-string>
124+ */
125+ protected function getCommands (): array
126+ {
127+ return [
128+ SkeletonCommand::class
129+ ];
130+ }
131+
132+ /**
133+ * @return array<Context>
134+ */
135+ protected function getContexts (): array
136+ {
137+ return [];
138+ }
139+
140+ /**
141+ * @return array<string, Icon>
142+ */
143+ protected function getIcons (): array
144+ {
145+ return [];
146+ }
147+
148+ /**
149+ * @return array<string>
150+ */
151+ protected function getRoutes (): array
152+ {
153+ return [];
154+ }
155+
156+ /**
157+ * @return array<string, mixed>
158+ */
159+ protected function getScriptData (): array
160+ {
161+ return [];
162+ }
163+
164+ /**
165+ * @return array<string>
166+ */
167+ protected function getMigrations (): array
168+ {
169+ return [
170+ 'create_skeleton_table '
54171 ];
55172 }
173+
174+ protected function registerMacros (): void
175+ {
176+ }
56177}
0 commit comments