castor
v0.21.0
castor是一个用 PHP 构建的面向 DX 的任务运行器,具有一系列用于常见任务处理的函数。
它可以被视为 Makefile、Fabric、Invoke、Shell 脚本等的替代品,但它利用了 PHP 的脚本功能和广泛的库生态系统。
它具有许多功能,可以让您的生活更轻松:
run()
:运行外部进程,实现与外部工具的无缝集成io()
:显示漂亮的输出并与终端交互watch()
:监视文件并自动触发文件修改操作fs()
:创建、删除和操作文件和目录笔记
castor仍处于早期开发阶段,API 还不稳定。即使不太可能,但未来仍然有可能发生变化。
在castor中,任务被设置为典型的PHP 函数,并在castor .php
文件中用#[AsTask()]
属性进行标记。
这些任务可以运行任何 PHP 代码,但也可以使用与castor一起预打包的各种函数来执行标准操作。
例如:
<?php
namespace greetings ;
use castor Attribute AsTask ;
use function castor io ;
#[AsTask()]
function hello (): void
{
io ()-> writeln ( ' Hello from castor ' );
}
将公开一个greetings:hello
任务,您可以使用castor greetings:hello
运行该任务:
$ castor greetings:hello
Hello from castor
然后,您可以疯狂地创建更复杂的任务:
#[AsTask(description: ' Clean the infrastructure (remove container, volume, networks) ' )]
function destroy ( bool $ force = false )
{
if (! $ force ) {
io ()-> warning ( ' This will permanently remove all containers, volumes, networks... created for this project. ' );
io ()-> comment ( ' You can use the --force option to avoid this confirmation. ' );
if (! io ()-> confirm ( ' Are you sure? ' , false )) {
io ()-> comment ( ' Aborted. ' );
return ;
}
}
run ( ' docker-compose down -v --remove-orphans --volumes --rmi=local ' );
notify ( ' The infrastructure has been destroyed. ' )
}
如果您想了解更多有关使用的信息,可以阅读基本使用文档,或者观看一些示例。
提示
这是在 Linux 和 macOS 上安装castor的推荐方法。它需要 PHP >= 8.1。
curl " https://castor.jolicode.com/install " | bash
还有其他安装castor方法,请参阅文档。
通过阅读文档了解更多信息:
run()
执行进程