forked from fivetanley/ember-cli-dotenv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
55 lines (48 loc) · 1.51 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/* jshint node: true */
module.exports = {
name: 'ember-cli-dotenv',
config: function(environment){
var path = require('path');
var fs = require('fs');
var dotenv = require('dotenv');
var project = this.project;
var loadedConfig;
var config = {};
var hasOwn = Object.prototype.hasOwnProperty;
var configFilePath,
dotEnvPath = this.app && this.app.options.dotEnv && this.app.options.dotEnv.path;
if (dotEnvPath) {
// path is defined
if (typeof dotEnvPath === 'string') {
configFilePath = dotEnvPath;
} else {
if (dotEnvPath[environment]) {
configFilePath = dotEnvPath[environment];
}
}
}
if (!configFilePath) {
configFilePath = path.join(project.root, '.env');
}
if (dotenv.config({path: configFilePath})) {
loadedConfig = dotenv.parse(fs.readFileSync(configFilePath));
} else {
loadedConfig = {};
}
var app = this.app;
if (!this.app) {
return;
}
if (app.options.dotEnv && hasOwn.call(app.options.dotEnv, 'allow')){
console.warn("[EMBER-CLI-DOTENV] app.options.allow has been deprecated. Please use clientAllowedKeys instead. Support will be removed in the next major version");
}
var allowedKeys = (app.options.dotEnv && (app.options.dotEnv.clientAllowedKeys || app.options.dotEnv.allow) || []);
allowedKeys.forEach(function(key){
config[key] = loadedConfig[key];
});
return config;
},
included: function(app){
this.app = app;
}
};