config_generator 0.1.0

  • Readme
  • Changelog
  • Installing
  • 44

Config Generator #

A simple generator to create implementations of config classes from build.yaml files.

Usage #

Add as a development dependency:

  config_generator: ^0.1.0

For each build environment create a build.<env>.yaml (e.g. file that configures this builder:

          include: ["lib/src/config.dart"]
        enabled: true
          env: dev
            apiKey: xxx

The include option should list a single dart file with a single class hierarchy - meaning that there should be a single toplevel class that is not used in any of the other classes.

All classes in the class hierarchy should be abstract, and have a const noarg constructor. The only valid members are methods, and getters with a type of either String, int or a class defined in the same file.

The settings under options in the build.<env>.yaml should map to the class hierarchy.

part 'config.g.dart';

abstract class Config {
  const Config();
  String get env;
  FirebaseConfig get firebase;

abstract class FirebaseConfig {
  const FirebaseConfig();
  String get apiKey;

Build with pub run build_runner build --config=<env> where <env> is one of the environments you created a build file for.

The build process will generate implementations of all the classes and a const value of the top level class with the name config and instantiated with the options values from the build.yaml file. This value can then be used in your code:

import 'src/config.dart';

someWhere() {
  if(config.env == 'dev') {
    // do something specific for dev environment

License #


Features and bugs #

Please file feature requests and bugs at the issue tracker.

Changelog #

0.1.0 #

  • Initial version.

Use this package as a library

1. Depend on it

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

  config_generator: ^0.1.0

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:config_generator/config_generator.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 Apr 8, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.6

Health issues and suggestions

Document public APIs. (-1 points)

2 out of 2 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.

Fix lib/src/config_generator_base.dart. (-1.99 points)

Analysis of lib/src/config_generator_base.dart reported 4 hints:

line 37 col 25: Use isNotEmpty instead of length

line 45 col 9: Use isEmpty instead of length

line 76 col 10: This function has a return type of 'String', but doesn't end with a return statement.

line 100 col 27: Unnecessary cast.

Format lib/config_generator.dart.

Run dartfmt to format lib/config_generator.dart.

Maintenance issues and suggestions

Support latest dependencies. (-10 points)

The version constraint in pubspec.yaml does not support the latest published versions for 1 dependency (analyzer).

Package is getting outdated. (-20.27 points)

The package was last published 62 weeks ago.

Maintain an example.

None of the files in the package's example/ directory matches known example patterns.

Common filename patterns include main.dart, example.dart, and config_generator.dart. Packages with multiple examples should provide example/

For more information see the pub package layout conventions.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev <3.0.0
analyzer >=0.33.3 <0.35.0 0.34.3 0.39.6
build ^1.0.0 1.1.0 1.2.2
code_builder ^3.1.3 3.2.1
source_gen ^0.9.0 0.9.4+1 0.9.5
Transitive dependencies
args 1.6.0
async 2.4.1
built_collection 4.3.2
built_value 7.0.9
charcode 1.1.3
collection 1.14.12
convert 2.1.1
crypto 2.1.4
csslib 0.16.1
dart_style 1.2.3 1.3.4
fixnum 0.10.11
front_end 0.1.9+1 0.1.29
glob 1.2.0
html 0.14.0+3
js 0.6.1+1
kernel 0.3.9+1 0.3.29
matcher 0.12.6
meta 1.1.8
node_interop 1.0.3
node_io 1.0.1+2
package_config 1.9.3
path 1.6.4
pedantic 1.9.0
plugin 0.2.0+3
pub_semver 1.4.4
quiver 2.1.3
source_span 1.7.0
stack_trace 1.9.3
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6
watcher 0.9.7+14
yaml 2.2.0
Dev dependencies
build_runner ^1.0.0
build_test any
logging ^0.11.0 0.11.4
test ^1.0.0