build_pubspec 0.1.2

  • Readme
  • Changelog
  • Example
  • Installing
  • new50

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
       - McPubby Pubspec <>
       build_runner: ^1.0.0
       # Look up latest version on
       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.

               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.

             enabled: false
             enabled: true
             generate_for: ['lib/src/my_lib.dart']
               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:

     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.

build_pubspec #

0.1.2 - October 17, 2019 #

  • Add option to override destination file.
  • Support custom field names in destination Dart code for all supported fields

0.1.1 - October 15, 2019 #

Add new supported fields: authors, description, documentation, homepage, issueTracker, name, repository.

In case the field is not present in the pubspec, the builder just skips it.

The code is still quite messy and the documentation is lacking.

0.1.0 - October 14, 2019 #

Create new package, build_pubspec based on build_version package.

  • Rename package
  • Improve documentation
  • Add example project

build_version #

This package is based on kevmoo/build_version. Here's the original change log.

build_version: 2.0.1 #

  • Support the latest package:build_config.

Merged from lexaknyazev/build_version

Got changes from lexaknyazev/build_version fork

  • Users can now customize the version constant name and the generated version file could be a part of an existing package library.

build_version: 2.0.0 #

  • The builder now runs when build_version is a dependency. build.yaml changes are no longer required.

build_version: 1.0.1 #

  • Support package:build_runner v1.0.0.

build_version: 1.0.0 #

  • Initial version, created by Stagehand


Examples #

Simple example #

Custom input pubspec file #

Invalid argument (Asset paths may not reach outside the package.): "../../pubspec.yaml"

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  build_pubspec: ^0.1.2

2. Install it

You can install packages from the command line:

with pub:

$ pub get

Alternatively, your editor might support pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:build_pubspec/builder.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Nov 11, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.6.0
  • pana: 0.12.21


Detected platforms: other

Platform components identified in package: build, io, mirrors.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.3.0 <3.0.0
build >=0.12.1 <2.0.0 1.2.1
build_config >=0.3.0 <0.5.0 0.4.1+1
pubspec_parse ^0.1.2+2 0.1.5
source_gen ^0.9.4 0.9.4+6
Transitive dependencies
_fe_analyzer_shared 1.0.0
analyzer 0.39.1
args 1.5.2
async 2.4.0
charcode 1.1.2
collection 1.14.12
convert 2.1.1
crypto 2.1.3
csslib 0.16.1
dart_style 1.3.3
front_end 0.1.29
glob 1.2.0
html 0.14.0+3
js 0.6.1+1
json_annotation 3.0.0
kernel 0.3.29
logging 0.11.3+2
meta 1.1.8
node_interop 1.0.3
node_io 1.0.1+2
package_config 1.1.0
path 1.6.4
pub_semver 1.4.2
source_span 1.5.5
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6
watcher 0.9.7+12
yaml 2.2.0
Dev dependencies
build_runner ^1.0.0
build_test ^0.10.3+1
build_verify ^1.0.0
checked_yaml ^1.0.2 1.0.2
pedantic ^1.4.0 1.8.0+1
test ^1.2.0