pubspec_version_hook 0.1.0
pubspec_version_hook: ^0.1.0 copied to clipboard
A Dart build hook utility to automatically sync the version in pubspec.yaml to a Dart source file.
pubspec_version_hook #
A Dart build hook utility (powered by Dart Native Assets) to automatically synchronize the version defined in pubspec.yaml to a Dart source file during the build process.
Usage #
-
Add
pubspec_version_hookas a dependency in yourpubspec.yaml:dependencies: hooks: ^2.0.0 pubspec_version_hook: ^0.1.0 -
Create a build hook at
hook/build.dartin your package:import 'package:hooks/hooks.dart'; import 'package:pubspec_version_hook/pubspec_version_hook.dart'; void main(List<String> args) async { await build(args, (input, output) async { await syncPubspecVersion(input, output); }); }
By default, this will read the version string from your pubspec.yaml and output it to lib/src/version.dart as a constant named packageVersion.
You can customize the output path and variable name:
await syncPubspecVersion(
input,
output,
outputRelativePath: 'lib/version.g.dart',
variableName: 'myCustomVersionConst',
);