craftcms/rector

此包最新版本(dev-main)没有提供许可证信息。

Rector 用于自动化 Craft CMS 升级

dev-main 2024-05-17 09:09 UTC

This package is auto-updated.

Last update: 2024-09-17 09:50:51 UTC


README

此包提供 Rector 规则,用于更新 Craft CMS 插件和模块,以支持

Craft CMS 3 → 4

首先,请确保已通过 Composer 安装 Craft 3.7.35 或更高版本。(Craft 的早期版本不兼容 Rector。)

composer update craftcms/cms 

然后运行以下命令

composer require php:^8.0.2 --ignore-platform-reqs
composer config minimum-stability dev
composer config prefer-stable true
composer require craftcms/rector:dev-main --dev --ignore-platform-reqs
vendor/bin/rector process src --config vendor/craftcms/rector/sets/craft-cms-40.php

如果您有扩展 Craft Commerce 类的代码,也可以运行以下命令

vendor/bin/rector process src --config vendor/craftcms/rector/sets/craft-commerce-40.php

Rector 完成后,您就可以更新 craftcms/cms

composer require craftcms/cms:^4.0.0-alpha -W --ignore-platform-reqs

Craft CMS 4 → 5

运行以下命令

composer require php:^8.2 --ignore-platform-reqs
composer config minimum-stability dev
composer config prefer-stable true
composer require craftcms/rector:dev-main --dev --ignore-platform-reqs
vendor/bin/rector process src --config vendor/craftcms/rector/sets/craft-cms-50.php

Rector 完成后,您就可以更新 craftcms/cms

composer require craftcms/cms:^5.0.0-beta.1 -W --ignore-platform-reqs

注意

高级配置

如果您想包含额外的 Rector 规则或自定义应处理的文件/目录,您需要为您的项目提供一个 rector.php 文件。

以下是一个示例,它运行 Craft 4 规则集,但跳过了 src/integrations/ 文件夹

<?php
declare(strict_types = 1);

use craft\rector\SetList as CraftSetList;
use Rector\Core\Configuration\Option;
use Rector\Config\RectorConfig;

return static function(RectorConfig $rectorConfig): void {
    // Skip the integrations folder
    $rectorConfig->skip([
        __DIR__ . '/src/integrations',
    ]);

    // Import the Craft 4 upgrade rule set
    $rectorConfig->sets([
        CraftSetList::CRAFT_CMS_40
    ]);
};