sabatino / artisan-dev
Laravel 运行多个开发脚本的辅助工具
Requires
- php: ^8.2
- laravel/framework: ^11.9
README
通过单个命令并行运行多个脚本,并集成日志记录。
安装
composer require sabatino/artisan-dev
此包发布一个 dev-scripts
配置文件
php artisan vendor:publish --tag=dev-services
配置
在 dev-scripts.php
配置文件中定义您的脚本,例如
<?php return [ 'scripts' => [ 'horizon' => [ 'command' => ['php', 'artisan', 'horizon'], 'style' => ['cyan', null, ['bold']], 'logging' => true, 'log_options' => [ 'apply_style_to_full_line' => true ], 'restart' => [ 'logging' => true, 'watch' => [ '.env', 'app/Jobs/*' ] ] ], 'reverb' => [ 'command' => ['php', 'artisan', 'reverb:start', '--verbose', '--debug'], 'style' => ['magenta', null, ['bold']], 'logging' => true, ], ] ];
用法
使用 php artisan dev
命令运行脚本
php artisan dev
文件监视器
restart.watch
选项允许您定义要监视的目录/文件列表。对这些文件的更改将触发脚本的重新启动。此功能由 JavaScript 文件监视器 Chokidar 提供,您可以通过以下方式安装它
NPM
npm install chokidar
Yarn
yarn add chokidar
日志记录
您可以通过将 logging
选项设置为 true
来为每个脚本启用日志记录。日志将在控制台显示,并以前缀脚本名称开头。为了使日志更易于阅读,您可以定义每个脚本的样式。
[
'style' => ['magenta', null, ['bold']],
]
日志选项
'log_options' => [
// Apply the style to the full line, not just the script name
'apply_style_to_full_line' => true
],
这些参数传递给 Symfony\Component\Console\Formatter\OutputFormatterStyle
的构造函数,您可以在以下文档中参考:[https://symfony.com.cn/doc/current/console/coloring.html](https://symfony.com.cn/doc/current/console/coloring.html)
工作目录
您可以通过设置 working_directory
选项来更改每个脚本的工作目录。当将 working_directory
选项与 restart.watch
选项结合使用时,restart.watch
选项中的路径应相对于 working_directory
。
'working_directory' => 'path/to/working/directory',
ENV
默认情况下,所有脚本都将使用与父进程相同的环境变量运行。当使用 working_directory
选项时,您可以在该目录中定义一个自定义的 .env
文件,以便用于该进程,而不是使用默认的环境变量。
鸣谢
file-watcher: [https://github.com/spatie/file-system-watcher/blob/main/bin/file-watcher.js](https://github.com/spatie/file-system-watcher/blob/main/bin/file-watcher.js)