build_pubspec 0.1.1
build_pubspec: ^0.1.1 copied to clipboard
Extract pubspec details (such as package version, author and description) into Dart code.
WIP. Fork of build_version, soon to include all fields from the pubspec.
explain when to use this: maybe if you publish multiple plugins and you want to include the example app's info?
example apps (or integration test cases):
- simple
- renamed
- .g.dart
- flutter
Include the version of your package in our source code.
-
Add
build_pubspec
topubspec.yaml
. field.name: my_pkg version: 1.2.3 dev_dependencies: build_runner: ^1.0.0 build_pubspec: ...
-
Run a build.
> pub run build_runner build
lib/src/pubspec.dart
will be generated with content:// Generated code. Do not modify. const version = '1.2.3';
-
To customize the name of the constants, a
build.yaml
'soption
can be used.targets: $default: builders: build_pubspec: options: version_field_name: 'myVersion' # defaults to 'version'
-
It is also possible to generate the version string as a part of an existing library in your package. In such a case, the default version builder needs to be disabled and the version part builder should be used.
targets: $default: builders: build_pubspec: enabled: false build_pubspec|build_pubspec_part: enabled: true generate_for: ['lib/src/my_lib.dart'] options: version_field_name: 'myLibraryVersion' # defaults to 'packageVersion'
Assuming that
lib/src/my_lib.dart
containspart 'my_lib.version.g.dart';
,lib/src/my_lib.version.g.dart
will be generated with content:// GENERATED CODE - DO NOT MODIFY BY HAND part of 'my_lib.dart'; // ************************************************************************** // _VersionPartGenerator // ************************************************************************** // Generated code. Do not modify. const packageVersion = '1.2.3';
Acknowledgements #
This package is based on build_version
. Thank you for the original author, Kevin Moore. It also includes fixes to the original repository from Alexey Knyazev.
If you find code or instructions that were not updated, open an issue, or ping me on Twitter. I appreciate your help in making this package better.