Add version builder

This commit is contained in:
2023-01-20 14:24:13 +01:00
parent 7000b13c14
commit 2ff82e1730
4 changed files with 38 additions and 2 deletions

View File

@@ -1,5 +1,4 @@
import "dart:io";
import "package:build/build.dart";
import "package:dart_pubspec_licenses/dart_pubspec_licenses.dart";
import "package:yaml/yaml.dart";

29
lib/version.dart Normal file
View File

@@ -0,0 +1,29 @@
import "dart:io";
import "package:build/build.dart";
import "package:yaml/yaml.dart";
class VersionBuilder implements Builder {
@override
Future build(BuildStep step) async {
final pubspecFile = loadYaml(
await File('pubspec.yaml').readAsString(),
);
String fileContent = '''
//// AUTO-GENERATED by build_runner ////
/// DO NOT EDIT BY HAND
part of "version.dart";
const pubspecVersionString = '${pubspecFile["version"]}';
''';
await step.writeAsString(step.allowedOutputs.first, fileContent);
}
@override
final buildExtensions = const {
"pubspec.yaml": [ "lib/shared/version.moxxy.dart" ]
};
}
Builder versionBuilder(BuilderOptions _) => VersionBuilder();