@dotenvx/dotenvx
Advanced tools
Comparing version 1.18.1 to 1.19.0
@@ -5,4 +5,10 @@ # Changelog | ||
## [Unreleased](https://github.com/dotenvx/dotenvx/compare/v1.18.1...main) | ||
## [Unreleased](https://github.com/dotenvx/dotenvx/compare/v1.19.0...main) | ||
## 1.19.0 | ||
### Added | ||
* support key glob filtering for `encrypt` and `decrypt`. example: `dotenvx encrypt -ek "NEXT_PUBLIC_*"` ([#397](https://github.com/dotenvx/dotenvx/pull/397)) | ||
## 1.18.1 | ||
@@ -9,0 +15,0 @@ |
{ | ||
"version": "1.18.1", | ||
"version": "1.19.0", | ||
"name": "@dotenvx/dotenvx", | ||
@@ -4,0 +4,0 @@ "description": "a better dotenv–from the creator of `dotenv`", |
@@ -1246,3 +1246,33 @@ [![dotenvx](https://dotenvx.com/better-banner.png)](https://dotenvx.com) | ||
Even specify a glob pattern. | ||
```sh | ||
$ echo "HELLO=World\nHOLA=Mundo" > .env | ||
$ dotenvx encrypt -k "HE*" | ||
✔ encrypted (.env) | ||
``` | ||
</details> | ||
* <details><summary>`encrypt -ek`</summary><br> | ||
Specify the key(s) to NOT encrypt by passing `--exclude-key`. | ||
```sh | ||
$ echo "HELLO=World\nHELLO2=Universe" > .env | ||
$ dotenvx encrypt -ek HELLO | ||
✔ encrypted (.env) | ||
``` | ||
Even specify a glob pattern. | ||
```sh | ||
$ echo "HELLO=World\nHOLA=Mundo" > .env | ||
$ dotenvx encrypt -ek "HO*" | ||
✔ encrypted (.env) | ||
``` | ||
</details> | ||
* <details><summary>`encrypt --stdout`</summary><br> | ||
@@ -1300,2 +1330,48 @@ | ||
</details> | ||
* <details><summary>`decrypt -k`</summary><br> | ||
Decrypt the contents of a specified key inside an encrypted `.env` file. | ||
```sh | ||
$ echo "HELLO=World\nHOLA=Mundo" > .env | ||
$ dotenvx encrypt | ||
✔ encrypted (.env) | ||
$ dotenvx decrypt -k HELLO | ||
✔ decrypted (.env) | ||
``` | ||
Even specify a glob pattern. | ||
```sh | ||
$ echo "HELLO=World\nHOLA=Mundo" > .env | ||
$ dotenvx encrypt | ||
✔ encrypted (.env) | ||
$ dotenvx decrypt -k "HE*" | ||
✔ encrypted (.env) | ||
``` | ||
</details> | ||
* <details><summary>`decrypt -ek`</summary><br> | ||
Decrypt the contents inside an encrypted `.env` file except for an exluded key. | ||
```sh | ||
$ echo "HELLO=World\nHOLA=Mundo" > .env | ||
$ dotenvx encrypt | ||
✔ encrypted (.env) | ||
$ dotenvx decrypt -ek HOLA | ||
✔ decrypted (.env) | ||
``` | ||
Even specify a glob pattern. | ||
```sh | ||
$ echo "HELLO=World\nHOLA=Mundo" > .env | ||
$ dotenvx encrypt | ||
✔ encrypted (.env) | ||
$ dotenvx decrypt -ek "HO*" | ||
✔ encrypted (.env) | ||
``` | ||
</details> | ||
* <details><summary>`decrypt --stdout`</summary><br> | ||
@@ -1302,0 +1378,0 @@ |
const fs = require('fs') | ||
const path = require('path') | ||
const dotenv = require('dotenv') | ||
const picomatch = require('picomatch') | ||
@@ -32,2 +33,5 @@ const smartDotenvPrivateKey = require('./../helpers/smartDotenvPrivateKey') | ||
const excludeKeys = this._excludeKeys() | ||
const exclude = picomatch(excludeKeys) | ||
const include = picomatch(keys, { ignore: excludeKeys }) | ||
for (const envFilepath of envFilepaths) { | ||
@@ -57,3 +61,3 @@ const filepath = path.resolve(envFilepath) | ||
// key excluded - don't decrypt it | ||
if (excludeKeys.includes(key)) { | ||
if (exclude(key)) { | ||
continue | ||
@@ -63,3 +67,3 @@ } | ||
// key effectively excluded (by not being in the list of includes) - don't encrypt it | ||
if (keys.length > 0 && !keys.includes(key)) { | ||
if (keys.length > 0 && !include(key)) { | ||
continue | ||
@@ -66,0 +70,0 @@ } |
const fs = require('fs') | ||
const path = require('path') | ||
const dotenv = require('dotenv') | ||
const picomatch = require('picomatch') | ||
@@ -33,2 +34,5 @@ const findOrCreatePublicKey = require('./../helpers/findOrCreatePublicKey') | ||
const excludeKeys = this._excludeKeys() | ||
const exclude = picomatch(excludeKeys) | ||
const include = picomatch(keys, { ignore: excludeKeys }) | ||
for (const envFilepath of envFilepaths) { | ||
@@ -71,3 +75,3 @@ const filepath = path.resolve(envFilepath) | ||
// key excluded - don't encrypt it | ||
if (excludeKeys.includes(key)) { | ||
if (exclude(key)) { | ||
continue | ||
@@ -77,3 +81,3 @@ } | ||
// key effectively excluded (by not being in the list of includes) - don't encrypt it | ||
if (keys.length > 0 && !keys.includes(key)) { | ||
if (keys.length > 0 && !include(key)) { | ||
continue | ||
@@ -80,0 +84,0 @@ } |
207124
3512
1792