UNPKG

663 BJavaScriptView Raw
1const fs = require('fs')
2const logger = require('@poi/logger')
3
4module.exports = (mode, dotenvPath) => {
5 const dotenvFiles = [
6 `${dotenvPath}.${mode}.local`,
7 `${dotenvPath}.${mode}`,
8 // Don't include `.env.local` for `test` mode
9 // since normally you expect tests to produce the same
10 // results for everyone
11 mode !== 'test' && `${dotenvPath}.local`,
12 dotenvPath
13 ].filter(Boolean)
14
15 dotenvFiles.forEach(dotenvFile => {
16 if (fs.existsSync(dotenvFile)) {
17 logger.debug('Using env file:', dotenvFile)
18 require('dotenv-expand')(
19 require('dotenv').config({
20 path: dotenvFile
21 })
22 )
23 }
24 })
25}