build_pubspec

This package helps you convert fields from your pubspec.yaml file into Dart code. Based on the fields in your pubspec, this package will generate Dart code so that you can access these fields easily from your Flutter, AngularDart, or backend app.

Pub Build Status

Common use-cases

  • Display current version of your app to your users
  • Add build information to your logs, analytics or backend calls
  • Create example apps for your Flutter packages and plugins with an up-to-date description and links to your docs, issue tracker and repository

Do you have another use case for this package? Tell me about it on Twitter or open a issue on GitHub. I appreciate your help in making this package better.

Usage

  1. Add build_pubspec to your pubspec.yaml as dev_dependency. Make sure build_runner is also listed as development dependency.

     name: your_package
     version: 1.2.3
     authors:
       - McPubby Pubspec <mcpubby.pubspec@example.com>
     dev_dependencies:
       build_runner: ^1.0.0
       # Look up latest version on https://pub.dev/packages/build_pubspec#-changelog-tab-
       build_pubspec: ^1.0.0
    
  2. Run a build.

     $ pub run build_runner build
    

    lib/src/pubspec.dart will be generated with content

     $ cat lib/src/pubspec.dart
     # TODO: once package's stable, include file content
    

Customization

Change output file

Change field names

Part files

Examples

I maintain various examples for this package. Check them all out at TODO: link.

example apps (or integration test cases):

  • simple
  • renamed
  • .g.dart
  • flutter
  1. 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'
    
  2. 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. I could not have created this package without their original work.

Libraries

builder
Configuration for using package:build-compatible build systems. [...]