@karmaniverous/get-dotenv 3.0.6 → 3.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +100 -118
- package/bin/getdotenv/index.js +3 -3
- package/dist/default/lib/getDotenv.js +24 -18
- package/dist/default/lib/getDotenvCli.js +191 -0
- package/dist/default/lib/index.js +5 -5
- package/dist/default/lib/options.js +51 -0
- package/dist/default/lib/readDotenv.js +2 -2
- package/getdotenv.config.json +24 -0
- package/lib/getDotenv.js +28 -16
- package/lib/getDotenvCli.js +450 -0
- package/lib/index.js +1 -1
- package/lib/options.js +79 -0
- package/lib/readDotenv.js +2 -2
- package/package.json +9 -8
- package/dist/default/lib/dotenvDefaults.js +0 -20
- package/dist/default/lib/getCli.js +0 -199
- package/lib/dotenvDefaults.js +0 -13
- package/lib/getCli.js +0 -357
package/README.md
CHANGED
|
@@ -6,10 +6,14 @@ Load environment variables with a cascade of environment-aware dotenv files. You
|
|
|
6
6
|
- Load variables for a specific environment or none.
|
|
7
7
|
- Define dynamic variables progressively in terms of other variables and other logic.
|
|
8
8
|
- Exclude public, private, global, environment-specific, or dynamic variables.
|
|
9
|
+
- Specify explicit variables to include.
|
|
9
10
|
- Extract the resulting variables to an object, `process.env`, a dotenv file, or a logger, in any combination.
|
|
11
|
+
- Execute a shell command within the resulting environment. You can even nest additional `getdotenv` calls!
|
|
10
12
|
- Specify the directories containing your dotenv files.
|
|
11
13
|
- Specify the filename token that identifies dotenv files (e.g. '.env').
|
|
12
14
|
- Specify the filename extension that identifies private variables (e.g. 'local').
|
|
15
|
+
- Set defaults for all options in a [`getdotenv.config.json`](./getdotenv.config.json) file in your project root directory.
|
|
16
|
+
- Generate a custom `getdotenv`-based CLI for use in your own projects.
|
|
13
17
|
|
|
14
18
|
`getdotenv` relies on the excellent [`dotenv`](https://www.npmjs.com/package/dotenv) parser and uses [`dotenv-expand`](https://www.npmjs.com/package/dotenv-expand) for recursive variable expansion.
|
|
15
19
|
|
|
@@ -63,7 +67,6 @@ Since keys will be evaluated progressively, each successive key function will ha
|
|
|
63
67
|
|
|
64
68
|
Implementation always runs a little behind documentation. These topics & improvements are coming soon:
|
|
65
69
|
|
|
66
|
-
- Rationalize the package's JSDOC to improve the API documentation below.
|
|
67
70
|
- An example of dotenv-based environment config.
|
|
68
71
|
- Integrating `getdotenv` into your npm scripts.
|
|
69
72
|
- Creating a `getdotenv`-based CLI.
|
|
@@ -71,57 +74,56 @@ Implementation always runs a little behind documentation. These topics & improve
|
|
|
71
74
|
|
|
72
75
|
# Command Line Interface
|
|
73
76
|
|
|
74
|
-
Note that the defaults below can be changed in your own environment by deriving your base CLI using the `
|
|
77
|
+
Note that the defaults below can be changed in your own environment by deriving your base CLI using the `getDotenvCli` function or placing a `getdotenv.options.json` file in your project root directory.
|
|
75
78
|
|
|
76
79
|
```text
|
|
77
80
|
Usage: getdotenv [options] [command]
|
|
78
81
|
|
|
79
|
-
Base CLI.
|
|
82
|
+
Base CLI.
|
|
80
83
|
|
|
81
84
|
Options:
|
|
82
|
-
-e, --env <string>
|
|
83
|
-
|
|
84
|
-
-
|
|
85
|
-
--
|
|
86
|
-
-
|
|
87
|
-
--
|
|
88
|
-
--
|
|
89
|
-
-
|
|
90
|
-
-
|
|
91
|
-
-
|
|
92
|
-
-
|
|
93
|
-
-
|
|
94
|
-
-
|
|
95
|
-
-
|
|
96
|
-
-
|
|
97
|
-
-
|
|
98
|
-
-
|
|
99
|
-
-
|
|
100
|
-
-
|
|
101
|
-
-
|
|
102
|
-
-
|
|
103
|
-
-
|
|
104
|
-
-
|
|
105
|
-
--dotenv-token <string>
|
|
106
|
-
--
|
|
107
|
-
-
|
|
108
|
-
-
|
|
85
|
+
-e, --env <string> target environment
|
|
86
|
+
-v, --vars <string> dotenv-expanded delimited key-value pairs: KEY1=VAL1 KEY2=VAL2 (default: "")
|
|
87
|
+
-c, --command <string> dotenv-expanded shell command string
|
|
88
|
+
-o, --output-path <string> consolidated output file, follows dotenv-expand rules using loaded env vars
|
|
89
|
+
-p, --load-process load variables to process.env ON (default)
|
|
90
|
+
-P, --load-process-off load variables to process.env OFF
|
|
91
|
+
-a, --exclude-all exclude all dotenv variables from loading ON
|
|
92
|
+
-A, --exclude-all-off exclude all dotenv variables from loading OFF (default)
|
|
93
|
+
-z, --exclude-dynamic exclude dynamic dotenv variables from loading ON
|
|
94
|
+
-Z, --exclude-dynamic-off exclude dynamic dotenv variables from loading OFF (default)
|
|
95
|
+
-n, --exclude-env exclude environment-specific dotenv variables from loading
|
|
96
|
+
-N, --exclude-env-off exclude environment-specific dotenv variables from loading OFF (default)
|
|
97
|
+
-g, --exclude-global exclude global dotenv variables from loading ON
|
|
98
|
+
-G, --exclude-global-off exclude global dotenv variables from loading OFF (default)
|
|
99
|
+
-r, --exclude-private exclude private dotenv variables from loading ON
|
|
100
|
+
-R, --exclude-private-off exclude private dotenv variables from loading OFF (default)
|
|
101
|
+
-u, --exclude-public exclude public dotenv variables from loading ON
|
|
102
|
+
-U, --exclude-public-off exclude public dotenv variables from loading OFF (default)
|
|
103
|
+
-l, --log console log loaded variables ON
|
|
104
|
+
-L, --log-off console log loaded variables OFF (default)
|
|
105
|
+
-d, --debug debug mode ON
|
|
106
|
+
-D, --debug-off debug mode OFF (default)
|
|
107
|
+
--default-env <string> default target environment (default: "dev")
|
|
108
|
+
--dotenv-token <string> dotenv-expanded token indicating a dotenv file (default: ".env")
|
|
109
|
+
--dynamic-path <string> dynamic variables path (default: "./env/dynamic.js")
|
|
110
|
+
--paths <string> dotenv-expanded delimited list of paths to dotenv directory (default: "./ ./env")
|
|
111
|
+
--paths-delimiter <string> paths delimiter string (default: " ")
|
|
112
|
+
--paths-delimiter-pattern <string> paths delimiter regex pattern (default: "\\s+")
|
|
113
|
+
--private-token <string> dotenv-expanded token indicating private variables (default: "local")
|
|
114
|
+
--vars-delimiter <string> vars delimiter string (default: " ")
|
|
115
|
+
--vars-delimiter-pattern <string> vars delimiter regex pattern (default: "\\s+")
|
|
116
|
+
--vars-assignor <string> vars assignment operator string (default: "=")
|
|
117
|
+
--vars-assignor-pattern <string> vars assignment operator regex pattern (default: "=")
|
|
118
|
+
-h, --help display help for command
|
|
109
119
|
|
|
110
120
|
Commands:
|
|
111
|
-
cmd
|
|
112
|
-
help [command]
|
|
121
|
+
cmd execute shell command string (default command)
|
|
122
|
+
help [command] display help for command
|
|
113
123
|
```
|
|
114
124
|
|
|
115
125
|
# API Documentation
|
|
116
126
|
|
|
117
|
-
## Constants
|
|
118
|
-
|
|
119
|
-
<dl>
|
|
120
|
-
<dt><a href="#getCli">getCli</a> ⇒ <code>object</code></dt>
|
|
121
|
-
<dd><p>Generate a CLI for get-dotenv.</p>
|
|
122
|
-
</dd>
|
|
123
|
-
</dl>
|
|
124
|
-
|
|
125
127
|
## Functions
|
|
126
128
|
|
|
127
129
|
<dl>
|
|
@@ -131,40 +133,25 @@ Commands:
|
|
|
131
133
|
<dt><a href="#getDotenvSync">getDotenvSync([options])</a> ⇒ <code>Object</code></dt>
|
|
132
134
|
<dd><p>Synchronously process dotenv files of the form .env[.<ENV>][.<PRIVATETOKEN>]</p>
|
|
133
135
|
</dd>
|
|
136
|
+
<dt><a href="#getDotenvCli">getDotenvCli([options])</a> ⇒ <code>object</code></dt>
|
|
137
|
+
<dd><p>Generate a CLI for get-dotenv.</p>
|
|
138
|
+
</dd>
|
|
134
139
|
</dl>
|
|
135
140
|
|
|
136
141
|
## Typedefs
|
|
137
142
|
|
|
138
143
|
<dl>
|
|
139
|
-
<dt><a href="#
|
|
140
|
-
<dd><p>
|
|
144
|
+
<dt><a href="#GetDotenvOptions">GetDotenvOptions</a> : <code>Object</code></dt>
|
|
145
|
+
<dd><p>get-dotenv options type</p>
|
|
141
146
|
</dd>
|
|
142
|
-
<dt><a href="#GetDotenvPreHookCallback">GetDotenvPreHookCallback</a> ⇒ <code
|
|
147
|
+
<dt><a href="#GetDotenvPreHookCallback">GetDotenvPreHookCallback</a> ⇒ <code>GetDotenvCliOptions</code></dt>
|
|
143
148
|
<dd><p>GetDotenv CLI Pre-hook Callback type. Transforms inbound options & executes side effects.</p>
|
|
144
149
|
</dd>
|
|
145
150
|
<dt><a href="#GetDotenvPostHookCallback">GetDotenvPostHookCallback</a> : <code>function</code></dt>
|
|
146
151
|
<dd><p>GetDotenv CLI Post-hook Callback type. Executes side effects within getdotenv context.</p>
|
|
147
152
|
</dd>
|
|
148
|
-
<dt><a href="#GetDotenvCliConfig">GetDotenvCliConfig</a> : <code>Object</code></dt>
|
|
149
|
-
<dd><p>GetDotenv CLI Config type</p>
|
|
150
|
-
</dd>
|
|
151
|
-
<dt><a href="#OptionsType">OptionsType</a> : <code>Object</code></dt>
|
|
152
|
-
<dd><p>get-dotenv options type</p>
|
|
153
|
-
</dd>
|
|
154
153
|
</dl>
|
|
155
154
|
|
|
156
|
-
<a name="getCli"></a>
|
|
157
|
-
|
|
158
|
-
## getCli ⇒ <code>object</code>
|
|
159
|
-
Generate a CLI for get-dotenv.
|
|
160
|
-
|
|
161
|
-
**Kind**: global constant
|
|
162
|
-
**Returns**: <code>object</code> - The CLI command.
|
|
163
|
-
|
|
164
|
-
| Param | Type | Description |
|
|
165
|
-
| --- | --- | --- |
|
|
166
|
-
| [config] | [<code>GetDotenvCliConfig</code>](#GetDotenvCliConfig) | config object |
|
|
167
|
-
|
|
168
155
|
<a name="getDotenv"></a>
|
|
169
156
|
|
|
170
157
|
## getDotenv([options]) ⇒ <code>Promise.<object></code>
|
|
@@ -175,7 +162,7 @@ Asynchronously process dotenv files of the form .env[.<ENV>][.<PRIVATE_TOKEN>]
|
|
|
175
162
|
|
|
176
163
|
| Param | Type | Description |
|
|
177
164
|
| --- | --- | --- |
|
|
178
|
-
| [options] | [<code>
|
|
165
|
+
| [options] | [<code>GetDotenvOptions</code>](#GetDotenvOptions) | options object |
|
|
179
166
|
|
|
180
167
|
<a name="getDotenvSync"></a>
|
|
181
168
|
|
|
@@ -187,21 +174,57 @@ Synchronously process dotenv files of the form .env[.<ENV>][.<PRIVATETOKEN>]
|
|
|
187
174
|
|
|
188
175
|
| Param | Type | Description |
|
|
189
176
|
| --- | --- | --- |
|
|
190
|
-
| [options] | [<code>
|
|
177
|
+
| [options] | [<code>GetDotenvOptions</code>](#GetDotenvOptions) | options object |
|
|
191
178
|
|
|
192
|
-
<a name="
|
|
179
|
+
<a name="getDotenvCli"></a>
|
|
193
180
|
|
|
194
|
-
##
|
|
195
|
-
|
|
181
|
+
## getDotenvCli([options]) ⇒ <code>object</code>
|
|
182
|
+
Generate a CLI for get-dotenv.
|
|
183
|
+
|
|
184
|
+
**Kind**: global function
|
|
185
|
+
**Returns**: <code>object</code> - The CLI command.
|
|
186
|
+
|
|
187
|
+
| Param | Type | Description |
|
|
188
|
+
| --- | --- | --- |
|
|
189
|
+
| [options] | <code>object</code> | options object |
|
|
190
|
+
| [options.alias] | <code>string</code> | cli alias (used for cli help) |
|
|
191
|
+
| [options.command] | <code>string</code> | [dotenv-expanded](https://github.com/motdotla/dotenv-expand/blob/master/tests/.env) shell command string |
|
|
192
|
+
| [options.debug] | <code>bool</code> | debug mode |
|
|
193
|
+
| [options.defaultEnv] | <code>string</code> | default target environment |
|
|
194
|
+
| [options.description] | <code>string</code> | cli description (used for cli help) |
|
|
195
|
+
| [options.dotenvToken] | <code>string</code> | [dotenv-expanded](https://github.com/motdotla/dotenv-expand/blob/master/tests/.env) token indicating a dotenv file |
|
|
196
|
+
| [options.dynamicPath] | <code>string</code> | path to file exporting an object keyed to dynamic variable functions |
|
|
197
|
+
| [options.excludeDynamic] | <code>bool</code> | exclude dynamic dotenv variables |
|
|
198
|
+
| [options.excludeEnv] | <code>bool</code> | exclude environment-specific dotenv variables |
|
|
199
|
+
| [options.excludeGlobal] | <code>bool</code> | exclude global dotenv variables |
|
|
200
|
+
| [options.excludePrivate] | <code>bool</code> | exclude private dotenv variables |
|
|
201
|
+
| [options.excludePublic] | <code>bool</code> | exclude public dotenv variables |
|
|
202
|
+
| [options.loadProcess] | <code>bool</code> | load variables to process.env |
|
|
203
|
+
| [options.log] | <code>bool</code> | log result to console |
|
|
204
|
+
| [options.logger] | <code>function</code> | logger function |
|
|
205
|
+
| [options.outputPath] | <code>string</code> | consolidated output file, [dotenv-expanded](https://github.com/motdotla/dotenv-expand/blob/master/tests/.env) using loaded env vars |
|
|
206
|
+
| [options.paths] | <code>string</code> | [dotenv-expanded](https://github.com/motdotla/dotenv-expand/blob/master/tests/.env) delimited list of input directory paths |
|
|
207
|
+
| [options.pathsDelimiter] | <code>string</code> | paths delimiter string |
|
|
208
|
+
| [options.pathsDelimiterPattern] | <code>string</code> | paths delimiter regex pattern |
|
|
209
|
+
| [config.preHook] | [<code>GetDotenvPreHookCallback</code>](#GetDotenvPreHookCallback) | transforms cli options & executes side effects |
|
|
210
|
+
| [options.privateToken] | <code>string</code> | [dotenv-expanded](https://github.com/motdotla/dotenv-expand/blob/master/tests/.env) token indicating private variables |
|
|
211
|
+
| [config.postHook] | [<code>GetDotenvPostHookCallback</code>](#GetDotenvPostHookCallback) | executes side effects within getdotenv context |
|
|
212
|
+
| [options.vars] | <code>string</code> | [dotenv-expanded](https://github.com/motdotla/dotenv-expand/blob/master/tests/.env) delimited list of explicit environment variable key-value pairs |
|
|
213
|
+
| [options.varsAssignor] | <code>string</code> | variable key-value assignor string |
|
|
214
|
+
| [options.varsAssignorPattern] | <code>string</code> | variable key-value assignor regex pattern |
|
|
215
|
+
| [options.varsDelimiter] | <code>string</code> | variable key-value pair delimiter string |
|
|
216
|
+
| [options.varsDelimiterPattern] | <code>string</code> | variable key-value pair delimiter regex pattern |
|
|
217
|
+
|
|
218
|
+
<a name="GetDotenvOptions"></a>
|
|
219
|
+
|
|
220
|
+
## GetDotenvOptions : <code>Object</code>
|
|
221
|
+
get-dotenv options type
|
|
196
222
|
|
|
197
223
|
**Kind**: global typedef
|
|
198
224
|
**Properties**
|
|
199
225
|
|
|
200
226
|
| Name | Type | Description |
|
|
201
227
|
| --- | --- | --- |
|
|
202
|
-
| [cliInvocation] | <code>string</code> | cli invocation string (used for cli help) |
|
|
203
|
-
| [debug] | <code>bool</code> | debug mode |
|
|
204
|
-
| [defaultEnv] | <code>string</code> | default target environment |
|
|
205
228
|
| [dotenvToken] | <code>string</code> | token indicating a dotenv file |
|
|
206
229
|
| [dynamicPath] | <code>string</code> | path to file exporting an object keyed to dynamic variable functions |
|
|
207
230
|
| [env] | <code>string</code> | target environment |
|
|
@@ -210,24 +233,25 @@ GetDotenv CLI Options type
|
|
|
210
233
|
| [excludeGlobal] | <code>bool</code> | exclude global & dynamic variables |
|
|
211
234
|
| [excludePrivate] | <code>bool</code> | exclude private variables |
|
|
212
235
|
| [excludePublic] | <code>bool</code> | exclude public variables |
|
|
213
|
-
| [
|
|
236
|
+
| [loadProcess] | <code>bool</code> | load dotenv to process.env |
|
|
237
|
+
| [log] | <code>bool</code> | log result to logger |
|
|
214
238
|
| [logger] | <code>function</code> | logger function |
|
|
215
239
|
| [outputPath] | <code>string</code> | if populated, writes consolidated .env file to this path (follows [dotenv-expand rules](https://github.com/motdotla/dotenv-expand/blob/master/tests/.env)) |
|
|
216
|
-
| [paths] | <code>string
|
|
217
|
-
| [privateToken] | <code>string</code> | token indicating private variables
|
|
218
|
-
| [
|
|
240
|
+
| [paths] | <code>Array.<string></code> | array of input directory paths |
|
|
241
|
+
| [privateToken] | <code>string</code> | token indicating private variables |
|
|
242
|
+
| [vars] | <code>object</code> | explicit variables to include |
|
|
219
243
|
|
|
220
244
|
<a name="GetDotenvPreHookCallback"></a>
|
|
221
245
|
|
|
222
|
-
## GetDotenvPreHookCallback ⇒
|
|
246
|
+
## GetDotenvPreHookCallback ⇒ <code>GetDotenvCliOptions</code>
|
|
223
247
|
GetDotenv CLI Pre-hook Callback type. Transforms inbound options & executes side effects.
|
|
224
248
|
|
|
225
249
|
**Kind**: global typedef
|
|
226
|
-
**Returns**:
|
|
250
|
+
**Returns**: <code>GetDotenvCliOptions</code> - transformed GetDotenv CLI Options object (undefined return value is ignored)
|
|
227
251
|
|
|
228
252
|
| Param | Type | Description |
|
|
229
253
|
| --- | --- | --- |
|
|
230
|
-
| options |
|
|
254
|
+
| options | <code>GetDotenvCliOptions</code> | inbound GetDotenv CLI Options object |
|
|
231
255
|
|
|
232
256
|
<a name="GetDotenvPostHookCallback"></a>
|
|
233
257
|
|
|
@@ -238,50 +262,8 @@ GetDotenv CLI Post-hook Callback type. Executes side effects within getdotenv co
|
|
|
238
262
|
|
|
239
263
|
| Param | Type | Description |
|
|
240
264
|
| --- | --- | --- |
|
|
241
|
-
| options | [<code>GetDotenvCliOptions</code>](#GetDotenvCliOptions) | GetDotenv CLI Options object |
|
|
242
265
|
| dotenv | <code>object</code> | dotenv object |
|
|
243
266
|
|
|
244
|
-
<a name="GetDotenvCliConfig"></a>
|
|
245
|
-
|
|
246
|
-
## GetDotenvCliConfig : <code>Object</code>
|
|
247
|
-
GetDotenv CLI Config type
|
|
248
|
-
|
|
249
|
-
**Kind**: global typedef
|
|
250
|
-
**Properties**
|
|
251
|
-
|
|
252
|
-
| Name | Type | Description |
|
|
253
|
-
| --- | --- | --- |
|
|
254
|
-
| [config] | <code>object</code> | config options |
|
|
255
|
-
| [config.defaultOptions] | [<code>GetDotenvCliOptions</code>](#GetDotenvCliOptions) | default options |
|
|
256
|
-
| [config.preHook] | [<code>GetDotenvPreHookCallback</code>](#GetDotenvPreHookCallback) | transforms inbound options & executes side effects |
|
|
257
|
-
| [config.postHook] | [<code>GetDotenvPostHookCallback</code>](#GetDotenvPostHookCallback) | executes side effects within getdotenv context |
|
|
258
|
-
|
|
259
|
-
<a name="OptionsType"></a>
|
|
260
|
-
|
|
261
|
-
## OptionsType : <code>Object</code>
|
|
262
|
-
get-dotenv options type
|
|
263
|
-
|
|
264
|
-
**Kind**: global typedef
|
|
265
|
-
**Properties**
|
|
266
|
-
|
|
267
|
-
| Name | Type | Description |
|
|
268
|
-
| --- | --- | --- |
|
|
269
|
-
| [dotenvToken] | <code>string</code> | token indicating a dotenv file |
|
|
270
|
-
| [dynamicPath] | <code>string</code> | path to file exporting an object keyed to dynamic variable functions |
|
|
271
|
-
| [env] | <code>string</code> | target environment |
|
|
272
|
-
| [excludeDynamic] | <code>bool</code> | exclude dynamic variables |
|
|
273
|
-
| [excludeEnv] | <code>bool</code> | exclude environment-specific variables |
|
|
274
|
-
| [excludeGlobal] | <code>bool</code> | exclude global & dynamic variables |
|
|
275
|
-
| [excludePrivate] | <code>bool</code> | exclude private variables |
|
|
276
|
-
| [excludePublic] | <code>bool</code> | exclude public variables |
|
|
277
|
-
| [loadProcess] | <code>bool</code> | load dotenv to process.env |
|
|
278
|
-
| [log] | <code>bool</code> | log result to logger |
|
|
279
|
-
| [logger] | <code>function</code> | logger function |
|
|
280
|
-
| [outputPath] | <code>string</code> | if populated, writes consolidated .env file to this path (follows [dotenv-expand rules](https://github.com/motdotla/dotenv-expand/blob/master/tests/.env)) |
|
|
281
|
-
| [paths] | <code>Array.<string></code> | array of input directory paths |
|
|
282
|
-
| [privateToken] | <code>string</code> | token indicating private variables |
|
|
283
|
-
| [vars] | <code>object</code> | explicit variables to include |
|
|
284
|
-
|
|
285
267
|
|
|
286
268
|
---
|
|
287
269
|
|
package/bin/getdotenv/index.js
CHANGED
|
@@ -6,20 +6,25 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.getDotenvSync = exports.getDotenv = void 0;
|
|
7
7
|
var _dotenvExpand = require("dotenv-expand");
|
|
8
8
|
var _fsExtra = _interopRequireDefault(require("fs-extra"));
|
|
9
|
+
var _lodash = _interopRequireDefault(require("lodash.pickby"));
|
|
9
10
|
var _path = _interopRequireDefault(require("path"));
|
|
10
11
|
var _nanoid = require("nanoid");
|
|
11
|
-
var
|
|
12
|
+
var _options = require("./options.js");
|
|
12
13
|
var _readDotenv = require("./readDotenv.js");
|
|
13
14
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
14
15
|
// npm imports
|
|
15
16
|
|
|
16
17
|
// lib imports
|
|
17
18
|
|
|
19
|
+
const pruneVars = (getdotenvDefaultOptions, options) => (0, _lodash.default)({
|
|
20
|
+
...(getdotenvDefaultOptions.vars ?? {}),
|
|
21
|
+
...(options.vars ?? {})
|
|
22
|
+
}, v => v?.length);
|
|
23
|
+
|
|
18
24
|
/**
|
|
19
25
|
* get-dotenv options type
|
|
20
26
|
*
|
|
21
|
-
* @typedef {Object}
|
|
22
|
-
*
|
|
27
|
+
* @typedef {Object} GetDotenvOptions
|
|
23
28
|
* @property {string} [dotenvToken] - token indicating a dotenv file
|
|
24
29
|
* @property {string} [dynamicPath] - path to file exporting an object keyed to dynamic variable functions
|
|
25
30
|
* @property {string} [env] - target environment
|
|
@@ -43,7 +48,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
43
48
|
* @async
|
|
44
49
|
* @function getDotenv
|
|
45
50
|
*
|
|
46
|
-
* @param {
|
|
51
|
+
* @param {GetDotenvOptions} [options] - options object
|
|
47
52
|
*
|
|
48
53
|
* @returns {Promise<object>} The combined parsed dotenv object.
|
|
49
54
|
*/
|
|
@@ -52,8 +57,8 @@ const getDotenv = async function () {
|
|
|
52
57
|
// Apply defaults.
|
|
53
58
|
let {
|
|
54
59
|
dotenvToken,
|
|
55
|
-
env,
|
|
56
60
|
dynamicPath,
|
|
61
|
+
env,
|
|
57
62
|
excludeDynamic,
|
|
58
63
|
excludeEnv,
|
|
59
64
|
excludeGlobal,
|
|
@@ -61,15 +66,15 @@ const getDotenv = async function () {
|
|
|
61
66
|
excludePublic,
|
|
62
67
|
loadProcess,
|
|
63
68
|
log,
|
|
64
|
-
logger,
|
|
69
|
+
logger = console.log,
|
|
65
70
|
outputPath,
|
|
66
71
|
paths,
|
|
67
|
-
privateToken
|
|
68
|
-
vars = {}
|
|
72
|
+
privateToken
|
|
69
73
|
} = {
|
|
70
|
-
...
|
|
74
|
+
..._options.getdotenvDefaultOptions,
|
|
71
75
|
...options
|
|
72
76
|
};
|
|
77
|
+
const vars = pruneVars(_options.getdotenvDefaultOptions, options);
|
|
73
78
|
|
|
74
79
|
// Read .env files.
|
|
75
80
|
const loaded = await paths.reduce(async (e, p) => {
|
|
@@ -101,7 +106,7 @@ const getDotenv = async function () {
|
|
|
101
106
|
});
|
|
102
107
|
|
|
103
108
|
// Process dynamic variables.
|
|
104
|
-
if (dynamicPath && !excludeDynamic) {
|
|
109
|
+
if (dynamicPath && !excludeDynamic && (await _fsExtra.default.exists(dynamicPath))) {
|
|
105
110
|
const dynamic = new Function(`return ${(await _fsExtra.default.readFile(dynamicPath)).toString()}`)()(dotenv);
|
|
106
111
|
Object.keys(dynamic).forEach(key => {
|
|
107
112
|
Object.assign(dotenv, {
|
|
@@ -129,8 +134,8 @@ const getDotenv = async function () {
|
|
|
129
134
|
if (loadProcess) Object.assign(process.env, dotenv, {
|
|
130
135
|
getdotenvOptions: JSON.stringify({
|
|
131
136
|
dotenvToken,
|
|
132
|
-
env,
|
|
133
137
|
dynamicPath,
|
|
138
|
+
env,
|
|
134
139
|
excludeDynamic,
|
|
135
140
|
excludeEnv,
|
|
136
141
|
excludeGlobal,
|
|
@@ -151,7 +156,7 @@ const getDotenv = async function () {
|
|
|
151
156
|
*
|
|
152
157
|
* @function getDotenvSync
|
|
153
158
|
*
|
|
154
|
-
* @param {
|
|
159
|
+
* @param {GetDotenvOptions} [options] - options object
|
|
155
160
|
*
|
|
156
161
|
* @returns {Object} The combined parsed dotenv object.
|
|
157
162
|
*/
|
|
@@ -161,8 +166,8 @@ const getDotenvSync = function () {
|
|
|
161
166
|
// Apply defaults.
|
|
162
167
|
let {
|
|
163
168
|
dotenvToken,
|
|
164
|
-
env,
|
|
165
169
|
dynamicPath,
|
|
170
|
+
env,
|
|
166
171
|
excludeDynamic,
|
|
167
172
|
excludeEnv,
|
|
168
173
|
excludeGlobal,
|
|
@@ -170,14 +175,15 @@ const getDotenvSync = function () {
|
|
|
170
175
|
excludePublic,
|
|
171
176
|
loadProcess,
|
|
172
177
|
log,
|
|
178
|
+
logger = console.log,
|
|
173
179
|
outputPath,
|
|
174
180
|
paths,
|
|
175
|
-
privateToken
|
|
176
|
-
vars
|
|
181
|
+
privateToken
|
|
177
182
|
} = {
|
|
178
|
-
...
|
|
183
|
+
..._options.getdotenvDefaultOptions,
|
|
179
184
|
...options
|
|
180
185
|
};
|
|
186
|
+
const vars = pruneVars(_options.getdotenvDefaultOptions, options);
|
|
181
187
|
|
|
182
188
|
// Read .env files.
|
|
183
189
|
const loaded = paths.reduce((e, p) => {
|
|
@@ -208,7 +214,7 @@ const getDotenvSync = function () {
|
|
|
208
214
|
});
|
|
209
215
|
|
|
210
216
|
// Process dynamic variables.
|
|
211
|
-
if (dynamicPath && !excludeDynamic) {
|
|
217
|
+
if (dynamicPath && !excludeDynamic && _fsExtra.default.existsSync(dynamicPath)) {
|
|
212
218
|
const dynamic = new Function(`return ${_fsExtra.default.readFileSync(dynamicPath).toString()}`)()(dotenv);
|
|
213
219
|
Object.keys(dynamic).forEach(key => {
|
|
214
220
|
Object.assign(dotenv, {
|
|
@@ -230,7 +236,7 @@ const getDotenvSync = function () {
|
|
|
230
236
|
}
|
|
231
237
|
|
|
232
238
|
// Log result.
|
|
233
|
-
if (log)
|
|
239
|
+
if (log) logger(dotenv);
|
|
234
240
|
|
|
235
241
|
// Load process.env.
|
|
236
242
|
if (loadProcess) Object.assign(process.env, dotenv, {
|