@karmaniverous/get-dotenv 3.0.4 → 3.0.5
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 +32 -24
- package/bin/getdotenv/index.js +1 -1
- package/dist/default/lib/getCli.js +35 -13
- package/lib/getCli.js +253 -187
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -79,31 +79,38 @@ 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>
|
|
83
|
-
--default-env <string>
|
|
84
|
-
-p, --paths <string>
|
|
85
|
-
--paths-delimiter <string>
|
|
86
|
-
-v, --vars <string>
|
|
87
|
-
--vars-delimiter <string>
|
|
88
|
-
--vars-assignor <string>
|
|
89
|
-
-y, --dynamic-path <string>
|
|
90
|
-
-o, --output-path <string>
|
|
91
|
-
-n, --exclude-env
|
|
92
|
-
-
|
|
93
|
-
-
|
|
94
|
-
-
|
|
95
|
-
-
|
|
96
|
-
-
|
|
97
|
-
-
|
|
98
|
-
-
|
|
99
|
-
-
|
|
100
|
-
--
|
|
101
|
-
|
|
102
|
-
-
|
|
82
|
+
-e, --env <string> target environment
|
|
83
|
+
--default-env <string> default target environment (default: "dev")
|
|
84
|
+
-p, --paths <string> delimited list of paths to dotenv directory (default: "./")
|
|
85
|
+
--paths-delimiter <string> regex paths delimiter (default: "\\s+")
|
|
86
|
+
-v, --vars <string> delimited list KEY=VALUE pairs
|
|
87
|
+
--vars-delimiter <string> regex vars delimiter (default: "\\s+")
|
|
88
|
+
--vars-assignor <string> regex vars assignment operator (default: "=")
|
|
89
|
+
-y, --dynamic-path <string> dynamic variables path
|
|
90
|
+
-o, --output-path <string> consolidated output file, follows dotenv-expand rules using loaded env vars
|
|
91
|
+
-n, --exclude-env exclude environment-specific variables
|
|
92
|
+
-N, --exclude-env-off exclude environment-specific variables OFF (default)
|
|
93
|
+
-g, --exclude-global exclude global variables
|
|
94
|
+
-G, --exclude-global-off exclude global variables OFF (default)
|
|
95
|
+
-r, --exclude-private exclude private variables
|
|
96
|
+
-R, --exclude-private-off exclude private variables OFF (default)
|
|
97
|
+
-u, --exclude-public exclude public variables
|
|
98
|
+
-U, --exclude-public-off exclude public variables OFF (default)
|
|
99
|
+
-z, --exclude-dynamic exclude dynamic variables
|
|
100
|
+
-Z, --exclude-dynamic-off exclude dynamic variables OFF (default)
|
|
101
|
+
-l, --log console log extracted variables
|
|
102
|
+
-L, --log-off console log extracted variables OFF (default)
|
|
103
|
+
-x, --suppress-dotenv suppress dotenv loading (default: false)
|
|
104
|
+
-c, --command <string> shell command string
|
|
105
|
+
-s, --shell <string> execa shell option
|
|
106
|
+
--dotenv-token <string> token indicating a dotenv file (default: ".env")
|
|
107
|
+
--private-token <string> token indicating private variables (default: "local")
|
|
108
|
+
-D, --debug debug mode
|
|
109
|
+
-h, --help display help for command
|
|
103
110
|
|
|
104
111
|
Commands:
|
|
105
|
-
cmd
|
|
106
|
-
help [command]
|
|
112
|
+
cmd execute shell command string (default command)
|
|
113
|
+
help [command] display help for command
|
|
107
114
|
```
|
|
108
115
|
|
|
109
116
|
# API Documentation
|
|
@@ -194,6 +201,7 @@ GetDotenv CLI Options type
|
|
|
194
201
|
| Name | Type | Description |
|
|
195
202
|
| --- | --- | --- |
|
|
196
203
|
| [cliInvocation] | <code>string</code> | cli invocation string (used for cli help) |
|
|
204
|
+
| [debug] | <code>bool</code> | debug mode |
|
|
197
205
|
| [defaultEnv] | <code>string</code> | default target environment |
|
|
198
206
|
| [dotenvToken] | <code>string</code> | token indicating a dotenv file |
|
|
199
207
|
| [dynamicPath] | <code>string</code> | path to file exporting an object keyed to dynamic variable functions |
|
|
@@ -208,7 +216,7 @@ GetDotenv CLI Options type
|
|
|
208
216
|
| [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)) |
|
|
209
217
|
| [paths] | <code>string</code> | space-delimited list of input directory paths |
|
|
210
218
|
| [privateToken] | <code>string</code> | token indicating private variables. |
|
|
211
|
-
| [shell] | <code>
|
|
219
|
+
| [shell] | <code>string</code> | execa shell option |
|
|
212
220
|
| [suppressDotenv] | <code>bool</code> | suppress dotenv loading |
|
|
213
221
|
|
|
214
222
|
<a name="GetDotenvPreHookCallback"></a>
|
package/bin/getdotenv/index.js
CHANGED
|
@@ -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 {bool} [debug] - debug mode
|
|
27
28
|
* @property {string} [defaultEnv] - default target environment
|
|
28
29
|
* @property {string} [dotenvToken] - token indicating a dotenv file
|
|
29
30
|
* @property {string} [dynamicPath] - path to file exporting an object keyed to dynamic variable functions
|
|
@@ -38,7 +39,7 @@ const booleanExpand = value => (0, _boolean.boolean)((0, _dotenvExpand.dotenvExp
|
|
|
38
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})
|
|
39
40
|
* @property {string} [paths] - space-delimited list of input directory paths
|
|
40
41
|
* @property {string} [privateToken] - token indicating private variables.
|
|
41
|
-
* @property {
|
|
42
|
+
* @property {string} [shell] - execa shell option
|
|
42
43
|
* @property {bool} [suppressDotenv] - suppress dotenv loading
|
|
43
44
|
*/
|
|
44
45
|
|
|
@@ -109,11 +110,7 @@ const getCli = function () {
|
|
|
109
110
|
...defaultOptions
|
|
110
111
|
};
|
|
111
112
|
if (Array.isArray(paths)) paths = paths.join(' ');
|
|
112
|
-
return new _commander.Command().name(cliInvocation)
|
|
113
|
-
// .usage('[options] [command] [command options] [commad args]')
|
|
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')
|
|
115
|
-
// .description('execute shell command string (default command)')
|
|
116
|
-
.configureHelp({
|
|
113
|
+
return new _commander.Command().name(cliInvocation).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).addOption(new _commander.Option('-n, --exclude-env', `exclude environment-specific variables${excludeEnv ? ' (default)' : ''}`).conflicts('excludeEnvOff')).addOption(new _commander.Option('-N, --exclude-env-off', `exclude environment-specific variables OFF${!excludeEnv ? ' (default)' : ''}`).conflicts('excludeEnv')).addOption(new _commander.Option('-g, --exclude-global', `exclude global variables${excludeGlobal ? ' (default)' : ''}`).conflicts('excludeGlobalOff')).addOption(new _commander.Option('-G, --exclude-global-off', `exclude global variables OFF${!excludeGlobal ? ' (default)' : ''}`).conflicts('excludeGlobal')).addOption(new _commander.Option('-r, --exclude-private', `exclude private variables${excludePrivate ? ' (default)' : ''}`).conflicts('excludePrivateOff')).addOption(new _commander.Option('-R, --exclude-private-off', `exclude private variables OFF${!excludePrivate ? ' (default)' : ''}`).conflicts('excludePrivate')).addOption(new _commander.Option('-u, --exclude-public', `exclude public variables${excludePublic ? ' (default)' : ''}`).conflicts('excludePublicOff')).addOption(new _commander.Option('-U, --exclude-public-off', `exclude public variables OFF${!excludePublic ? ' (default)' : ''}`).conflicts('excludePublic')).addOption(new _commander.Option('-z, --exclude-dynamic', `exclude dynamic variables${excludeDynamic ? ' (default)' : ''}`).conflicts('excludeDynamicOff')).addOption(new _commander.Option('-Z, --exclude-dynamic-off', `exclude dynamic variables OFF${!excludeDynamic ? ' (default)' : ''}`).conflicts('excludeDynamic')).addOption(new _commander.Option('-l, --log', `console log extracted variables${log ? ' (default)' : ''}`).conflicts('logOff')).addOption(new _commander.Option('-L, --log-off', `console log extracted variables OFF${!log ? ' (default)' : ''}`).conflicts('log')).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).option('-D, --debug', 'debug mode').addCommand(new _commander.Command().name('cmd').description('execute shell command string (default command)').configureHelp({
|
|
117
114
|
showGlobalOptions: true
|
|
118
115
|
}).enablePositionalOptions().passThroughOptions().action(async (options, _ref) => {
|
|
119
116
|
let {
|
|
@@ -124,22 +121,39 @@ const getCli = function () {
|
|
|
124
121
|
stdio: 'inherit',
|
|
125
122
|
shell: parent.opts().shell
|
|
126
123
|
});
|
|
127
|
-
})
|
|
128
|
-
|
|
129
|
-
).hook('preSubcommand', async thisCommand => {
|
|
124
|
+
}), {
|
|
125
|
+
isDefault: true
|
|
126
|
+
}).hook('preSubcommand', async thisCommand => {
|
|
130
127
|
var _paths;
|
|
131
128
|
// Inherit options from parent command.
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
129
|
+
const getdotenvOptions = process.env['getdotenvOptions'] ? JSON.parse(process.env['getdotenvOptions']) : {};
|
|
130
|
+
const {
|
|
131
|
+
excludeDynamicOff,
|
|
132
|
+
excludeEnvOff,
|
|
133
|
+
excludeGlobalOff,
|
|
134
|
+
excludePrivateOff,
|
|
135
|
+
excludePublicOff,
|
|
136
|
+
logOff,
|
|
137
|
+
...localOptions
|
|
138
|
+
} = thisCommand.opts();
|
|
139
|
+
if (excludeDynamicOff) localOptions.excludeDynamic = false;
|
|
140
|
+
if (excludeEnvOff) localOptions.excludeEnv = false;
|
|
141
|
+
if (excludeGlobalOff) localOptions.excludeGlobal = false;
|
|
142
|
+
if (excludePrivateOff) localOptions.excludePrivate = false;
|
|
143
|
+
if (excludePublicOff) localOptions.excludePublic = false;
|
|
144
|
+
if (logOff) localOptions.log = false;
|
|
145
|
+
let mergedOptions = {
|
|
146
|
+
...getdotenvOptions,
|
|
147
|
+
...localOptions
|
|
135
148
|
};
|
|
136
149
|
|
|
137
150
|
// Execute pre-hook.
|
|
138
|
-
|
|
151
|
+
const options = preHook ? (await preHook(mergedOptions)) ?? mergedOptions : mergedOptions;
|
|
139
152
|
|
|
140
153
|
// Get options.
|
|
141
154
|
let {
|
|
142
155
|
command,
|
|
156
|
+
debug,
|
|
143
157
|
defaultEnv,
|
|
144
158
|
env,
|
|
145
159
|
paths,
|
|
@@ -153,6 +167,13 @@ const getCli = function () {
|
|
|
153
167
|
|
|
154
168
|
// Parse vars.
|
|
155
169
|
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;
|
|
170
|
+
if (debug) {
|
|
171
|
+
console.log('*** getdotenvOptions ***', getdotenvOptions);
|
|
172
|
+
console.log('*** localOptions ***', localOptions);
|
|
173
|
+
console.log('*** mergedOptions ***', mergedOptions);
|
|
174
|
+
console.log('*** options ***', options);
|
|
175
|
+
console.log('*** vars ***', vars);
|
|
176
|
+
}
|
|
156
177
|
|
|
157
178
|
// Execute getdotenv.
|
|
158
179
|
if ((_paths = paths) !== null && _paths !== void 0 && _paths.length && !suppressDotenv) {
|
|
@@ -166,6 +187,7 @@ const getCli = function () {
|
|
|
166
187
|
vars
|
|
167
188
|
});
|
|
168
189
|
}
|
|
190
|
+
if (debug) console.log('*** dotenv ***', dotenv);
|
|
169
191
|
|
|
170
192
|
// Execute post-hook.
|
|
171
193
|
if (postHook) await postHook(options, dotenv);
|
package/lib/getCli.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// npm imports
|
|
2
2
|
import { boolean } from 'boolean';
|
|
3
|
-
import { Command } from 'commander';
|
|
3
|
+
import { Command, Option } from 'commander';
|
|
4
4
|
import { execaCommand } from 'execa';
|
|
5
5
|
import fromPairs from 'lodash.frompairs';
|
|
6
6
|
import isString from 'lodash.isstring';
|
|
@@ -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 {bool} [debug] - debug mode
|
|
20
21
|
* @property {string} [defaultEnv] - default target environment
|
|
21
22
|
* @property {string} [dotenvToken] - token indicating a dotenv file
|
|
22
23
|
* @property {string} [dynamicPath] - path to file exporting an object keyed to dynamic variable functions
|
|
@@ -31,7 +32,7 @@ const booleanExpand = (value) => boolean(dotenvExpand(value));
|
|
|
31
32
|
* @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})
|
|
32
33
|
* @property {string} [paths] - space-delimited list of input directory paths
|
|
33
34
|
* @property {string} [privateToken] - token indicating private variables.
|
|
34
|
-
* @property {
|
|
35
|
+
* @property {string} [shell] - execa shell option
|
|
35
36
|
* @property {bool} [suppressDotenv] - suppress dotenv loading
|
|
36
37
|
*/
|
|
37
38
|
|
|
@@ -99,196 +100,261 @@ export const getCli = ({ defaultOptions = {}, preHook, postHook } = {}) => {
|
|
|
99
100
|
|
|
100
101
|
if (Array.isArray(paths)) paths = paths.join(' ');
|
|
101
102
|
|
|
102
|
-
return (
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
'
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
.
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
'
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
'
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
'
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
'
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
'
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
'
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
103
|
+
return new Command()
|
|
104
|
+
.name(cliInvocation)
|
|
105
|
+
.description(
|
|
106
|
+
'Base CLI. All options except delimiters follow dotenv-expand rules.'
|
|
107
|
+
)
|
|
108
|
+
.enablePositionalOptions()
|
|
109
|
+
.passThroughOptions()
|
|
110
|
+
.option('-e, --env <string>', 'target environment', dotenvExpand, env)
|
|
111
|
+
.option(
|
|
112
|
+
'--default-env <string>',
|
|
113
|
+
'default target environment',
|
|
114
|
+
dotenvExpand,
|
|
115
|
+
defaultEnv
|
|
116
|
+
)
|
|
117
|
+
.option(
|
|
118
|
+
'-p, --paths <string>',
|
|
119
|
+
'delimited list of paths to dotenv directory',
|
|
120
|
+
dotenvExpand,
|
|
121
|
+
paths
|
|
122
|
+
)
|
|
123
|
+
.option(
|
|
124
|
+
'--paths-delimiter <string>',
|
|
125
|
+
'regex paths delimiter',
|
|
126
|
+
pathsDelimiter
|
|
127
|
+
)
|
|
128
|
+
.option(
|
|
129
|
+
'-v, --vars <string>',
|
|
130
|
+
'delimited list KEY=VALUE pairs',
|
|
131
|
+
dotenvExpand,
|
|
132
|
+
vars
|
|
133
|
+
)
|
|
134
|
+
.option('--vars-delimiter <string>', 'regex vars delimiter', varsDelimiter)
|
|
135
|
+
.option(
|
|
136
|
+
'--vars-assignor <string>',
|
|
137
|
+
'regex vars assignment operator',
|
|
138
|
+
varsAssignor
|
|
139
|
+
)
|
|
140
|
+
.option(
|
|
141
|
+
'-y, --dynamic-path <string>',
|
|
142
|
+
'dynamic variables path',
|
|
143
|
+
dotenvExpand,
|
|
144
|
+
dynamicPath
|
|
145
|
+
)
|
|
146
|
+
.option(
|
|
147
|
+
'-o, --output-path <string>',
|
|
148
|
+
'consolidated output file, follows dotenv-expand rules using loaded env vars',
|
|
149
|
+
dotenvExpand,
|
|
150
|
+
outputPath
|
|
151
|
+
)
|
|
152
|
+
.addOption(
|
|
153
|
+
new Option(
|
|
154
|
+
'-n, --exclude-env',
|
|
155
|
+
`exclude environment-specific variables${
|
|
156
|
+
excludeEnv ? ' (default)' : ''
|
|
157
|
+
}`
|
|
158
|
+
).conflicts('excludeEnvOff')
|
|
159
|
+
)
|
|
160
|
+
.addOption(
|
|
161
|
+
new Option(
|
|
162
|
+
'-N, --exclude-env-off',
|
|
163
|
+
`exclude environment-specific variables OFF${
|
|
164
|
+
!excludeEnv ? ' (default)' : ''
|
|
165
|
+
}`
|
|
166
|
+
).conflicts('excludeEnv')
|
|
167
|
+
)
|
|
168
|
+
.addOption(
|
|
169
|
+
new Option(
|
|
170
|
+
'-g, --exclude-global',
|
|
171
|
+
`exclude global variables${excludeGlobal ? ' (default)' : ''}`
|
|
172
|
+
).conflicts('excludeGlobalOff')
|
|
173
|
+
)
|
|
174
|
+
.addOption(
|
|
175
|
+
new Option(
|
|
176
|
+
'-G, --exclude-global-off',
|
|
177
|
+
`exclude global variables OFF${!excludeGlobal ? ' (default)' : ''}`
|
|
178
|
+
).conflicts('excludeGlobal')
|
|
179
|
+
)
|
|
180
|
+
.addOption(
|
|
181
|
+
new Option(
|
|
182
|
+
'-r, --exclude-private',
|
|
183
|
+
`exclude private variables${excludePrivate ? ' (default)' : ''}`
|
|
184
|
+
).conflicts('excludePrivateOff')
|
|
185
|
+
)
|
|
186
|
+
.addOption(
|
|
187
|
+
new Option(
|
|
188
|
+
'-R, --exclude-private-off',
|
|
189
|
+
`exclude private variables OFF${!excludePrivate ? ' (default)' : ''}`
|
|
190
|
+
).conflicts('excludePrivate')
|
|
191
|
+
)
|
|
192
|
+
.addOption(
|
|
193
|
+
new Option(
|
|
194
|
+
'-u, --exclude-public',
|
|
195
|
+
`exclude public variables${excludePublic ? ' (default)' : ''}`
|
|
196
|
+
).conflicts('excludePublicOff')
|
|
197
|
+
)
|
|
198
|
+
.addOption(
|
|
199
|
+
new Option(
|
|
200
|
+
'-U, --exclude-public-off',
|
|
201
|
+
`exclude public variables OFF${!excludePublic ? ' (default)' : ''}`
|
|
202
|
+
).conflicts('excludePublic')
|
|
203
|
+
)
|
|
204
|
+
.addOption(
|
|
205
|
+
new Option(
|
|
206
|
+
'-z, --exclude-dynamic',
|
|
207
|
+
`exclude dynamic variables${excludeDynamic ? ' (default)' : ''}`
|
|
208
|
+
).conflicts('excludeDynamicOff')
|
|
209
|
+
)
|
|
210
|
+
.addOption(
|
|
211
|
+
new Option(
|
|
212
|
+
'-Z, --exclude-dynamic-off',
|
|
213
|
+
`exclude dynamic variables OFF${!excludeDynamic ? ' (default)' : ''}`
|
|
214
|
+
).conflicts('excludeDynamic')
|
|
215
|
+
)
|
|
216
|
+
.addOption(
|
|
217
|
+
new Option(
|
|
218
|
+
'-l, --log',
|
|
219
|
+
`console log extracted variables${log ? ' (default)' : ''}`
|
|
220
|
+
).conflicts('logOff')
|
|
221
|
+
)
|
|
222
|
+
.addOption(
|
|
223
|
+
new Option(
|
|
224
|
+
'-L, --log-off',
|
|
225
|
+
`console log extracted variables OFF${!log ? ' (default)' : ''}`
|
|
226
|
+
).conflicts('log')
|
|
227
|
+
)
|
|
228
|
+
.option(
|
|
229
|
+
'-x, --suppress-dotenv',
|
|
230
|
+
'suppress dotenv loading',
|
|
231
|
+
booleanExpand,
|
|
232
|
+
suppressDotenv ?? false
|
|
233
|
+
)
|
|
234
|
+
.option(
|
|
235
|
+
'-c, --command <string>',
|
|
236
|
+
'shell command string',
|
|
237
|
+
dotenvExpand,
|
|
238
|
+
command
|
|
239
|
+
)
|
|
240
|
+
.option('-s, --shell <string>', 'execa shell option', dotenvExpand, shell)
|
|
241
|
+
.option(
|
|
242
|
+
'--dotenv-token <string>',
|
|
243
|
+
'token indicating a dotenv file',
|
|
244
|
+
dotenvExpand,
|
|
245
|
+
dotenvToken
|
|
246
|
+
)
|
|
247
|
+
.option(
|
|
248
|
+
'--private-token <string>',
|
|
249
|
+
'token indicating private variables',
|
|
250
|
+
dotenvExpand,
|
|
251
|
+
privateToken
|
|
252
|
+
)
|
|
253
|
+
.option('-D, --debug', 'debug mode')
|
|
254
|
+
.addCommand(
|
|
255
|
+
new Command()
|
|
256
|
+
.name('cmd')
|
|
257
|
+
.description('execute shell command string (default command)')
|
|
258
|
+
.configureHelp({ showGlobalOptions: true })
|
|
259
|
+
.enablePositionalOptions()
|
|
260
|
+
.passThroughOptions()
|
|
261
|
+
.action(async (options, { args, parent }) => {
|
|
262
|
+
if (args.length)
|
|
263
|
+
await execaCommand(args.join(' '), {
|
|
264
|
+
stdio: 'inherit',
|
|
265
|
+
shell: parent.opts().shell,
|
|
266
|
+
});
|
|
267
|
+
}),
|
|
268
|
+
{ isDefault: true }
|
|
269
|
+
)
|
|
270
|
+
.hook('preSubcommand', async (thisCommand) => {
|
|
271
|
+
// Inherit options from parent command.
|
|
272
|
+
const getdotenvOptions = process.env['getdotenvOptions']
|
|
273
|
+
? JSON.parse(process.env['getdotenvOptions'])
|
|
274
|
+
: {};
|
|
243
275
|
|
|
244
|
-
|
|
245
|
-
|
|
276
|
+
const {
|
|
277
|
+
excludeDynamicOff,
|
|
278
|
+
excludeEnvOff,
|
|
279
|
+
excludeGlobalOff,
|
|
280
|
+
excludePrivateOff,
|
|
281
|
+
excludePublicOff,
|
|
282
|
+
logOff,
|
|
283
|
+
...localOptions
|
|
284
|
+
} = thisCommand.opts();
|
|
246
285
|
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
286
|
+
if (excludeDynamicOff) localOptions.excludeDynamic = false;
|
|
287
|
+
if (excludeEnvOff) localOptions.excludeEnv = false;
|
|
288
|
+
if (excludeGlobalOff) localOptions.excludeGlobal = false;
|
|
289
|
+
if (excludePrivateOff) localOptions.excludePrivate = false;
|
|
290
|
+
if (excludePublicOff) localOptions.excludePublic = false;
|
|
291
|
+
if (logOff) localOptions.log = false;
|
|
292
|
+
|
|
293
|
+
let mergedOptions = {
|
|
294
|
+
...getdotenvOptions,
|
|
295
|
+
...localOptions,
|
|
296
|
+
};
|
|
297
|
+
|
|
298
|
+
// Execute pre-hook.
|
|
299
|
+
const options = preHook
|
|
300
|
+
? (await preHook(mergedOptions)) ?? mergedOptions
|
|
301
|
+
: mergedOptions;
|
|
302
|
+
|
|
303
|
+
// Get options.
|
|
304
|
+
let {
|
|
305
|
+
command,
|
|
306
|
+
debug,
|
|
307
|
+
defaultEnv,
|
|
308
|
+
env,
|
|
309
|
+
paths,
|
|
310
|
+
pathsDelimiter,
|
|
311
|
+
suppressDotenv,
|
|
312
|
+
vars: varsStr,
|
|
313
|
+
varsDelimiter,
|
|
314
|
+
varsAssignor,
|
|
315
|
+
...rest
|
|
316
|
+
} = options;
|
|
260
317
|
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
318
|
+
// Parse vars.
|
|
319
|
+
const vars = varsStr?.length
|
|
320
|
+
? fromPairs(
|
|
321
|
+
varsStr
|
|
322
|
+
.split(new RegExp(varsDelimiter))
|
|
323
|
+
.map((v) => v.split(new RegExp(varsAssignor)))
|
|
324
|
+
)
|
|
325
|
+
: undefined;
|
|
269
326
|
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
327
|
+
if (debug) {
|
|
328
|
+
console.log('*** getdotenvOptions ***', getdotenvOptions);
|
|
329
|
+
console.log('*** localOptions ***', localOptions);
|
|
330
|
+
console.log('*** mergedOptions ***', mergedOptions);
|
|
331
|
+
console.log('*** options ***', options);
|
|
332
|
+
console.log('*** vars ***', vars);
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
// Execute getdotenv.
|
|
336
|
+
if (paths?.length && !suppressDotenv) {
|
|
337
|
+
if (isString(paths)) paths = paths?.split(new RegExp(pathsDelimiter));
|
|
338
|
+
|
|
339
|
+
var dotenv = await getDotenv({
|
|
340
|
+
...rest,
|
|
341
|
+
env: env ?? defaultEnv,
|
|
342
|
+
loadProcess: true,
|
|
343
|
+
paths,
|
|
344
|
+
vars,
|
|
345
|
+
});
|
|
346
|
+
}
|
|
273
347
|
|
|
274
|
-
|
|
275
|
-
...rest,
|
|
276
|
-
env: env ?? defaultEnv,
|
|
277
|
-
loadProcess: true,
|
|
278
|
-
paths,
|
|
279
|
-
vars,
|
|
280
|
-
});
|
|
281
|
-
}
|
|
348
|
+
if (debug) console.log('*** dotenv ***', dotenv);
|
|
282
349
|
|
|
283
|
-
|
|
284
|
-
|
|
350
|
+
// Execute post-hook.
|
|
351
|
+
if (postHook) await postHook(options, dotenv);
|
|
285
352
|
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
);
|
|
353
|
+
// Execute shell command.
|
|
354
|
+
if (command)
|
|
355
|
+
await execaCommand(command, {
|
|
356
|
+
stdio: 'inherit',
|
|
357
|
+
shell,
|
|
358
|
+
});
|
|
359
|
+
});
|
|
294
360
|
};
|