@dotenvx/dotenvx 0.40.0 → 0.42.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 +31 -0
- package/package.json +1 -1
- package/src/cli/actions/{encryptme.js → convert.js} +4 -4
- package/src/cli/actions/run.js +6 -0
- package/src/cli/actions/vault/convert.js +47 -0
- package/src/cli/commands/vault.js +5 -0
- package/src/cli/dotenvx.js +4 -4
- package/src/lib/helpers/replace.js +1 -1
- package/src/lib/main.js +3 -3
package/README.md
CHANGED
|
@@ -994,6 +994,37 @@ More examples
|
|
|
994
994
|
set HELLO (.env.ci)
|
|
995
995
|
```
|
|
996
996
|
|
|
997
|
+
</details>
|
|
998
|
+
* <details><summary>`convert`</summary><br>
|
|
999
|
+
|
|
1000
|
+
Convert a `.env` file to an encrypted `.env` file.
|
|
1001
|
+
|
|
1002
|
+
```sh
|
|
1003
|
+
$ echo "HELLO=World" > .env
|
|
1004
|
+
|
|
1005
|
+
$ dotenvx convert
|
|
1006
|
+
✔ encrypted (.env)
|
|
1007
|
+
✔ key added to .env.keys (DOTENV_PRIVATE_KEY)
|
|
1008
|
+
ℹ add .env.keys to .gitignore: [echo ".env.keys" >> .gitignore]
|
|
1009
|
+
ℹ run [DOTENV_PRIVATE_KEY='122...0b8' dotenvx run -- yourcommand] to test decryption locally
|
|
1010
|
+
```
|
|
1011
|
+
|
|
1012
|
+
</details>
|
|
1013
|
+
* <details><summary>`convert -f`</summary><br>
|
|
1014
|
+
|
|
1015
|
+
Convert a specified `.env` file to an encrypted `.env` file.
|
|
1016
|
+
|
|
1017
|
+
```sh
|
|
1018
|
+
$ echo "HELLO=World" > .env
|
|
1019
|
+
$ echo "HELLO=Production" > .env.production
|
|
1020
|
+
|
|
1021
|
+
$ dotenvx convert -f .env.production
|
|
1022
|
+
✔ encrypted (.env.production)
|
|
1023
|
+
✔ key added to .env.keys (DOTENV_PRIVATE_KEY_PRODUCTION)
|
|
1024
|
+
ℹ add .env.keys to .gitignore: [echo ".env.keys" >> .gitignore]
|
|
1025
|
+
ℹ run [DOTENV_PRIVATE_KEY_PRODUCTION='bff..bc4' dotenvx run -- yourcommand] to test decryption locally
|
|
1026
|
+
```
|
|
1027
|
+
|
|
997
1028
|
</details>
|
|
998
1029
|
* <details><summary>`ls`</summary><br>
|
|
999
1030
|
|
package/package.json
CHANGED
|
@@ -7,7 +7,7 @@ const isIgnoringDotenvKeys = require('../../lib/helpers/isIgnoringDotenvKeys')
|
|
|
7
7
|
|
|
8
8
|
const ENCODING = 'utf8'
|
|
9
9
|
|
|
10
|
-
async function
|
|
10
|
+
async function convert () {
|
|
11
11
|
const options = this.opts()
|
|
12
12
|
logger.debug(`options: ${JSON.stringify(options)}`)
|
|
13
13
|
|
|
@@ -16,14 +16,14 @@ async function encryptme () {
|
|
|
16
16
|
processedEnvFiles,
|
|
17
17
|
changedFilepaths,
|
|
18
18
|
unchangedFilepaths
|
|
19
|
-
} = main.
|
|
19
|
+
} = main.convert(options.envFile)
|
|
20
20
|
|
|
21
21
|
for (const processedEnvFile of processedEnvFiles) {
|
|
22
22
|
logger.verbose(`encrypting ${processedEnvFile.envFilepath} (${processedEnvFile.filepath})`)
|
|
23
23
|
if (processedEnvFile.error) {
|
|
24
24
|
if (processedEnvFile.error.code === 'MISSING_ENV_FILE') {
|
|
25
25
|
logger.warn(processedEnvFile.error)
|
|
26
|
-
logger.help(`? add one with [echo "HELLO=World" > ${processedEnvFile.envFilepath}] and re-run [dotenvx
|
|
26
|
+
logger.help(`? add one with [echo "HELLO=World" > ${processedEnvFile.envFilepath}] and re-run [dotenvx convert]`)
|
|
27
27
|
} else {
|
|
28
28
|
logger.warn(processedEnvFile.error)
|
|
29
29
|
}
|
|
@@ -70,4 +70,4 @@ async function encryptme () {
|
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
-
module.exports =
|
|
73
|
+
module.exports = convert
|
package/src/cli/actions/run.js
CHANGED
|
@@ -113,6 +113,12 @@ async function run () {
|
|
|
113
113
|
envs = this.envs
|
|
114
114
|
}
|
|
115
115
|
|
|
116
|
+
if (process.env.DOTENV_KEY) {
|
|
117
|
+
logger.warn('DEPRECATION NOTICE: Setting DOTENV_KEY with .env.vault is deprecated.')
|
|
118
|
+
logger.warn('DEPRECATION NOTICE: Run [dotenvx vault convert] for instructions on converting your .env.vault file to encrypted .env files (using public key encryption algorithm secp256k1)')
|
|
119
|
+
logger.warn('DEPRECATION NOTICE: Read more at [https://github.com/dotenvx/dotenvx/blob/main/CHANGELOG.md#0380]')
|
|
120
|
+
}
|
|
121
|
+
|
|
116
122
|
const {
|
|
117
123
|
processedEnvs,
|
|
118
124
|
readableStrings,
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
const logger = require('./../../../shared/logger')
|
|
2
|
+
|
|
3
|
+
function convert (directory) {
|
|
4
|
+
// debug args
|
|
5
|
+
logger.debug(`directory: ${directory}`)
|
|
6
|
+
|
|
7
|
+
const options = this.opts()
|
|
8
|
+
logger.debug(`options: ${JSON.stringify(options)}`)
|
|
9
|
+
|
|
10
|
+
try {
|
|
11
|
+
logger.help2('To convert your .env.vault file to encrypted .env file(s):')
|
|
12
|
+
logger.help('')
|
|
13
|
+
logger.help(' 1. Run [dotenvx vault decrypt]')
|
|
14
|
+
logger.help(' 2. Run [ls -a .env*]')
|
|
15
|
+
logger.help('')
|
|
16
|
+
logger.help2('Lastly, convert each .env(.environment) file:')
|
|
17
|
+
logger.help('')
|
|
18
|
+
logger.help(' 3. Run [dotenvx convert -f .env.production]')
|
|
19
|
+
logger.help2('')
|
|
20
|
+
logger.help2('For example:')
|
|
21
|
+
logger.help2('')
|
|
22
|
+
logger.help2(' $ dotenvx convert -f .env')
|
|
23
|
+
logger.help2(' $ dotenvx convert -f .env.ci')
|
|
24
|
+
logger.help2(' $ dotenvx convert -f .env.production')
|
|
25
|
+
logger.help2('')
|
|
26
|
+
logger.help2('Afterward:')
|
|
27
|
+
logger.help2('')
|
|
28
|
+
logger.help2('Update production with your new DOTENV_PRIVATE_KEY_PRODUCTION located in .env.keys')
|
|
29
|
+
logger.help2('')
|
|
30
|
+
logger.success('Learn more at [https://dotenvx.com/docs/quickstart#add-encryption]')
|
|
31
|
+
logger.help2('')
|
|
32
|
+
} catch (error) {
|
|
33
|
+
logger.error(error.message)
|
|
34
|
+
if (error.help) {
|
|
35
|
+
logger.help(error.help)
|
|
36
|
+
}
|
|
37
|
+
if (error.debug) {
|
|
38
|
+
logger.debug(error.debug)
|
|
39
|
+
}
|
|
40
|
+
if (error.code) {
|
|
41
|
+
logger.debug(`ERROR_CODE: ${error.code}`)
|
|
42
|
+
}
|
|
43
|
+
process.exit(1)
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
module.exports = convert
|
|
@@ -7,6 +7,11 @@ const vault = new Command('vault')
|
|
|
7
7
|
vault
|
|
8
8
|
.description('manage .env.vault files')
|
|
9
9
|
|
|
10
|
+
// dotenvx vault convert
|
|
11
|
+
vault.command('convert')
|
|
12
|
+
.description('instructions for converting .env.vault to encrypted env file(s)')
|
|
13
|
+
.action(require('./../actions/vault/convert'))
|
|
14
|
+
|
|
10
15
|
// dotenvx vault encrypt
|
|
11
16
|
vault.command('encrypt')
|
|
12
17
|
.description('encrypt .env.* to .env.vault')
|
package/src/cli/dotenvx.js
CHANGED
|
@@ -103,11 +103,11 @@ program.command('set')
|
|
|
103
103
|
.option('-c, --encrypt', 'encrypt value')
|
|
104
104
|
.action(require('./actions/set'))
|
|
105
105
|
|
|
106
|
-
// dotenvx
|
|
107
|
-
program.command('
|
|
108
|
-
.description('
|
|
106
|
+
// dotenvx convert
|
|
107
|
+
program.command('convert')
|
|
108
|
+
.description('convert env file(s) to encrypted env file(s)')
|
|
109
109
|
.option('-f, --env-file <paths...>', 'path(s) to your env file(s)')
|
|
110
|
-
.action(require('./actions/
|
|
110
|
+
.action(require('./actions/convert'))
|
|
111
111
|
|
|
112
112
|
// dotenvx ls
|
|
113
113
|
program.command('ls')
|
|
@@ -7,7 +7,7 @@ function replace (src, key, value) {
|
|
|
7
7
|
const parsed = dotenv.parse(src)
|
|
8
8
|
if (Object.prototype.hasOwnProperty.call(parsed, key)) {
|
|
9
9
|
// replace
|
|
10
|
-
const regex = new RegExp(`^${key}
|
|
10
|
+
const regex = new RegExp(`^${key}=(?:(["'\`])[^\\1]*\\1|[^\\n]*)(\\n[^A-Z0-9_].*)*`, 'm')
|
|
11
11
|
output = src.replace(regex, formatted)
|
|
12
12
|
} else {
|
|
13
13
|
// append
|
package/src/lib/main.js
CHANGED
|
@@ -42,7 +42,7 @@ const parse = function (src) {
|
|
|
42
42
|
return dotenv.parse(src)
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
// DEPRECATED: will became the same function as
|
|
45
|
+
// DEPRECATED: will became the same function as convert
|
|
46
46
|
const encrypt = function (directory, envFile) {
|
|
47
47
|
return new VaultEncrypt(directory, envFile).run()
|
|
48
48
|
}
|
|
@@ -67,7 +67,7 @@ const set = function (key, value, envFile, encrypt) {
|
|
|
67
67
|
return new Sets(key, value, envFile, encrypt).run()
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
-
const
|
|
70
|
+
const convert = function (envFile) {
|
|
71
71
|
return new Encrypt(envFile).run()
|
|
72
72
|
}
|
|
73
73
|
|
|
@@ -109,7 +109,7 @@ module.exports = {
|
|
|
109
109
|
ls,
|
|
110
110
|
get,
|
|
111
111
|
set,
|
|
112
|
-
|
|
112
|
+
convert,
|
|
113
113
|
status,
|
|
114
114
|
genexample,
|
|
115
115
|
// settings
|