build_pubspec 0.1.1 copy "build_pubspec: ^0.1.1" to clipboard
build_pubspec: ^0.1.1 copied to clipboard

outdated

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

Pub Build Status

Include the version of your package in our source code.

  1. Add build_pubspec to pubspec.yaml. field.

    name: my_pkg
    version: 1.2.3
    dev_dependencies:
      build_runner: ^1.0.0
      build_pubspec: ...
    
  2. 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';
    
  3. To customize the name of the constants, a build.yaml's option can be used.

    targets:
      $default:
        builders:
          build_pubspec:
            options:
              version_field_name: 'myVersion' # defaults to 'version'
    
  4. 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 contains part '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.

5
likes
0
pub points
7%
popularity

Publisher

verified publisherdartside.dev

Extract pubspec details (such as package version, author and description) into Dart code.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

build, build_config, pubspec_parse, source_gen

More

Packages that depend on build_pubspec