1 | "use strict";
|
2 |
|
3 | var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4 |
|
5 | var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
6 |
|
7 | const config = require('./config');
|
8 |
|
9 | const dotenv = require('dotenv');
|
10 |
|
11 | const variableExpansion = require('dotenv-expand');
|
12 |
|
13 | function loadEnv(_x) {
|
14 | return _loadEnv.apply(this, arguments);
|
15 | }
|
16 |
|
17 | function _loadEnv() {
|
18 | _loadEnv = (0, _asyncToGenerator2.default)(function* (filepath) {
|
19 | const NODE_ENV = process.env.NODE_ENV || 'development';
|
20 | const dotenvFiles = [`.env.${NODE_ENV}.local`, `.env.${NODE_ENV}`,
|
21 |
|
22 |
|
23 | NODE_ENV !== 'test' && '.env.local', '.env'].filter(Boolean);
|
24 | yield Promise.all(dotenvFiles.map(
|
25 |
|
26 | function () {
|
27 | var _ref = (0, _asyncToGenerator2.default)(function* (dotenvFile) {
|
28 | const envPath = yield config.resolve(filepath, [dotenvFile]);
|
29 |
|
30 | if (envPath) {
|
31 | const envs = dotenv.config({
|
32 | path: envPath
|
33 | });
|
34 | variableExpansion(envs);
|
35 | }
|
36 | });
|
37 |
|
38 | return function (_x2) {
|
39 | return _ref.apply(this, arguments);
|
40 | };
|
41 | }()));
|
42 | });
|
43 | return _loadEnv.apply(this, arguments);
|
44 | }
|
45 |
|
46 | module.exports = loadEnv; |
\ | No newline at end of file |