70 lines
2.0 KiB
Dart
70 lines
2.0 KiB
Dart
import 'dart:io';
|
|
|
|
void main(List<String> args) {
|
|
if (args.isEmpty) {
|
|
stderr.writeln('Usage: dart run tool/bump_version.dart <patch|minor|major|build>');
|
|
exit(1);
|
|
}
|
|
|
|
final action = args[0].toLowerCase();
|
|
final pubspecFile = File('pubspec.yaml');
|
|
if (!pubspecFile.existsSync()) {
|
|
stderr.writeln('Error: pubspec.yaml not found.');
|
|
exit(1);
|
|
}
|
|
|
|
final pubspecContent = pubspecFile.readAsStringSync();
|
|
final versionRegex = RegExp(r'^version:\s*([0-9]+)\.([0-9]+)\.([0-9]+)\+([0-9]+)', multiLine: true);
|
|
final match = versionRegex.firstMatch(pubspecContent);
|
|
|
|
if (match == null) {
|
|
stderr.writeln('Error: could not find version pattern in pubspec.yaml');
|
|
exit(1);
|
|
}
|
|
|
|
int major = int.parse(match.group(1)!);
|
|
int minor = int.parse(match.group(2)!);
|
|
int patch = int.parse(match.group(3)!);
|
|
int build = int.parse(match.group(4)!);
|
|
|
|
switch (action) {
|
|
case 'major':
|
|
major++;
|
|
minor = 0;
|
|
patch = 0;
|
|
build++;
|
|
break;
|
|
case 'minor':
|
|
minor++;
|
|
patch = 0;
|
|
build++;
|
|
break;
|
|
case 'patch':
|
|
patch++;
|
|
build++;
|
|
break;
|
|
case 'build':
|
|
build++;
|
|
break;
|
|
default:
|
|
stderr.writeln('Unknown action "$action". Use patch, minor, major, or build.');
|
|
exit(1);
|
|
}
|
|
|
|
final newVersion = '$major.$minor.$patch+$build';
|
|
stdout.writeln('Bumping version to: $newVersion');
|
|
|
|
final updatedPubspec = pubspecContent.replaceFirst(versionRegex, 'version: $newVersion');
|
|
pubspecFile.writeAsStringSync(updatedPubspec);
|
|
|
|
final appInfoFile = File('lib/core/app_info.dart');
|
|
if (appInfoFile.existsSync()) {
|
|
final appInfoContent = appInfoFile.readAsStringSync();
|
|
final appInfoRegex = RegExp(r"static const String fallbackVersion = '([^']+)';");
|
|
final updatedAppInfo = appInfoContent.replaceFirst(appInfoRegex, "static const String fallbackVersion = '$newVersion';");
|
|
appInfoFile.writeAsStringSync(updatedAppInfo);
|
|
}
|
|
|
|
stdout.writeln('Successfully updated pubspec.yaml and lib/core/app_info.dart to $newVersion');
|
|
}
|