1 Star 1 Fork 1

慧婷小猪爱浩哥/namida

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
chlog.dart 2.56 KB
一键复制 编辑 原始数据 按行查看 历史
MSOB7YY 提交于 2023-12-03 21:59 . update CHANGELOG.md
// ignore_for_file: avoid_print
import 'dart:io';
import 'package:intl/intl.dart';
void main(List<String> argumentsPre) async {
final changelog = File('CHANGELOG.md');
DateTime? startDatetime;
DateTime? stopDatetime;
if (argumentsPre.isNotEmpty) {
startDatetime = DateTime.tryParse(argumentsPre.first);
if (argumentsPre.length == 2) stopDatetime = DateTime.tryParse(argumentsPre.last);
}
final fileLines = changelog.readAsLinesSync();
if (startDatetime == null) {
// fetching the latest date found inside [ChANGELOG.md]
// format has to be [dd/MM/yyyy] if not found then it
// should be at least parsable.
for (final l in fileLines) {
final line = l.split('#').last;
final splitted = line.split('/');
if (splitted.length == 3) {
final y = int.tryParse(splitted[2]);
final m = int.tryParse(splitted[1]);
final d = int.tryParse(splitted[0]);
if (y != null && m != null && d != null) {
final datetime = DateTime(y, m, d);
startDatetime = datetime;
break;
}
}
}
}
if (startDatetime == null) {
for (final l in fileLines) {
final line = l.split('#').last;
final datetime = DateTime.tryParse(line);
if (datetime != null) {
startDatetime = datetime;
break;
}
}
}
if (startDatetime == null) {
print('Warning: first date isn\'t provided, fetching all changes...');
}
final gitOutput = await Process.run('git', <String>[
'log',
'--oneline',
'--decorate',
'--no-abbrev-commit',
// '--pretty=%s',
// '--first-parent',
if (startDatetime != null) '--after="$startDatetime"',
if (stopDatetime != null) '--before="$stopDatetime"',
]);
final outputLines = (gitOutput.stdout as String).split('\n');
final map = <String, List<String>>{};
for (final line in outputLines) {
final parts = line.split(':');
final firstPart = parts.first.toLowerCase().trim().split(' ');
final hash = firstPart.first;
final key = firstPart.last;
final val = "$hash: ${parts.last.trim()}";
if (map[key] == null) {
map[key] = [val];
} else {
map[key]!.add(val);
}
}
final stringy = map.entries.map((e) => '- ${e.key}:\n${e.value.reversed.map((e) => ' - $e').join('\n')}');
final dateText = DateFormat('dd/MM/yyyy').format(stopDatetime ?? DateTime.now());
const title = '# Namida Changelog';
final finalString = "$title\n\n## $dateText\n${stringy.join('\n')}\n${changelog.readAsStringSync().replaceFirst(title, '')}";
changelog.writeAsStringSync(finalString);
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Dart
1
https://gitee.com/haogg/namida.git
git@gitee.com:haogg/namida.git
haogg
namida
namida
home-widgets

搜索帮助

0d507c66 1850385 C8b1a773 1850385