dartodef 0.1.4 copy "dartodef: ^0.1.4" to clipboard
dartodef: ^0.1.4 copied to clipboard

Set variable values in compile time. Set the environment variable DARTODEF to define which property of the map defined in the pubspec.yaml should be used.

dartodef #

dartodef is a transformer (preprocessor) for pub build which replaces variable values on compile-time. The values can be defined in the pubspec.yaml. For different environment values create a property in the transformer options for dartodef and pass the name of the property as environment variable to the pub build process. PLEASE NOTICE: dartson is in alpha status. I just wrote it in a few hours

Setup dartodef #

pubspec.yaml

name: dartodef_sample_setup
version: 0.1.0
dependencies:
  browser: any
  js: any
  dartodef: any
transformers:
  - dartodef:
      live:
        environment: 'live'
        doIt: true
      preview:
        environment: 'preview'
        doIt: false

main.dart (for example)

library sample_app;

import 'package:dartodef/dartodef.dart';

@Definition(name:'environment')
const String ENV = 'development';

class Test {
  @Definition(name:'doIt')
  static bool done = false;
}

Running pub build now:

DARTODEF=live pub build

If no environment is set the default values will be used.

Available types #

...
transformers:
  - dartodef:
      live:
        string: hallo
        other_string: "hallo test"
        int: 1
        num: 1
        double: 1.1
        bool: true
        list: [1, 2, "simple", 1.1, true]
        map:
          key: "value"
          key2: 1

Only simple types can be used. Lists and maps will be serialized.

What you need to know #

  • always import dartodef as it is. DO NOT USE "as"
  • only variables that are already initialized can be used. And the initialization needs to match the type (for example mapping on string when code looks like: "String variable = null;" failes)
  • use const if you want to make sure that dead is removed

Plans for the future #

  • load values for each environment from dart scripts or other external files (JSON, YAML)

How to run tests #

DARTODEF=test pub serve --port=4444 test/
pub run test --pub-serve=4444 
0
likes
35
pub points
0%
popularity

Publisher

unverified uploader

Set variable values in compile time. Set the environment variable DARTODEF to define which property of the map defined in the pubspec.yaml should be used.

Repository (GitHub)
View/report issues

License

MIT (LICENSE)

Dependencies

analyzer, barback, source_maps, source_span

More

Packages that depend on dartodef