Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update for Laravel 7.x #2

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Use this repo as a skeleton for your new preset, once you're done please open an issue on [this repo](https://github.com/laravel-frontend-presets/internals).

Here's the latest documentation on Laravel 5.5:
Here's the latest documentation on Laravel 7.x:

https://laravel.com/docs/master/

Expand Down
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
{
"name": "laravel-frontend-presets/skeleton",
"description": "Laravel 5.5.x Front-end preset for skeleton",
"description": "Laravel 7.x Front-end preset for skeleton",
"keywords": ["laravel", "preset", "skeleton"],
"license": "MIT",
"require": {
"laravel/framework": "5.5.*"
"laravel/framework": "^7.0",
"laravel/ui": "^2.0"
},
"autoload": {
"psr-4": {
Expand Down
128 changes: 85 additions & 43 deletions src/SkeletonPreset.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
<?php
namespace LaravelFrontendPresets\SkeletonPreset;

use Artisan;
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 SkeletonPreset extends Preset
{
Expand All @@ -13,22 +15,25 @@ class SkeletonPreset extends Preset
*
* @return void
*/
public static function install($withAuth = false)
public static function install()
{
static::updatePackages();
static::updateSass(); // or static::updateLess()
static::updateBootstrapping();

if($withAuth)
{
static::addAuthTemplates(); // optional
}
else
{
static::updateWelcomePage(); //optional
}
static::updatePackages();
static::updateStyles();
static::updateBootstrapping();
static::updateWelcomePage();
// static::updatePagination();
static::removeNodeModules();
}

static::removeNodeModules();
/**
* Install the preset with auth routes.
*
* @return void
*/
public static function installAuth()
{
static::scaffoldController();
static::scaffoldAuth();
}

/**
Expand All @@ -42,7 +47,7 @@ protected static function updatePackageArray(array $packages)
// packages to add to the package.json
$packagesToAdd = ['package-name' => '^version'];
// packages to remove from the package.json
$packagesToRemove = ['package-name' => '^version'];
$packagesToRemove = ['package-name'];
return $packagesToAdd + Arr::except($packages, $packagesToRemove);
}

Expand All @@ -51,18 +56,19 @@ protected static function updatePackageArray(array $packages)
*
* @return void
*/
protected static function updateSass()
protected static function updateStyles()
{
// clean up all the files in the sass folder
$orphan_sass_files = glob(resource_path('/assets/sass/*.*'));
tap(new Filesystem, function ($filesystem) {
$filesystem->deleteDirectory(resource_path('sass'));
$filesystem->delete(public_path('js/app.js'));
$filesystem->delete(public_path('css/app.css'));

foreach($orphan_sass_files as $sass_file)
{
(new Filesystem)->delete($sass_file);
}
if (! $filesystem->isDirectory($directory = resource_path('css'))) {
$filesystem->makeDirectory($directory, 0755, true);
}

// copy files from the stubs folder
copy(__DIR__.'/skeleton-stubs/app.scss', resource_path('assets/sass/app.scss'));
$filesystem->copyDirectory(__DIR__.'/skeleton-stubs/resources/sass', resource_path('sass'));
});
}

/**
Expand All @@ -72,13 +78,7 @@ protected static function updateSass()
*/
protected static function updateBootstrapping()
{
// remove exisiting bootstrap.js file
(new Filesystem)->delete(
resource_path('assets/js/bootstrap.js')
);

// copy a new bootstrap.js file from your stubs folder
copy(__DIR__.'/skeleton-stubs/bootstrap.js', resource_path('assets/js/bootstrap.js'));
copy(__DIR__.'/skeleton-stubs/resources/js/bootstrap.js', resource_path('js/bootstrap.js'));
}

/**
Expand All @@ -94,24 +94,66 @@ protected static function updateWelcomePage()
);

// copy new one from your stubs folder
copy(__DIR__.'/skeleton-stubs/views/welcome.blade.php', resource_path('views/welcome.blade.php'));
copy(__DIR__.'/skeleton-stubs/resources/views/welcome.blade.php', resource_path('views/welcome.blade.php'));
}

/**
* Scaffold Auth controllers into project.
*
* @return void
*/
protected static function scaffoldController()
{
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()))
);
});
}

/**
* Copy Auth view templates.
* Scaffold Auth views into project.
*
* @return void
*/
protected static function addAuthTemplates()
protected static function scaffoldAuth()
{
// Add Home controller
copy(__DIR__.'/stubs-stubs/Controllers/HomeController.php', app_path('Http/Controllers/HomeController.php'));
file_put_contents(app_path('Http/Controllers/HomeController.php'), static::compileControllerStub());

// Add Auth routes in 'routes/web.php'
$auth_route_entry = "Auth::routes();\n\nRoute::get('/home', 'HomeController@index')->name('home');\n\n";
file_put_contents('./routes/web.php', $auth_route_entry, FILE_APPEND);
file_put_contents(
base_path('routes/web.php'),
"Auth::routes();\n\nRoute::get('/home', 'HomeController@index')->name('home');\n\n",
FILE_APPEND
);

tap(new Filesystem, function ($filesystem) {
$filesystem->copyDirectory(__DIR__.'/skeleton-stubs/resources/views', resource_path('views'));

collect($filesystem->allFiles(base_path('vendor/laravel/ui/stubs/migrations')))
->each(function (SplFileInfo $file) use ($filesystem) {
$filesystem->copy(
$file->getPathname(),
database_path('migrations/'.$file->getFilename())
);
});
});
}

// Copy Skeleton auth views from the stubs folder
(new Filesystem)->copyDirectory(__DIR__.'/foundation-stubs/views', resource_path('views'));

protected static function compileControllerStub()
{
return str_replace(
'{{namespace}}',
Container::getInstance()->getNamespace(),
file_get_contents(__DIR__.'/skeleton-stubs/controllers/HomeController.stub')
);
}
}
18 changes: 10 additions & 8 deletions src/SkeletonPresetServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
namespace LaravelFrontendPresets\SkeletonPreset;

use Illuminate\Support\ServiceProvider;
use Illuminate\Foundation\Console\PresetCommand;
use Laravel\Ui\UiCommand;

class SkeletonPresetServiceProvider extends ServiceProvider
{
Expand All @@ -13,15 +13,17 @@ class SkeletonPresetServiceProvider extends ServiceProvider
*/
public function boot()
{
PresetCommand::macro('skeleton', function ($command) {
SkeletonPreset::install(false);
UiCommand::macro('skeleton', function ($command) {
SkeletonPreset::install();

$command->info('Skeleton scaffolding installed successfully.');
$command->comment('Please run "npm install && npm run dev" to compile your fresh scaffolding.');
});

PresetCommand::macro('skeleton-auth', function ($command) { //optional
SkeletonPreset::install(true);
$command->info('Skeleton scaffolding with Auth views installed successfully.');
if ($command->option('auth')) {
SkeletonPreset::installAuth();

$command->info('Skeleton auth scaffolding installed successfully.');
}

$command->comment('Please run "npm install && npm run dev" to compile your fresh scaffolding.');
});
}
Expand Down
File renamed without changes.