From 848c2783b8881a87cd7ebb561a04b1bb415acd80 Mon Sep 17 00:00:00 2001 From: Adam Weston Date: Fri, 9 Dec 2022 11:41:26 -0500 Subject: [PATCH] remove PluginServiceProvider and configure updates --- .../package/package.json | 5 +- .../package}/plugin.css | 0 configure-stubs/theme/package.json | 15 ++ configure-stubs/theme/plugin.css | 1 + configure.php | 44 +++-- postcss.config.js | 2 + src/SkeletonServiceProvider.php | 151 ++++++++++++++++-- src/SkeletonTheme.php | 10 ++ src/Testing/TestsSkeleton.php | 14 ++ tailwind.config.js | 18 +-- 10 files changed, 218 insertions(+), 42 deletions(-) rename package.json => configure-stubs/package/package.json (72%) rename {resources/css => configure-stubs/package}/plugin.css (100%) create mode 100644 configure-stubs/theme/package.json create mode 100644 configure-stubs/theme/plugin.css create mode 100644 src/Testing/TestsSkeleton.php diff --git a/package.json b/configure-stubs/package/package.json similarity index 72% rename from package.json rename to configure-stubs/package/package.json index 74f1cc9..6362285 100644 --- a/package.json +++ b/configure-stubs/package/package.json @@ -1,9 +1,9 @@ { "private": true, "scripts": { - "dev:styles": "npx tailwindcss -i resources/css/plugin.css -o resources/dist/skeleton.css --postcss --watch", + "dev:styles": "npx tailwindcss -i config-stubs/theme/plugin.css -o resources/dist/skeleton.css --postcss --watch", "dev:scripts": "esbuild resources/js/plugin.js --bundle --sourcemap=inline --outfile=resources/dist/skeleton.js --watch", - "build:styles": "npx tailwindcss -i resources/css/plugin.css -o resources/dist/skeleton.css --postcss --minify && npm run purge", + "build:styles": "npx tailwindcss -i config-stubs/theme/plugin.css -o resources/dist/skeleton.css --postcss --minify && npm run purge", "build:scripts": "esbuild resources/js/plugin.js --bundle --minify --outfile=resources/dist/skeleton.js", "purge": "filament-purge -i resources/dist/skeleton.css -o resources/dist/skeleton.css", "dev": "npm-run-all --parallel dev:*", @@ -15,6 +15,7 @@ "esbuild": "^0.8.57", "npm-run-all": "^4.1.5", "postcss": "^8.4.14", + "postcss-import": "^15.0.0", "prettier": "^2.7.1", "prettier-plugin-tailwindcss": "^0.1.13", "tailwindcss": "^3.2" diff --git a/resources/css/plugin.css b/configure-stubs/package/plugin.css similarity index 100% rename from resources/css/plugin.css rename to configure-stubs/package/plugin.css diff --git a/configure-stubs/theme/package.json b/configure-stubs/theme/package.json new file mode 100644 index 0000000..ca3a04c --- /dev/null +++ b/configure-stubs/theme/package.json @@ -0,0 +1,15 @@ +{ + "private": true, + "scripts": { + "dev": "npx tailwindcss -i config-stubs/theme/plugin.css -o resources/dist/skeleton.css --postcss --watch", + "build": "npx tailwindcss -i config-stubs/theme/plugin.css -o resources/dist/skeleton.css --postcss --minify" + }, + "devDependencies": { + "autoprefixer": "^10.4.7", + "postcss": "^8.4.14", + "postcss-import": "^15.0.0", + "prettier": "^2.7.1", + "prettier-plugin-tailwindcss": "^0.1.13", + "tailwindcss": "^3.2" + } +} diff --git a/configure-stubs/theme/plugin.css b/configure-stubs/theme/plugin.css new file mode 100644 index 0000000..1f7b952 --- /dev/null +++ b/configure-stubs/theme/plugin.css @@ -0,0 +1 @@ +@import "../../vendor/filament/filament/resources/css/index.css"; diff --git a/configure.php b/configure.php index a2785bb..d82d80f 100644 --- a/configure.php +++ b/configure.php @@ -35,7 +35,7 @@ $useUpdateChangelogWorkflow = confirm('Use automatic changelog updater workflow? $isTheme = confirm('Is this a custom theme?'); $formsOnly = ! $isTheme && confirm('Is this for Forms only?'); -$tablesOnly = ! $formsOnly && confirm('Is this for Tables only?'); +$tablesOnly = ! ($isTheme || $formsOnly) && confirm('Is this for Tables only?'); writeln("\r"); writeln('------'); @@ -83,15 +83,23 @@ if ($formsOnly) { ]); } else { if ($isTheme) { - safeUnlink(__DIR__.'/src/SkeletonServiceProvider.php'); - remove_package_script(['purge']); - remove_package_script(['dev:scripts']); - remove_package_script(['build:scripts']); - remove_package_script(['@awcodes/filament-plugin-purge']); - remove_package_script(['esbuild']); - replace_in_file(__DIR__.'/package.json', [' && npm run purge' => '']); + copy(__DIR__ . '/configure-stubs/theme/package.json', __DIR__ . '/package.json'); + copy(__DIR__ . '/configure-stubs/theme/plugin.css', __DIR__ . '/resources/css/plugin.css'); + safeUnlink(__DIR__ . '/src/SkeletonServiceProvider.php'); + safeUnlink(__DIR__ . '/src/Skeleton.php'); + removeDirectory(__DIR__ . '/config'); + removeDirectory(__DIR__ . '/database'); + removeDirectory(__DIR__ . '/stubs'); + removeDirectory(__DIR__ . '/resources/js'); + removeDirectory(__DIR__ . '/resources/lang'); + removeDirectory(__DIR__ . '/resources/views'); + removeDirectory(__DIR__ . '/src/Commands'); + removeDirectory(__DIR__ . '/src/Facades'); + removeDirectory(__DIR__ . '/src/Testing'); } else { - safeUnlink(__DIR__.'/src/SkeletonTheme.php'); + safeUnlink(__DIR__ . '/src/SkeletonTheme.php'); + copy(__DIR__ . '/configure-stubs/package/package.json', __DIR__ . '/package.json'); + copy(__DIR__ . '/configure-stubs/package/plugin.css', __DIR__ . '/resources/css/plugin.css'); } remove_composer_filament_deps([ @@ -124,6 +132,7 @@ foreach ($files as $file) { str_contains($file, determineSeparator('src/SkeletonTheme.php')) => rename($file, determineSeparator('./src/'.$className.'Theme.php')), str_contains($file, determineSeparator('src/Facades/Skeleton.php')) => rename($file, determineSeparator('./src/Facades/'.$className.'.php')), str_contains($file, determineSeparator('src/Commands/SkeletonCommand.php')) => rename($file, determineSeparator('./src/Commands/'.$className.'Command.php')), + str_contains($file, determineSeparator('src/Testing/TestsSkeleton.php')) => rename($file, determineSeparator('./src/Testing/Tests'.$className.'.php')), str_contains($file, determineSeparator('database/migrations/create_skeleton_table.php.stub')) => rename($file, determineSeparator('./database/migrations/create_'.$packageSlugWithoutPrefix.'_table.php.stub')), str_contains($file, determineSeparator('config/skeleton.php')) => rename($file, determineSeparator('./config/'.$packageSlugWithoutPrefix.'.php')), str_contains($file, 'README.md') => remove_tag($file, 'delete'), @@ -174,7 +183,10 @@ if (! $useUpdateChangelogWorkflow) { confirm('Execute `composer install` and run tests?') && run('composer install && composer test'); -confirm('Let this script delete itself?', true) && unlink(__FILE__); +if (confirm('Let this script delete itself?', true)) { + removeDirectory(__DIR__ . '/configure-stubs'); + unlink(__FILE__); +} function ask(string $question, string $default = ''): string { @@ -362,3 +374,15 @@ function replaceForAllOtherOSes(): array { return explode(PHP_EOL, run('grep -E -r -l -i ":author|:vendor|:package|VendorName|skeleton|vendor_name|vendor_slug|author@domain.com" --exclude-dir=vendor ./* ./.github/* | grep -v '.basename(__FILE__))); } + +function removeDirectory($dir): void { + if (is_dir($dir)) { + $objects = scandir($dir); + foreach ($objects as $object) { + if ($object != "." && $object != "..") { + if (filetype($dir."/".$object) == "dir") removeDirectory($dir."/".$object); else unlink($dir."/".$object); + } + } + rmdir($dir); + } +} diff --git a/postcss.config.js b/postcss.config.js index fef1b22..2855394 100644 --- a/postcss.config.js +++ b/postcss.config.js @@ -1,5 +1,7 @@ module.exports = { plugins: { + "postcss-import": {}, + "tailwindcss/nesting": {}, tailwindcss: {}, autoprefixer: {}, }, diff --git a/src/SkeletonServiceProvider.php b/src/SkeletonServiceProvider.php index bf03283..be6ddb8 100644 --- a/src/SkeletonServiceProvider.php +++ b/src/SkeletonServiceProvider.php @@ -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 + */ + protected function getCommands(): array + { + return [ + SkeletonCommand::class + ]; + } + + /** + * @return array + */ + protected function getContexts(): array + { + return []; + } + + /** + * @return array + */ + protected function getIcons(): array + { + return []; + } + + /** + * @return array + */ + protected function getRoutes(): array + { + return []; + } + + /** + * @return array + */ + protected function getScriptData(): array + { + return []; + } + + /** + * @return array + */ + protected function getMigrations(): array + { + return [ + 'create_skeleton_table' + ]; + } + + protected function registerMacros(): void + { + } } diff --git a/src/SkeletonTheme.php b/src/SkeletonTheme.php index 7da9697..5cfb55a 100644 --- a/src/SkeletonTheme.php +++ b/src/SkeletonTheme.php @@ -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'); } diff --git a/src/Testing/TestsSkeleton.php b/src/Testing/TestsSkeleton.php new file mode 100644 index 0000000..8fa9c0e --- /dev/null +++ b/src/Testing/TestsSkeleton.php @@ -0,0 +1,14 @@ +