diff --git a/build.yaml b/build.yaml index b419b69..f45015a 100644 --- a/build.yaml +++ b/build.yaml @@ -16,3 +16,11 @@ builders: - lib/ui/licenses.moxxy.dart build_to: source auto_apply: root_package + versionBuilder: + import: "package:moxxyv2_builders/version.dart" + builder_factories: [ "versionBuilder" ] + build_extensions: + pubspec.yaml: + - lib/shared/version.moxxy.dart + build_to: source + auto_apply: root_package diff --git a/lib/licenses.dart b/lib/licenses.dart index 5ebe5ec..4306402 100644 --- a/lib/licenses.dart +++ b/lib/licenses.dart @@ -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"; diff --git a/lib/version.dart b/lib/version.dart new file mode 100644 index 0000000..58af420 --- /dev/null +++ b/lib/version.dart @@ -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(); diff --git a/pubspec.yaml b/pubspec.yaml index ea44a8a..aa67606 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: moxxyv2_builders description: A colection of builders for Moxxyv2 -version: 0.1.0 +version: 0.2.0 homepage: https://codeberg.org/moxxy/moxxyv2_builders publish_to: https://git.polynom.me/api/packages/Moxxy/pub