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()
執行行程