config_generator 0.1.0

  • README.md
  • CHANGELOG.md
  • Installing
  • Versions
  • 49

Config Generator #

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

Usage #

Add as a development dependency:

dev_dependencies:
  config_generator: ^0.1.0

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

targets:
  $default:
    builders:
      config_generator|config_builder:
        generate_for:
          include: ["lib/src/config.dart"]
        enabled: true
        options:
          env: dev
          firebase:
            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 #

BSD-3-Clause.

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:


dependencies:
  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';
  
Version Uploaded Documentation Archive
0.1.0 Jan 24, 2019 Go to the documentation of config_generator 0.1.0 Download config_generator 0.1.0 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
0
Health:
Code health derived from static analysis. [more]
97
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
49
Learn more about scoring.

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

  • Dart: 2.2.0
  • pana: 0.12.14

Platforms

Detected platforms: other

Primary library: package:config_generator/config_generator.dart with components: io, build, mirrors.

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 3: 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 suggestions

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/README.md.

For more information see the pub package layout conventions.

Dependencies

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.36.0
build ^1.0.0 1.1.0 1.1.3
code_builder ^3.1.3 3.2.0
source_gen ^0.9.0 0.9.4+1 0.9.4+2
Transitive dependencies
args 1.5.1
async 2.2.0
built_collection 4.2.0
built_value 6.4.0
charcode 1.1.2
collection 1.14.11
convert 2.1.1
crypto 2.0.6
csslib 0.15.0
dart_style 1.2.3 1.2.7
fixnum 0.10.9
front_end 0.1.9+1 0.1.15
glob 1.1.7
html 0.14.0+1
kernel 0.3.9+1 0.3.15
matcher 0.12.5
meta 1.1.7
package_config 1.0.5
path 1.6.2
plugin 0.2.0+3
pub_semver 1.4.2
quiver 2.0.3
source_span 1.5.5
stack_trace 1.9.3
string_scanner 1.0.4
term_glyph 1.1.0
typed_data 1.1.6
watcher 0.9.7+10
yaml 2.1.15
Dev dependencies
build_runner ^1.0.0
build_test any
logging ^0.11.0 0.11.3+2
test ^1.0.0