@karmaniverous/get-dotenv 3.0.0 → 3.0.2
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 +4 -1
- package/dist/default/lib/getCli.js +10 -4
- package/dist/default/lib/getDotenv.js +11 -6
- package/lib/getCli.js +18 -8
- package/lib/getDotenv.js +9 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -79,7 +79,8 @@ Usage: getdotenv [options] [command]
|
|
|
79
79
|
Base CLI. All options except delimiters follow dotenv-expand rules.
|
|
80
80
|
|
|
81
81
|
Options:
|
|
82
|
-
-e, --env <string> environment
|
|
82
|
+
-e, --env <string> target environment
|
|
83
|
+
--default-env <string> default target environment (default: "dev")
|
|
83
84
|
-p, --paths <string> delimited list of paths to dotenv directory (default: "./")
|
|
84
85
|
--paths-delimiter <string> regex paths delimiter (default: "\\s+")
|
|
85
86
|
-v, --vars <string> delimited list KEY=VALUE pairs
|
|
@@ -193,6 +194,7 @@ GetDotenv CLI Options type
|
|
|
193
194
|
| Name | Type | Description |
|
|
194
195
|
| --- | --- | --- |
|
|
195
196
|
| [cliInvocation] | <code>string</code> | cli invocation string (used for cli help) |
|
|
197
|
+
| [defaultEnv] | <code>string</code> | default target environment |
|
|
196
198
|
| [dotenvToken] | <code>string</code> | token indicating a dotenv file |
|
|
197
199
|
| [dynamicPath] | <code>string</code> | path to file exporting an object keyed to dynamic variable functions |
|
|
198
200
|
| [env] | <code>string</code> | target environment |
|
|
@@ -272,6 +274,7 @@ get-dotenv options type
|
|
|
272
274
|
| [outputPath] | <code>string</code> | if populated, writes consolidated .env file to this path (follows [dotenv-expand rules](https://github.com/motdotla/dotenv-expand/blob/master/tests/.env)) |
|
|
273
275
|
| [paths] | <code>Array.<string></code> | array of input directory paths |
|
|
274
276
|
| [privateToken] | <code>string</code> | token indicating private variables |
|
|
277
|
+
| [vars] | <code>object</code> | explicit variables to include |
|
|
275
278
|
|
|
276
279
|
|
|
277
280
|
---
|
|
@@ -24,6 +24,7 @@ const booleanExpand = value => (0, _boolean.boolean)((0, _dotenvExpand.dotenvExp
|
|
|
24
24
|
*
|
|
25
25
|
* @typedef {Object} GetDotenvCliOptions
|
|
26
26
|
* @property {string} [cliInvocation] - cli invocation string (used for cli help)
|
|
27
|
+
* @property {string} [defaultEnv] - default target environment
|
|
27
28
|
* @property {string} [dotenvToken] - token indicating a dotenv file
|
|
28
29
|
* @property {string} [dynamicPath] - path to file exporting an object keyed to dynamic variable functions
|
|
29
30
|
* @property {string} [env] - target environment
|
|
@@ -84,6 +85,7 @@ const getCli = function () {
|
|
|
84
85
|
let {
|
|
85
86
|
cliInvocation = 'getdotenv',
|
|
86
87
|
command,
|
|
88
|
+
defaultEnv = 'dev',
|
|
87
89
|
dotenvToken,
|
|
88
90
|
dynamicPath,
|
|
89
91
|
env,
|
|
@@ -109,7 +111,7 @@ const getCli = function () {
|
|
|
109
111
|
if (Array.isArray(paths)) paths = paths.join(' ');
|
|
110
112
|
return new _commander.Command().name(cliInvocation)
|
|
111
113
|
// .usage('[options] [command] [command options] [commad args]')
|
|
112
|
-
.description('Base CLI. All options except delimiters follow dotenv-expand rules.').enablePositionalOptions().passThroughOptions().option('-e, --env <string>', 'environment
|
|
114
|
+
.description('Base CLI. All options except delimiters follow dotenv-expand rules.').enablePositionalOptions().passThroughOptions().option('-e, --env <string>', 'target environment', _dotenvExpand.dotenvExpand, env).option('--default-env <string>', 'default target environment', _dotenvExpand.dotenvExpand, defaultEnv).option('-p, --paths <string>', 'delimited list of paths to dotenv directory', _dotenvExpand.dotenvExpand, paths).option('--paths-delimiter <string>', 'regex paths delimiter', pathsDelimiter).option('-v, --vars <string>', 'delimited list KEY=VALUE pairs', _dotenvExpand.dotenvExpand, vars).option('--vars-delimiter <string>', 'regex vars delimiter', varsDelimiter).option('--vars-assignor <string>', 'regex vars assignment operator', varsAssignor).option('-y, --dynamic-path <string>', 'dynamic variables path', _dotenvExpand.dotenvExpand, dynamicPath).option('-o, --output-path <string>', 'consolidated output file, follows dotenv-expand rules using loaded env vars', _dotenvExpand.dotenvExpand, outputPath).option('-n, --exclude-env [bool]', 'exclude environment-specific variables', booleanExpand, excludeEnv ?? false).option('-g, --exclude-global [bool]', 'exclude global & dynamic variables', booleanExpand, excludeGlobal ?? false).option('-r, --exclude-private [bool]', 'exclude private variables', booleanExpand, excludePrivate ?? false).option('-u, --exclude-public [bool]', 'exclude public variables', booleanExpand, excludePublic ?? false).option('-z, --exclude-dynamic [bool]', 'exclude dynamic variables', booleanExpand, excludeDynamic ?? false).option('-l, --log [bool]', 'console log extracted variables', booleanExpand, log ?? false).option('-x, --suppress-dotenv', 'suppress dotenv loading', booleanExpand, suppressDotenv ?? false).option('-c, --command <string>', 'shell command string', _dotenvExpand.dotenvExpand, command).option('-s, --shell <string>', 'execa shell option', _dotenvExpand.dotenvExpand, shell).option('--dotenv-token <string>', 'token indicating a dotenv file', _dotenvExpand.dotenvExpand, dotenvToken).option('--private-token <string>', 'token indicating private variables', _dotenvExpand.dotenvExpand, privateToken).addCommand(new _commander.Command().name('cmd').description('execute shell command string (default command)').configureHelp({
|
|
113
115
|
showGlobalOptions: true
|
|
114
116
|
}).enablePositionalOptions().passThroughOptions().action(async (options, _ref) => {
|
|
115
117
|
let {
|
|
@@ -136,17 +138,19 @@ const getCli = function () {
|
|
|
136
138
|
// Get options.
|
|
137
139
|
let {
|
|
138
140
|
command,
|
|
141
|
+
defaultEnv,
|
|
142
|
+
env,
|
|
139
143
|
paths,
|
|
140
144
|
pathsDelimiter,
|
|
141
145
|
suppressDotenv,
|
|
142
|
-
vars,
|
|
146
|
+
vars: varsStr,
|
|
143
147
|
varsDelimiter,
|
|
144
148
|
varsAssignor,
|
|
145
149
|
...rest
|
|
146
150
|
} = options;
|
|
147
151
|
|
|
148
152
|
// Parse vars.
|
|
149
|
-
|
|
153
|
+
const vars = varsStr !== null && varsStr !== void 0 && varsStr.length ? (0, _lodash.default)(varsStr.split(new RegExp(varsDelimiter)).map(v => v.split(new RegExp(varsAssignor)))) : undefined;
|
|
150
154
|
|
|
151
155
|
// Execute getdotenv.
|
|
152
156
|
if ((_paths = paths) !== null && _paths !== void 0 && _paths.length && !suppressDotenv) {
|
|
@@ -154,8 +158,10 @@ const getCli = function () {
|
|
|
154
158
|
if ((0, _lodash2.default)(paths)) paths = (_paths2 = paths) === null || _paths2 === void 0 ? void 0 : _paths2.split(new RegExp(pathsDelimiter));
|
|
155
159
|
var dotenv = await (0, _getDotenv.getDotenv)({
|
|
156
160
|
...rest,
|
|
161
|
+
env: env ?? defaultEnv,
|
|
157
162
|
loadProcess: true,
|
|
158
|
-
paths
|
|
163
|
+
paths,
|
|
164
|
+
vars
|
|
159
165
|
});
|
|
160
166
|
}
|
|
161
167
|
|
|
@@ -34,6 +34,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
34
34
|
* @property {string} [outputPath] - if populated, writes consolidated .env file to this path (follows {@link https://github.com/motdotla/dotenv-expand/blob/master/tests/.env dotenv-expand rules})
|
|
35
35
|
* @property {string[]} [paths] - array of input directory paths
|
|
36
36
|
* @property {string} [privateToken] - token indicating private variables
|
|
37
|
+
* @property {object} [vars] - explicit variables to include
|
|
37
38
|
*/
|
|
38
39
|
|
|
39
40
|
/**
|
|
@@ -63,14 +64,15 @@ const getDotenv = async function () {
|
|
|
63
64
|
logger,
|
|
64
65
|
outputPath,
|
|
65
66
|
paths,
|
|
66
|
-
privateToken
|
|
67
|
+
privateToken,
|
|
68
|
+
vars = {}
|
|
67
69
|
} = {
|
|
68
70
|
..._dotenvDefaults.dotenvDefaults,
|
|
69
71
|
...options
|
|
70
72
|
};
|
|
71
73
|
|
|
72
74
|
// Read .env files.
|
|
73
|
-
const
|
|
75
|
+
const loaded = await paths.reduce(async (e, p) => {
|
|
74
76
|
let publicGlobal = excludePublic || excludeGlobal ? {} : (0, _readDotenv.readDotenv)(_path.default.resolve(p, dotenvToken));
|
|
75
77
|
let publicEnv = excludePublic || excludeEnv ? {} : (0, _readDotenv.readDotenv)(_path.default.resolve(p, `${dotenvToken}.${env}`));
|
|
76
78
|
let privateGlobal = excludePrivate || excludeGlobal ? {} : (0, _readDotenv.readDotenv)(_path.default.resolve(p, `${dotenvToken}.${privateToken}`));
|
|
@@ -90,7 +92,8 @@ const getDotenv = async function () {
|
|
|
90
92
|
} = (0, _dotenvExpand.expand)({
|
|
91
93
|
ignoreProcessEnv: true,
|
|
92
94
|
parsed: {
|
|
93
|
-
...
|
|
95
|
+
...loaded,
|
|
96
|
+
...vars,
|
|
94
97
|
...(outputPath ? {
|
|
95
98
|
[outputKey]: outputPath
|
|
96
99
|
} : {})
|
|
@@ -169,14 +172,15 @@ const getDotenvSync = function () {
|
|
|
169
172
|
log,
|
|
170
173
|
outputPath,
|
|
171
174
|
paths,
|
|
172
|
-
privateToken
|
|
175
|
+
privateToken,
|
|
176
|
+
vars
|
|
173
177
|
} = {
|
|
174
178
|
..._dotenvDefaults.dotenvDefaults,
|
|
175
179
|
...options
|
|
176
180
|
};
|
|
177
181
|
|
|
178
182
|
// Read .env files.
|
|
179
|
-
const
|
|
183
|
+
const loaded = paths.reduce((e, p) => {
|
|
180
184
|
let publicGlobal = excludePublic || excludeGlobal ? {} : (0, _readDotenv.readDotenvSync)(_path.default.resolve(p, dotenvToken));
|
|
181
185
|
let publicEnv = excludePublic || excludeEnv ? {} : (0, _readDotenv.readDotenvSync)(_path.default.resolve(p, `${dotenvToken}.${env}`));
|
|
182
186
|
let privateGlobal = excludePrivate || excludeGlobal ? {} : (0, _readDotenv.readDotenvSync)(_path.default.resolve(p, `${dotenvToken}.${privateToken}`));
|
|
@@ -195,7 +199,8 @@ const getDotenvSync = function () {
|
|
|
195
199
|
} = (0, _dotenvExpand.expand)({
|
|
196
200
|
ignoreProcessEnv: true,
|
|
197
201
|
parsed: {
|
|
198
|
-
...
|
|
202
|
+
...loaded,
|
|
203
|
+
...vars,
|
|
199
204
|
...(outputPath ? {
|
|
200
205
|
[outputKey]: outputPath
|
|
201
206
|
} : {})
|
package/lib/getCli.js
CHANGED
|
@@ -17,6 +17,7 @@ const booleanExpand = (value) => boolean(dotenvExpand(value));
|
|
|
17
17
|
*
|
|
18
18
|
* @typedef {Object} GetDotenvCliOptions
|
|
19
19
|
* @property {string} [cliInvocation] - cli invocation string (used for cli help)
|
|
20
|
+
* @property {string} [defaultEnv] - default target environment
|
|
20
21
|
* @property {string} [dotenvToken] - token indicating a dotenv file
|
|
21
22
|
* @property {string} [dynamicPath] - path to file exporting an object keyed to dynamic variable functions
|
|
22
23
|
* @property {string} [env] - target environment
|
|
@@ -72,6 +73,7 @@ export const getCli = ({ defaultOptions = {}, preHook, postHook } = {}) => {
|
|
|
72
73
|
let {
|
|
73
74
|
cliInvocation = 'getdotenv',
|
|
74
75
|
command,
|
|
76
|
+
defaultEnv = 'dev',
|
|
75
77
|
dotenvToken,
|
|
76
78
|
dynamicPath,
|
|
77
79
|
env,
|
|
@@ -106,7 +108,13 @@ export const getCli = ({ defaultOptions = {}, preHook, postHook } = {}) => {
|
|
|
106
108
|
)
|
|
107
109
|
.enablePositionalOptions()
|
|
108
110
|
.passThroughOptions()
|
|
109
|
-
.option('-e, --env <string>', 'environment
|
|
111
|
+
.option('-e, --env <string>', 'target environment', dotenvExpand, env)
|
|
112
|
+
.option(
|
|
113
|
+
'--default-env <string>',
|
|
114
|
+
'default target environment',
|
|
115
|
+
dotenvExpand,
|
|
116
|
+
defaultEnv
|
|
117
|
+
)
|
|
110
118
|
.option(
|
|
111
119
|
'-p, --paths <string>',
|
|
112
120
|
'delimited list of paths to dotenv directory',
|
|
@@ -238,25 +246,25 @@ export const getCli = ({ defaultOptions = {}, preHook, postHook } = {}) => {
|
|
|
238
246
|
// Get options.
|
|
239
247
|
let {
|
|
240
248
|
command,
|
|
249
|
+
defaultEnv,
|
|
250
|
+
env,
|
|
241
251
|
paths,
|
|
242
252
|
pathsDelimiter,
|
|
243
253
|
suppressDotenv,
|
|
244
|
-
vars,
|
|
254
|
+
vars: varsStr,
|
|
245
255
|
varsDelimiter,
|
|
246
256
|
varsAssignor,
|
|
247
257
|
...rest
|
|
248
258
|
} = options;
|
|
249
259
|
|
|
250
260
|
// Parse vars.
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
fromPairs(
|
|
255
|
-
vars
|
|
261
|
+
const vars = varsStr?.length
|
|
262
|
+
? fromPairs(
|
|
263
|
+
varsStr
|
|
256
264
|
.split(new RegExp(varsDelimiter))
|
|
257
265
|
.map((v) => v.split(new RegExp(varsAssignor)))
|
|
258
266
|
)
|
|
259
|
-
|
|
267
|
+
: undefined;
|
|
260
268
|
|
|
261
269
|
// Execute getdotenv.
|
|
262
270
|
if (paths?.length && !suppressDotenv) {
|
|
@@ -264,8 +272,10 @@ export const getCli = ({ defaultOptions = {}, preHook, postHook } = {}) => {
|
|
|
264
272
|
|
|
265
273
|
var dotenv = await getDotenv({
|
|
266
274
|
...rest,
|
|
275
|
+
env: env ?? defaultEnv,
|
|
267
276
|
loadProcess: true,
|
|
268
277
|
paths,
|
|
278
|
+
vars,
|
|
269
279
|
});
|
|
270
280
|
}
|
|
271
281
|
|
package/lib/getDotenv.js
CHANGED
|
@@ -27,6 +27,7 @@ import { readDotenv, readDotenvSync } from './readDotenv.js';
|
|
|
27
27
|
* @property {string} [outputPath] - if populated, writes consolidated .env file to this path (follows {@link https://github.com/motdotla/dotenv-expand/blob/master/tests/.env dotenv-expand rules})
|
|
28
28
|
* @property {string[]} [paths] - array of input directory paths
|
|
29
29
|
* @property {string} [privateToken] - token indicating private variables
|
|
30
|
+
* @property {object} [vars] - explicit variables to include
|
|
30
31
|
*/
|
|
31
32
|
|
|
32
33
|
/**
|
|
@@ -56,10 +57,11 @@ export const getDotenv = async (options = {}) => {
|
|
|
56
57
|
outputPath,
|
|
57
58
|
paths,
|
|
58
59
|
privateToken,
|
|
60
|
+
vars = {},
|
|
59
61
|
} = { ...dotenvDefaults, ...options };
|
|
60
62
|
|
|
61
63
|
// Read .env files.
|
|
62
|
-
const
|
|
64
|
+
const loaded = await paths.reduce(async (e, p) => {
|
|
63
65
|
let publicGlobal =
|
|
64
66
|
excludePublic || excludeGlobal
|
|
65
67
|
? {}
|
|
@@ -94,7 +96,8 @@ export const getDotenv = async (options = {}) => {
|
|
|
94
96
|
const { parsed: dotenv } = expand({
|
|
95
97
|
ignoreProcessEnv: true,
|
|
96
98
|
parsed: {
|
|
97
|
-
...
|
|
99
|
+
...loaded,
|
|
100
|
+
...vars,
|
|
98
101
|
...(outputPath ? { [outputKey]: outputPath } : {}),
|
|
99
102
|
},
|
|
100
103
|
});
|
|
@@ -182,10 +185,11 @@ export const getDotenvSync = (options = {}) => {
|
|
|
182
185
|
outputPath,
|
|
183
186
|
paths,
|
|
184
187
|
privateToken,
|
|
188
|
+
vars,
|
|
185
189
|
} = { ...dotenvDefaults, ...options };
|
|
186
190
|
|
|
187
191
|
// Read .env files.
|
|
188
|
-
const
|
|
192
|
+
const loaded = paths.reduce((e, p) => {
|
|
189
193
|
let publicGlobal =
|
|
190
194
|
excludePublic || excludeGlobal
|
|
191
195
|
? {}
|
|
@@ -218,7 +222,8 @@ export const getDotenvSync = (options = {}) => {
|
|
|
218
222
|
const { parsed: dotenv } = expand({
|
|
219
223
|
ignoreProcessEnv: true,
|
|
220
224
|
parsed: {
|
|
221
|
-
...
|
|
225
|
+
...loaded,
|
|
226
|
+
...vars,
|
|
222
227
|
...(outputPath ? { [outputKey]: outputPath } : {}),
|
|
223
228
|
},
|
|
224
229
|
});
|