开源软件名称(OpenSource Name):mad-web/laravel-initializer开源软件地址(OpenSource Url):https://github.com/mad-web/laravel-initializer开源编程语言(OpenSource Language):PHP 100.0%开源软件介绍(OpenSource Introduction):A convenient way to initialize your application. IntroductionWe all know, that every application should contain readme file and Installation section with list of actions that you should to do for preparing an application to work. Typical instruction:
Some of actions you should do on every application update (composer update, git pull...) or branch change (git checkout) for preparing an application to work. Laravel Initializer gives you the ability to declare these processes and run it by simple Also With Laravel Initializer you keep both of these processes in the source control.
InstallationVia Composer composer require mad-web/laravel-initializer then publish initializer classes: php artisan vendor:publish --tag=initializers It will create You can override config key which stores current environment value, publish config file and set php artisan vendor:publish --provider="MadWeb\Initializer\InitializerServiceProvider" --tag=config by default value is set to UsageUsage of Install class contents: namespace App;
use MadWeb\Initializer\Contracts\Runner;
class Install
{
public function production(Runner $run)
{
$run->external('composer', 'install', '--no-dev', '--prefer-dist', '--optimize-autoloader')
->artisan('key:generate')
->artisan('migrate', ['--force' => true])
->artisan('storage:link')
// ->dispatch(new MakeCronTask)
->external('npm', 'install', '--production')
->external('npm', 'run', 'production')
->artisan('route:cache')
->artisan('config:cache')
->artisan('event:cache');
}
public function local(Runner $run)
{
$run->external('composer', 'install')
->artisan('key:generate')
->artisan('migrate')
->artisan('storage:link')
->external('npm', 'install')
->external('npm', 'run', 'development');
}
} Update class contents: namespace App;
use MadWeb\Initializer\Contracts\Runner;
class Update
{
public function production(Runner $run)
{
$run->external('composer', 'install', '--no-dev', '--prefer-dist', '--optimize-autoloader')
->external('npm', 'install', '--production')
->external('npm', 'run', 'production')
->artisan('route:cache')
->artisan('config:cache')
->artisan('event:cache')
->artisan('migrate', ['--force' => true])
->artisan('cache:clear')
->artisan('queue:restart'); // ->artisan('horizon:terminate');
}
public function local(Runner $run)
{
$run->external('composer', 'install')
->external('npm', 'install')
->external('npm', 'run', 'development')
->artisan('migrate')
->artisan('cache:clear');
}
} You can add any other method which should have the same name as your environment name, for example If you need to run actions with root privileges separately, you can define a method according to the following convention: namespace App;
use MadWeb\Initializer\Contracts\Runner;
use MadWeb\Initializer\Jobs\Supervisor\MakeQueueSupervisorConfig;
use MadWeb\Initializer\Jobs\Supervisor\MakeSocketSupervisorConfig;
class Install
{
public function production(Runner $run) { ... }
public function productionRoot(Runner $run)
{
$run->dispatch(new MakeQueueSupervisorConfig)
->dispatch(new MakeSocketSupervisorConfig)
->external('supervisorctl', 'reread')
->external('supervisorctl', 'update');
}
} Run it by passing "root" option: artisan app:install --root To see details of running actions use verbosity mode: php artisan app:update -v You can inject any service from service container in constructor: class Update
{
public function __construct(Filesystem $storage)
{
$this->storage = $storage;
}
// ...
} If you want to move config classes from the $this->app->bind('app.installer', \AnotherNamespace\Install::class);
$this->app->bind('app.updater', \AnotherNamespace\Update::class); Runner API (available actions to run)$run
->artisan('command', ['argument' => 'argument_value', '-param' => 'param_value', '--option' => 'option_value', ...]) // Artisan command
->external('command', 'argument', '-param', 'param_value', '--option=option_value', ...) // Any external command by arguments
->external('command argument -param param_value --option=option_value') // Any external command by string
->callable(function ($arg) {}, $arg) // 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 single service provider assets
->publish([
ServiceProvider::class,
AnotherServiceProvider::class,
]) // Publish multiple packages assets
->publish([ServiceProvider::class => 'public']) // Publish package assets with tag
->publish([ServiceProvider::class => ['public', 'assets']]) // Publish package assets with multiple tags
->publishForce(ServiceProvider::class) // Force publish, works in any variations
->publishTag('public') // Publish specific tag
->publishTag(['public', 'assets']) // Publish multiple tags
->publishTagForce('public') // Force publish tags Laravel NovaIf you use Laravel Nova, don't forget to publish Nova assets on each update: // Update class
$run
...
->artisan('nova:publish')
// or
->publishTag('nova-assets') Useful jobsLaravel initializer provides some useful jobs to make initializing of your application much easier. Create cron task for scheduling tasksTo enable Laravel Scheduling add dispatch $run
...
->dispatch(new \MadWeb\Initializer\Jobs\MakeCronTask) This job will add
to crontab list. Create laravel-echo-server.json config fileIf you use Laravel Echo Server for broadcasting events in your application, add dispatch $run
...
->dispatch(new \MadWeb\Initializer\Jobs\MakeEchoServerConfig); It will create configuration file with default options of laravel-echo-server and prefilled values from your laravel application configuration. You can override default value by passing array into the job constructor. It would be a good practice to create additional config value for laravel-echo-server in /*
|--------------------------------------------------------------------------
| Laravel Echo server configurations
|--------------------------------------------------------------------------
|
| Here you may define all of laravel echo server options
|
*/
'server' => [
'authEndpoint' => '/broadcasting/auth',
'port' => env('SOCKET_PORT', '6001'),
'sslCertPath' => env('SSL_CERT', ''),
'sslKeyPath' => env('SSL_PATH', '')
], And pass these values to $run
...
->dispatch(new \MadWeb\Initializer\Jobs\MakeEchoServerConfig(config('broadcasting.server'))); Create supervisor config file for queuesThis job creates supervisor config file for queue workers.
Add dispatch $run
...
->dispatch(new \MadWeb\Initializer\Jobs\Supervisor\MakeQueueSupervisorConfig); This job creates configuration file with the command If you want to override default options, pass it into job constructor. For example if you want to use Laravel Horizon instead of default queue workers. $run
...
->dispatch(new \MadWeb\Initializer\Jobs\Supervisor\MakeQueueSupervisorConfig([
'command' => 'php artisan horizon',
])); Create supervisor config file for laravel echo serverOn the same way as Both config files save log files to Installation by one commandFor running Add "scripts": {
"app-install": [
"@composer install",
"@php artisan app:install"
],
} Then you can run just composer app-install to initialize your application. If your application has actions that require root privileges and you use Unix based system, add the following command into your runner chain: public function production(Runner $run)
{
$run->artisan(...)
...
->external('sudo', 'php', 'artisan', 'app:install', '--root');
}
public function productionRoot(Runner $run) { ... } Safe UpdateIn cases when latest changes has been pulled from source control and some functionality of currently not installed package is used in one of a Service Provider you will get an error. To prevent this issue you should make "scripts": {
"app-update": [
"@composer install",
"@php artisan app:update"
],
}, Then you can run: composer app-update UpgradingPlease see UPGRADING for details. ChangelogPlease see CHANGELOG for more information what has changed recently. Testingcomposer test ContributingPlease see CONTRIBUTING and CONDUCT for details. SecurityIf you discover any security related issues, please email madweb.dev@gmail.com instead of using the issue tracker. CreditsThanks Nuno Maduro for laravel-console-task package which gives pretty tasks outputs LicenseThe MIT License (MIT). Please see License File for more information. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论