Skip to content

Commit

Permalink
feat(silent): Adding helper function to display warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
iansu committed May 30, 2017
1 parent 72c9fba commit e5572ce
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ class Dotenv {
if (options.safe) {
options.safe = options.sample
}
if (!options.silent) {
console.warn('dotenv-webpack: "options.sample" is a deprecated property. Please update your configuration to use "options.safe" instead.')
}
this.warn('dotenv-webpack: "options.sample" is a deprecated property. Please update your configuration to use "options.safe" instead.', options.silent)
}

let vars = {}
Expand Down Expand Up @@ -75,12 +73,19 @@ class Dotenv {
try {
return dotenv.parse(fs.readFileSync(file))
} catch (err) {
if (!silent) {
console.warn(`Failed to load ${file}.`)
}
this.warn(`Failed to load ${file}.`, silent)
return {}
}
}

/**
* Displays a console message if 'silent' is falsey
* @param {String} msg - The message.
* @param {Bool} silent - If true, display the message, if false, suppress the message.
*/
warn (msg, silent) {
!silent && console.warn(msg)
}
}

export default Dotenv

0 comments on commit e5572ce

Please sign in to comment.