boisly_config

Automatically expose haxe.config.json as a singleton in your haxe apps. (supports YAML and XML)
https://github.com/brave-pi/boisly_config/

To install, run:

haxelib install boisly_config 1.1.1 

See using Haxelib in Haxelib documentation for more information.

README.md

boisly_config

boisly_config brings app config files into your app with zero hassle.

Simply add --library boisly_config to your .hxml, tag a class with @:config and boisly.AppSettings.config will point to an instance of the class you decorated with @:config, populated from haxe.config.json (in the current working directory from which you executed the compiled Haxe program).

Example:

@:config 
class Configly {
  var boisly:{
    is:Dynamic<Bool>,
    createdBy:String,
    utility:Int,
    niftToGriftRatio:Float,
    binaryBlurb:haxe.io.Bytes
  };
}
class Test {
  public static function main() {
    trace(AppSettings.config);
    $type(AppSettings.config);
    // { boisly : { utility : Int, niftToGriftRatio : Float, is : Dynamic<Bool>, createdBy : String, binaryBlurb : haxe.io.Bytes } }
  }
}

Output:

src/Test.hx:18: {
  boisly: {
    binaryBlurb: { length: 48, b: [Uint8Array] },
    createdBy: 'piboistudios',
    is: { cool: true, convenient: true, opinionated: false },
    niftToGriftRatio: 0.9,
    utility: 10
  }
}

Custom config file name

Use the compiler flag -D boisly.appSettings.configFile=<your config file path> to set the config file name/path to whatever you desire.

Currently, XML, JSON and YAML files are supported through tink_xml, tink_json and yaml respectively (this also unfortunately means that, if you want configs to be compatible with all three, they must be compatible wtih tink_xml, since it parses the smallest set of possible types).

~~Caveats~~

~~You have to use fully qualified type names. This is also why there's an asterisk (*) next to "instance" above... this really turns the class into an anonymous type so that tink_json can parse it without complaining about there not being a @:jsonParse tag.~~

~~Probably, it will be better to actually use an instance of a class (and I guess generate a @:jsonParse tag by default if the class doesn't have one).. but for now this works.~~

This now generates a @:jsonParse decorator if one doesn't exist. Note that the default decorator will use type inspection and resolution to generate an empty instance and then populate it (so the constructor will not be called unless you implement your own @:jsonParse decorator).

Also, it no longer converts classes into anons. The config type is the class, so feel free to give it functions and whatnot.

Contributors
piboistudios
Version
1.1.1
Published
4 years ago
Dependencies
License
MIT

All libraries are free

Every month, more than a thousand developers use Haxelib to find, share, and reuse code — and assemble it in powerful new ways. Enjoy Haxe; It is great!

Explore Haxe

Haxe Manual

Haxe Code Cookbook

Haxe API documentation

You can try Haxe in the browser! try.haxe.org

Join us on GitHub!

Haxe is being developed on GitHub. Feel free to contribute or report issues to our projects.

Haxe on GitHub