forked from namidaco/namida
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bump_version.dart
47 lines (44 loc) · 1.74 KB
/
bump_version.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
// ignore_for_file: avoid_print
import 'dart:io';
void main(List<String> args) {
final pubspec = File('pubspec.yaml');
final pubspecLines = pubspec.readAsLinesSync();
const versionLinePrefix = 'version: ';
bool didUpdate = false;
for (int i = 0; i < pubspecLines.length; i++) {
final line = pubspecLines[i];
if (line.startsWith(versionLinePrefix)) {
final currentName = line.split(versionLinePrefix).last.split('+').first;
final currentVersion = currentName.split('-').first; // stripping `-beta`
if (args.isEmpty) {
print('please provide version name, current is: $currentVersion');
break;
}
final versionName = args[0];
if (currentVersion == versionName) {
print('you entered the same version name: $currentVersion, enter `y` to force bump');
final input = stdin.readLineSync();
if (input?.toLowerCase() != 'y') break;
}
final isRelease = args.contains('-r');
final suffix = isRelease ? '' : '-beta';
final newVersionName = "$versionName$suffix";
final date = DateTime.now().toUtc();
final year = date.year.toString();
String padLeft(int number) => number.toString().padLeft(2, '0');
final minutesPercentage = (date.minute / 60).toString().substring(2, 3);
final newBuildNumber = "${year.substring(2)}${padLeft(date.month)}${padLeft(date.day)}${padLeft(date.hour)}$minutesPercentage";
final newLine = '$versionLinePrefix$newVersionName+$newBuildNumber';
print("old $line");
pubspecLines[i] = newLine;
print("new $newLine");
didUpdate = true;
pubspec.writeAsStringSync("""${pubspecLines.join('\n')}
""");
break;
}
}
if (!didUpdate) {
print('couldnt bump version');
}
}