Reason/BuckleScript bindings to the nconf library.
npm install reason-nconf


This is a very rough implementation that will enable very simple use cases.
reason
type config = {
..
"THING1": string,
"THING2": int
};let baseDir = "/path/to/somewhere"
let appConfig: config =
Nconf.(
make()
|> argv()
|> env()
|> filePathNamed("locals", {j|$baseDir/config/locals.json|j})
|> filePathNamed("defaults", {j|$baseDir/config/defaults.json|j})
|> get()
);
`$3
This is accomplished from an internal module written in ReasonML. The internal
module is a near 1-to-1 copy of [nconf-js]
`reason
let appConfig =
Nconf.(
make()
|> jsFilePathNamed("example", {j|/path/to/file.js|j})
|> get()
);
`$3
#### String Literal
`reason
let appConfig =
Nconf.(
make()
|> setLiteral("some:key:path", Str("foo"))
#### Integer Literal
`reason
let appConfig =
Nconf.(
make()
|> setLiteral("some:key:path", Int(42))
#### Object Literal
`reason
let appConfig =
Nconf.(
make()
|> setObject("some:key:path", { "foo": "bar" })
|> get()
)
`$3
`reason
let appConfig =
Nconf.(
make()
|> jsFilePathNamed("example", {j|./__tests__/assets/data.js|j})
)
let username =
switch(Nconf.getKey(appConfig, "obj:auth:username") |> Js.Nullable.to_opt) {
| None => Js.Exn.raiseError("Could not retrieve username")
| Some(x) => x
};
`
How do I install it?
Inside of a BuckleScript project:
`shell
yarn install --save reason-nconf
`Then add
reason-nconf to your bs-dependencies in bsconfig.json:
`json
{
"bs-dependencies": [
"reason-nconf"
]
}
``See the Usage section above...
Mostly everything...
[node-nconf]: https://www.npmjs.com/package/nconf
[nconf-js]: https://github.com/yoneal/nconf-js