whitecube / laravel-preset
Custom Laravel Preset for the Whitecube workflow.
Installs: 7 683
Dependents: 0
Suggesters: 0
Security: 0
Stars: 4
Watchers: 3
Forks: 1
Open Issues: 3
Requires
- php: ^8.3
- laravel/prompts: ^0.2.0
- laravel/ui: ^4.6
- dev-master
- v2.0.1
- v2.0.0
- v1.0.5
- v1.0.4
- v1.0.3
- v1.0.2
- v1.0.1
- v1.0.0
- v0.1.3
- v0.1.2
- v0.1.1
- v0.1.0
- v0.0.16
- v0.0.15
- v0.0.14
- v0.0.13
- v0.0.12
- v0.0.11
- v0.0.10
- v0.0.9
- v0.0.8
- v0.0.7
- v0.0.6
- v0.0.5
- v0.0.4
- v0.0.3
- v0.0.2
- v0.0.1
- dev-feat-svg-spritemap
- dev-vite
- dev-feature-post
- dev-feature-lightbox
- dev-feature-sidebar
- dev-feature-faq
- dev-feature-pagination
- dev-feature-badge
- dev-form-fields
- dev-feature-loader
- dev-feature-form
This package is auto-updated.
Last update: 2024-12-20 13:28:23 UTC
README
This preset will install and setup everything that is needed for new Laravel projects at Whitecube.
To start a new project:
- Create the new Laravel project
laravel new my-project cd my-project
- Install the preset
composer require whitecube/laravel-preset --dev
- Activate the preset
php artisan ui whitecube
- You're done! You can now compile, watch, etc!
yarn dev yarn watch yarn icons yarn watch-icons
Everything you'd expect should be there, and you can get to work right away.
Setting up new Hiker projects
After doing the above commands, do the following:
- Add the Hiker repository to the
composer.json
file:
composer config repositories.hiker composer https://repo.hiker.dev
- The, run the following terminal commands:
composer require hiker-dev/hiker
-
When prompted, add your Hiker.dev user & license. You can store these credentials in a
auth.json
, but don't forget to add this file to the project's.gitignore
! -
Finally, run Hiker's installation command:
php artisan hiker:install
Publish the base files for common components
This package ships with a set of publishable components that will help setup the project's front-end basics in a few seconds. The following command will prompt for the components you can install:
php artisan publish:component
Creating new publishable components
In order to create a publishable component, one should simply create a new "Publisher" class inside src/Components/Publishers
and implement Whitecube\LaravelPreset\Components\PublisherInterface
:
namespace Whitecube\LaravelPreset\Components\Publishers; use Whitecube\LaravelPreset\Components\File; use Whitecube\LaravelPreset\Components\FilesCollection; use Whitecube\LaravelPreset\Components\PublisherInterface; class Wysiwyg implements PublisherInterface { /** * Get the component's displayable name. */ public function label(): string { return 'WYSIWYG section'; } /** * Let the publisher prompt for eventual extra input * and return a collection of publishable files. */ public function handle(): FilesCollection { $style = File::makeFromStub( stub: 'components/wysiwyg/part.scss', destination: resource_path('sass/parts/_wysiwyg.scss'), ); $view = File::makeFromStub( stub: 'components/wysiwyg/view.blade.php', destination: resource_path('views/components/wysiwyg.blade.php'), ); return FilesCollection::make([$style, $view]); } /** * Get the component's usage instructions */ public function instructions(): ?string { return "1. Add `@import 'parts/wysiwyg';` to `resources/sass/app.scss`\r\n2. Use the blade component: `<x-wysiwyg><p>Some content</p></x-wysiwyg>`"; } }
Most of the heavy-lifting will be achieved inside the publisher's handle()
method. For instance, it's a great place to prompt for additional component-specific information and configure the publishable files accordingly.
The handle()
method's main purpose is to collect and return the publishable files, that's why this package provides a File
class with several useful methods and features. First, you can choose to create a File
instance using one of these methods:
File::makeFromStub(string $destination, string $stub)
: useful when working with existing files ;File::make(string $destination, string $content, ?string $origin = null)
: useful when creating files from scratch.
Most of the time, File::makeFromStub
should be used in order to keep a clear commit history on the component's original files somewhere in this package's components/[your-component]
directory.
These File
instances can be manipulated before publication with a few useful methods:
$sassFile->replaceVariableValue('wysiwyg_width_columns', 10)
;$sassFile->replaceBemBase('wysiwyg', 'foo')
;$bladeFile->replaceBemBase('wysiwyg', 'foo')
;
Of course, Laravel Prompts can be used anywhere inside a publisher's handle()
method, which is useful for file configuration:
use function Laravel\Prompts\text; $style = File::makeFromStub( stub: 'components/wysiwyg/part.scss', destination: resource_path('sass/parts/_wysiwyg.scss'), ); $width = text( label: 'How many columns should the WYSIWYG\'s container width be?', default: 10, hint: 'Based on a 12 columns grid', ); $style->replaceVariableValue('wysiwyg_width_columns', $width);