2021-05-14 11:27:54 +00:00
|
|
|
# angel3_configuration
|
|
|
|
[![version](https://img.shields.io/badge/pub-v2.12.4-brightgreen)](https://pub.dartlang.org/packages/angel3_configuration)
|
|
|
|
[![Null Safety](https://img.shields.io/badge/null-safety-brightgreen)](https://dart.dev/null-safety)
|
2021-05-15 06:01:47 +00:00
|
|
|
[![Gitter](https://img.shields.io/gitter/room/angel_dart/discussion)](https://gitter.im/angel_dart/discussion)
|
2021-05-14 11:27:54 +00:00
|
|
|
|
|
|
|
[![License](https://img.shields.io/github/license/dukefirehawk/angel)](https://github.com/dukefirehawk/angel/tree/angel3/packages/configuration/LICENSE)
|
2016-11-23 20:51:20 +00:00
|
|
|
|
|
|
|
|
2017-06-14 18:48:13 +00:00
|
|
|
Automatic YAML configuration loader for Angel.
|
2016-04-22 01:17:31 +00:00
|
|
|
|
|
|
|
# About
|
|
|
|
Any web app needs different configuration for development and production. This plugin will search
|
2017-09-25 13:50:56 +00:00
|
|
|
for a `config/default.yaml` file. If it is found, configuration from it is loaded into `app.configuration`.
|
2016-04-22 01:17:31 +00:00
|
|
|
Then, it will look for a `config/$ANGEL_ENV` file. (i.e. config/development.yaml). If this found, all of its
|
|
|
|
configuration be loaded, and will override anything loaded from the `default.yaml` file. This allows for your
|
|
|
|
app to work under different conditions without you re-coding anything. :)
|
|
|
|
|
|
|
|
# Installation
|
|
|
|
In `pubspec.yaml`:
|
|
|
|
|
2016-09-19 11:19:22 +00:00
|
|
|
```yaml
|
|
|
|
dependencies:
|
2021-05-14 11:27:54 +00:00
|
|
|
angel3_configuration: ^3.0.0
|
2016-09-19 11:19:22 +00:00
|
|
|
```
|
2016-04-22 01:17:31 +00:00
|
|
|
|
|
|
|
# Usage
|
|
|
|
|
2017-06-14 18:48:13 +00:00
|
|
|
**Example Configuration**
|
|
|
|
```yaml
|
|
|
|
# Define normal YAML objects
|
|
|
|
some_key: foo
|
|
|
|
this_is_a_map:
|
|
|
|
a_string: "string"
|
|
|
|
another_string: "string"
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
You can also load configuration from the environment:
|
|
|
|
```yaml
|
|
|
|
# Loaded from the environment
|
|
|
|
system_path: $PATH
|
|
|
|
```
|
|
|
|
|
2020-05-04 16:05:14 +00:00
|
|
|
If a `.env` file is present in your configuration directory (i.e. `config/.env`), then it will be loaded before
|
2017-06-14 18:48:13 +00:00
|
|
|
applying YAML configuration.
|
|
|
|
|
2020-05-04 16:05:14 +00:00
|
|
|
You can also include values from one file into another:
|
|
|
|
```yaml
|
|
|
|
_include:
|
|
|
|
- "./include-prod.yaml"
|
|
|
|
- "./include-misc.yaml"
|
|
|
|
_include: "just-one-file.yaml"
|
|
|
|
```
|
|
|
|
|
2016-09-19 20:31:32 +00:00
|
|
|
**Server-side**
|
2017-09-25 13:50:56 +00:00
|
|
|
Call `configuration()`. The loaded configuration will be available in your application's
|
2018-08-21 19:08:32 +00:00
|
|
|
`configuration` map.
|
2016-04-22 01:17:31 +00:00
|
|
|
|
2017-09-25 13:50:56 +00:00
|
|
|
`configuration` also accepts a `sourceDirectory` or `overrideEnvironmentName` parameter.
|
2016-04-22 01:17:31 +00:00
|
|
|
The former will allow you to search in a directory other than `config`, and the latter lets you
|
2017-06-14 18:48:13 +00:00
|
|
|
override `$ANGEL_ENV` by specifying a specific configuration name to look for (i.e. `production`).
|
2016-09-19 20:31:32 +00:00
|
|
|
|
2017-08-16 00:29:13 +00:00
|
|
|
This package uses
|
|
|
|
[`package:merge_map`](https://github.com/thosakwe/merge_map)
|
|
|
|
internally, so existing configurations can be deeply merged.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
|
|
|
```yaml
|
|
|
|
# default.yaml
|
|
|
|
foo:
|
|
|
|
bar: baz
|
|
|
|
quux: hello
|
|
|
|
|
|
|
|
# production.yaml
|
|
|
|
foo:
|
|
|
|
quux: goodbye
|
|
|
|
yellow: submarine
|
|
|
|
|
|
|
|
# Propagates to:
|
|
|
|
foo:
|
|
|
|
bar: baz
|
|
|
|
quux: goodbye
|
|
|
|
yellow: submarine
|
2020-05-04 16:05:14 +00:00
|
|
|
```
|