configorama 0.6.2 → 0.6.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "configorama",
3
- "version": "0.6.2",
3
+ "version": "0.6.4",
4
4
  "description": "Variable support for configuration files",
5
5
  "main": "src/index.js",
6
6
  "files": [
@@ -37,6 +37,7 @@
37
37
  "@davidwells/box-logger": "^1.0.10",
38
38
  "@iarna/toml": "^2.2.5",
39
39
  "dot-prop": "^5.3.0",
40
+ "env-stage-loader": "^1.1.1",
40
41
  "find-up": "^3.0.0",
41
42
  "git-url-parse": "^14.0.0",
42
43
  "js-yaml": "^3.14.1",
package/src/index.js CHANGED
@@ -1,6 +1,5 @@
1
1
  const Configorama = require('./main')
2
2
  const parsers = require('./parsers')
3
- const forceSync = require('sync-rpc')
4
3
 
5
4
  module.exports.Configorama = Configorama
6
5
 
@@ -23,12 +22,18 @@ module.exports = async (configPathOrObject, settings = {}) => {
23
22
  }
24
23
 
25
24
  module.exports.sync = (configPathOrObject, settings = {}) => {
26
- if (settings.dynamicArgs && typeof settings.dynamicArgs === 'function') {
25
+ const _settings = settings || {}
26
+ if (_settings.dynamicArgs && typeof _settings.dynamicArgs === 'function') {
27
27
  throw new Error('Dynamic args must be serializable value for sync usage. Use Async instead')
28
28
  }
29
- return forceSync(require.resolve('./sync'), settings.variableSources)({
29
+ if (!_settings.options) {
30
+ const cliArgs = require('minimist')(process.argv.slice(2))
31
+ _settings.options = cliArgs
32
+ }
33
+ const forceSync = require('sync-rpc')
34
+ return forceSync(require.resolve('./sync'), _settings.variableSources)({
30
35
  filePath: configPathOrObject,
31
- settings: settings
36
+ settings: _settings
32
37
  })
33
38
  }
34
39
 
package/src/main.js CHANGED
@@ -677,6 +677,27 @@ class Configorama {
677
677
  return Promise.resolve(originalConfig)
678
678
  }
679
679
 
680
+ const useDotEnv = this.originalConfig.useDotenv || this.originalConfig.useDotEnv
681
+ if ((useDotEnv && useDotEnv === true) || this.opts.useDotEnvFiles) {
682
+ let providerStage
683
+ /* has hardcoded stage */
684
+ if (
685
+ this.originalConfig && this.originalConfig.provider &&
686
+ this.originalConfig.provider.stage && !this.originalConfig.provider.stage.match(this.variableSyntax)
687
+ ) {
688
+ providerStage = this.originalConfig.provider.stage
689
+ }
690
+ const stage = cliOpts.stage || providerStage || process.env.NODE_ENV || 'dev'
691
+ /* Load env variables into process.env */
692
+ const values = require('env-stage-loader')({
693
+ // silent: true,
694
+ // debug: true,
695
+ env: stage,
696
+ // defaultEnv: 'prod',
697
+ // ignoreFiles: ['.env']
698
+ })
699
+ }
700
+
680
701
  /* Parse variables */
681
702
  return this.initialCall(() => {
682
703
  return Promise.resolve()