-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdotenv.js
35 lines (29 loc) · 799 Bytes
/
dotenv.js
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
32
33
34
35
const fs = require("fs");
const dotenv = require("dotenv");
const path = require("path");
const chalk = require("chalk");
const os = require("os");
const buildEnv = process.env["FSF_START_ENV"];
const envFilePath = path.join(
fs.realpathSync(process.cwd()),
getFileName(buildEnv)
);
if (!fs.existsSync(envFilePath)) {
console.error(chalk.redBright(`Env file not found ${envFilePath}.`));
process.exit(1);
}
const getEnv = dotenv.config({
path: envFilePath,
});
if (getEnv.error) {
console.error(
chalk.redBright(
`Something went wrong getting your environment file:${os.EOL}${getEnv.error}.`
)
);
process.exit(1);
}
console.info(chalk.yellow(`Environment file ${envFilePath}`));
function getFileName(buildEnv) {
return buildEnv ? `.env.${buildEnv}` : ".env";
}