-
Notifications
You must be signed in to change notification settings - Fork 53
/
Copy pathversion_sync.dart
133 lines (111 loc) · 4.47 KB
/
version_sync.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
import 'dart:io';
import 'package:yaml/yaml.dart';
void main() {
final pubspecFile = File('pubspec.yaml');
if (!pubspecFile.existsSync()) {
print('pubspec.yaml not found');
exit(1);
}
final pubspecContent = pubspecFile.readAsStringSync();
final pubspec = loadYaml(pubspecContent);
final version = pubspec['version'] as String;
final versionParts = version.split('+');
if (versionParts.length != 2) {
print('Invalid version format in pubspec.yaml');
exit(1);
}
final versionName = versionParts[0];
final versionCode = versionParts[1];
print("$versionParts");
updateAndroidVersion(versionName, versionCode);
// updateIOSVersion(versionName, versionCode);
// updateMacOSVersion(versionName, versionCode);
// updateLinuxVersion(versionName, versionCode);
// updateWindowsVersion(versionName, versionCode);
print('Version updated successfully');
}
void updateAndroidVersion(String versionName, String versionCode) {
final buildGradleFile = File('android/app/build.gradle');
if (!buildGradleFile.existsSync()) {
print('android/app/build.gradle not found');
return;
}
final buildGradleContent = buildGradleFile.readAsStringSync();
final updatedContent = buildGradleContent
.replaceAll(RegExp(r'versionCode = .*$', multiLine: true),
'versionCode = $versionCode')
.replaceAll(RegExp(r'versionName = .*$', multiLine: true),
'versionName = "$versionName"');
buildGradleFile.writeAsStringSync(updatedContent);
print('Android version updated');
}
void updateIOSVersion(String versionName, String versionCode) {
final plistFile = File('ios/Runner/Info.plist');
if (!plistFile.existsSync()) {
print('ios/Runner/Info.plist not found');
return;
}
final plistContent = plistFile.readAsStringSync();
final updatedContent = plistContent
.replaceAll(
RegExp(
r'<key>CFBundleShortVersionString</key>\s*<string>[^<]+</string>'),
'<key>CFBundleShortVersionString</key>\n\t<string>$versionName</string>')
.replaceAll(
RegExp(r'<key>CFBundleVersion</key>\s*<string>[^<]+</string>'),
'<key>CFBundleVersion</key>\n\t<string>$versionCode</string>');
plistFile.writeAsStringSync(updatedContent);
print('iOS version updated');
}
void updateMacOSVersion(String versionName, String versionCode) {
final plistFile = File('macos/Runner/Info.plist');
if (!plistFile.existsSync()) {
print('macos/Runner/Info.plist not found');
return;
}
final plistContent = plistFile.readAsStringSync();
final updatedContent = plistContent
.replaceAll(
RegExp(
r'<key>CFBundleShortVersionString</key>\s*<string>[^<]+</string>'),
'<key>CFBundleShortVersionString</key>\n\t<string>$versionName</string>')
.replaceAll(
RegExp(r'<key>CFBundleVersion</key>\s*<string>[^<]+</string>'),
'<key>CFBundleVersion</key>\n\t<string>$versionCode</string>');
plistFile.writeAsStringSync(updatedContent);
print('macOS version updated');
}
void updateLinuxVersion(String versionName, String versionCode) {
final cmakeFile = File('linux/CMakeLists.txt');
if (!cmakeFile.existsSync()) {
print('linux/CMakeLists.txt not found');
return;
}
final cmakeContent = cmakeFile.readAsStringSync();
final updatedContent = cmakeContent
.replaceAll(RegExp(r'set\(PROJECT_VERSION "[^"]+"\)'),
'set(PROJECT_VERSION "$versionName")')
.replaceAll(RegExp(r'set\(PROJECT_VERSION_CODE \d+\)'),
'set(PROJECT_VERSION_CODE $versionCode)');
cmakeFile.writeAsStringSync(updatedContent);
print('Linux version updated');
}
void updateWindowsVersion(String versionName, String versionCode) {
final rcFile = File('windows/runner/Runner.rc');
if (!rcFile.existsSync()) {
print('windows/runner/Runner.rc not found');
return;
}
final rcContent = rcFile.readAsStringSync();
final updatedContent = rcContent
.replaceAll(RegExp(r'FILEVERSION \d+,\d+,\d+,\d+'),
'FILEVERSION ${versionName.replaceAll('.', ',')},$versionCode')
.replaceAll(RegExp(r'PRODUCTVERSION \d+,\d+,\d+,\d+'),
'PRODUCTVERSION ${versionName.replaceAll('.', ',')},$versionCode')
.replaceAll(RegExp(r'VALUE "FileVersion", "[^"]+"'),
'VALUE "FileVersion", "$versionName.$versionCode"')
.replaceAll(RegExp(r'VALUE "ProductVersion", "[^"]+"'),
'VALUE "ProductVersion", "$versionName.$versionCode"');
rcFile.writeAsStringSync(updatedContent);
print('Windows version updated');
}