diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml deleted file mode 100644 index cdf1660..0000000 --- a/.github/workflows/run-tests.yml +++ /dev/null @@ -1,44 +0,0 @@ -name: Tests - -on: [push, pull_request] - -jobs: - test: - runs-on: ${{ matrix.os }} - strategy: - fail-fast: true - matrix: - os: [ubuntu-latest, windows-latest] - php: [7.4] - laravel: [8.*] - dependency-version: [prefer-lowest, prefer-stable] - include: - - laravel: 8.* - testbench: 6.* - - name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.dependency-version }} - ${{ matrix.os }} - - steps: - - name: Checkout code - uses: actions/checkout@v2 - - - name: Cache dependencies - uses: actions/cache@v2 - with: - path: ~/.composer/cache/files - key: dependencies-laravel-${{ matrix.laravel }}-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }} - - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: ${{ matrix.php }} - extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick - coverage: none - - - name: Install dependencies - run: | - composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update - composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction --no-suggest - - - name: Execute tests - run: vendor/bin/phpunit diff --git a/README.md b/README.md index 28c67c4..2e8bea0 100644 --- a/README.md +++ b/README.md @@ -10,32 +10,24 @@ FortifyUI is an unopinionated authentication starter, powered by [Laravel Fortif ## Installation -To get started, you'll need to install [Laravel Fortify](https://github.com/laravel/fortify) and follow the instructions to configure it. Next, install FortifyUI using Composer: +To get started, you'll need to install FortifyUI using Composer. This will install Laravel Fortify, as well so, please make sure you *do not* have it installed, already. ```bash -composer require zacksmash/fortify-ui laravel/fortify +composer require zacksmash/fortify-ui ``` -Next, publish FortifyUI's resources: +Next, you'll need to run the install command: ```bash -php artisan vendor:publish --provider="Zacksmash\FortifyUI\FortifyUIServiceProvider" +php artisan fortify-ui:install ``` -This command will publish FortifyUI's service provider to your `app/Providers` directory. You should ensure this file is registered within the `providers` array of your `app` configuration file. +This command will publish FortifyUI's views, add the `home` route to `web.php`, and add the FortifyUI service provider to your `app/Providers` directory. -```php -'providers' => [ - ... - App\Providers\FortifyServiceProvider::class, - App\Providers\FortifyUIServiceProvider::class, -], -``` - -If you'd rather not include the service provider file, you can publish just the required views to your project. +If you'd rather not include the service provider file, you can skip the providers file by using the `--skip-provider` flag. ```bash -php artisan vendor:publish --provider="Zacksmash\FortifyUI\FortifyUIServiceProvider" --tag=views +php artisan fortify-ui:install --skip-provider ``` Then, you can add this to Your `AppServiceProvider` or `FortifyServiceProvider`, in the `boot()` method. @@ -68,14 +60,6 @@ Fortify::resetPasswordView(function ($request) { Now, you should have the required views for Laravel Fortify, including basic layout and home views, as well as optional password confirmation and email verification views. -Lastly, you should run the `fortify-ui` command from the terminal: - -```bash -php artisan fortify-ui -``` - -This will update your routes file with the `home` route. - ## Features diff --git a/composer.json b/composer.json index c33bbd5..5c17d37 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,8 @@ ], "require": { "php": "^7.4", - "illuminate/contracts": "^8.0" + "illuminate/contracts": "^8.0", + "laravel/fortify": "^1.5" }, "require-dev": { "friendsofphp/php-cs-fixer": "^2.16", @@ -27,8 +28,7 @@ }, "autoload": { "psr-4": { - "Zacksmash\\FortifyUI\\": "src", - "Zacksmash\\FortifyUI\\Database\\Factories\\": "database/factories" + "Zacksmash\\FortifyUI\\": "src" } }, "autoload-dev": { @@ -49,10 +49,7 @@ "laravel": { "providers": [ "Zacksmash\\FortifyUI\\FortifyUIServiceProvider" - ], - "aliases": { - "FortifyUI": "Zacksmash\\FortifyUI\\FortifyUIFacade" - } + ] } }, "minimum-stability": "dev", diff --git a/src/Commands/FortifyUICommand.php b/src/Commands/FortifyUICommand.php index d808721..10b825f 100644 --- a/src/Commands/FortifyUICommand.php +++ b/src/Commands/FortifyUICommand.php @@ -3,21 +3,73 @@ namespace Zacksmash\FortifyUI\Commands; use Illuminate\Console\Command; +use Illuminate\Support\Str; class FortifyUICommand extends Command { - public $signature = 'fortify-ui'; + public $signature = 'fortify-ui:install {--skip-provider}'; - public $description = 'Setup Fortify UI routes and other junk'; + public $description = 'Setup Fortify UI routes, service providers and views'; public function handle() + { + $this->publishAssets(); + $this->updateServiceProviders(); + $this->updateRoutes(); + + $this->comment('FortifyUI is now installed.'); + + if ($this->option('skip-provider')) { + $this->info('Please, remember to include the Fortify view registrations!'); + } + + $this->info('Please, run php artisan migrate!'); + } + + protected function publishAssets() + { + $this->callSilent('vendor:publish', ['--provider' => 'Laravel\Fortify\FortifyServiceProvider']); + + if (! $this->option('skip-provider')) { + $this->callSilent('vendor:publish', ['--tag' => 'provider', '--force' => true]); + } + + $this->callSilent('vendor:publish', ['--tag' => 'views', '--force' => true]); + } + + public function updateServiceProviders() + { + $appConfig = file_get_contents(config_path('app.php')); + + if ($this->option('skip-provider')) { + if (! Str::contains($appConfig, 'App\\Providers\\FortifyServiceProvider::class')) { + file_put_contents(config_path('app.php'), str_replace( + "App\Providers\RouteServiceProvider::class,", + "App\Providers\RouteServiceProvider::class,".PHP_EOL." App\Providers\FortifyServiceProvider::class,", + $appConfig + )); + } + } else { + if ( + ! Str::contains($appConfig, 'App\\Providers\\FortifyServiceProvider::class') + && + ! Str::contains($appConfig, 'App\\Providers\\FortifyUIServiceProvider::class') + ) { + file_put_contents(config_path('app.php'), str_replace( + "App\Providers\RouteServiceProvider::class,", + "App\Providers\RouteServiceProvider::class,".PHP_EOL." App\Providers\FortifyServiceProvider::class,".PHP_EOL." App\\Providers\\FortifyUIServiceProvider::class", + $appConfig + )); + } + } + } + + protected function updateRoutes() { file_put_contents( base_path('routes/web.php'), "\nRoute::view('home', 'home')\n\t->name('home')\n\t->middleware(['auth', 'verified']);\n", FILE_APPEND ); - - $this->comment('FortifyUI is now setup!'); } }