diff --git a/README.md b/README.md index d2c3a7af..c17030b9 100644 --- a/README.md +++ b/README.md @@ -1,25 +1,21 @@ -# Laravel 6.0+ Frontend preset for Tailwind CSS +# Laravel 7.0+ Frontend preset for Tailwind CSS A Laravel front-end scaffolding preset for [Tailwind CSS](https://tailwindcss.com) - a Utility-First CSS Framework for Rapid UI Development. -## 1. Basic usage +## Usage -1. Run `npx use-tailwind-preset` - -## 2. Advanced Usage - -1. Fresh install Laravel >= 6.0 and `cd` to your app. +1. Fresh install Laravel >= 7.0 and `cd` to your app. 2. Install this preset via `composer require laravel-frontend-presets/tailwindcss --dev`. Laravel will automatically discover this package. No need to register the service provider. ### a. For Presets without Authentication -1. Use `php artisan preset tailwindcss` for the basic Tailwind CSS preset +1. Use `php artisan ui tailwindcss` for the basic Tailwind CSS preset 2. `npm install && npm run dev` 3. `php artisan serve` (or equivalent) to run server and test preset. ### b. For Presets with Authentication -1. Use `php artisan preset tailwindcss-auth` for the basic preset, auth route entry and Tailwind CSS auth views in one go. (NOTE: If you run this command several times, be sure to clean up the duplicate Auth entries in `routes/web.php`) +1. Use `php artisan ui tailwindcss --auth` for the basic preset, auth route entry and Tailwind CSS auth views in one go. (NOTE: If you run this command several times, be sure to clean up the duplicate Auth entries in `routes/web.php`) 4. `npm install && npm run dev` 5. Configure your favorite database (mysql, sqlite etc.) 6. `php artisan migrate` to create basic user tables. diff --git a/composer.json b/composer.json index e368ac6d..7cf25a74 100644 --- a/composer.json +++ b/composer.json @@ -4,7 +4,8 @@ "keywords": ["laravel", "preset", "tailwindcss"], "license": "MIT", "require": { - "laravel/framework": "^5.5 || ^6.0" + "laravel/framework": "^7.0", + "laravel/ui": "^2.0" }, "autoload": { "psr-4": { diff --git a/src/TailwindCssPreset.php b/src/TailwindCssPreset.php index 4f2a22bf..b169316d 100644 --- a/src/TailwindCssPreset.php +++ b/src/TailwindCssPreset.php @@ -3,9 +3,11 @@ namespace LaravelFrontendPresets\TailwindCssPreset; use Illuminate\Support\Arr; +use Illuminate\Support\Str; use Illuminate\Container\Container; use Illuminate\Filesystem\Filesystem; -use Illuminate\Foundation\Console\Presets\Preset; +use Laravel\Ui\Presets\Preset; +use Symfony\Component\Finder\SplFileInfo; class TailwindCssPreset extends Preset { @@ -22,6 +24,7 @@ public static function install() public static function installAuth() { static::install(); + static::scaffoldController(); static::scaffoldAuth(); } @@ -66,6 +69,13 @@ protected static function updateBootstrapping() copy(__DIR__.'/tailwindcss-stubs/resources/js/bootstrap.js', resource_path('js/bootstrap.js')); } + protected static function updatePagination() + { + (new Filesystem)->delete(resource_path('views/vendor/paginate')); + + (new Filesystem)->copyDirectory(__DIR__.'/tailwindcss-stubs/resources/views/vendor/pagination', resource_path('views/vendor/pagination')); + } + protected static function updateWelcomePage() { (new Filesystem)->delete(resource_path('views/welcome.blade.php')); @@ -73,11 +83,21 @@ protected static function updateWelcomePage() copy(__DIR__.'/tailwindcss-stubs/resources/views/welcome.blade.php', resource_path('views/welcome.blade.php')); } - protected static function updatePagination() + protected static function scaffoldController() { - (new Filesystem)->delete(resource_path('views/vendor/paginate')); - - (new Filesystem)->copyDirectory(__DIR__.'/tailwindcss-stubs/resources/views/vendor/pagination', resource_path('views/vendor/pagination')); + if (! is_dir($directory = app_path('Http/Controllers/Auth'))) { + mkdir($directory, 0755, true); + } + + $filesystem = new Filesystem; + + collect($filesystem->allFiles(base_path('vendor/laravel/ui/stubs/Auth'))) + ->each(function (SplFileInfo $file) use ($filesystem) { + $filesystem->copy( + $file->getPathname(), + app_path('Http/Controllers/Auth/'.Str::replaceLast('.stub', '.php', $file->getFilename())) + ); + }); } protected static function scaffoldAuth() diff --git a/src/TailwindCssPresetServiceProvider.php b/src/TailwindCssPresetServiceProvider.php index 470690eb..d6cf6f72 100644 --- a/src/TailwindCssPresetServiceProvider.php +++ b/src/TailwindCssPresetServiceProvider.php @@ -4,24 +4,25 @@ use Illuminate\Pagination\Paginator; use Illuminate\Support\ServiceProvider; -use Illuminate\Foundation\Console\PresetCommand; +use Laravel\Ui\UiCommand; +use Laravel\Ui\AuthCommand; class TailwindCssPresetServiceProvider extends ServiceProvider { public function boot() { - PresetCommand::macro('tailwindcss', function ($command) { + UiCommand::macro('tailwindcss', function ($command) { TailwindCssPreset::install(); $command->info('Tailwind CSS scaffolding installed successfully.'); - $command->info('Please run "npm install && npm run dev" to compile your fresh scaffolding.'); + $command->comment('Please run "npm install && npm run dev" to compile your fresh scaffolding.'); }); - PresetCommand::macro('tailwindcss-auth', function ($command) { + AuthCommand::macro('tailwindcss', function ($command) { TailwindCssPreset::installAuth(); $command->info('Tailwind CSS scaffolding with auth views installed successfully.'); - $command->info('Please run "npm install && npm run dev" to compile your fresh scaffolding.'); + $command->comment('Please run "npm install && npm run dev" to compile your fresh scaffolding.'); }); Paginator::defaultView('pagination::default');