Skip to content
This repository was archived by the owner on Dec 11, 2021. It is now read-only.

Commit 5075694

Browse files
committed
Init
0 parents  commit 5075694

22 files changed

+427
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/.idea
2+
/vendor
3+
composer.lock

LICENSE.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) Tailwindcomponents
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Laravel preset for TailwindCSS

composer.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"name": "tailwindcomponents/laravel-preset",
3+
"description": "Laravel frontend preset for Tailwind CSS",
4+
"keywords": ["laravel", "preset", "tailwindcss"],
5+
"license": "MIT",
6+
"require": {
7+
"laravel/framework": "^7.0",
8+
"laravel/ui": "^2.0"
9+
},
10+
"autoload": {
11+
"psr-4": {
12+
"TailwindComponents\\LaravelPreset\\": "src/"
13+
}
14+
},
15+
"extra": {
16+
"laravel": {
17+
"providers": [
18+
"TailwindComponents\\LaravelPreset\\LaravelPresetServiceProvider"
19+
]
20+
}
21+
}
22+
}

src/LaravelPreset.php

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
<?php
2+
3+
namespace TailwindComponents\LaravelPreset;
4+
5+
use Illuminate\Support\Arr;
6+
use Illuminate\Support\Str;
7+
use Illuminate\Container\Container;
8+
use Illuminate\Filesystem\Filesystem;
9+
use Laravel\Ui\Presets\Preset;
10+
use Symfony\Component\Finder\SplFileInfo;
11+
12+
class LaravelPreset extends Preset
13+
{
14+
public static function install()
15+
{
16+
static::updatePackages();
17+
static::updateStyles();
18+
static::updateBootstrapping();
19+
static::updatePagination();
20+
static::removeNodeModules();
21+
}
22+
23+
public static function installAuth()
24+
{
25+
static::scaffoldController();
26+
static::scaffoldAuth();
27+
}
28+
29+
protected static function updatePackageArray(array $packages)
30+
{
31+
return array_merge([
32+
'laravel-mix' => '^5.0.1',
33+
'tailwindcss' => '^1.4',
34+
'@tailwindcss/custom-forms' => '^0.2',
35+
], Arr::except($packages, [
36+
'bootstrap',
37+
'bootstrap-sass',
38+
'popper.js',
39+
'laravel-mix',
40+
'jquery',
41+
]));
42+
}
43+
44+
protected static function updateStyles()
45+
{
46+
tap(new Filesystem, function ($filesystem) {
47+
$filesystem->deleteDirectory(resource_path('sass'));
48+
$filesystem->delete(public_path('js/app.js'));
49+
$filesystem->delete(public_path('css/app.css'));
50+
51+
if (! $filesystem->isDirectory($directory = resource_path('css'))) {
52+
$filesystem->makeDirectory($directory, 0755, true);
53+
}
54+
});
55+
56+
copy(__DIR__.'/stubs/resources/css/app.css', resource_path('css/app.css'));
57+
}
58+
59+
protected static function updateBootstrapping()
60+
{
61+
copy(__DIR__.'/stubs/tailwind.config.js', base_path('tailwind.config.js'));
62+
63+
copy(__DIR__.'/stubs/webpack.mix.js', base_path('webpack.mix.js'));
64+
65+
copy(__DIR__.'/stubs/resources/js/app.js', resource_path('js/app.js'));
66+
67+
copy(__DIR__.'/stubs/resources/js/bootstrap.js', resource_path('js/bootstrap.js'));
68+
69+
(new Filesystem)->copyDirectory(__DIR__.'/stubs/resources/js/components', resource_path('js/components'));
70+
}
71+
72+
protected static function updatePagination()
73+
{
74+
(new Filesystem)->delete(resource_path('views/vendor/paginate'));
75+
76+
(new Filesystem)->copyDirectory(__DIR__.'/stubs/resources/views/vendor/pagination', resource_path('views/vendor/pagination'));
77+
}
78+
79+
protected static function scaffoldController()
80+
{
81+
if (! is_dir($directory = app_path('Http/Controllers/Auth'))) {
82+
mkdir($directory, 0755, true);
83+
}
84+
85+
$filesystem = new Filesystem;
86+
87+
collect($filesystem->allFiles(base_path('vendor/laravel/ui/stubs/Auth')))
88+
->each(function (SplFileInfo $file) use ($filesystem) {
89+
$filesystem->copy(
90+
$file->getPathname(),
91+
app_path('Http/Controllers/Auth/'.Str::replaceLast('.stub', '.php', $file->getFilename()))
92+
);
93+
});
94+
}
95+
96+
protected static function scaffoldAuth()
97+
{
98+
file_put_contents(app_path('Http/Controllers/HomeController.php'), static::compileControllerStub());
99+
100+
file_put_contents(
101+
base_path('routes/web.php'),
102+
"Auth::routes();\n\nRoute::get('/home', 'HomeController@index')->name('home');\n\n",
103+
FILE_APPEND
104+
);
105+
106+
tap(new Filesystem, function ($filesystem) {
107+
$filesystem->copyDirectory(__DIR__.'/stubs/resources/views', resource_path('views'));
108+
109+
collect($filesystem->allFiles(base_path('vendor/laravel/ui/stubs/migrations')))
110+
->each(function (SplFileInfo $file) use ($filesystem) {
111+
$filesystem->copy(
112+
$file->getPathname(),
113+
database_path('migrations/'.$file->getFilename())
114+
);
115+
});
116+
});
117+
}
118+
119+
protected static function compileControllerStub()
120+
{
121+
return str_replace(
122+
'{{namespace}}',
123+
Container::getInstance()->getNamespace(),
124+
file_get_contents(__DIR__.'/stubs/controllers/HomeController.stub')
125+
);
126+
}
127+
}

src/LaravelPresetServiceProvider.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
namespace TailwindComponents\LaravelPreset;
4+
5+
use Laravel\Ui\UiCommand;
6+
use Illuminate\Pagination\Paginator;
7+
use Illuminate\Support\ServiceProvider;
8+
9+
class LaravelPresetServiceProvider extends ServiceProvider
10+
{
11+
public function boot()
12+
{
13+
UiCommand::macro('tailwindcss', function ($command) {
14+
LaravelPreset::install();
15+
16+
$command->info('Tailwind CSS scaffolding installed successfully.');
17+
18+
if ($command->option('auth')) {
19+
LaravelPreset::installAuth();
20+
21+
$command->info('Tailwind CSS auth scaffolding installed successfully.');
22+
}
23+
24+
$command->comment('Please run "npm install && npm run dev" to compile your fresh scaffolding.');
25+
});
26+
27+
Paginator::defaultView('pagination::default');
28+
}
29+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
namespace {{namespace}}Http\Controllers;
4+
5+
use Illuminate\Http\Request;
6+
7+
class HomeController extends Controller
8+
{
9+
/**
10+
* Create a new controller instance.
11+
*
12+
* @return void
13+
*/
14+
public function __construct()
15+
{
16+
$this->middleware('auth');
17+
}
18+
19+
/**
20+
* Show the application dashboard.
21+
*
22+
* @return \Illuminate\Contracts\Support\Renderable
23+
*/
24+
public function index()
25+
{
26+
return view('home');
27+
}
28+
}

src/stubs/resources/css/app.css

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
@import url('https://fonts.googleapis.com/css?family=Nunito');
2+
3+
@tailwind base;
4+
5+
@tailwind components;
6+
7+
@tailwind utilities;

src/stubs/resources/js/app.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
* First we will load all of this project's JavaScript dependencies which
3+
* includes Vue and other libraries. It is a great starting point when
4+
* building robust, powerful web applications using Vue and Laravel.
5+
*/
6+
7+
require('./bootstrap');
8+
9+
window.Vue = require('vue');
10+
11+
/**
12+
* The following block of code may be used to automatically register your
13+
* Vue components. It will recursively scan this directory for the Vue
14+
* components and automatically register them with their "basename".
15+
*
16+
* Eg. ./components/ExampleComponent.vue -> <example-component></example-component>
17+
*/
18+
19+
// const files = require.context('./', true, /\.vue$/i)
20+
// files.keys().map(key => Vue.component(key.split('/').pop().split('.')[0], files(key).default))
21+
22+
Vue.component('example-component', require('./components/ExampleComponent.vue').default);
23+
24+
/**
25+
* Next, we will create a fresh Vue application instance and attach it to
26+
* the page. Then, you may begin adding components to this application
27+
* or customize the JavaScript scaffolding to fit your unique needs.
28+
*/
29+
30+
const app = new Vue({
31+
el: '#app',
32+
});

src/stubs/resources/js/bootstrap.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
window._ = require('lodash');
2+
3+
/**
4+
* We'll load the axios HTTP library which allows us to easily issue requests
5+
* to our Laravel back-end. This library automatically handles sending the
6+
* CSRF token as a header based on the value of the "XSRF" token cookie.
7+
*/
8+
9+
window.axios = require('axios');
10+
11+
window.axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';
12+
13+
/**
14+
* Echo exposes an expressive API for subscribing to channels and listening
15+
* for events that are broadcast by Laravel. Echo and event broadcasting
16+
* allows your team to easily build robust real-time web applications.
17+
*/
18+
19+
// import Echo from 'laravel-echo';
20+
21+
// window.Pusher = require('pusher-js');
22+
23+
// window.Echo = new Echo({
24+
// broadcaster: 'pusher',
25+
// key: process.env.MIX_PUSHER_APP_KEY,
26+
// cluster: process.env.MIX_PUSHER_APP_CLUSTER,
27+
// forceTLS: true
28+
// });

0 commit comments

Comments
 (0)