48 lines
1.4 KiB
Dart
48 lines
1.4 KiB
Dart
import 'dart:io';
|
|
|
|
void main() {
|
|
final file = File('Jenkinsfile');
|
|
if (!file.existsSync()) {
|
|
print('错误: 在项目根目录中找不到 Jenkinsfile。请确保在此目录下执行此脚本。');
|
|
exit(1);
|
|
}
|
|
|
|
final flavorsDir = Directory('flavors');
|
|
if (!flavorsDir.existsSync()) {
|
|
print('错误: 在项目根目录中找不到 flavors 文件夹。');
|
|
exit(1);
|
|
}
|
|
|
|
final apps = flavorsDir
|
|
.listSync()
|
|
.whereType<File>()
|
|
.where((f) => f.path.endsWith('.yaml'))
|
|
.map((f) => f.path.split(Platform.pathSeparator).last.replaceAll('.yaml', ''))
|
|
.toList();
|
|
|
|
apps.sort();
|
|
// 固定加上 'all' 的选项
|
|
apps.add('all');
|
|
|
|
final choicesString = apps.map((a) => "'$a'").join(', ');
|
|
|
|
var content = file.readAsStringSync();
|
|
|
|
// 匹配形如:
|
|
// name: 'APP_NAME',
|
|
// choices: ['aixue', 'test', 'yunxiao', 'all'],
|
|
final regex = RegExp(r"name:\s*'APP_NAME',\s*\n\s*choices:\s*\[.*\],");
|
|
|
|
if (regex.hasMatch(content)) {
|
|
content = content.replaceFirst(
|
|
regex,
|
|
"name: 'APP_NAME',\n choices: [$choicesString],",
|
|
);
|
|
file.writeAsStringSync(content);
|
|
print("✅ 已自动更新 Jenkinsfile 中的可选 Apps: ${apps.join(', ')}");
|
|
} else {
|
|
print('❌ 更换失败: 未能匹配到 Jenkinsfile 中的 APP_NAME choices 定位。如果更改过文件结构,请更新此脚本里的正则表达式。');
|
|
exit(1);
|
|
}
|
|
}
|