1 | const fs = require('fs')
|
2 | const logger = require('@poi/logger')
|
3 |
|
4 | module.exports = (mode, dotenvPath) => {
|
5 | const dotenvFiles = [
|
6 | `${dotenvPath}.${mode}.local`,
|
7 | `${dotenvPath}.${mode}`,
|
8 |
|
9 |
|
10 |
|
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 | }
|