@dotenvx/dotenvx 0.38.0 → 0.39.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 +567 -17
- package/package.json +1 -1
- package/src/cli/actions/get.js +11 -1
- package/src/cli/actions/run.js +0 -2
- package/src/cli/commands/hub.js +1 -1
- package/src/cli/dotenvx.js +11 -10
package/README.md
CHANGED
|
@@ -492,7 +492,7 @@ More examples
|
|
|
492
492
|
</details>
|
|
493
493
|
* <details><summary>`--convention` flag</summary><br>
|
|
494
494
|
|
|
495
|
-
|
|
495
|
+
Load envs using [Next.js' convention](https://nextjs.org/docs/pages/building-your-application/configuring/environment-variables#environment-variable-load-order). Set `--convention` to `nextjs`:
|
|
496
496
|
|
|
497
497
|
```sh
|
|
498
498
|
$ echo "HELLO=development local" > .env.development.local
|
|
@@ -504,8 +504,6 @@ More examples
|
|
|
504
504
|
Hello development local
|
|
505
505
|
```
|
|
506
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
507
|
(more conventions available upon request)
|
|
510
508
|
|
|
511
509
|
</details>
|
|
@@ -523,7 +521,7 @@ set HELLO with encryption (.env)
|
|
|
523
521
|
|
|
524
522
|

|
|
525
523
|
|
|
526
|
-
> A `DOTENV_PUBLIC_KEY` (encryption key) and a `DOTENV_PRIVATE_KEY` (decryption key)
|
|
524
|
+
> A `DOTENV_PUBLIC_KEY` (encryption key) and a `DOTENV_PRIVATE_KEY` (decryption key) are generated using the same public-key cryptography as [Bitcoin](https://en.bitcoin.it/wiki/Secp256k1).
|
|
527
525
|
|
|
528
526
|
More examples
|
|
529
527
|
|
|
@@ -586,23 +584,575 @@ More examples
|
|
|
586
584
|
|
|
587
585
|
|
|
588
586
|
|
|
589
|
-
##
|
|
587
|
+
## Advanced usage
|
|
588
|
+
|
|
589
|
+
* <details><summary>`run` - Variable Expansion</summary><br>
|
|
590
|
+
|
|
591
|
+
Reference and expand variables already on your machine for use in your .env file.
|
|
592
|
+
|
|
593
|
+
```ini
|
|
594
|
+
# .env
|
|
595
|
+
USERNAME="username"
|
|
596
|
+
DATABASE_URL="postgres://${USERNAME}@localhost/my_database"
|
|
597
|
+
```
|
|
598
|
+
```js
|
|
599
|
+
// index.js
|
|
600
|
+
console.log('DATABASE_URL', process.env.DATABASE_URL)
|
|
601
|
+
```
|
|
602
|
+
```sh
|
|
603
|
+
$ dotenvx run --debug -- node index.js
|
|
604
|
+
[dotenvx] injecting env (2) from .env
|
|
605
|
+
DATABASE_URL postgres://username@localhost/my_database
|
|
606
|
+
```
|
|
607
|
+
|
|
608
|
+
</details>
|
|
609
|
+
* <details><summary>`run` - Command Substitution</summary><br>
|
|
610
|
+
|
|
611
|
+
Add the output of a command to one of your variables in your .env file.
|
|
612
|
+
|
|
613
|
+
```ini
|
|
614
|
+
# .env
|
|
615
|
+
DATABASE_URL="postgres://$(whoami)@localhost/my_database"
|
|
616
|
+
```
|
|
617
|
+
```js
|
|
618
|
+
// index.js
|
|
619
|
+
console.log('DATABASE_URL', process.env.DATABASE_URL)
|
|
620
|
+
```
|
|
621
|
+
```sh
|
|
622
|
+
$ dotenvx run --debug -- node index.js
|
|
623
|
+
[dotenvx] injecting env (1) from .env
|
|
624
|
+
DATABASE_URL postgres://yourusername@localhost/my_database
|
|
625
|
+
```
|
|
626
|
+
|
|
627
|
+
</details>
|
|
628
|
+
* <details><summary>`run` - multiple `-f` flags</summary><br>
|
|
629
|
+
|
|
630
|
+
Compose multiple `.env` files for environment variables loading, as you need.
|
|
631
|
+
|
|
632
|
+
```sh
|
|
633
|
+
$ echo "HELLO=local" > .env.local
|
|
634
|
+
$ echo "HELLO=World" > .env
|
|
635
|
+
$ echo "console.log('Hello ' + process.env.HELLO)" > index.js
|
|
636
|
+
|
|
637
|
+
$ dotenvx run -f .env.local -f .env -- node index.js
|
|
638
|
+
[dotenvx] injecting env (1) from .env.local, .env
|
|
639
|
+
Hello local
|
|
640
|
+
```
|
|
641
|
+
|
|
642
|
+
</details>
|
|
643
|
+
* <details><summary>`run --env HELLO=String`</summary><br>
|
|
644
|
+
|
|
645
|
+
Set environment variables as a simple `KEY=value` string pair.
|
|
646
|
+
|
|
647
|
+
```sh
|
|
648
|
+
$ echo "HELLO=World" > .env
|
|
649
|
+
$ echo "console.log('Hello ' + process.env.HELLO)" > index.js
|
|
650
|
+
|
|
651
|
+
$ dotenvx run --env HELLO=String -f .env -- node index.js
|
|
652
|
+
[dotenvx] injecting env (1) from .env, and --env flag
|
|
653
|
+
Hello String
|
|
654
|
+
```
|
|
655
|
+
|
|
656
|
+
</details>
|
|
657
|
+
* <details><summary>`run --overload`</summary><br>
|
|
658
|
+
|
|
659
|
+
Override existing env variables. These can be variables already on your machine or variables loaded as files consecutively. The last variable seen will 'win'.
|
|
660
|
+
|
|
661
|
+
```sh
|
|
662
|
+
$ echo "HELLO=local" > .env.local
|
|
663
|
+
$ echo "HELLO=World" > .env
|
|
664
|
+
$ echo "console.log('Hello ' + process.env.HELLO)" > index.js
|
|
665
|
+
|
|
666
|
+
$ dotenvx run -f .env.local -f .env --overload -- node index.js
|
|
667
|
+
[dotenvx] injecting env (1) from .env.local, .env
|
|
668
|
+
Hello World
|
|
669
|
+
```
|
|
670
|
+
|
|
671
|
+
</details>
|
|
672
|
+
* <details><summary>`run --verbose`</summary><br>
|
|
673
|
+
|
|
674
|
+
Set log level to `verbose`. ([log levels](https://github.com/winstonjs/winston?tab=readme-ov-file#logging))
|
|
675
|
+
|
|
676
|
+
```sh
|
|
677
|
+
$ echo "HELLO=production" > .env.production
|
|
678
|
+
$ echo "console.log('Hello ' + process.env.HELLO)" > index.js
|
|
679
|
+
|
|
680
|
+
$ dotenvx run -f .env.production --verbose -- node index.js
|
|
681
|
+
loading env from .env.production (/path/to/.env.production)
|
|
682
|
+
HELLO set
|
|
683
|
+
[dotenvx] injecting env (1) from .env.production
|
|
684
|
+
Hello production
|
|
685
|
+
```
|
|
686
|
+
|
|
687
|
+
</details>
|
|
688
|
+
* <details><summary>`run --debug`</summary><br>
|
|
689
|
+
|
|
690
|
+
Set log level to `debug`. ([log levels](https://github.com/winstonjs/winston?tab=readme-ov-file#logging))
|
|
691
|
+
|
|
692
|
+
```sh
|
|
693
|
+
$ echo "HELLO=production" > .env.production
|
|
694
|
+
$ echo "console.log('Hello ' + process.env.HELLO)" > index.js
|
|
695
|
+
|
|
696
|
+
$ dotenvx run -f .env.production --debug -- node index.js
|
|
697
|
+
process command [node index.js]
|
|
698
|
+
options: {"env":[],"envFile":[".env.production"]}
|
|
699
|
+
loading env from .env.production (/path/to/.env.production)
|
|
700
|
+
{"HELLO":"production"}
|
|
701
|
+
HELLO set
|
|
702
|
+
HELLO set to production
|
|
703
|
+
[dotenvx] injecting env (1) from .env.production
|
|
704
|
+
executing process command [node index.js]
|
|
705
|
+
expanding process command to [/opt/homebrew/bin/node index.js]
|
|
706
|
+
Hello production
|
|
707
|
+
```
|
|
708
|
+
|
|
709
|
+
</details>
|
|
710
|
+
* <details><summary>`run --quiet`</summary><br>
|
|
711
|
+
|
|
712
|
+
Use `--quiet` to suppress all output (except errors). ([log levels](https://github.com/winstonjs/winston?tab=readme-ov-file#logging))
|
|
713
|
+
|
|
714
|
+
```sh
|
|
715
|
+
$ echo "HELLO=production" > .env.production
|
|
716
|
+
$ echo "console.log('Hello ' + process.env.HELLO)" > index.js
|
|
717
|
+
|
|
718
|
+
$ dotenvx run -f .env.production --quiet -- node index.js
|
|
719
|
+
Hello production
|
|
720
|
+
```
|
|
721
|
+
|
|
722
|
+
</details>
|
|
723
|
+
* <details><summary>`run --log-level`</summary><br>
|
|
724
|
+
|
|
725
|
+
Set `--log-level` to whatever you wish. For example, to supress warnings (risky), set log level to `error`:
|
|
726
|
+
|
|
727
|
+
```sh
|
|
728
|
+
$ echo "HELLO=production" > .env.production
|
|
729
|
+
$ echo "console.log('Hello ' + process.env.HELLO)" > index.js
|
|
730
|
+
|
|
731
|
+
$ dotenvx run -f .env.production --log-level=error -- node index.js
|
|
732
|
+
Hello production
|
|
733
|
+
```
|
|
734
|
+
|
|
735
|
+
Available log levels are `error, warn, info, verbose, debug, silly` ([source](https://github.com/winstonjs/winston?tab=readme-ov-file#logging))
|
|
736
|
+
|
|
737
|
+
</details>
|
|
738
|
+
* <details><summary>`run --convention=nextjs`</summary><br>
|
|
739
|
+
|
|
740
|
+
Load envs using [Next.js' convention](https://nextjs.org/docs/pages/building-your-application/configuring/environment-variables#environment-variable-load-order). Set `--convention` to `nextjs`:
|
|
741
|
+
|
|
742
|
+
```sh
|
|
743
|
+
$ echo "HELLO=development local" > .env.development.local
|
|
744
|
+
$ echo "HELLO=local" > .env.local
|
|
745
|
+
$ echo "HELLO=development" > .env.development
|
|
746
|
+
$ echo "HELLO=env" > .env
|
|
747
|
+
$ echo "console.log('Hello ' + process.env.HELLO)" > index.js
|
|
748
|
+
|
|
749
|
+
$ dotenvx run --convention=nextjs -- node index.js
|
|
750
|
+
[dotenvx] injecting env (1) from .env.development.local, .env.local, .env.development, .env
|
|
751
|
+
Hello development local
|
|
752
|
+
```
|
|
753
|
+
|
|
754
|
+
(more conventions available upon request)
|
|
755
|
+
|
|
756
|
+
</details>
|
|
757
|
+
* <details><summary>`get KEY`</summary><br>
|
|
758
|
+
|
|
759
|
+
Return a single environment variable's value.
|
|
760
|
+
|
|
761
|
+
```sh
|
|
762
|
+
$ echo "HELLO=World" > .env
|
|
763
|
+
|
|
764
|
+
$ dotenvx get HELLO
|
|
765
|
+
World
|
|
766
|
+
```
|
|
767
|
+
|
|
768
|
+
</details>
|
|
769
|
+
* <details><summary>`get KEY -f`</summary><br>
|
|
770
|
+
|
|
771
|
+
Return a single environment variable's value from a specific `.env` file.
|
|
772
|
+
|
|
773
|
+
```sh
|
|
774
|
+
$ echo "HELLO=World" > .env
|
|
775
|
+
$ echo "HELLO=production" > .env.production
|
|
776
|
+
|
|
777
|
+
$ dotenvx get HELLO -f .env.production
|
|
778
|
+
production
|
|
779
|
+
```
|
|
780
|
+
|
|
781
|
+
</details>
|
|
782
|
+
* <details><summary>`get KEY --env`</summary><br>
|
|
783
|
+
|
|
784
|
+
Return a single environment variable's value from a `--env` string.
|
|
785
|
+
|
|
786
|
+
```sh
|
|
787
|
+
$ dotenvx get HELLO --env HELLO=String -f .env.production
|
|
788
|
+
String
|
|
789
|
+
```
|
|
790
|
+
|
|
791
|
+
</details>
|
|
792
|
+
|
|
793
|
+
* <details><summary>`get KEY --overload`</summary><br>
|
|
794
|
+
|
|
795
|
+
Return a single environment variable's value where each found value is overloaded.
|
|
796
|
+
|
|
797
|
+
```sh
|
|
798
|
+
$ echo "HELLO=World" > .env
|
|
799
|
+
$ echo "HELLO=production" > .env.production
|
|
800
|
+
|
|
801
|
+
$ dotenvx get HELLO -f .env.production --env HELLO=String -f .env --overload
|
|
802
|
+
World
|
|
803
|
+
```
|
|
804
|
+
|
|
805
|
+
</details>
|
|
806
|
+
* <details><summary>`get KEY --convention=nextjs`</summary><br>
|
|
807
|
+
|
|
808
|
+
Return a single environment variable's value using [Next.js' convention](https://nextjs.org/docs/pages/building-your-application/configuring/environment-variables#environment-variable-load-order). Set `--convention` to `nextjs`:
|
|
809
|
+
|
|
810
|
+
```sh
|
|
811
|
+
$ echo "HELLO=development local" > .env.development.local
|
|
812
|
+
$ echo "HELLO=local" > .env.local
|
|
813
|
+
$ echo "HELLO=development" > .env.development
|
|
814
|
+
$ echo "HELLO=env" > .env
|
|
815
|
+
$ echo "console.log('Hello ' + process.env.HELLO)" > index.js
|
|
816
|
+
|
|
817
|
+
$ dotenvx get HELLO --convention=nextjs
|
|
818
|
+
development local
|
|
819
|
+
```
|
|
820
|
+
|
|
821
|
+
</details>
|
|
822
|
+
* <details><summary>`get` (json)</summary><br>
|
|
823
|
+
|
|
824
|
+
Return a json response of all key/value pairs in a `.env` file.
|
|
825
|
+
|
|
826
|
+
```sh
|
|
827
|
+
$ echo "HELLO=World" > .env
|
|
828
|
+
|
|
829
|
+
$ dotenvx get
|
|
830
|
+
{"HELLO":"World"}
|
|
831
|
+
```
|
|
832
|
+
|
|
833
|
+
</details>
|
|
834
|
+
* <details><summary>`get --all`</summary><br>
|
|
835
|
+
|
|
836
|
+
Return preset machine envs as well.
|
|
837
|
+
|
|
838
|
+
```sh
|
|
839
|
+
$ echo "HELLO=World" > .env
|
|
840
|
+
|
|
841
|
+
$ dotenvx get --all
|
|
842
|
+
{"PWD":"/some/file/path","USER":"username","LIBRARY_PATH":"/usr/local/lib", ..., "HELLO":"World"}
|
|
843
|
+
```
|
|
844
|
+
|
|
845
|
+
</details>
|
|
846
|
+
* <details><summary>`get --all --pretty-print`</summary><br>
|
|
847
|
+
|
|
848
|
+
Make the output more readable - pretty print it.
|
|
849
|
+
|
|
850
|
+
```sh
|
|
851
|
+
$ echo "HELLO=World" > .env
|
|
852
|
+
|
|
853
|
+
$ dotenvx get --all --pretty-print
|
|
854
|
+
{
|
|
855
|
+
"PWD": "/some/filepath",
|
|
856
|
+
"USER": "username",
|
|
857
|
+
"LIBRARY_PATH": "/usr/local/lib",
|
|
858
|
+
...,
|
|
859
|
+
"HELLO": "World"
|
|
860
|
+
}
|
|
861
|
+
```
|
|
862
|
+
|
|
863
|
+
</details>
|
|
864
|
+
* <details><summary>`set KEY value`</summary><br>
|
|
865
|
+
|
|
866
|
+
Set a single key/value.
|
|
867
|
+
|
|
868
|
+
```sh
|
|
869
|
+
$ touch .env
|
|
870
|
+
|
|
871
|
+
$ dotenvx set HELLO World
|
|
872
|
+
set HELLO (.env)
|
|
873
|
+
```
|
|
874
|
+
|
|
875
|
+
</details>
|
|
876
|
+
* <details><summary>`set KEY value --encrypt`</summary><br>
|
|
877
|
+
|
|
878
|
+
Set an encrypted key/value.
|
|
879
|
+
|
|
880
|
+
```sh
|
|
881
|
+
$ touch .env
|
|
882
|
+
|
|
883
|
+
$ dotenvx set HELLO World --encrypt
|
|
884
|
+
set HELLO with encryption (.env)
|
|
885
|
+
```
|
|
886
|
+
|
|
887
|
+
</details>
|
|
888
|
+
* <details><summary>`set KEY value -f`</summary><br>
|
|
889
|
+
|
|
890
|
+
Set an (encrypted) key/value for another `.env` file.
|
|
891
|
+
|
|
892
|
+
```sh
|
|
893
|
+
$ touch .env.production
|
|
894
|
+
|
|
895
|
+
$ dotenvx set HELLO production --encrypt -f .env.production
|
|
896
|
+
set HELLO with encryption (.env.production)
|
|
897
|
+
```
|
|
898
|
+
|
|
899
|
+
</details>
|
|
900
|
+
* <details><summary>`set KEY "value with spaces"`</summary><br>
|
|
901
|
+
|
|
902
|
+
Set a value containing spaces.
|
|
903
|
+
|
|
904
|
+
```sh
|
|
905
|
+
$ touch .env.ci
|
|
906
|
+
|
|
907
|
+
$ dotenvx set HELLO "my ci" -f .env.ci
|
|
908
|
+
set HELLO (.env.ci)
|
|
909
|
+
```
|
|
910
|
+
|
|
911
|
+
</details>
|
|
912
|
+
* <details><summary>`ls`</summary><br>
|
|
913
|
+
|
|
914
|
+
Print all `.env` files in a tree structure.
|
|
915
|
+
|
|
916
|
+
```sh
|
|
917
|
+
$ touch .env
|
|
918
|
+
$ touch .env.production
|
|
919
|
+
$ mkdir -p apps/backend
|
|
920
|
+
$ touch apps/backend/.env
|
|
921
|
+
|
|
922
|
+
$ dotenvx ls
|
|
923
|
+
├─ .env.production
|
|
924
|
+
├─ .env
|
|
925
|
+
└─ apps
|
|
926
|
+
└─ backend
|
|
927
|
+
└─ .env
|
|
928
|
+
```
|
|
929
|
+
|
|
930
|
+
</details>
|
|
931
|
+
* <details><summary>`ls directory`</summary><br>
|
|
932
|
+
|
|
933
|
+
Print all `.env` files inside a specified path to a directory.
|
|
934
|
+
|
|
935
|
+
```sh
|
|
936
|
+
$ touch .env
|
|
937
|
+
$ touch .env.production
|
|
938
|
+
$ mkdir -p apps/backend
|
|
939
|
+
$ touch apps/backend/.env
|
|
940
|
+
|
|
941
|
+
$ dotenvx ls apps/backend
|
|
942
|
+
└─ .env
|
|
943
|
+
```
|
|
944
|
+
|
|
945
|
+
</details>
|
|
946
|
+
* <details><summary>`ls -f`</summary><br>
|
|
947
|
+
|
|
948
|
+
Glob `.env` filenames matching a wildcard.
|
|
949
|
+
|
|
950
|
+
```sh
|
|
951
|
+
$ touch .env
|
|
952
|
+
$ touch .env.production
|
|
953
|
+
$ mkdir -p apps/backend
|
|
954
|
+
$ touch apps/backend/.env
|
|
955
|
+
$ touch apps/backend/.env.prod
|
|
956
|
+
|
|
957
|
+
$ dotenvx ls -f **/.env.prod*
|
|
958
|
+
├─ .env.production
|
|
959
|
+
└─ apps
|
|
960
|
+
└─ backend
|
|
961
|
+
└─ .env.prod
|
|
962
|
+
```
|
|
963
|
+
|
|
964
|
+
</details>
|
|
965
|
+
* <details><summary>`genexample`</summary><br>
|
|
966
|
+
|
|
967
|
+
In one command, generate a `.env.example` file from your current `.env` file contents.
|
|
968
|
+
|
|
969
|
+
```sh
|
|
970
|
+
$ echo "HELLO=World" > .env
|
|
971
|
+
|
|
972
|
+
$ dotenvx genexample
|
|
973
|
+
✔ updated .env.example (1)
|
|
974
|
+
```
|
|
975
|
+
|
|
976
|
+
```ini
|
|
977
|
+
# .env.example
|
|
978
|
+
HELLO=""
|
|
979
|
+
```
|
|
980
|
+
|
|
981
|
+
</details>
|
|
982
|
+
* <details><summary>`genexample -f`</summary><br>
|
|
983
|
+
|
|
984
|
+
Pass multiple `.env` files to generate your `.env.example` file from the combination of their contents.
|
|
985
|
+
|
|
986
|
+
```sh
|
|
987
|
+
$ echo "HELLO=World" > .env
|
|
988
|
+
$ echo "DB_HOST=example.com" > .env.production
|
|
989
|
+
|
|
990
|
+
$ dotenvx genexample -f .env -f .env.production
|
|
991
|
+
✔ updated .env.example (2)
|
|
992
|
+
```
|
|
590
993
|
|
|
591
|
-
|
|
994
|
+
```ini
|
|
995
|
+
# .env.example
|
|
996
|
+
HELLO=""
|
|
997
|
+
DB_HOST=""
|
|
998
|
+
```
|
|
592
999
|
|
|
593
|
-
|
|
594
|
-
*
|
|
595
|
-
* [`dotenvx prebuild`](https://dotenvx.com/docs/features/prebuild) – prevent `.env` files from being built into your docker container
|
|
596
|
-
* [`dotenvx precommit`](https://dotenvx.com/docs/features/precommit) – prevent `.env` files from being committed to code
|
|
597
|
-
* [`dotenvx scan`](https://dotenvx.com/docs/features/scan) – scan for leaked secrets in code
|
|
1000
|
+
</details>
|
|
1001
|
+
* <details><summary>`genexample directory`</summary><br>
|
|
598
1002
|
|
|
599
|
-
|
|
1003
|
+
Generate a `.env.example` file inside the specified directory. Useful for monorepos.
|
|
1004
|
+
|
|
1005
|
+
```sh
|
|
1006
|
+
$ echo "HELLO=World" > .env
|
|
1007
|
+
$ mkdir -p apps/backend
|
|
1008
|
+
$ echo "HELLO=Backend" > apps/backend/.env
|
|
1009
|
+
|
|
1010
|
+
$ dotenvx genexample apps/backend
|
|
1011
|
+
✔ updated .env.example (1)
|
|
1012
|
+
```
|
|
1013
|
+
|
|
1014
|
+
```ini
|
|
1015
|
+
# apps/backend/.env.example
|
|
1016
|
+
HELLO=""
|
|
1017
|
+
```
|
|
1018
|
+
|
|
1019
|
+
</details>
|
|
1020
|
+
* <details><summary>`gitignore`</summary><br>
|
|
1021
|
+
|
|
1022
|
+
Gitignore your `.env` files.
|
|
1023
|
+
|
|
1024
|
+
```sh
|
|
1025
|
+
$ dotenvx gitignore
|
|
1026
|
+
creating .gitignore
|
|
1027
|
+
appending .env* to .gitignore
|
|
1028
|
+
done
|
|
1029
|
+
```
|
|
1030
|
+
|
|
1031
|
+
</details>
|
|
1032
|
+
* <details><summary>`precommit`</summary><br>
|
|
1033
|
+
|
|
1034
|
+
Prevent `.env` files from being committed to code.
|
|
1035
|
+
|
|
1036
|
+
```sh
|
|
1037
|
+
$ dotenvx precommit
|
|
1038
|
+
[dotenvx][precommit] success
|
|
1039
|
+
```
|
|
1040
|
+
|
|
1041
|
+
</details>
|
|
1042
|
+
* <details><summary>`precommit --install`</summary><br>
|
|
1043
|
+
|
|
1044
|
+
Install a shell script to `.git/hooks/pre-commit` to prevent accidentally committing any `.env` files to source control.
|
|
1045
|
+
|
|
1046
|
+
```sh
|
|
1047
|
+
$ dotenvx precommit --install
|
|
1048
|
+
[dotenvx][precommit] dotenvx precommit installed [.git/hooks/pre-commit]
|
|
1049
|
+
```
|
|
600
1050
|
|
|
601
|
-
|
|
602
|
-
*
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
1051
|
+
</details>
|
|
1052
|
+
* <details><summary>`prebuild`</summary><br>
|
|
1053
|
+
|
|
1054
|
+
Prevent `.env` files from being built into your docker containers.
|
|
1055
|
+
|
|
1056
|
+
Add it to your `Dockerfile`.
|
|
1057
|
+
|
|
1058
|
+
```sh
|
|
1059
|
+
RUN curl -fsS https://dotenvx.sh/ | sh
|
|
1060
|
+
|
|
1061
|
+
...
|
|
1062
|
+
|
|
1063
|
+
RUN dotenvx prebuild
|
|
1064
|
+
CMD ["dotenvx", "run", "--", "node", "index.js"]
|
|
1065
|
+
```
|
|
1066
|
+
|
|
1067
|
+
</details>
|
|
1068
|
+
* <details><summary>`scan`</summary><br>
|
|
1069
|
+
|
|
1070
|
+
Use [gitleaks](https://gitleaks.io) under the hood to scan for possible secrets in your code.
|
|
1071
|
+
|
|
1072
|
+
```sh
|
|
1073
|
+
$ dotenvx scan
|
|
1074
|
+
|
|
1075
|
+
○
|
|
1076
|
+
│╲
|
|
1077
|
+
│ ○
|
|
1078
|
+
○ ░
|
|
1079
|
+
░ gitleaks
|
|
1080
|
+
|
|
1081
|
+
100 commits scanned.
|
|
1082
|
+
no leaks found
|
|
1083
|
+
```
|
|
1084
|
+
|
|
1085
|
+
</details>
|
|
1086
|
+
* <details><summary>`help`</summary><br>
|
|
1087
|
+
|
|
1088
|
+
Output help for `dotenvx`.
|
|
1089
|
+
|
|
1090
|
+
```sh
|
|
1091
|
+
$ dotenvx help
|
|
1092
|
+
Usage: @dotenvx/dotenvx [options] [command]
|
|
1093
|
+
|
|
1094
|
+
a better dotenv–from the creator of `dotenv`
|
|
1095
|
+
|
|
1096
|
+
Options:
|
|
1097
|
+
-l, --log-level <level> set log level (default: "info")
|
|
1098
|
+
-q, --quiet sets log level to error
|
|
1099
|
+
-v, --verbose sets log level to verbose
|
|
1100
|
+
-d, --debug sets log level to debug
|
|
1101
|
+
-V, --version output the version number
|
|
1102
|
+
-h, --help display help for command
|
|
1103
|
+
|
|
1104
|
+
Commands:
|
|
1105
|
+
run [options] inject env at runtime [dotenvx run -- yourcommand]
|
|
1106
|
+
get [options] [key] return a single environment variable
|
|
1107
|
+
set [options] <KEY> <value> set a single environment variable
|
|
1108
|
+
...
|
|
1109
|
+
help [command] display help for command
|
|
1110
|
+
```
|
|
1111
|
+
|
|
1112
|
+
You can get more detailed help per command with `dotenvx help COMMAND`.
|
|
1113
|
+
|
|
1114
|
+
```sh
|
|
1115
|
+
$ dotenvx help run
|
|
1116
|
+
Usage: @dotenvx/dotenvx run [options]
|
|
1117
|
+
|
|
1118
|
+
inject env at runtime [dotenvx run -- yourcommand]
|
|
1119
|
+
|
|
1120
|
+
Options:
|
|
1121
|
+
-e, --env <strings...> environment variable(s) set as string (example: "HELLO=World") (default: [])
|
|
1122
|
+
-f, --env-file <paths...> path(s) to your env file(s) (default: [])
|
|
1123
|
+
-fv, --env-vault-file <paths...> path(s) to your .env.vault file(s) (default: [])
|
|
1124
|
+
-o, --overload override existing env variables
|
|
1125
|
+
--convention <name> load a .env convention (available conventions: ['nextjs'])
|
|
1126
|
+
-h, --help display help for command
|
|
1127
|
+
|
|
1128
|
+
Examples:
|
|
1129
|
+
|
|
1130
|
+
$ dotenvx run -- npm run dev
|
|
1131
|
+
$ dotenvx run -- flask --app index run
|
|
1132
|
+
$ dotenvx run -- php artisan serve
|
|
1133
|
+
$ dotenvx run -- bin/rails s
|
|
1134
|
+
|
|
1135
|
+
Try it:
|
|
1136
|
+
|
|
1137
|
+
$ echo "HELLO=World" > .env
|
|
1138
|
+
$ echo "console.log('Hello ' + process.env.HELLO)" > index.js
|
|
1139
|
+
|
|
1140
|
+
$ dotenvx run -- node index.js
|
|
1141
|
+
[dotenvx] injecting env (1) from .env
|
|
1142
|
+
Hello World
|
|
1143
|
+
```
|
|
1144
|
+
|
|
1145
|
+
</details>
|
|
1146
|
+
* <details><summary>`--version`</summary><br>
|
|
1147
|
+
|
|
1148
|
+
Check current version of `dotenvx`.
|
|
1149
|
+
|
|
1150
|
+
```sh
|
|
1151
|
+
$ dotenvx --version
|
|
1152
|
+
X.X.X
|
|
1153
|
+
```
|
|
1154
|
+
|
|
1155
|
+
</details>
|
|
606
1156
|
|
|
607
1157
|
|
|
608
1158
|
|
package/package.json
CHANGED
package/src/cli/actions/get.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
const logger = require('./../../shared/logger')
|
|
2
2
|
|
|
3
|
+
const conventions = require('./../../lib/helpers/conventions')
|
|
4
|
+
|
|
3
5
|
const main = require('./../../lib/main')
|
|
4
6
|
|
|
5
7
|
function get (key) {
|
|
@@ -8,7 +10,15 @@ function get (key) {
|
|
|
8
10
|
const options = this.opts()
|
|
9
11
|
logger.debug(`options: ${JSON.stringify(options)}`)
|
|
10
12
|
|
|
11
|
-
|
|
13
|
+
let envs = []
|
|
14
|
+
// handle shorthand conventions - like --convention=nextjs
|
|
15
|
+
if (options.convention) {
|
|
16
|
+
envs = conventions(options.convention).concat(this.envs)
|
|
17
|
+
} else {
|
|
18
|
+
envs = this.envs
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const value = main.get(key, envs, options.overload, process.env.DOTENV_KEY, options.all)
|
|
12
22
|
|
|
13
23
|
if (typeof value === 'object' && value !== null) {
|
|
14
24
|
if (options.prettyPrint) {
|
package/src/cli/actions/run.js
CHANGED
|
@@ -138,8 +138,6 @@ async function run () {
|
|
|
138
138
|
if (processedEnv.error.code === 'MISSING_ENV_FILE') {
|
|
139
139
|
logger.warnv(processedEnv.error)
|
|
140
140
|
logger.help(`? in development: add one with [echo "HELLO=World" > ${processedEnv.filepath}] and re-run [dotenvx run -- ${commandArgs.join(' ')}]`)
|
|
141
|
-
logger.help('? for production: set [DOTENV_KEY] on your server and re-deploy')
|
|
142
|
-
logger.help('? for ci: set [DOTENV_KEY] on your ci and re-build')
|
|
143
141
|
} else {
|
|
144
142
|
logger.warnv(processedEnv.error)
|
|
145
143
|
}
|
package/src/cli/commands/hub.js
CHANGED
package/src/cli/dotenvx.js
CHANGED
|
@@ -85,6 +85,7 @@ program.command('get')
|
|
|
85
85
|
.option('-f, --env-file <paths...>', 'path(s) to your env file(s)', collectEnvs('envFile'), [])
|
|
86
86
|
.option('-fv, --env-vault-file <paths...>', 'path(s) to your .env.vault file(s)', collectEnvs('envVaultFile'), [])
|
|
87
87
|
.option('-o, --overload', 'override existing env variables')
|
|
88
|
+
.option('--convention <name>', 'load a .env convention (available conventions: [\'nextjs\'])')
|
|
88
89
|
.option('-a, --all', 'include all machine envs as well')
|
|
89
90
|
.option('-pp, --pretty-print', 'pretty print output')
|
|
90
91
|
.action(function (...args) {
|
|
@@ -102,6 +103,13 @@ program.command('set')
|
|
|
102
103
|
.option('-c, --encrypt', 'encrypt value')
|
|
103
104
|
.action(require('./actions/set'))
|
|
104
105
|
|
|
106
|
+
// dotenvx ls
|
|
107
|
+
program.command('ls')
|
|
108
|
+
.description('print all .env files in a tree structure')
|
|
109
|
+
.argument('[directory]', 'directory to list .env files from', '.')
|
|
110
|
+
.option('-f, --env-file <filenames...>', 'path(s) to your env file(s)', '.env*')
|
|
111
|
+
.action(require('./actions/ls'))
|
|
112
|
+
|
|
105
113
|
// dotenvx genexample
|
|
106
114
|
program.command('genexample')
|
|
107
115
|
.description('generate .env.example')
|
|
@@ -133,13 +141,6 @@ program.command('scan')
|
|
|
133
141
|
.description('scan for leaked secrets')
|
|
134
142
|
.action(require('./actions/scan'))
|
|
135
143
|
|
|
136
|
-
// dotenvx ls
|
|
137
|
-
program.command('ls')
|
|
138
|
-
.description('print all .env files in a tree structure')
|
|
139
|
-
.argument('[directory]', 'directory to list .env files from', '.')
|
|
140
|
-
.option('-f, --env-file <filenames...>', 'path(s) to your env file(s)', '.env*')
|
|
141
|
-
.action(require('./actions/ls'))
|
|
142
|
-
|
|
143
144
|
// dotenvx settings
|
|
144
145
|
program.command('settings')
|
|
145
146
|
.description('print current dotenvx settings')
|
|
@@ -147,6 +148,9 @@ program.command('settings')
|
|
|
147
148
|
.option('-pp, --pretty-print', 'pretty print output')
|
|
148
149
|
.action(require('./actions/settings'))
|
|
149
150
|
|
|
151
|
+
// dotenvx vault
|
|
152
|
+
program.addCommand(require('./commands/vault'))
|
|
153
|
+
|
|
150
154
|
// dotenvx encrypt
|
|
151
155
|
const encryptAction = require('./actions/vault/encrypt')
|
|
152
156
|
program.command('encrypt')
|
|
@@ -183,9 +187,6 @@ program.command('status')
|
|
|
183
187
|
statusAction.apply(this, args)
|
|
184
188
|
})
|
|
185
189
|
|
|
186
|
-
// dotenvx vault
|
|
187
|
-
program.addCommand(require('./commands/vault'))
|
|
188
|
-
|
|
189
190
|
// dotenvx hub
|
|
190
191
|
program.addCommand(require('./commands/hub'))
|
|
191
192
|
|