-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate_meta.dart
34 lines (27 loc) · 907 Bytes
/
update_meta.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
import 'dart:io';
void main() {
var metaDartFile = File("bin/meta.dart");
try {
// Read the pubspec.yaml file
final pubspecFile = File('pubspec.yaml');
final pubspecContent = pubspecFile.readAsStringSync();
// Use a regular expression to extract the version
final versionMatch = RegExp(r'version: (.+)').firstMatch(pubspecContent);
// Check if a match was found
if (versionMatch != null) {
final version = versionMatch.group(1)!;
String metaDartFileContents = """
/// DO NOT EDIT THIS FILE EXCEPT TO ENTER INITIAL VERSION AND OTHER META INFO
/// THIS FILE IS AUTOMATICALLY OVER WRITTEN BY MetaUpdate
Map<String, String> meta = <String, String>{
"version":"$version",
};
""";
metaDartFile.writeAsStringSync(metaDartFileContents);
} else {
print('Version not found in pubspec.yaml');
}
} catch (e) {
print('Error: $e');
}
}