forked from fivetanley/ember-cli-dotenv
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
initial commit to rewrite ember-cli-dotenv
- Loading branch information
Showing
7 changed files
with
5,243 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/* eslint-env node */ | ||
|
||
'use strict'; | ||
|
||
const path = require('path'); | ||
|
||
module.exports = function(/* env */) { | ||
return { | ||
clientAllowedKeys: ['DROPBOX_KEY'], | ||
path: path.join(__dirname, '.env') | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
'use strict'; | ||
|
||
module.exports = { | ||
description: 'Setup ember-cli-dotenv', | ||
normalizeEntityName() {} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,44 @@ | ||
/* jshint node: true */ | ||
|
||
'use strict'; | ||
|
||
const fs = require('fs'); | ||
const path = require('path'); | ||
const dotenv = require('dotenv'); | ||
const existsSync = require('exists-sync'); | ||
const EmberApp = require('ember-cli/lib/broccoli/ember-app'); | ||
|
||
module.exports = { | ||
name: 'ember-cli-dotenv', | ||
config: function(environment){ | ||
var path = require('path'); | ||
var fs = require('fs'); | ||
var dotenv = require('dotenv'); | ||
var existsSync = require('exists-sync'); | ||
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'); | ||
} | ||
init() { | ||
this._super.apply(this, arguments); | ||
|
||
if (existsSync(configFilePath) && dotenv.config({path: configFilePath})) { | ||
loadedConfig = dotenv.parse(fs.readFileSync(configFilePath)); | ||
} else { | ||
loadedConfig = {}; | ||
} | ||
let project = this.project; | ||
let hasOwn = Object.prototype.hasOwnProperty; | ||
let configFactory = path.join(project.root, 'dotenv.js'); | ||
let options = { | ||
path: path.join(project.root, '.env'), | ||
clientAllowedKeys: [] | ||
}; | ||
|
||
var app = this.app; | ||
if (!this.app) { | ||
return; | ||
if (existsSync(configFactory)) { | ||
Object.assign(options, require(configFactory)(this.env)); | ||
} | ||
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]; | ||
}); | ||
if (existsSync(options.path) && dotenv.config({ path: options.path })) { | ||
let loadedConfig = dotenv.parse(fs.readFileSync(options.path)); | ||
let allowedKeys = options.clientAllowedKeys || []; | ||
|
||
this._config = allowedKeys.reduce((accumulator, key) => { | ||
accumulator[key] = loadedConfig[key]; | ||
|
||
return config; | ||
return accumulator; | ||
}, {}); | ||
} | ||
}, | ||
included: function(app){ | ||
this.app = app; | ||
this._super.included.apply(this, arguments); | ||
|
||
config(env, baseConfig) { | ||
return this._config; | ||
} | ||
}; |
Oops, something went wrong.