@dotenvx/dotenvx 1.11.5 → 1.12.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/CHANGELOG.md CHANGED
@@ -2,7 +2,11 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
- ## [Unreleased](https://github.com/dotenvx/dotenvx/compare/v1.11.5...main)
5
+ ## [Unreleased](https://github.com/dotenvx/dotenvx/compare/v1.12.0...main)
6
+
7
+ ## 1.12.0
8
+
9
+ * add `dotenvx get --format shell` option ([#363](https://github.com/dotenvx/dotenvx/pull/363))
6
10
 
7
11
  ## 1.11.5
8
12
 
package/README.md CHANGED
@@ -1041,6 +1041,31 @@ More examples
1041
1041
  {"HELLO":"World"}
1042
1042
  ```
1043
1043
 
1044
+ </details>
1045
+ * <details><summary>`get --format shell`</summary><br>
1046
+
1047
+ Return a shell formatted response of all key/value pairs in a `.env` file.
1048
+
1049
+ ```sh
1050
+ $ echo "HELLO=World\n" > .env
1051
+ $ echo "KEY=value\n" >> .env
1052
+
1053
+ $ dotenvx get --format shell
1054
+ HELLO="World" KEY="value"
1055
+ ```
1056
+
1057
+ This can be useful when combined with `env` on the command line.
1058
+
1059
+ ```
1060
+ $ env $(dotenvx get format --shell) your-command
1061
+ ```
1062
+
1063
+ or with `export`.
1064
+
1065
+ ```
1066
+ $ export $(dotenvx get format --shell) your-command
1067
+ ```
1068
+
1044
1069
  </details>
1045
1070
  * <details><summary>`get --all`</summary><br>
1046
1071
 
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.11.5",
2
+ "version": "1.12.0",
3
3
  "name": "@dotenvx/dotenvx",
4
4
  "description": "a better dotenv–from the creator of `dotenv`",
5
5
  "author": "@motdotla",
@@ -20,21 +20,33 @@ function get (key) {
20
20
  envs = this.envs
21
21
  }
22
22
 
23
- const value = main.get(key, envs, options.overload, process.env.DOTENV_KEY, options.all)
23
+ const results = main.get(key, envs, options.overload, process.env.DOTENV_KEY, options.all)
24
+
25
+ if (typeof results === 'object' && results !== null) {
26
+ // inline shell format - env $(dotenvx get --format shell) your-command
27
+ if (options.format === 'shell') {
28
+ let inline = ''
29
+ for (const [key, value] of Object.entries(results)) {
30
+ inline += `${key}="${value}" `
31
+ }
32
+ inline = inline.trim()
33
+
34
+ process.stdout.write(inline)
35
+ // json format
36
+ } else {
37
+ let space = 0
38
+ if (options.prettyPrint) {
39
+ space = 2
40
+ }
24
41
 
25
- if (typeof value === 'object' && value !== null) {
26
- let space = 0
27
- if (options.prettyPrint) {
28
- space = 2
42
+ process.stdout.write(JSON.stringify(results, null, space))
29
43
  }
30
-
31
- process.stdout.write(JSON.stringify(value, null, space))
32
44
  } else {
33
- if (value === undefined) {
45
+ if (results === undefined) {
34
46
  process.stdout.write('')
35
47
  process.exit(1)
36
48
  } else {
37
- process.stdout.write(value)
49
+ process.stdout.write(results)
38
50
  }
39
51
  }
40
52
  }
@@ -75,6 +75,7 @@ program.command('get')
75
75
  .option('--convention <name>', 'load a .env convention (available conventions: [\'nextjs\'])')
76
76
  .option('-a, --all', 'include all machine envs as well')
77
77
  .option('-pp, --pretty-print', 'pretty print output')
78
+ .option('--format <type>', 'format of the output (json, shell)', 'json')
78
79
  .action(function (...args) {
79
80
  this.envs = envs
80
81
 
@@ -14,12 +14,6 @@ function detectEncoding (filepath) {
14
14
  return 'utf8'
15
15
  }
16
16
 
17
- // Check if the file is entirely US-ASCII (0x00 - 0x7F), which is valid UTF-8
18
- for (let i = 0; i < buffer.length; i++) {
19
- if (buffer[i] > 0x7F) {
20
- break
21
- }
22
- }
23
17
  /* c8 ignore stop */
24
18
 
25
19
  return 'utf8'