forked from hyiso/commitlint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate_version.dart
24 lines (23 loc) · 918 Bytes
/
generate_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
import 'dart:io' show File;
import 'package:path/path.dart' show join;
import 'package:yaml/yaml.dart' show YamlMap, loadYaml;
Future<void> main() async {
final outputPath =
join('packages', 'commitlint_cli', 'lib', 'src', 'version.g.dart');
final outputFile = File(outputPath);
if (!outputFile.existsSync()) {
outputFile.createSync(recursive: true);
}
// ignore: avoid_print
print('Updating generated file $outputPath');
final pubspec = File(join('packages', 'commitlint_cli', 'pubspec.yaml'));
final yamlMap = loadYaml(pubspec.readAsStringSync()) as YamlMap;
final currentVersion = yamlMap['version'] as String;
final fileContents = '''
/// This file is generated. Do not manually edit.
const kCurrentVersion = '$currentVersion';
''';
outputFile.writeAsStringSync(fileContents);
// ignore: avoid_print
print('Updated version to $currentVersion in generated file $outputPath');
}