mirror of
https://gitee.com/ulthon/ulthon_admin.git
synced 2026-07-09 19:42:47 +08:00
feat(update): 新增 --dry-run 预览模式
This commit is contained in:
@@ -25,6 +25,8 @@ class AdminUpdateServiceBase
|
||||
|
||||
public $type = 'ulthon_admin';
|
||||
|
||||
public $dryRun = false;
|
||||
|
||||
/**
|
||||
* @var Input
|
||||
*/
|
||||
@@ -261,6 +263,9 @@ class AdminUpdateServiceBase
|
||||
}
|
||||
|
||||
if (!empty($optional_update_waring_files)) {
|
||||
if ($this->dryRun) {
|
||||
$need_process_files = array_merge($need_process_files, $optional_update_waring_files);
|
||||
} else {
|
||||
foreach ($optional_update_waring_files as $file_path => $type) {
|
||||
$output->writeln($file_path . ' ' . $type);
|
||||
}
|
||||
@@ -274,8 +279,12 @@ class AdminUpdateServiceBase
|
||||
$need_process_files = array_merge($need_process_files, $optional_update_waring_files);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($force_update_waring_files)) {
|
||||
if ($this->dryRun) {
|
||||
$need_process_files = array_merge($need_process_files, $force_update_waring_files);
|
||||
} else {
|
||||
foreach ($force_update_waring_files as $file_path => $type) {
|
||||
$output->writeln($file_path . ' ' . $type);
|
||||
}
|
||||
@@ -290,6 +299,7 @@ class AdminUpdateServiceBase
|
||||
$need_process_files = array_merge($need_process_files, $force_update_waring_files);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($need_process_files)) {
|
||||
$output->writeln('没有需要更新的文件');
|
||||
@@ -300,6 +310,7 @@ class AdminUpdateServiceBase
|
||||
|
||||
// 处理需要更新的文件
|
||||
|
||||
if (!$this->dryRun) {
|
||||
foreach ($need_process_files as $file_path => $type) {
|
||||
$now_file_path = $now_dir . '/' . $file_path;
|
||||
$last_file_path = $last_version_dir . '/' . $file_path;
|
||||
@@ -316,6 +327,19 @@ class AdminUpdateServiceBase
|
||||
copy($last_file_path, $now_file_path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->dryRun && !empty($need_process_files)) {
|
||||
$add_count = count(array_filter($need_process_files, fn($t) => $t === 'add'));
|
||||
$delete_count = count(array_filter($need_process_files, fn($t) => $t === 'delete'));
|
||||
$update_count = count(array_filter($need_process_files, fn($t) => $t === 'update'));
|
||||
$output->writeln('');
|
||||
$output->writeln('[预览模式] 以下文件将被变更:');
|
||||
foreach ($need_process_files as $file_path => $type) {
|
||||
$output->writeln(" [{$type}] " . $file_path);
|
||||
}
|
||||
$output->writeln("统计: 新增 {$add_count}, 删除 {$delete_count}, 更新 {$update_count}");
|
||||
}
|
||||
|
||||
// 检测now的composer依赖和最新的composer依赖
|
||||
$last_composer_json = file_get_contents($last_version_dir . '/composer.json');
|
||||
|
||||
@@ -24,6 +24,7 @@ class UpdateBase extends Command
|
||||
->addOption('reinstall', null, Option::VALUE_NONE, '重装版本')
|
||||
->addOption('update-ulthon', null, Option::VALUE_NONE, '更新 ulthon_admin')
|
||||
->addOption('update-master', null, Option::VALUE_NONE, '更新 ulthon_admin 的 master 分支')
|
||||
->addOption('dry-run', null, Option::VALUE_NONE, '预览模式,只输出变更不执行')
|
||||
->setDescription('更新系统代码');
|
||||
}
|
||||
|
||||
@@ -41,6 +42,7 @@ class UpdateBase extends Command
|
||||
$update_service = new AdminUpdateService($repo);
|
||||
$update_service->input = $input;
|
||||
$update_service->output = $output;
|
||||
$update_service->dryRun = (bool)$input->getOption('dry-run');
|
||||
|
||||
$update_service->update();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user