mirror of
https://gitee.com/ulthon/ulthon_admin.git
synced 2026-07-01 15:32:48 +08:00
feat: 版本命令支持生成说明文件
This commit is contained in:
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace base\common\command\admin;
|
||||
|
||||
use app\common\tools\PathTools;
|
||||
use think\App as ThinkApp;
|
||||
use think\console\Command;
|
||||
use think\console\Input;
|
||||
@@ -19,16 +20,36 @@ class VersionBase extends Command
|
||||
public const LAYUI_VERSION = '2.9.18';
|
||||
|
||||
public const COMMENT = [
|
||||
'优化curd临时生成对应到正式目录,方便IDE可直接定位打开',
|
||||
'tableData组件多选时默认在两侧拼接逗号',
|
||||
'增加数据库的文件字段数据迁移',
|
||||
'发布新版本',
|
||||
'版本更新说明:',
|
||||
'【新功能】',
|
||||
'- 优化首页的最新修改样式',
|
||||
'- 实现token认证机制',
|
||||
'- 实现后台请求兼容接口的模式',
|
||||
'- view支持读取assign的数据',
|
||||
'- 完善demo机制;实现tab的demo和var标签的demo;',
|
||||
'- 增加var标签',
|
||||
'- 增加通用的扩展字符返回内容处理;',
|
||||
'- 当url的hash对应的tab存在时,直接打开;',
|
||||
'【重构】',
|
||||
'- 优化后台兼容接口请求的判断',
|
||||
'【其他】',
|
||||
'- 设置php时区',
|
||||
'- 增加注释',
|
||||
'- tableData增加打开页面参数;',
|
||||
'- databrage增加强制转对象参数;',
|
||||
'- 修改图片默认不搜索',
|
||||
'- 切换新版layui;增加表格多模板机制;增加local操作方法;增加页面记忆操作方法;删除多余代码;',
|
||||
'- 兼容新版layui',
|
||||
'- 引入新版layui',
|
||||
'- 开始多模版',
|
||||
'- 优化手机端表现',
|
||||
];
|
||||
|
||||
protected function configure()
|
||||
{
|
||||
// 指令配置
|
||||
$this->setName('admin:version')
|
||||
->addOption('generate-comment', null, Option::VALUE_NONE, '使用git命令生成说明文件')
|
||||
->addOption('push-tag', null, Option::VALUE_NONE, '使用git命令生成tag并推送')
|
||||
->setDescription('查看当前ulthon_admin的版本号');
|
||||
}
|
||||
@@ -55,20 +76,112 @@ class VersionBase extends Command
|
||||
$output->highlight('开发文档地址:http://doc.ulthon.com/home/read/ulthon_admin/home.html');
|
||||
|
||||
$is_push_tag = $input->hasOption('push-tag');
|
||||
|
||||
if ($is_push_tag) {
|
||||
$output->writeln('>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>');
|
||||
$this->pushTag();
|
||||
}
|
||||
|
||||
$version = static::VERSION;
|
||||
if(!empty(static::PRODUCT_VERSION)) {
|
||||
$version = static::PRODUCT_VERSION;
|
||||
}
|
||||
$comment = implode(';', static::COMMENT);
|
||||
$output->info('生成标签:' . $version);
|
||||
$output->info('标签描述:' . $comment);
|
||||
exec("git tag -a $version -m \"$comment\"");
|
||||
$output->info('推送到远程仓库');
|
||||
exec('git push --tags');
|
||||
$is_generate_comment = $input->hasOption('generate-comment');
|
||||
if ($is_generate_comment) {
|
||||
$this->generateComment();
|
||||
}
|
||||
}
|
||||
|
||||
protected function pushTag()
|
||||
{
|
||||
$input = $this->input;
|
||||
$output = $this->output;
|
||||
|
||||
$output->writeln('>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>');
|
||||
|
||||
$version = static::VERSION;
|
||||
if (!empty(static::PRODUCT_VERSION)) {
|
||||
$version = static::PRODUCT_VERSION;
|
||||
}
|
||||
$comment = implode(';', static::COMMENT);
|
||||
$output->info('生成标签:' . $version);
|
||||
$output->info('标签描述:' . $comment);
|
||||
exec("git tag -a $version -m \"$comment\"");
|
||||
$output->info('推送到远程仓库');
|
||||
exec('git push --tags');
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成版本更新说明
|
||||
* 读取自上次tag到现在所有的提交说明.
|
||||
* @return string
|
||||
*/
|
||||
public function generateComment()
|
||||
{
|
||||
// 获取最新的tag
|
||||
$lastTag = shell_exec('git describe --tags --abbrev=0');
|
||||
$lastTag = trim($lastTag);
|
||||
|
||||
// 获取从最新tag到现在的所有提交
|
||||
$commits = shell_exec("git log {$lastTag}..HEAD --pretty=format:\"%s\"");
|
||||
|
||||
if (empty($commits)) {
|
||||
return '暂无更新说明';
|
||||
}
|
||||
|
||||
$commits = explode("\n", $commits);
|
||||
|
||||
// 定义提交类型
|
||||
$types = [
|
||||
'feat' => '新功能',
|
||||
'fix' => '修复',
|
||||
'docs' => '文档',
|
||||
'style' => '样式',
|
||||
'refactor' => '重构',
|
||||
'perf' => '性能优化',
|
||||
'test' => '测试',
|
||||
'build' => '构建',
|
||||
'ci' => '持续集成',
|
||||
'chore' => '其他',
|
||||
'revert' => '回退',
|
||||
];
|
||||
|
||||
// 按类型分组提交
|
||||
$groupedCommits = [];
|
||||
foreach ($commits as $commit) {
|
||||
$matched = false;
|
||||
foreach ($types as $type => $desc) {
|
||||
if (preg_match("/^{$type}:/i", $commit)) {
|
||||
$message = preg_replace("/^{$type}:/i", '', $commit);
|
||||
$groupedCommits[$desc][] = trim($message);
|
||||
$matched = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// 如果没有匹配到任何类型,归类为"其他"
|
||||
if (!$matched) {
|
||||
$groupedCommits['其他'][] = trim($commit);
|
||||
}
|
||||
}
|
||||
|
||||
// 生成更新说明
|
||||
$comment = "版本更新说明:\n";
|
||||
|
||||
foreach ($groupedCommits as $type => $messages) {
|
||||
$comment .= "\n【{$type}】\n";
|
||||
foreach ($messages as $message) {
|
||||
$comment .= "- {$message}\n";
|
||||
}
|
||||
}
|
||||
$this->output->writeln($comment);
|
||||
|
||||
// 生成数组格式文件
|
||||
$comment_arr = explode("\n", $comment);
|
||||
$comment_arr = array_filter($comment_arr, function ($item) {
|
||||
return !empty($item);
|
||||
});
|
||||
$comment_arr = array_map(function ($item) {
|
||||
return "'" . addslashes(trim($item)) . "',";
|
||||
}, $comment_arr);
|
||||
|
||||
$comment_arr_code = implode("\n", $comment_arr);
|
||||
$tmp_comment_file = PathTools::tempBuildPath('commit_comment.php');
|
||||
file_put_contents($tmp_comment_file, "<?php\nreturn [\n" . $comment_arr_code . "\n];");
|
||||
$this->output->info('已生成版本更新说明:' . $tmp_comment_file);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user