@karmaniverous/get-dotenv 1.2.0 → 2.0.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 CHANGED
@@ -86,18 +86,18 @@ dotenv files. You can:
86
86
 
87
87
  Options:
88
88
  -p, --paths <strings...> space-delimited paths to dotenv directory (default './')
89
- -t, --dotenv-token <string> token indicating a dotenv file (default: '.env')
90
- -i, --private-token <string> token indicating private variables (default: 'local')
91
- -d, --defaultEnvironment <string> default environment
92
- -e, --environment <string> designated environment
93
- -v, --variable <string> environment from variable
89
+ -y, --dynamic-path <string> dynamic variables path
90
+ -d, --defaultEnvironment <string> default environment (prefix with $ to use environment variable)
91
+ -e, --environment <string> designated environment (prefix with $ to use environment variable)
94
92
  -n, --exclude-env exclude environment-specific variables (default: false)
95
93
  -g, --exclude-global exclude global & dynamic variables (default: false)
96
94
  -r, --exclude-private exclude private variables (default: false)
97
95
  -u, --exclude-public exclude public variables (default: false)
98
- -y, --dynamic-path <string> dynamic variables path
96
+ -z, --exclude-dynamic exclude dynamic variables (default: false)
99
97
  -c, --command <string> shell command string
100
98
  -l, --log log extracted variables (default: false)
99
+ -t, --dotenv-token <string> token indicating a dotenv file (default: '.env')
100
+ -i, --private-token <string> token indicating private variables (default: 'local')
101
101
  -h, --help display help for command
102
102
  ```
103
103
 
@@ -159,6 +159,7 @@ get-dotenv options type
159
159
  | [dotenvToken] | <code>string</code> | token indicating a dotenv file (default: '.env') |
160
160
  | [dynamicPath] | <code>string</code> | path to file exporting an object keyed to dynamic variable functions |
161
161
  | [env] | <code>string</code> | target environment |
162
+ | [excludeDynamic] | <code>bool</code> | exclude dynamic variables (default: false) |
162
163
  | [excludeEnv] | <code>bool</code> | exclude environment-specific variables (default: false) |
163
164
  | [excludeGlobal] | <code>bool</code> | exclude global & dynamic variables (default: false) |
164
165
  | [excludePrivate] | <code>bool</code> | exclude private variables (default: false) |
@@ -2,6 +2,7 @@
2
2
 
3
3
  // Import npm packages.
4
4
  import spawn from 'cross-spawn';
5
+ import _ from 'lodash';
5
6
  import { parseArgsStringToArgv } from 'string-argv';
6
7
 
7
8
  // Import package exports.
@@ -10,6 +11,11 @@ import { getDotenv } from '@karmaniverous/get-dotenv';
10
11
  // Create CLI.
11
12
  import { program } from 'commander';
12
13
 
14
+ const envMerge = (value) =>
15
+ !_.isUndefined(value) && value.startsWith('$')
16
+ ? process.env[value.slice(1)]
17
+ : value;
18
+
13
19
  // CLI description.
14
20
  program
15
21
  .name('getdotenv')
@@ -41,17 +47,17 @@ program
41
47
  '-p, --paths <strings...>',
42
48
  "space-delimited paths to dotenv directory (default './')"
43
49
  )
50
+ .option('-y, --dynamic-path <string>', 'dynamic variables path')
44
51
  .option(
45
- '-t, --dotenv-token <string>',
46
- "token indicating a dotenv file (default: '.env')"
52
+ '-d, --defaultEnvironment <string>',
53
+ 'default environment (prefix with $ to use environment variable)',
54
+ envMerge
47
55
  )
48
56
  .option(
49
- '-i, --private-token <string>',
50
- "token indicating private variables (default: 'local')"
57
+ '-e, --environment <string>',
58
+ 'designated environment (prefix with $ to use environment variable)',
59
+ envMerge
51
60
  )
52
- .option('-d, --defaultEnvironment <string>', 'default environment')
53
- .option('-e, --environment <string>', 'designated environment')
54
- .option('-v, --variable <string>', 'environment from variable')
55
61
  .option(
56
62
  '-n, --exclude-env',
57
63
  'exclude environment-specific variables (default: false)'
@@ -62,9 +68,17 @@ program
62
68
  )
63
69
  .option('-r, --exclude-private', 'exclude private variables (default: false)')
64
70
  .option('-u, --exclude-public', 'exclude public variables (default: false)')
65
- .option('-y, --dynamic-path <string>', 'dynamic variables path')
71
+ .option('-z, --exclude-dynamic', 'exclude dynamic variables (default: false)')
66
72
  .option('-c, --command <string>', 'shell command string')
67
- .option('-l, --log', 'log extracted variables (default: false)');
73
+ .option('-l, --log', 'log extracted variables (default: false)')
74
+ .option(
75
+ '-t, --dotenv-token <string>',
76
+ "token indicating a dotenv file (default: '.env')"
77
+ )
78
+ .option(
79
+ '-i, --private-token <string>',
80
+ "token indicating private variables (default: 'local')"
81
+ );
68
82
 
69
83
  // Parse CLI options from command line.
70
84
  program.parse();
@@ -81,13 +95,12 @@ const {
81
95
  log,
82
96
  paths,
83
97
  privateToken,
84
- variable,
85
98
  } = program.opts();
86
99
 
87
100
  if (command && program.args.length) program.error('command specified twice');
88
101
 
89
102
  // Get environment.
90
- const env = environment ?? process.env[variable] ?? defaultEnvironment;
103
+ const env = environment ?? defaultEnvironment;
91
104
 
92
105
  // Load dotenvs.
93
106
  await getDotenv({
@@ -21,6 +21,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
21
21
  * @property {string} [dotenvToken] - token indicating a dotenv file (default: '.env')
22
22
  * @property {string} [dynamicPath] - path to file exporting an object keyed to dynamic variable functions
23
23
  * @property {string} [env] - target environment
24
+ * @property {bool} [excludeDynamic] - exclude dynamic variables (default: false)
24
25
  * @property {bool} [excludeEnv] - exclude environment-specific variables (default: false)
25
26
  * @property {bool} [excludeGlobal] - exclude global & dynamic variables (default: false)
26
27
  * @property {bool} [excludePrivate] - exclude private variables (default: false)
@@ -46,6 +47,7 @@ const getDotenv = async function () {
46
47
  dotenvToken = '.env',
47
48
  env,
48
49
  dynamicPath,
50
+ excludeDynamic = false,
49
51
  excludeEnv = false,
50
52
  excludeGlobal = false,
51
53
  excludePrivate = false,
@@ -77,7 +79,7 @@ const getDotenv = async function () {
77
79
  if (error) throw new Error(error);
78
80
 
79
81
  // Process dynamic variables.
80
- if (!excludePublic && dynamicPath) {
82
+ if (dynamicPath && !excludeDynamic) {
81
83
  const dynamic = new Function(`return ${(await _fsExtra.default.readFile(dynamicPath)).toString()}`)()(dotenv);
82
84
  Object.keys(dynamic).forEach(key => {
83
85
  Object.assign(dotenv, {
@@ -109,6 +111,7 @@ const getDotenvSync = function () {
109
111
  dotenvToken = '.env',
110
112
  dynamicPath,
111
113
  env,
114
+ excludeDynamic = false,
112
115
  excludeEnv = false,
113
116
  excludeGlobal = false,
114
117
  excludePrivate = false,
@@ -140,7 +143,7 @@ const getDotenvSync = function () {
140
143
  if (error) throw new Error(error);
141
144
 
142
145
  // Process dynamic variables.
143
- if (!excludePublic && dynamicPath) {
146
+ if (dynamicPath && !excludeDynamic) {
144
147
  const dynamic = new Function(`return ${_fsExtra.default.readFileSync(dynamicPath).toString()}`)()(dotenv);
145
148
  Object.keys(dynamic).forEach(key => {
146
149
  Object.assign(dotenv, {
@@ -14,6 +14,7 @@ import { readDotenv, readDotenvSync } from '../readDotEnv/readDotenv.js';
14
14
  * @property {string} [dotenvToken] - token indicating a dotenv file (default: '.env')
15
15
  * @property {string} [dynamicPath] - path to file exporting an object keyed to dynamic variable functions
16
16
  * @property {string} [env] - target environment
17
+ * @property {bool} [excludeDynamic] - exclude dynamic variables (default: false)
17
18
  * @property {bool} [excludeEnv] - exclude environment-specific variables (default: false)
18
19
  * @property {bool} [excludeGlobal] - exclude global & dynamic variables (default: false)
19
20
  * @property {bool} [excludePrivate] - exclude private variables (default: false)
@@ -38,6 +39,7 @@ export const getDotenv = async ({
38
39
  dotenvToken = '.env',
39
40
  env,
40
41
  dynamicPath,
42
+ excludeDynamic = false,
41
43
  excludeEnv = false,
42
44
  excludeGlobal = false,
43
45
  excludePrivate = false,
@@ -87,7 +89,7 @@ export const getDotenv = async ({
87
89
  if (error) throw new Error(error);
88
90
 
89
91
  // Process dynamic variables.
90
- if (!excludePublic && dynamicPath) {
92
+ if (dynamicPath && !excludeDynamic) {
91
93
  const dynamic = new Function(
92
94
  `return ${(await fs.readFile(dynamicPath)).toString()}`
93
95
  )()(dotenv);
@@ -118,6 +120,7 @@ export const getDotenvSync = ({
118
120
  dotenvToken = '.env',
119
121
  dynamicPath,
120
122
  env,
123
+ excludeDynamic = false,
121
124
  excludeEnv = false,
122
125
  excludeGlobal = false,
123
126
  excludePrivate = false,
@@ -167,7 +170,7 @@ export const getDotenvSync = ({
167
170
  if (error) throw new Error(error);
168
171
 
169
172
  // Process dynamic variables.
170
- if (!excludePublic && dynamicPath) {
173
+ if (dynamicPath && !excludeDynamic) {
171
174
  const dynamic = new Function(
172
175
  `return ${fs.readFileSync(dynamicPath).toString()}`
173
176
  )()(dotenv);
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "bin": {
4
4
  "getdotenv": "bin/getdotenv/index.js"
5
5
  },
6
- "version": "1.2.0",
6
+ "version": "2.0.0",
7
7
  "publishConfig": {
8
8
  "access": "public"
9
9
  },