@dotenvx/dotenvx 0.5.0 → 0.6.0
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 +60 -10
- package/package.json +2 -2
- package/src/cli/dotenvx.js +3 -0
- package/src/cli/ignores.js +67 -0
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]
|
|
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]
|
|
204
|
+
[dotenvx][INFO] injecting 13 environment variables from .env.local,.env
|
|
154
205
|
```
|
|
155
206
|
|
|
156
207
|
|
|
@@ -188,7 +239,7 @@ Run it with `dotenvx`.
|
|
|
188
239
|
|
|
189
240
|
```sh
|
|
190
241
|
$ dotenvx run -- node index.js
|
|
191
|
-
[dotenvx
|
|
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
|
|
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
|
|
217
|
-
[dotenvx
|
|
218
|
-
[dotenvx
|
|
219
|
-
[dotenvx
|
|
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
|
|
286
|
+
[dotenvx][INFO] injecting 1 environment variable from .env
|
|
236
287
|
Hello World
|
|
237
288
|
```
|
|
238
289
|
|
|
@@ -269,7 +320,6 @@ npx @dotenvx/dotenvx help
|
|
|
269
320
|
npm i @dotenvx/dotenvx --save
|
|
270
321
|
```
|
|
271
322
|
```json
|
|
272
|
-
// package.json
|
|
273
323
|
"scripts": {
|
|
274
324
|
"start": "./node_modules/.bin/dotenvx run -- nodex index.js"
|
|
275
325
|
}
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.
|
|
2
|
+
"version": "0.6.0",
|
|
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",
|
package/src/cli/dotenvx.js
CHANGED
|
@@ -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 }
|