Skip to content

Package provides ability to setup application initialization actions

License

Notifications You must be signed in to change notification settings

seguce92/laravel-initializer

Repository files navigation

Application installation command

Latest Version on Packagist Software License Build Status StyleCI Coverage Status Quality Score Total Downloads

This package adds artisan app:install command, which runs defined commands related to the current environment

Installation

For Laravel <= 5.4 - Via Composer

$ composer require mad-web/laravel-initializer:~0.1.0

For Laravel >= 5.5 - Via Composer

$ composer require mad-web/laravel-initializer

For Laravel >= 5.5 - Now add the service provider in config/app.php file:

'providers' => [
    // ...
    MadWeb\Initializer\InitializerServiceProvider::class,
];

Run artisan make:installer command to create installer config in app directory

You can override config key where stored current environment, just publish config file, and set env_config_key value

php artisan vendor:publish --provider="MadWeb\Initializer\InitializerServiceProvider" --tag=config

By default it set to app.env

Usage

InstallerConfig contents:

namespace App;

use MadWeb\Initializer\Contracts\Runner;

class InstallerConfig
{
    public function production(Runner $run)
    {
        return $run
            ->artisan('key:generate')
            ->artisan('migrate')
            ->external('npm', 'install', '--production')
            ->external('npm', 'run', 'production')
            ->artisan('route:cache')
            ->artisan('config:cache')
            ->artisan('optimize')
            ->external('composer', 'dump-autoload', '--optimize');
    }

    public function local(Runner $run)
    {
        return $run
            ->artisan('key:generate')
            ->artisan('migrate')
            ->external('npm', 'install')
            ->external('npm', 'run', 'development');
    }
}

You can add any another method which called the same as your environment name, for example staging and define different commands

If you need to run commands with root privileges separately you can define method with next convention

namespace App;

use MadWeb\Initializer\Contracts\Runner;

class InstallerConfig
{
    public function local(Runner $run)
    {
        return $run
            ->artisan('key:generate')
            ->artisan('migrate')
            ->external('npm', 'install')
            ->external('npm', 'run', 'development');
    }
    
    public function localRoot(Runner $run)
    {
        return $run
            ->external('service', 'php-fpm', 'restart')
            ->external('supervisorctl', 'reread')
            ->external('supervisorctl', 'update');
    }
}

Run it by passing "root" option - artisan app:insstall --root

If you want to move config file from the app directory to a different place, just add a new binding in the AppServiceProvider

$this->app->bind('project.installer', \AnotherNameSpace\InstallerConfig::class);

####List of commands available to run

$run
    ->artisan('command', ['argument' => 'argument_value', '-param' => 'param_value', '--option' => 'option_value', ...]) // Artisan command
    ->external('command', 'argument', 'argument_value', '-param', 'param_value', '--option=option_value', ...) // Any external command
    ->callable('command', 'argument', ...) // Callable function (like for call_user_func)
    ->dispatch(new JobClass) // Dispatch job task
    ->dispatchNow(new JobClass) // Dispatch job task without queue
    ->publish([ServiceProvider::class]) // Publish package assets
    ->publish([ServiceProvider::class => 'tag']) // Publish package assets with tag

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

License

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

About

Package provides ability to setup application initialization actions

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages