@dotenvx/dotenvx 0.36.1 → 0.37.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
@@ -490,7 +490,25 @@ More examples
490
490
  Available log levels are `error, warn, info, verbose, debug, silly`
491
491
 
492
492
  </details>
493
+ * <details><summary>`--convention` flag</summary><br>
493
494
 
495
+ Want to load envs conveniently usng the same convention as Next.js? Set `--convention` to `nextjs`:
496
+
497
+ ```sh
498
+ $ echo "HELLO=development local" > .env.development.local
499
+ $ echo "HELLO=local" > .env.local
500
+ $ echo "HELLO=development" > .env.development
501
+ $ echo "HELLO=env" > .env
502
+
503
+ $ dotenvx run --convention=nextjs -- node index.js
504
+ Hello development local
505
+ ```
506
+
507
+ See [next.js environment variable load order](https://nextjs.org/docs/pages/building-your-application/configuring/environment-variables#environment-variable-load-order)
508
+
509
+ (more conventions available upon request)
510
+
511
+ </details>
494
512
 
495
513
  &nbsp;
496
514
 
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.36.1",
2
+ "version": "0.37.1",
3
3
  "name": "@dotenvx/dotenvx",
4
4
  "description": "a better dotenv–from the creator of `dotenv`",
5
5
  "author": "@motdotla",
@@ -5,6 +5,8 @@ const logger = require('./../../shared/logger')
5
5
 
6
6
  const Run = require('./../../lib/services/run')
7
7
 
8
+ const conventions = require('./../../lib/helpers/conventions')
9
+
8
10
  const executeCommand = async function (commandArgs, env) {
9
11
  const signals = [
10
12
  'SIGHUP', 'SIGQUIT', 'SIGILL', 'SIGTRAP', 'SIGABRT',
@@ -102,9 +104,15 @@ async function run () {
102
104
  const options = this.opts()
103
105
  logger.debug(`options: ${JSON.stringify(options)}`)
104
106
 
105
- const envs = this.envs
106
-
107
107
  try {
108
+ let envs = []
109
+ // handle shorthand conventions - like --convention=nextjs
110
+ if (options.convention) {
111
+ envs = conventions(options.convention).concat(this.envs)
112
+ } else {
113
+ envs = this.envs
114
+ }
115
+
108
116
  const {
109
117
  processedEnvs,
110
118
  readableStrings,
@@ -9,40 +9,69 @@ function status (directory) {
9
9
  const options = this.opts()
10
10
  logger.debug(`options: ${JSON.stringify(options)}`)
11
11
 
12
- const { changes, nochanges } = main.status(directory)
12
+ try {
13
+ const { changes, nochanges, untracked } = main.status(directory)
13
14
 
14
- const changeFilenames = []
15
- const nochangeFilenames = []
15
+ const changeFilenames = []
16
+ const nochangeFilenames = []
17
+ const untrackedFilenames = []
16
18
 
17
- for (const row of nochanges) {
18
- nochangeFilenames.push(row.filename)
19
- }
19
+ for (const row of nochanges) {
20
+ nochangeFilenames.push(row.filename)
21
+ }
20
22
 
21
- if (nochangeFilenames.length > 0) {
22
- logger.blank(`no changes (${nochangeFilenames.join(', ')})`)
23
- }
23
+ if (nochangeFilenames.length > 0) {
24
+ logger.blank(`no changes (${nochangeFilenames.join(', ')})`)
25
+ }
24
26
 
25
- for (const row of changes) {
26
- changeFilenames.push(row.filename)
27
- }
27
+ for (const row of changes) {
28
+ changeFilenames.push(row.filename)
29
+ }
28
30
 
29
- if (changeFilenames.length > 0) {
30
- logger.warn(`changes (${changeFilenames.join(', ')})`)
31
- }
31
+ if (changeFilenames.length > 0) {
32
+ logger.warn(`changes (${changeFilenames.join(', ')})`)
33
+ }
32
34
 
33
- for (const row of changes) {
34
- logger.blank('')
35
- const padding = ' '
36
- logger.blank(`${padding}\`\`\`${row.filename}`)
37
- const paddedResult = row.coloredDiff.split('\n').map(line => padding + line).join('\n')
38
- console.log(paddedResult)
39
- logger.blank(`${padding}\`\`\``)
40
- }
35
+ for (const row of changes) {
36
+ logger.blank('')
37
+ const padding = ' '
38
+ logger.blank(`${padding}\`\`\`${row.filename}`)
39
+ const paddedResult = row.coloredDiff.split('\n').map(line => padding + line).join('\n')
40
+ console.log(paddedResult)
41
+ logger.blank(`${padding}\`\`\``)
42
+ }
43
+
44
+ if (changeFilenames.length > 0) {
45
+ logger.blank('')
46
+ const optionalDirectory = directory === '.' ? '' : ` ${directory}`
47
+ logger.blank(`run [dotenvx encrypt${optionalDirectory}] to apply changes to .env.vault`)
48
+ }
49
+
50
+ if (nochangeFilenames.length < 1 && changeFilenames.length < 1) {
51
+ logger.warn('no .env* files.')
52
+ logger.help('? add one with [echo "HELLO=World" > .env] and then run [dotenvx status]')
53
+ }
54
+
55
+ for (const row of untracked) {
56
+ untrackedFilenames.push(row.filename)
57
+ }
41
58
 
42
- if (changeFilenames.length > 0) {
43
- logger.blank('')
44
- const optionalDirectory = directory === '.' ? '' : ` ${directory}`
45
- logger.blank(`run [dotenvx encrypt${optionalDirectory}] to apply changes to .env.vault`)
59
+ if (untrackedFilenames.length > 0) {
60
+ logger.warn(`untracked (${untrackedFilenames.join(', ')})`)
61
+ logger.help(`? track them with [dotenvx encrypt ${directory}]`)
62
+ }
63
+ } catch (error) {
64
+ logger.error(error.message)
65
+ if (error.help) {
66
+ logger.help(error.help)
67
+ }
68
+ if (error.debug) {
69
+ logger.debug(error.debug)
70
+ }
71
+ if (error.code) {
72
+ logger.debug(`ERROR_CODE: ${error.code}`)
73
+ }
74
+ process.exit(1)
46
75
  }
47
76
  }
48
77
 
@@ -69,6 +69,7 @@ program.command('run')
69
69
  .option('-f, --env-file <paths...>', 'path(s) to your env file(s)', collectEnvs('envFile'), [])
70
70
  .option('-fv, --env-vault-file <paths...>', 'path(s) to your .env.vault file(s)', collectEnvs('envVaultFile'), [])
71
71
  .option('-o, --overload', 'override existing env variables')
72
+ .option('--convention <name>', 'load a .env convention (available conventions: [\'nextjs\'])')
72
73
  .action(function (...args) {
73
74
  this.envs = envs
74
75
 
@@ -0,0 +1,29 @@
1
+ function conventions (convention) {
2
+ if (convention === 'nextjs') {
3
+ const nodeEnv = process.env.NODE_ENV || 'development'
4
+
5
+ const envs = []
6
+
7
+ if (['development', 'test', 'production'].includes(nodeEnv)) {
8
+ envs.push({ type: 'envFile', value: `.env.${nodeEnv}.local` })
9
+ }
10
+
11
+ if (['development', 'production'].includes(nodeEnv)) {
12
+ envs.push({ type: 'envFile', value: '.env.local' })
13
+ }
14
+
15
+ if (['development', 'test', 'production'].includes(nodeEnv)) {
16
+ envs.push({ type: 'envFile', value: `.env.${nodeEnv}` })
17
+ }
18
+
19
+ if (['development', 'test', 'production'].includes(nodeEnv)) {
20
+ envs.push({ type: 'envFile', value: '.env' })
21
+ }
22
+
23
+ return envs
24
+ } else {
25
+ throw new Error(`INVALID_CONVENTION: '${convention}'. permitted conventions: ['nextjs']`)
26
+ }
27
+ }
28
+
29
+ module.exports = conventions
@@ -16,6 +16,7 @@ class Status {
16
16
  this.directory = directory
17
17
  this.changes = []
18
18
  this.nochanges = []
19
+ this.untracked = [] // not tracked in .env.vault
19
20
  }
20
21
 
21
22
  run () {
@@ -60,7 +61,14 @@ class Status {
60
61
 
61
62
  // grab decrypted
62
63
  const { processedEnvs } = new Decrypt(this.directory, row.environment).run()
63
- row.decrypted = processedEnvs[0].decrypted
64
+ const result = processedEnvs[0]
65
+
66
+ // handle warnings
67
+ row.decrypted = result.decrypted
68
+ if (result.warning) {
69
+ this.untracked.push(row)
70
+ continue
71
+ }
64
72
 
65
73
  // differences
66
74
  row.differences = diff.diffWords(row.decrypted, row.raw)
@@ -78,7 +86,8 @@ class Status {
78
86
 
79
87
  return {
80
88
  changes: this.changes,
81
- nochanges: this.nochanges
89
+ nochanges: this.nochanges,
90
+ untracked: this.untracked
82
91
  }
83
92
  }
84
93