Skip to content

qruto/laravel-flora

Repository files navigation

Laravel Flora Logo

A convenient way to automate setup of your application.

Laravel Flora Code Example

Build Status Styles check Types check Refactor code Total Downloads Latest Stable Version

Laravel Flora Demo

Goal

The main goal of Flora is define and automate the setup process of Laravel application. All necessary actions to make the application ready to work in one place.

Packages discovering, assets building and publishing, running database migrations, caching etc...

🧠🚀 Put the knowledge of setup instructions at the application level.

Introduction

Revival of Laravel Initializer. Rethinked, improved, prettified, renamed.

Flora allows you to bring Laravel application to live by one command. Use default or define custom chain of actions required to install or update an application.

Run install when you fetch a fresh application to prepare it to launch on new environment.

  • after git clone

Run update on every dependency or source code change.

  • after composer install|update
  • after git pull|checkout|megre|...
  • in deploy script
  • in CI/CD pipeline

it will take care of the rest of the work.

Support

Since of February 24, unfortunately I haven't any commercial work, permanent living place or the ability to plan anything for the long term. However, I have a greater desire to continue creating useful solutions for people around the world. It makes me feel better these days.

support me

GitHub Sponsorships profile is ready! There you can find current work, future plans, goals and dreams... Your stars make me happier each day ❤️ ⭐ Sponsorship will enable us to live more peacefully and continue to work on useful solutions for you.

I would be very grateful for mentions or just a sincere "thank you".

💳 Sponsoring directly to savings jar with card or Apple Pay/Google Pay.

Installation

Via Composer:

composer require qruto/laravel-flora

Usage

Replace installation section in readme file with:

php artisan install

Refresh application state by:

php artisan update

ℹ️ Instruction depends on current environment. Package has predefined actions suitable for most cases.

See detailed output in verbosity mode:

php artisan app:update -v

You can automate the update process by adding @php artisan update command to your application composer.json script post-autoload-dump section and remove default vendor:publish command from post-update-cmd section. update command will take care of assets publishing for you.

Setup it with:

php artisan flora:setup --script

composer.json changes:

"post-autoload-dump": [
    "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump", 
-     "@php artisan package:discover --ansi"
+     "@php artisan update"
],
- "post-update-cmd": [
-     "@php artisan vendor:publish --tag=laravel-assets --ansi --force"
- ],

Register Task Scheduler

Conditions:

  • any scheduler task registered
  • installation process performed
  • application in production environment

then you will be prompted for the addition of a cron entry to run the task scheduler every minute.

Task Scheduler

Configuration

To customize instructions for each environment, you need to publish setup files.

php artisan flora:setup

This command will create routes/setup.php file with predefined instructions for local and production environments.

use Qruto\Flora\Run;

App::install('local', fn (Run $run) => $run
    ->command('key:generate')
    ->command('migrate')
    ->command('storage:link')
    ->script('build')
);

App::install('production', fn (Run $run) => $run
    ->command('key:generate', ['--force' => true])
    ->command('migrate', ['--force' => true])
    ->command('storage:link')
    ->script('cache')
    ->script('build')
);

App::update('local', fn (Run $run) => $run
    ->command('migrate')
    ->command('cache:clear')
    ->script('build')
);

App::update('production', fn (Run $run) => $run
    ->script('cache')
    ->command('migrate', ['--force' => true])
    ->command('cache:clear')
    ->command('queue:restart')
    ->script('build')
);

Feel free to change it any way you need or add specific environment like staging.

`build` and `cache` script details

build script contains assets building commands:

npm install
npm run build

cache script provides general application caching:

php artisan route:cache
php artisan config:cache
php artisan event:cache

In addition, it will create config/flora.php for configuration assets publishing.

return [
    /*
    |--------------------------------------------------------------------------
    | Force Assets Publish
    |--------------------------------------------------------------------------
    |
    | Force publish assets on every installation or update. By default, assets
    | will always be force published, which would completely automate the
    | setup. Switch it to false if you want to manually publish assets.
    | For example if you prefer to commit them.
    */
    'force_publish' => true,

    /*
    |--------------------------------------------------------------------------
    | Publishable Assets
    |--------------------------------------------------------------------------
    |
    | List of assets that will be published during installation or update.
    | Most of required assets detects on the way. If you need specific
    | tag or provider, feel free to add it to the array.
    */
    'assets' => [
        'laravel-assets',
    ],
];

If you need to customize just assets publishing, you can publish only configuration file:

php artisan vendor:publish --tag=flora-config

Side Packages Support

Flora automatically detects several packages for performing necessary actions on install or update. For example: publish Vapor UI assets, generate IDE helper files, terminate Horizon workers etc.

Supported:

Soon:

Custom Scripts

Override or define custom script in service provider's boot method:

Run::newScript('cache', fn (Run $run) => $run
    ->command('route:cache')
    ->command('config:cache')
    ->command('event:cache')
    ->command('view:cache')
);

Available Actions

$run
    ->command('command') // Run artisan command
    ->script('build') // Perform custom script
    ->exec('process') // Execute external process
    ->job(new JobClass) // Dispatch job
    ->call(fn () => makeSomething()) // Call callable function 
    ->notify('Done!') // Send notification

Upgrading

Please see UPGRADING for details.

Changelog

Please see CHANGELOG for more information what has changed recently.

Testing

composer test

Contributing

Please see CONTRIBUTING and CONDUCT for details.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Credits

Thanks Nuno Maduro for laravel-desktop-notifier package which brings desktop notifications to Laravel.

License

The MIT License (MIT). Please see License File for more information.