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