@karmaniverous/get-dotenv 3.1.5 → 3.1.7
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 +2 -2
- package/bin/getdotenv/index.js +1 -1
- package/dist/default/lib/getDotenv.js +3 -3
- package/dist/default/lib/getDotenvCli.js +14 -13
- package/lib/getDotenv.js +3 -3
- package/lib/getDotenvCli.js +20 -9
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@ Load environment variables with a cascade of environment-aware dotenv files. You
|
|
|
7
7
|
- Define dynamic variables progressively in terms of other variables and other logic.
|
|
8
8
|
- Exclude public, private, global, environment-specific, or dynamic variables.
|
|
9
9
|
- Specify explicit variables to include.
|
|
10
|
-
- Extract the resulting variables to an object, `process.env`, a dotenv file, or a logger, in any combination.
|
|
10
|
+
- Extract the resulting variables to an object, `process.env`, a dotenv file, or a logger object, in any combination.
|
|
11
11
|
- Execute a shell command within the resulting environment. You can even nest additional `getdotenv` calls!
|
|
12
12
|
- Specify the directories containing your dotenv files.
|
|
13
13
|
- Specify the filename token that identifies dotenv files (e.g. '.env').
|
|
@@ -235,7 +235,7 @@ get-dotenv options type
|
|
|
235
235
|
| [excludePublic] | <code>bool</code> | exclude public variables |
|
|
236
236
|
| [loadProcess] | <code>bool</code> | load dotenv to process.env |
|
|
237
237
|
| [log] | <code>bool</code> | log result to logger |
|
|
238
|
-
| [logger] | <code>function</code> | logger
|
|
238
|
+
| [logger] | <code>function</code> | logger object (defaults to console) |
|
|
239
239
|
| [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)) |
|
|
240
240
|
| [paths] | <code>Array.<string></code> | array of input directory paths |
|
|
241
241
|
| [privateToken] | <code>string</code> | token indicating private variables |
|
package/bin/getdotenv/index.js
CHANGED
|
@@ -35,7 +35,7 @@ const pruneVars = (getdotenvDefaultOptions, options) => (0, _lodash.default)({
|
|
|
35
35
|
* @property {bool} [excludePublic] - exclude public variables
|
|
36
36
|
* @property {bool} [loadProcess] - load dotenv to process.env
|
|
37
37
|
* @property {bool} [log] - log result to logger
|
|
38
|
-
* @property {function} [logger] - logger
|
|
38
|
+
* @property {function} [logger] - logger object (defaults to console)
|
|
39
39
|
* @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})
|
|
40
40
|
* @property {string[]} [paths] - array of input directory paths
|
|
41
41
|
* @property {string} [privateToken] - token indicating private variables
|
|
@@ -66,7 +66,7 @@ const getDotenv = async function () {
|
|
|
66
66
|
excludePublic,
|
|
67
67
|
loadProcess,
|
|
68
68
|
log,
|
|
69
|
-
logger = console
|
|
69
|
+
logger = console,
|
|
70
70
|
outputPath,
|
|
71
71
|
paths,
|
|
72
72
|
privateToken
|
|
@@ -159,7 +159,7 @@ const getDotenvSync = function () {
|
|
|
159
159
|
excludePublic,
|
|
160
160
|
loadProcess,
|
|
161
161
|
log,
|
|
162
|
-
logger = console
|
|
162
|
+
logger = console,
|
|
163
163
|
outputPath,
|
|
164
164
|
paths,
|
|
165
165
|
privateToken
|
|
@@ -66,7 +66,7 @@ var _options = require("./options.js");
|
|
|
66
66
|
*/
|
|
67
67
|
const getDotenvCli = function () {
|
|
68
68
|
let {
|
|
69
|
-
logger = console
|
|
69
|
+
logger = console,
|
|
70
70
|
preHook,
|
|
71
71
|
postHook,
|
|
72
72
|
...cliOptionsCustom
|
|
@@ -104,10 +104,10 @@ const getDotenvCli = function () {
|
|
|
104
104
|
const excludeAll = excludeDynamic && (excludeEnv && excludeGlobal || excludePrivate && excludePublic);
|
|
105
105
|
return new _commander.Command().name(alias).description(description).enablePositionalOptions().passThroughOptions().option('-e, --env <string>', 'target environment', _dotenvExpand.dotenvExpand, env).option('-v, --vars <string>', `dotenv-expanded delimited key-value pairs: ${[['KEY1', 'VAL1'], ['KEY2', 'VAL2']].map(v => v.join(varsAssignor)).join(varsDelimiter)}`, _dotenvExpand.dotenvExpand).option('-c, --command <string>', 'dotenv-expanded shell command string', _dotenvExpand.dotenvExpand, command).option('-o, --output-path <string>', 'consolidated output file, follows dotenv-expand rules using loaded env vars', _dotenvExpand.dotenvExpand, outputPath).addOption(new _commander.Option('-p, --load-process', `load variables to process.env ON${loadProcess ? ' (default)' : ''}`).conflicts('loadProcessOff')).addOption(new _commander.Option('-P, --load-process-off', `load variables to process.env OFF${!loadProcess ? ' (default)' : ''}`).conflicts('loadProcess')).addOption(new _commander.Option('-a, --exclude-all', `exclude all dotenv variables from loading ON${excludeAll ? ' (default)' : ''}`).conflicts('excludeAllOff')).addOption(new _commander.Option('-A, --exclude-all-off', `exclude all dotenv variables from loading OFF${!excludeAll ? ' (default)' : ''}`).conflicts('excludeAll')).addOption(new _commander.Option('-z, --exclude-dynamic', `exclude dynamic dotenv variables from loading ON${excludeDynamic ? ' (default)' : ''}`).conflicts('excludeDynamicOff')).addOption(new _commander.Option('-Z, --exclude-dynamic-off', `exclude dynamic dotenv variables from loading OFF${!excludeDynamic ? ' (default)' : ''}`).conflicts('excludeDynamic')).addOption(new _commander.Option('-n, --exclude-env', `exclude environment-specific dotenv variables from loading${excludeEnv ? ' (default)' : ''}`).conflicts('excludeEnvOff')).addOption(new _commander.Option('-N, --exclude-env-off', `exclude environment-specific dotenv variables from loading OFF${!excludeEnv ? ' (default)' : ''}`).conflicts('excludeEnv')).addOption(new _commander.Option('-g, --exclude-global', `exclude global dotenv variables from loading ON${excludeGlobal ? ' (default)' : ''}`).conflicts('excludeGlobalOff')).addOption(new _commander.Option('-G, --exclude-global-off', `exclude global dotenv variables from loading OFF${!excludeGlobal ? ' (default)' : ''}`).conflicts('excludeGlobal')).addOption(new _commander.Option('-r, --exclude-private', `exclude private dotenv variables from loading ON${excludePrivate ? ' (default)' : ''}`).conflicts('excludePrivateOff')).addOption(new _commander.Option('-R, --exclude-private-off', `exclude private dotenv variables from loading OFF${!excludePrivate ? ' (default)' : ''}`).conflicts('excludePrivate')).addOption(new _commander.Option('-u, --exclude-public', `exclude public dotenv variables from loading ON${excludePublic ? ' (default)' : ''}`).conflicts('excludePublicOff')).addOption(new _commander.Option('-U, --exclude-public-off', `exclude public dotenv variables from loading OFF${!excludePublic ? ' (default)' : ''}`).conflicts('excludePublic')).addOption(new _commander.Option('-l, --log', `console log loaded variables ON${log ? ' (default)' : ''}`).conflicts('logOff')).addOption(new _commander.Option('-L, --log-off', `console log loaded variables OFF${!log ? ' (default)' : ''}`).conflicts('log')).addOption(new _commander.Option('-d, --debug', `debug mode ON${debug ? ' (default)' : ''}`).conflicts('debugOff')).addOption(new _commander.Option('-D, --debug-off', `debug mode OFF${!debug ? ' (default)' : ''}`).conflicts('debug')).option('--default-env <string>', 'default target environment', _dotenvExpand.dotenvExpand, defaultEnv).option('--dotenv-token <string>', 'dotenv-expanded token indicating a dotenv file', _dotenvExpand.dotenvExpand, dotenvToken).option('--dynamic-path <string>', 'dynamic variables path', _dotenvExpand.dotenvExpand, dynamicPath).option('--paths <string>', 'dotenv-expanded delimited list of paths to dotenv directory', _dotenvExpand.dotenvExpand, paths).option('--paths-delimiter <string>', 'paths delimiter string', pathsDelimiter).option('--paths-delimiter-pattern <string>', 'paths delimiter regex pattern', pathsDelimiterPattern).option('--private-token <string>', 'dotenv-expanded token indicating private variables', _dotenvExpand.dotenvExpand, privateToken).option('--vars-delimiter <string>', 'vars delimiter string', varsDelimiter).option('--vars-delimiter-pattern <string>', 'vars delimiter regex pattern', varsDelimiterPattern).option('--vars-assignor <string>', 'vars assignment operator string', varsAssignor).option('--vars-assignor-pattern <string>', 'vars assignment operator regex pattern', varsAssignorPattern).addCommand(new _commander.Command().name('cmd').description('execute shell command string (default command)').configureHelp({
|
|
106
106
|
showGlobalOptions: true
|
|
107
|
-
}).enablePositionalOptions().passThroughOptions().action(async (options,
|
|
108
|
-
|
|
107
|
+
}).enablePositionalOptions().passThroughOptions().action(async (options, command) => {
|
|
108
|
+
const {
|
|
109
109
|
args
|
|
110
|
-
} =
|
|
110
|
+
} = command;
|
|
111
111
|
if (args.length) await (0, _execa.execaCommand)(args.join('\\ '), {
|
|
112
112
|
stdio: 'inherit',
|
|
113
113
|
shell: true
|
|
@@ -116,7 +116,7 @@ const getDotenvCli = function () {
|
|
|
116
116
|
isDefault: true
|
|
117
117
|
}).hook('preSubcommand', async thisCommand => {
|
|
118
118
|
const rawOptions = thisCommand.opts();
|
|
119
|
-
if (rawOptions.debug) logger('\n*** raw options ***\n', {
|
|
119
|
+
if (rawOptions.debug) logger('\n*** raw cli options ***\n', {
|
|
120
120
|
rawOptions
|
|
121
121
|
});
|
|
122
122
|
|
|
@@ -146,14 +146,14 @@ const getDotenvCli = function () {
|
|
|
146
146
|
cliOptions.excludePublic = resolveExclusionAll(cliOptions.excludePublic, excludePublicOff, excludePublic);
|
|
147
147
|
cliOptions.log = resolveExclusion(cliOptions.log, logOff, log);
|
|
148
148
|
cliOptions.loadProcess = resolveExclusion(cliOptions.loadProcess, loadProcessOff, loadProcess);
|
|
149
|
-
if (cliOptions.debug) logger('\n*** after default resolution ***\n', {
|
|
149
|
+
if (cliOptions.debug) logger('\n*** cli options after default resolution ***\n', {
|
|
150
150
|
cliOptions
|
|
151
151
|
});
|
|
152
152
|
|
|
153
153
|
// Execute pre-hook.
|
|
154
154
|
if (preHook) {
|
|
155
155
|
cliOptions = (await preHook(cliOptions)) ?? cliOptions;
|
|
156
|
-
if (cliOptions.debug) logger('\n*** after pre-hook ***\n', cliOptions);
|
|
156
|
+
if (cliOptions.debug) logger('\n*** cli options after pre-hook ***\n', cliOptions);
|
|
157
157
|
}
|
|
158
158
|
|
|
159
159
|
// Get getdotenv options from parent command.
|
|
@@ -163,23 +163,24 @@ const getDotenvCli = function () {
|
|
|
163
163
|
...parentGetdotenvOptions,
|
|
164
164
|
...cliGetdotenvOptions
|
|
165
165
|
};
|
|
166
|
-
if (cliOptions.debug) logger('\n***
|
|
166
|
+
if (cliOptions.debug) logger('\n*** getdotenv option resolution ***\n', {
|
|
167
167
|
parentGetdotenvOptions,
|
|
168
168
|
cliGetdotenvOptions,
|
|
169
169
|
getdotenvOptions
|
|
170
170
|
});
|
|
171
171
|
|
|
172
172
|
// Execute getdotenv.
|
|
173
|
-
|
|
173
|
+
thisCommand.getdotenvOptions = {
|
|
174
174
|
...getdotenvOptions,
|
|
175
175
|
logger
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
|
|
176
|
+
};
|
|
177
|
+
thisCommand.dotenv = await (0, _getDotenv.getDotenv)(thisCommand.getdotenvOptions);
|
|
178
|
+
if (cliOptions.debug) console.log('\n*** resulting dotenv values ***\n', {
|
|
179
|
+
dotenv: thisCommand.dotenv
|
|
179
180
|
});
|
|
180
181
|
|
|
181
182
|
// Execute post-hook.
|
|
182
|
-
if (postHook) await postHook(dotenv);
|
|
183
|
+
if (postHook) await postHook(thisCommand.dotenv);
|
|
183
184
|
|
|
184
185
|
// Execute shell command.
|
|
185
186
|
if (command) await (0, _execa.execaCommand)(command.replace(/ /g, '\\ '), {
|
package/lib/getDotenv.js
CHANGED
|
@@ -32,7 +32,7 @@ const pruneVars = (getdotenvDefaultOptions, options) =>
|
|
|
32
32
|
* @property {bool} [excludePublic] - exclude public variables
|
|
33
33
|
* @property {bool} [loadProcess] - load dotenv to process.env
|
|
34
34
|
* @property {bool} [log] - log result to logger
|
|
35
|
-
* @property {function} [logger] - logger
|
|
35
|
+
* @property {function} [logger] - logger object (defaults to console)
|
|
36
36
|
* @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})
|
|
37
37
|
* @property {string[]} [paths] - array of input directory paths
|
|
38
38
|
* @property {string} [privateToken] - token indicating private variables
|
|
@@ -62,7 +62,7 @@ export const getDotenv = async (options = {}) => {
|
|
|
62
62
|
excludePublic,
|
|
63
63
|
loadProcess,
|
|
64
64
|
log,
|
|
65
|
-
logger = console
|
|
65
|
+
logger = console,
|
|
66
66
|
outputPath,
|
|
67
67
|
paths,
|
|
68
68
|
privateToken,
|
|
@@ -175,7 +175,7 @@ export const getDotenvSync = (options = {}) => {
|
|
|
175
175
|
excludePublic,
|
|
176
176
|
loadProcess,
|
|
177
177
|
log,
|
|
178
|
-
logger = console
|
|
178
|
+
logger = console,
|
|
179
179
|
outputPath,
|
|
180
180
|
paths,
|
|
181
181
|
privateToken,
|
package/lib/getDotenvCli.js
CHANGED
|
@@ -63,7 +63,7 @@ import {
|
|
|
63
63
|
* @returns {object} The CLI command.
|
|
64
64
|
*/
|
|
65
65
|
export const getDotenvCli = ({
|
|
66
|
-
logger = console
|
|
66
|
+
logger = console,
|
|
67
67
|
preHook,
|
|
68
68
|
postHook,
|
|
69
69
|
...cliOptionsCustom
|
|
@@ -326,7 +326,8 @@ export const getDotenvCli = ({
|
|
|
326
326
|
.configureHelp({ showGlobalOptions: true })
|
|
327
327
|
.enablePositionalOptions()
|
|
328
328
|
.passThroughOptions()
|
|
329
|
-
.action(async (options,
|
|
329
|
+
.action(async (options, command) => {
|
|
330
|
+
const { args } = command;
|
|
330
331
|
if (args.length)
|
|
331
332
|
await execaCommand(args.join('\\ '), {
|
|
332
333
|
stdio: 'inherit',
|
|
@@ -338,7 +339,8 @@ export const getDotenvCli = ({
|
|
|
338
339
|
.hook('preSubcommand', async (thisCommand) => {
|
|
339
340
|
const rawOptions = thisCommand.opts();
|
|
340
341
|
|
|
341
|
-
if (rawOptions.debug)
|
|
342
|
+
if (rawOptions.debug)
|
|
343
|
+
logger('\n*** raw cli options ***\n', { rawOptions });
|
|
342
344
|
|
|
343
345
|
// Load options.
|
|
344
346
|
let {
|
|
@@ -407,12 +409,15 @@ export const getDotenvCli = ({
|
|
|
407
409
|
);
|
|
408
410
|
|
|
409
411
|
if (cliOptions.debug)
|
|
410
|
-
logger('\n*** after default resolution ***\n', {
|
|
412
|
+
logger('\n*** cli options after default resolution ***\n', {
|
|
413
|
+
cliOptions,
|
|
414
|
+
});
|
|
411
415
|
|
|
412
416
|
// Execute pre-hook.
|
|
413
417
|
if (preHook) {
|
|
414
418
|
cliOptions = (await preHook(cliOptions)) ?? cliOptions;
|
|
415
|
-
if (cliOptions.debug)
|
|
419
|
+
if (cliOptions.debug)
|
|
420
|
+
logger('\n*** cli options after pre-hook ***\n', cliOptions);
|
|
416
421
|
}
|
|
417
422
|
|
|
418
423
|
// Get getdotenv options from parent command.
|
|
@@ -428,20 +433,26 @@ export const getDotenvCli = ({
|
|
|
428
433
|
};
|
|
429
434
|
|
|
430
435
|
if (cliOptions.debug)
|
|
431
|
-
logger('\n***
|
|
436
|
+
logger('\n*** getdotenv option resolution ***\n', {
|
|
432
437
|
parentGetdotenvOptions,
|
|
433
438
|
cliGetdotenvOptions,
|
|
434
439
|
getdotenvOptions,
|
|
435
440
|
});
|
|
436
441
|
|
|
437
442
|
// Execute getdotenv.
|
|
438
|
-
|
|
443
|
+
thisCommand.getdotenvOptions = {
|
|
444
|
+
...getdotenvOptions,
|
|
445
|
+
logger,
|
|
446
|
+
};
|
|
447
|
+
thisCommand.dotenv = await getDotenv(thisCommand.getdotenvOptions);
|
|
439
448
|
|
|
440
449
|
if (cliOptions.debug)
|
|
441
|
-
console.log('\n***
|
|
450
|
+
console.log('\n*** resulting dotenv values ***\n', {
|
|
451
|
+
dotenv: thisCommand.dotenv,
|
|
452
|
+
});
|
|
442
453
|
|
|
443
454
|
// Execute post-hook.
|
|
444
|
-
if (postHook) await postHook(dotenv);
|
|
455
|
+
if (postHook) await postHook(thisCommand.dotenv);
|
|
445
456
|
|
|
446
457
|
// Execute shell command.
|
|
447
458
|
if (command)
|