@dotenvx/dotenvx 0.5.0 → 0.6.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 CHANGED
@@ -72,6 +72,28 @@ More examples
72
72
  Hello World
73
73
  ```
74
74
 
75
+ </details>
76
+ * <details><summary>Java ☕️</summary><br>
77
+
78
+ ```sh
79
+ $ echo 'public class Index { public static void main(String[] args) { System.out.println("Hello " + System.getenv("HELLO")); } }' > index.java
80
+
81
+ $ dotenvx run -- java index.java
82
+ Hello World
83
+ ```
84
+
85
+ </details>
86
+ * <details><summary>.NET 🔵</summary><br>
87
+
88
+ ```sh
89
+ $ dotnet new console -n HelloWorld -o HelloWorld
90
+ $ cd HelloWorld
91
+ $ echo 'Console.WriteLine($"Hello {Environment.GetEnvironmentVariable("HELLO")}");' > Program.cs && echo "HELLO=World" > .env
92
+
93
+ $ dotenvx run -- dotnet run
94
+ Hello World
95
+ ```
96
+
75
97
  </details>
76
98
  * <details><summary>Frameworks ▲</summary><br>
77
99
 
@@ -124,6 +146,35 @@ More examples
124
146
  ```
125
147
 
126
148
  </details>
149
+ * <details><summary>npm</summary><br>
150
+
151
+ ```sh
152
+ $ npm install @dotenvx/dotenvx --save
153
+ ```
154
+
155
+ ```json
156
+ {
157
+ "scripts": {
158
+ "start": "./node_modules/.bin/dotenvx run -- node index.js"
159
+ },
160
+ "dependencies": {
161
+ "@dotenvx/dotenvx": "^0.5.0"
162
+ }
163
+ }
164
+ ```
165
+
166
+ ```sh
167
+ $ npm run start
168
+
169
+ > start
170
+ > ./node_modules/.bin/dotenvx run -- node index.js
171
+
172
+ [dotenvx][INFO] injecting 1 environment variable from .env
173
+ Hello World
174
+ ```
175
+
176
+ </details>
177
+
127
178
  * <details><summary>Git</summary><br>
128
179
 
129
180
  ```sh
@@ -143,14 +194,14 @@ Pass the `--env-file` flag (shorthand `-f`) to run any environment from a `.env.
143
194
 
144
195
  ```sh
145
196
  $ dotenvx run --env-file=.env.production -- node index.js
146
- [dotenvx][INFO] Injecting 12 production environment variables into your application process
197
+ [dotenvx][INFO] injecting 12 environment variables from .env.production
147
198
  ```
148
199
 
149
200
  Combine multiple `.env` files if you like.
150
201
 
151
202
  ```
152
203
  $ dotenvx run --env-file=.env.local --env-file=.env -- node index.js
153
- [dotenvx][INFO] Injecting 12 local, 1 development environment variables into your application process
204
+ [dotenvx][INFO] injecting 13 environment variables from .env.local,.env
154
205
  ```
155
206
 
156
207
  &nbsp;
@@ -188,7 +239,7 @@ Run it with `dotenvx`.
188
239
 
189
240
  ```sh
190
241
  $ dotenvx run -- node index.js
191
- [dotenvx@x.x.x][WARN] ENOENT: no such file or directory, open '/../../.env'
242
+ [dotenvx][WARN] ENOENT: no such file or directory, open '/../../.env'
192
243
  Hello undefined
193
244
  ```
194
245
 
@@ -205,7 +256,7 @@ Run it again.
205
256
 
206
257
  ```sh
207
258
  $ dotenvx run -- node index.js
208
- [dotenvx@x.x.x][INFO] Injecting 0 environment variables into your application process
259
+ [dotenvx][INFO] injecting 0 environment variables from .env
209
260
  Hello undefined
210
261
  ```
211
262
 
@@ -213,10 +264,10 @@ Hrm, still undefined. Pass the `--debug` flag to debug the issue. I'll give you
213
264
 
214
265
  ```sh
215
266
  $ dotenvx run --debug -- node index.js
216
- [dotenvx@x.x.x][VERBOSE] Loading env from /../../.env
217
- [dotenvx@x.x.x][DEBUG] Reading env from /../../.env
218
- [dotenvx@x.x.x][DEBUG] Parsing env from /../../.env
219
- [dotenvx@x.x.x][DEBUG] {"JELLO":"World"}
267
+ [dotenvx][VERBOSE] Loading env from /../../.env
268
+ [dotenvx][DEBUG] Reading env from /../../.env
269
+ [dotenvx][DEBUG] Parsing env from /../../.env
270
+ [dotenvx][DEBUG] {"JELLO":"World"}
220
271
 
221
272
  # Oops, HELLO not JELLO ^^
222
273
  ```
@@ -232,7 +283,7 @@ One last time. [Le tired](https://youtu.be/kCpjgl2baLs?t=45).
232
283
 
233
284
  ```sh
234
285
  $ dotenvx run -- node index.js
235
- [dotenvx@x.x.x][INFO] Injecting 1 environment variable into your application process
286
+ [dotenvx][INFO] injecting 1 environment variable from .env
236
287
  Hello World
237
288
  ```
238
289
 
@@ -251,51 +302,41 @@ brew install dotenvx/brew/dotenvx
251
302
 
252
303
  ### Other Ways to Install
253
304
 
254
- 1. After `brew`, installing globally using [`npm`](https://www.npmjs.com/package/@dotenvx/dotenvx) is easiest:
305
+ #### 1. global npm
306
+
307
+ After `brew`, installing globally using [`npm`](https://www.npmjs.com/package/@dotenvx/dotenvx) is easiest:
255
308
 
256
309
  ```sh
257
310
  npm install @dotenvx/dotenvx --global
258
311
  ```
259
312
 
260
- 2. Or use with [`npx`](https://www.npmjs.com/package/npx):
313
+ #### 2. local npm
261
314
 
262
- ```sh
263
- npx @dotenvx/dotenvx help
264
- ```
265
-
266
- 3. Or install in your `package.json`
315
+ Or install in your `package.json`:
267
316
 
268
317
  ```sh
269
318
  npm i @dotenvx/dotenvx --save
270
319
  ```
271
320
  ```json
272
- // package.json
273
- "scripts": {
274
- "start": "./node_modules/.bin/dotenvx run -- nodex index.js"
321
+ {
322
+ "scripts": {
323
+ "start": "./node_modules/.bin/dotenvx run -- node index.js"
324
+ },
325
+ "dependencies": {
326
+ "@dotenvx/dotenvx": "^0.6.0"
327
+ }
275
328
  }
276
329
  ```
277
330
 
278
- 3. Or download it directly as a standalone binary:
331
+ #### 3. standalone binary
279
332
 
280
- ```sh
281
- curl -fsS https://dotenvx.sh/ | sh
282
- ```
333
+ Or download it directly as a standalone binary:
283
334
 
284
335
  ```sh
285
- # download it to `./dotenvx`
336
+ # download it to `/user/local/bin/dotenvx`
286
337
  curl -fsS https://dotenvx.sh/ | sh
287
338
 
288
339
  # check it works
289
- ./dotenvx help
290
-
291
- # move it to `/usr/local/bin/dotenvx`
292
- sudo install -m 755 dotenvx /usr/local/bin
293
-
294
- # check it still works
295
- /usr/local/bin/dotenvx help
296
-
297
- # check it is in your path
298
- which dotenv
299
340
  dotenvx help
300
341
  ```
301
342
 
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.5.0",
2
+ "version": "0.6.1",
3
3
  "name": "@dotenvx/dotenvx",
4
4
  "description": "a better dotenv–from the creator of `dotenv`",
5
5
  "author": "@motdotla",
@@ -21,7 +21,7 @@
21
21
  "scripts": {
22
22
  "standard": "standard",
23
23
  "standard:fix": "standard --fix",
24
- "test": "jest"
24
+ "test": "jest --verbose"
25
25
  },
26
26
  "dependencies": {
27
27
  "commander": "^11.1.0",
@@ -9,6 +9,7 @@ const ENCODING = 'utf8'
9
9
 
10
10
  const logger = require('./../shared/logger')
11
11
  const helpers = require('./helpers')
12
+ const { AppendToIgnores } = require('./ignores')
12
13
  const packageJson = require('./../shared/packageJson')
13
14
  const main = require('./../lib/main')
14
15
 
@@ -19,6 +20,8 @@ program
19
20
  .option('-v, --verbose', 'sets log level to verbose')
20
21
  .option('-d, --debug', 'sets log level to debug')
21
22
  .hook('preAction', (thisCommand, actionCommand) => {
23
+ new AppendToIgnores().run()
24
+
22
25
  const options = thisCommand.opts()
23
26
 
24
27
  if (options.logLevel) {
@@ -0,0 +1,67 @@
1
+ const fs = require('fs')
2
+
3
+ const FORMATS = ['.env*', '!.env.vault', '.flaskenv*']
4
+
5
+ class Generic {
6
+ constructor (filename, touchFile = false) {
7
+ this.filename = filename
8
+ this.formats = FORMATS
9
+ this.touchFile = touchFile
10
+ }
11
+
12
+ append (str) {
13
+ fs.appendFileSync(this.filename, `\n${str}`)
14
+ }
15
+
16
+ run () {
17
+ if (!fs.existsSync(this.filename)) {
18
+ if (this.touchFile === true) {
19
+ fs.writeFileSync(this.filename, '')
20
+ } else {
21
+ return
22
+ }
23
+ }
24
+
25
+ const lines = fs.readFileSync(this.filename, 'utf8').split(/\r?\n/)
26
+ this.formats.forEach(format => {
27
+ if (!lines.includes(format.trim())) {
28
+ this.append(format)
29
+ }
30
+ })
31
+ }
32
+ }
33
+
34
+ class Git {
35
+ run () {
36
+ new Generic('.gitignore', true).run()
37
+ }
38
+ }
39
+
40
+ class Docker {
41
+ run () {
42
+ new Generic('.dockerignore').run()
43
+ }
44
+ }
45
+
46
+ class Npm {
47
+ run () {
48
+ new Generic('.npmignore').run()
49
+ }
50
+ }
51
+
52
+ class Vercel {
53
+ run () {
54
+ new Generic('.vercelignore').run()
55
+ }
56
+ }
57
+
58
+ class AppendToIgnores {
59
+ run () {
60
+ new Docker().run()
61
+ new Git().run()
62
+ new Npm().run()
63
+ new Vercel().run()
64
+ }
65
+ }
66
+
67
+ module.exports = { AppendToIgnores, Generic }
@@ -7,14 +7,10 @@ const transports = winston.transports
7
7
 
8
8
  const packageJson = require('./packageJson')
9
9
 
10
- function pad (word) {
11
- return word.padEnd(9, ' ')
12
- }
13
-
14
10
  const dotenvxFormat = printf(({ level, message, label, timestamp }) => {
15
11
  const formattedMessage = typeof message === 'object' ? JSON.stringify(message) : message
16
12
 
17
- return `[dotenvx@${packageJson.version}]${pad(`[${level.toUpperCase()}]`)} ${formattedMessage}`
13
+ return `[dotenvx@${packageJson.version}][${level.toUpperCase()}] ${formattedMessage}`
18
14
  })
19
15
 
20
16
  const logger = createLogger({