fnx_config 1.2.0

  • README.md
  • CHANGELOG.md
  • Installing
  • Versions
  • 61

fnx_config - configuration management

This is a transformer which helps you manage different configurations for different builds of your web app.

Usually you need different configuration for different environments:

String apiRoot = "http://localhost:8080/api/v1
// Use in production!!!!!
// String apiRoot = "http://this-is-very-important.qwerty/api/v1/"

... and that's just terrible. Let's try something else.

Usage

Add transformer to your pubspec.yaml:

dependencies:
  fnx_config: ^1.0.0

transformers:
- fnx_config

Then create configuration profiles (YAML files). Usually you will need two of them.

  • lib/conf/config_debug.yaml - for pub serve
  • lib/conf/config_release.yaml - for pub build

Content of those files is completely up to you, it's probably going to be something like this:

ourSecretApiKey: qwertyuiop
ourSecretApiUrl: http://this-is-very-secret.qwerty/api/v1/

Then add <script type="pub/fnx_config"></script> into the <head> of your HTML files and run pub serve.

Result

Transformer searches for HTML files with this instruction, and replaces it with encoded content of your YAML file:

var fnx_config = "eyJjb25maWciOnsiYWhvai  ... tMjlUMTg6NDE6MjAuMTkwIn19";

The reason why we encode the configuration, is that we don't want to tempt the user with too much knowledge. We don't need any bored teenager to play with our API endpoints and API keys.

Please don't mistake this feature for any kind of security, it's just simple BASE64 and the configuration will be accessible to any skilled user. But a little bit of obfuscation cannot do any harm.

See example.

Reading

Import

import 'package:fnx_config/fnx_config_read.dart';

and access your configuration via global function:

String apiKey = fnxConfig()["ourSecretApiKey"];

fnx_config also adds few metadata you might find useful:

fnxConfigMeta()["mode"]; // pub build mode (--mode=qwerty)
fnxConfigMeta()["timestamp"]; // timestamp of build    
    

Multiple configuration profiles

Simply add more configuration files:

lib/conf/config_qwerty.yaml
lib/conf/config_jenkins.yaml

and use them with pub:

pub build --mode=qwerty
pub serve --mode=jenkins

Examples

Polymer

With Polymer, place fnx_config transformer after web_components

- web_components:
		entry_points: web/index.html
- reflectable:
		entry_points: web/index.dart
- fnx_config

Angular2

Also with Angular2, keep the transformer at the end of the list.

Firebase example

Typical usage with firebase looks like this:

config_debug.yaml

firebase:
  apiKey: "AIzaSyDq6qYBJHOMmdsdsEsKFiotLxKmjqA"
  authDomain: "my-app-1af5.firebaseapp.com"
  databaseURL: "https://my-app-1af5.firebaseio.com"
  storageBucket: "my-app-1af5.appspot.com"
  

main.dart

import 'package:firebase3/firebase.dart' as f;
import 'package:fnx_config/fnx_config_read.dart';
  
...
  
Map cfg = fnxConfig();    
f.App app = f.initializeApp(
  apiKey: cfg["firebase"]["apiKey"],
  authDomain: cfg["firebase"]["authDomain"],
  databaseURL: cfg["firebase"]["databaseURL"],
  storageBucket: cfg["firebase"]["storageBucket"]
);      


1.1.0

  • Allowed versions of crypto >=0.9.1 <3.0.0.
  • Firebase example in README.
  • Replaced packaged html5lib with html

1.0.1

Small bugfix.

1.0.0

Initial public version.

1. Depend on it

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


dependencies:
  fnx_config: "^1.2.0"

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter packages get

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

3. Import it

Now in your Dart code, you can use:


import 'package:fnx_config/fnx_config.dart';
        
Version Uploaded Documentation Archive
1.2.0 Oct 28, 2016 Go to the documentation of fnx_config 1.2.0 Download fnx_config 1.2.0 archive
1.1.0 Oct 12, 2016 Go to the documentation of fnx_config 1.1.0 Download fnx_config 1.1.0 archive
1.0.1 Mar 2, 2016 Go to the documentation of fnx_config 1.0.1 Download fnx_config 1.0.1 archive
1.0.0 Oct 30, 2015 Go to the documentation of fnx_config 1.0.0 Download fnx_config 1.0.0 archive

Analysis

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

  • Dart: 2.0.0-dev.46.0
  • pana: 0.10.6

Scores

Popularity:
Describes how popular the package is relative to other packages. [more]
46 / 100
Health:
Code health derived from static analysis. [more]
92 / 100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
56 / 100
Overall score:
Weighted score of the above. [more]
61
Learn more about scoring.

Platforms

Detected platforms: Flutter, other

Primary library: package:fnx_config/fnx_config.dart with components: io, isolate, build.

Suggestions

  • Fix analysis and formatting issues.

    Analysis or formatting checks reported 7 hints.

    Run dartfmt to format lib/fnx_config.dart.

    Run dartfmt to format lib/fnx_config_read.dart.

  • Maintain an example.

    None of the files in your example/ directory matches a known example patterns. Common file name patterns include: main.dart, example.dart or you could also use fnx_config.dart.

  • Use analysis_options.yaml.

    Rename old .analysis_options file to analysis_options.yaml.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.8.0 <2.0.0
barback ^0.15.2 0.15.2+15
html ^0.13.0 0.13.3
yaml ^2.1.7 2.1.13
Transitive dependencies
args 1.4.1
async 2.0.6
charcode 1.1.1
collection 1.14.9
csslib 0.14.1
logging 0.11.3+1
path 1.5.1
pool 1.3.4
source_span 1.4.0
stack_trace 1.9.2
string_scanner 1.0.2
utf 0.9.0+4
Dev dependencies
browser any