sails-js-hook-dotenv
Advanced tools
Comparing version 1.0.0 to 1.0.1
41
index.js
@@ -1,4 +0,4 @@ | ||
dotenv = require('dotenv'); | ||
dotenv = require('dotenv') | ||
module.exports = function(sails) { | ||
module.exports = function (sails) { | ||
@@ -8,26 +8,33 @@ return { | ||
defaults: { | ||
__configKey__: { | ||
active: true, | ||
throwOnFailure: true, | ||
}, | ||
}, | ||
active: true | ||
initialize: function (cb) { | ||
if (!sails.config[this.configKey].active) { | ||
sails.log.verbose('Dotenv hook deactivated.') | ||
return cb() | ||
} | ||
}, | ||
initialize: function(cb) { | ||
const result = dotenv.config() | ||
if (!sails.config[ this.configKey ].active) { | ||
// dotenv config failed to load | ||
if (result.error) { | ||
sails.log.verbose('Dotenv hook deactivated.'); | ||
return cb(); | ||
if (sails.config[this.configKey].throwOnFailure) { | ||
throw result.error | ||
} else { | ||
sails.config[this.configKey].active = false | ||
sails.log.verbose('Dotenv hook deactivated.') | ||
} | ||
return cb() | ||
} | ||
dotenv.config(); | ||
return cb(); | ||
return cb() | ||
}, | ||
}; | ||
}; | ||
} | ||
} |
{ | ||
"name": "sails-js-hook-dotenv", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Sails.js hook for loading .env files", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -18,3 +18,23 @@ # sails-hook-dotenv | ||
You can add configuration options for this hook in `config/dotenv.js` by default. Currently, the only option is a boolean: `active`. Setting this to false will disable this hook. | ||
```js | ||
module.exports.dotenv = { | ||
default: { | ||
/** | ||
* Setting this to false will disable this hook | ||
*/ | ||
active: true, | ||
/** | ||
* Setting this to false will cause the application | ||
* NOT to throw an error if the config fails to load | ||
*/ | ||
throwOnFailure: true, | ||
} | ||
} | ||
``` | ||
### Testing | ||
@@ -25,1 +45,5 @@ | ||
Then run `npm run test` in your terminal. | ||
### Changelog | ||
[Changelog](CHANGELOG.md) |
7323
14
60
48