forked from netlify/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenv.js
More file actions
31 lines (24 loc) · 801 Bytes
/
Copy pathenv.js
File metadata and controls
31 lines (24 loc) · 801 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
const path = require('path')
const fs = require('fs')
const { promisify } = require('util')
const dotenv = require('dotenv')
const fileStat = promisify(fs.stat)
const readFile = promisify(fs.readFile)
async function getEnvSettings(projectDir) {
const envDevelopmentFile = path.resolve(projectDir, '.env.development')
const envFile = path.resolve(projectDir, '.env')
const settings = {}
try {
if ((await fileStat(envFile)).isFile()) settings.file = envFile
} catch (err) {
// nothing
}
try {
if ((await fileStat(envDevelopmentFile)).isFile()) settings.file = envDevelopmentFile
} catch (err) {
// nothing
}
if (settings.file) settings.vars = dotenv.parse(await readFile(settings.file)) || {}
return settings
}
module.exports.getEnvSettings = getEnvSettings