1.0.0
This commit is contained in:
parent
0076547a2a
commit
7259d2b73a
3 changed files with 13 additions and 12 deletions
|
@ -4,9 +4,9 @@ import 'dart:io';
|
|||
import 'package:angel_framework/angel_framework.dart';
|
||||
import 'package:yaml/yaml.dart';
|
||||
|
||||
_loadYamlFile(Angel app, File yamlFile) {
|
||||
if (yamlFile.existsSync()) {
|
||||
Map config = loadYaml(yamlFile.readAsStringSync());
|
||||
_loadYamlFile(Angel app, File yamlFile) async {
|
||||
if (await yamlFile.exists()) {
|
||||
Map config = loadYaml(await yamlFile.readAsString());
|
||||
for (String key in config.keys) {
|
||||
app.properties[key] = config[key];
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ _loadYamlFile(Angel app, File yamlFile) {
|
|||
|
||||
loadConfigurationFile(
|
||||
{String directoryPath: "./config", String overrideEnvironmentName}) {
|
||||
return (Angel app) {
|
||||
return (Angel app) async {
|
||||
Directory sourceDirectory = new Directory(directoryPath);
|
||||
String environmentName = Platform.environment['ANGEL_ENV'] ?? 'development';
|
||||
|
||||
|
@ -25,12 +25,12 @@ loadConfigurationFile(
|
|||
|
||||
File defaultYaml = new File.fromUri(
|
||||
sourceDirectory.absolute.uri.resolve("default.yaml"));
|
||||
_loadYamlFile(app, defaultYaml);
|
||||
await _loadYamlFile(app, defaultYaml);
|
||||
|
||||
String configFilePath = "$environmentName.yaml";
|
||||
File configFile = new File.fromUri(
|
||||
sourceDirectory.absolute.uri.resolve(configFilePath));
|
||||
|
||||
_loadYamlFile(app, configFile);
|
||||
await _loadYamlFile(app, configFile);
|
||||
};
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
name: angel_configuration
|
||||
description: YAML configuration loader for Angel.
|
||||
version: 1.0.0-dev
|
||||
version: 1.0.0
|
||||
author: thosakwe <thosakwe@gmail.com>
|
||||
homepage: https://github.com/angel-dart/angel_configuration
|
||||
dependencies:
|
||||
|
|
|
@ -2,13 +2,14 @@ import 'package:angel_framework/angel_framework.dart';
|
|||
import 'package:angel_configuration/angel_configuration.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
main() {
|
||||
main() async {
|
||||
// Note: Set ANGEL_ENV to 'development'
|
||||
|
||||
Angel angel = new Angel();
|
||||
await angel.configure(
|
||||
loadConfigurationFile(directoryPath: './test/config'));
|
||||
|
||||
test('can load based on ANGEL_ENV', () {
|
||||
angel.configure(loadConfigurationFile(directoryPath: './test/config'));
|
||||
test('can load based on ANGEL_ENV', () async {
|
||||
expect(angel.properties['hello'], equals('world'));
|
||||
expect(angel.properties['foo']['version'], equals('bar'));
|
||||
});
|
||||
|
@ -18,8 +19,8 @@ main() {
|
|||
});
|
||||
|
||||
|
||||
test('can override ANGEL_ENV', () {
|
||||
angel.configure(loadConfigurationFile(
|
||||
test('can override ANGEL_ENV', () async {
|
||||
await angel.configure(loadConfigurationFile(
|
||||
directoryPath: './test/config', overrideEnvironmentName: 'override'));
|
||||
expect(angel.properties['hello'], equals('goodbye'));
|
||||
expect(angel.properties['foo']['version'], equals('baz'));
|
||||
|
|
Loading…
Reference in a new issue