platform/lib/angel_configuration.dart

36 lines
1.1 KiB
Dart
Raw Normal View History

2016-04-22 01:17:31 +00:00
library angel_configuration;
import 'dart:io';
import 'package:angel_framework/angel_framework.dart';
import 'package:yaml/yaml.dart';
2016-05-02 23:35:21 +00:00
_loadYamlFile(Angel app, File yamlFile) async {
if (await yamlFile.exists()) {
Map config = loadYaml(await yamlFile.readAsString());
2016-04-22 01:17:31 +00:00
for (String key in config.keys) {
app.properties[key] = config[key];
}
}
}
loadConfigurationFile(
{String directoryPath: "./config", String overrideEnvironmentName}) {
2016-05-02 23:35:21 +00:00
return (Angel app) async {
2016-04-22 01:17:31 +00:00
Directory sourceDirectory = new Directory(directoryPath);
String environmentName = Platform.environment['ANGEL_ENV'] ?? 'development';
if (overrideEnvironmentName != null) {
environmentName = overrideEnvironmentName;
}
File defaultYaml = new File.fromUri(
sourceDirectory.absolute.uri.resolve("default.yaml"));
2016-05-02 23:35:21 +00:00
await _loadYamlFile(app, defaultYaml);
2016-04-22 01:17:31 +00:00
String configFilePath = "$environmentName.yaml";
File configFile = new File.fromUri(
sourceDirectory.absolute.uri.resolve(configFilePath));
2016-05-02 23:35:21 +00:00
await _loadYamlFile(app, configFile);
2016-04-22 01:17:31 +00:00
};
}