@dotenvx/dotenvx 0.36.1 → 0.37.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/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.36.1",
2
+ "version": "0.37.0",
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,59 @@ 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 } = main.status(directory)
13
14
 
14
- const changeFilenames = []
15
- const nochangeFilenames = []
15
+ const changeFilenames = []
16
+ const nochangeFilenames = []
16
17
 
17
- for (const row of nochanges) {
18
- nochangeFilenames.push(row.filename)
19
- }
18
+ for (const row of nochanges) {
19
+ nochangeFilenames.push(row.filename)
20
+ }
20
21
 
21
- if (nochangeFilenames.length > 0) {
22
- logger.blank(`no changes (${nochangeFilenames.join(', ')})`)
23
- }
22
+ if (nochangeFilenames.length > 0) {
23
+ logger.blank(`no changes (${nochangeFilenames.join(', ')})`)
24
+ }
24
25
 
25
- for (const row of changes) {
26
- changeFilenames.push(row.filename)
27
- }
26
+ for (const row of changes) {
27
+ changeFilenames.push(row.filename)
28
+ }
28
29
 
29
- if (changeFilenames.length > 0) {
30
- logger.warn(`changes (${changeFilenames.join(', ')})`)
31
- }
30
+ if (changeFilenames.length > 0) {
31
+ logger.warn(`changes (${changeFilenames.join(', ')})`)
32
+ }
32
33
 
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
- }
34
+ for (const row of changes) {
35
+ logger.blank('')
36
+ const padding = ' '
37
+ logger.blank(`${padding}\`\`\`${row.filename}`)
38
+ const paddedResult = row.coloredDiff.split('\n').map(line => padding + line).join('\n')
39
+ console.log(paddedResult)
40
+ logger.blank(`${padding}\`\`\``)
41
+ }
42
+
43
+ if (changeFilenames.length > 0) {
44
+ logger.blank('')
45
+ const optionalDirectory = directory === '.' ? '' : ` ${directory}`
46
+ logger.blank(`run [dotenvx encrypt${optionalDirectory}] to apply changes to .env.vault`)
47
+ }
41
48
 
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`)
49
+ if (nochangeFilenames.length < 1 && changeFilenames.length < 1) {
50
+ logger.warn('no .env* files.')
51
+ logger.help('? add one with [echo "HELLO=World" > .env] and then run [dotenvx status]')
52
+ }
53
+ } catch (error) {
54
+ logger.error(error.message)
55
+ if (error.help) {
56
+ logger.help(error.help)
57
+ }
58
+ if (error.debug) {
59
+ logger.debug(error.debug)
60
+ }
61
+ if (error.code) {
62
+ logger.debug(`ERROR_CODE: ${error.code}`)
63
+ }
64
+ process.exit(1)
46
65
  }
47
66
  }
48
67
 
@@ -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