2018-08-31 21:59:06 -06:00
|
|
|
import * as fs from "fs";
|
|
|
|
|
|
|
|
// tslint:disable-next-line:no-var-requires
|
|
|
|
const paths = require("paths");
|
|
|
|
|
|
|
|
const NODE_ENV = process.env.NODE_ENV || "development";
|
|
|
|
|
|
|
|
const dotenvFiles: string[] = [
|
|
|
|
`${paths.dotenv}.${NODE_ENV}.local`,
|
|
|
|
`${paths.dotenv}.${NODE_ENV}`,
|
|
|
|
// Don"t include `.env.local` for `test` environment
|
|
|
|
// since normally you expect tests to produce the same
|
|
|
|
// results for everyone
|
|
|
|
NODE_ENV !== "test" && `${paths.dotenv}.local`,
|
2018-09-02 02:57:55 -06:00
|
|
|
paths.dotenv
|
2018-08-31 21:59:06 -06:00
|
|
|
].filter(Boolean) as string[];
|
|
|
|
|
2018-09-02 02:57:55 -06:00
|
|
|
dotenvFiles.forEach(dotenvFile => {
|
2018-08-31 21:59:06 -06:00
|
|
|
if (fs.existsSync(dotenvFile)) {
|
|
|
|
require("dotenv").config({
|
2018-09-02 02:57:55 -06:00
|
|
|
path: dotenvFile
|
2018-08-31 21:59:06 -06:00
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|