Skip to content
This repository has been archived by the owner on May 27, 2022. It is now read-only.

Commit

Permalink
Clean up preset class
Browse files Browse the repository at this point in the history
  • Loading branch information
zaknesler committed May 23, 2018
1 parent 2515aa6 commit e417ec5
Showing 1 changed file with 46 additions and 54 deletions.
100 changes: 46 additions & 54 deletions src/Tailwind.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,28 @@

use Illuminate\Support\Arr;
use Illuminate\Container\Container;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Support\Facades\File;
use Illuminate\Foundation\Console\Presets\Preset;

class Tailwind extends Preset
{
/**
* Setup basic assets.
*
* @return void
*/
private static function setup()
{
static::ensureComponentDirectoryExists();
static::updatePackages();

static::installScripts();
static::installStyles();
static::updateExampleComponent();

static::removeNodeModules();
}

/**
* Install single welcome view.
*
Expand All @@ -18,7 +35,7 @@ public static function install()
{
static::setup();

(new Filesystem)->copyDirectory(__DIR__.'/stubs/views/default', resource_path('views'));
File::copyDirectory(__DIR__.'/stubs/views/default', resource_path('views'));
}

/**
Expand All @@ -29,35 +46,29 @@ public static function install()
public static function installWithAuth()
{
static::setup();
static::installAuthRoutes();

file_put_contents(app_path('Http/Controllers/HomeController.php'), static::compileControllerStub());

file_put_contents(
base_path('routes/web.php'),
"\nAuth::routes();\n\nRoute::get('/home', 'HomeController@index')->name('home');\n",
FILE_APPEND
);

(new Filesystem)->copyDirectory(__DIR__.'/stubs/views/auth', resource_path('views'));
File::copyDirectory(__DIR__.'/stubs/views/auth', resource_path('views'));
}

/**
* Setup basic assets.
* Install authentication routes if they are not present.
*
* @return void
*/
private static function setup()
protected static function installAuthRoutes()
{
static::updatePackages();
static::updateWebpackConfiguration();

static::ensureComponentDirectoryExists();
static::updateExampleComponent();
static::updateBootstrapping();
static::installLess();
static::installTailwindConfiguration();
if (str_contains(file_get_contents(base_path('routes/web.php')), 'Auth::routes();')) {
return;
}

static::removeNodeModules();
file_put_contents(
base_path('routes/web.php'),
"\nAuth::routes();\n\nRoute::get('/home', 'HomeController@index')->name('home');\n",
FILE_APPEND
);
}

/**
Expand All @@ -69,10 +80,8 @@ private static function setup()
protected static function updatePackageArray(array $packages)
{
return array_merge([
'vue' => '^2.5',
'less' => '^3.0',
'less-loader' => '^4.1',
'laravel-mix' => '^2.1',
'laravel-mix-purgecss' => '^2.1',
'laravel-mix-tailwind' => '^0.1',
], Arr::except($packages, [
Expand All @@ -98,65 +107,48 @@ protected static function compileControllerStub()
}

/**
* Update the Webpack configuration.
* Install all JavaScript files.
*
* @return void
*/
protected static function updateWebpackConfiguration()
protected static function installScripts()
{
copy(__DIR__.'/stubs/webpack.stub.mix.js', base_path('webpack.mix.js'));
}

/**
* Update the bootstrapping files.
*
* @return void
*/
protected static function updateBootstrapping()
{
copy(__DIR__.'/stubs/js/app.stub.js', resource_path('assets/js/app.js'));
copy(__DIR__.'/stubs/js/bootstrap.stub.js', resource_path('assets/js/bootstrap.js'));
}

/**
* Update the example Vue component.
*
* @return void
*/
protected static function updateExampleComponent()
{
(new Filesystem)->delete(resource_path('assets/js/components/Example.js'));
(new Filesystem)->delete(resource_path('assets/js/components/ExampleComponent.vue'));

copy(
__DIR__.'/stubs/js/components/ExampleComponent.stub.vue',
resource_path('assets/js/components/ExampleComponent.vue')
);
copy(__DIR__.'/stubs/tailwind.stub.js', base_path('tailwind.js'));
}

/**
* Install less files.
* Install stylesheets.
*
* @return void
*/
protected static function installLess()
protected static function installStyles()
{
(new Filesystem)->deleteDirectory(resource_path('assets/sass'));
File::deleteDirectory(resource_path('assets/sass'));

if (!file_exists(resource_path('assets/less'))) {
if (! file_exists(resource_path('assets/less'))) {
mkdir(resource_path('assets/less'), 0777, true);
}

copy(__DIR__.'/stubs/less/app.stub.less', resource_path('assets/less/app.less'));
}

/**
* Install Tailwind configuration.
* Update the example Vue component.
*
* @return void
*/
protected static function installTailwindConfiguration()
protected static function updateExampleComponent()
{
copy(__DIR__.'/stubs/tailwind.stub.js', base_path('tailwind.js'));
File::cleanDirectory(resource_path('assets/js/components'));

copy(
__DIR__.'/stubs/js/components/ExampleComponent.stub.vue',
resource_path('assets/js/components/ExampleComponent.vue')
);
}
}

0 comments on commit e417ec5

Please sign in to comment.