Skip to content

Commit

Permalink
Merge branch 'yaelahan/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeldyrynda committed Mar 5, 2020
2 parents ea82c54 + af3867a commit 64e82b0
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 20 deletions.
14 changes: 5 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
30 changes: 25 additions & 5 deletions src/TailwindCssPreset.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -22,6 +24,7 @@ public static function install()
public static function installAuth()
{
static::install();
static::scaffoldController();
static::scaffoldAuth();
}

Expand Down Expand Up @@ -66,18 +69,35 @@ 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'));

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()
Expand Down
11 changes: 6 additions & 5 deletions src/TailwindCssPresetServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down

0 comments on commit 64e82b0

Please sign in to comment.