@karmaniverous/get-dotenv 4.1.0 → 4.2.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
@@ -121,7 +121,7 @@ You can also use `getdotenv` from the command line:
121
121
  # --vars-delimiter-pattern <string> vars delimiter regex pattern
122
122
  # --vars-assignor <string> vars assignment operator string (default: "=")
123
123
  # --vars-assignor-pattern <string> vars assignment operator regex pattern
124
- -h, --help display help for command
124
+ # -h, --help display help for command
125
125
  #
126
126
  # Commands:
127
127
  # batch [options] Batch shell commands across multiple working directories.
@@ -25764,6 +25764,7 @@ const defaultGetDotenvCliOptionsGlobal = {
25764
25764
  paths: './',
25765
25765
  pathsDelimiter: ' ',
25766
25766
  privateToken: 'local',
25767
+ shellScripts: {},
25767
25768
  vars: '',
25768
25769
  varsAssignor: '=',
25769
25770
  varsDelimiter: ' ',
@@ -25800,6 +25801,10 @@ const defaultGetDotenvCliOptionsLocal = (fs$a.existsSync(defaultGetDotenvCliOpti
25800
25801
  const mergeGetDotenvOptions = (target = {}, source = {}) => ({
25801
25802
  ...source,
25802
25803
  ...target,
25804
+ shellScripts: {
25805
+ ...(source.shellScripts ?? {}),
25806
+ ...(target.shellScripts ?? {}),
25807
+ },
25803
25808
  vars: _.pickBy({
25804
25809
  ...(source.vars ?? {}),
25805
25810
  ...(target.vars ?? {}),
@@ -25832,6 +25837,10 @@ const getDotenvCliOptions2Options = ({ paths, pathsDelimiter, pathsDelimiterPatt
25832
25837
  const getDotenvDefaultOptions = getDotenvCliOptions2Options({
25833
25838
  ...defaultGetDotenvCliOptionsGlobal,
25834
25839
  ...defaultGetDotenvCliOptionsLocal,
25840
+ shellScripts: {
25841
+ ...(defaultGetDotenvCliOptionsGlobal.shellScripts ?? {}),
25842
+ ...(defaultGetDotenvCliOptionsLocal.shellScripts ?? {}),
25843
+ },
25835
25844
  });
25836
25845
 
25837
25846
  var main$1 = {exports: {}};
@@ -34183,18 +34192,21 @@ const cmdCommand$1 = new Command()
34183
34192
  throw new Error(`unable to resolve parent command`);
34184
34193
  if (!thisCommand.parent.parent)
34185
34194
  throw new Error(`unable to resolve root command`);
34186
- const { getDotenvOptions: { logger = console }, } = thisCommand.parent.parent;
34195
+ const { getDotenvOptions: { logger = console, shellScripts }, } = thisCommand.parent.parent;
34187
34196
  const { ignoreErrors, globs, list, pkgCwd, rootPath } = thisCommand.parent.opts();
34188
34197
  // Execute shell command.
34189
- await execShellCommandBatch({
34190
- command: thisCommand.args.join(' '),
34191
- globs,
34192
- ignoreErrors,
34193
- list,
34194
- logger,
34195
- pkgCwd,
34196
- rootPath,
34197
- });
34198
+ {
34199
+ const command = thisCommand.args.join(' ');
34200
+ await execShellCommandBatch({
34201
+ command: shellScripts?.[command] ?? command,
34202
+ globs,
34203
+ ignoreErrors,
34204
+ list,
34205
+ logger,
34206
+ pkgCwd,
34207
+ rootPath,
34208
+ });
34209
+ }
34198
34210
  });
34199
34211
 
34200
34212
  const batchCommand = new Command()
@@ -34211,7 +34223,7 @@ const batchCommand = new Command()
34211
34223
  .hook('preSubcommand', async (thisCommand) => {
34212
34224
  if (!thisCommand.parent)
34213
34225
  throw new Error(`unable to resolve root command`);
34214
- const { getDotenvOptions: { logger = console }, } = thisCommand.parent;
34226
+ const { getDotenvOptions: { logger = console, shellScripts }, } = thisCommand.parent;
34215
34227
  const { command, ignoreErrors, globs, list, pkgCwd, rootPath } = thisCommand.opts();
34216
34228
  if (command && thisCommand.args.length) {
34217
34229
  logger.error(`--command option conflicts with cmd subcommand.`);
@@ -34220,7 +34232,7 @@ const batchCommand = new Command()
34220
34232
  // Execute shell command.
34221
34233
  if (command)
34222
34234
  await execShellCommandBatch({
34223
- command,
34235
+ command: shellScripts?.[command] ?? command,
34224
34236
  globs,
34225
34237
  ignoreErrors,
34226
34238
  list,
@@ -34240,8 +34252,9 @@ const cmdCommand = new Command()
34240
34252
  .action(async (options, thisCommand) => {
34241
34253
  if (!thisCommand.parent)
34242
34254
  throw new Error('parent command not found');
34243
- const { getDotenvOptions: { debug, logger = console }, } = thisCommand.parent;
34244
- const shellCommand = thisCommand.args.join(' ');
34255
+ const { getDotenvOptions: { debug, logger = console, shellScripts }, } = thisCommand.parent;
34256
+ const command = thisCommand.args.join(' ');
34257
+ const shellCommand = shellScripts?.[command] ?? command;
34245
34258
  if (debug)
34246
34259
  logger.log('\n*** shell command ***\n', shellCommand);
34247
34260
  await execaCommand(shellCommand, {
@@ -34254,10 +34267,15 @@ const cmdCommand = new Command()
34254
34267
  * Generate a Commander CLI Command for get-dotenv.
34255
34268
  */
34256
34269
  const generateGetDotenvCli = ({ logger = console, preHook, postHook, ...cliOptionsCustom } = {}) => {
34257
- const { alias = 'getdotenv', debug, defaultEnv, description = 'Base CLI.', dotenvToken, dynamicPath, env, excludeDynamic, excludeEnv, excludeGlobal, excludePrivate, excludePublic, loadProcess, log, outputPath, paths, pathsDelimiter, pathsDelimiterPattern, privateToken, varsAssignor, varsAssignorPattern, varsDelimiter, varsDelimiterPattern, } = {
34270
+ const { alias = 'getdotenv', debug, defaultEnv, description = 'Base CLI.', dotenvToken, dynamicPath, env, excludeDynamic, excludeEnv, excludeGlobal, excludePrivate, excludePublic, loadProcess, log, outputPath, paths, pathsDelimiter, pathsDelimiterPattern, privateToken, shellScripts, varsAssignor, varsAssignorPattern, varsDelimiter, varsDelimiterPattern, } = {
34258
34271
  ...defaultGetDotenvCliOptionsGlobal,
34259
34272
  ...cliOptionsCustom,
34260
34273
  ...defaultGetDotenvCliOptionsLocal,
34274
+ shellScripts: {
34275
+ ...(defaultGetDotenvCliOptionsGlobal.shellScripts ?? {}),
34276
+ ...(cliOptionsCustom.shellScripts ?? {}),
34277
+ ...(defaultGetDotenvCliOptionsLocal.shellScripts ?? {}),
34278
+ },
34261
34279
  };
34262
34280
  const excludeAll = !!excludeDynamic &&
34263
34281
  ((!!excludeEnv && !!excludeGlobal) ||
@@ -34305,6 +34323,9 @@ const generateGetDotenvCli = ({ logger = console, preHook, postHook, ...cliOptio
34305
34323
  .option('--vars-delimiter-pattern <string>', 'vars delimiter regex pattern', varsDelimiterPattern)
34306
34324
  .option('--vars-assignor <string>', 'vars assignment operator string', varsAssignor)
34307
34325
  .option('--vars-assignor-pattern <string>', 'vars assignment operator regex pattern', varsAssignorPattern)
34326
+ .addOption(new Option('--shell-scripts <string>')
34327
+ .default(JSON.stringify(shellScripts))
34328
+ .hideHelp())
34308
34329
  .addCommand(batchCommand)
34309
34330
  .addCommand(cmdCommand, { isDefault: true })
34310
34331
  .hook('preSubcommand', async (thisCommand) => {
@@ -34312,7 +34333,12 @@ const generateGetDotenvCli = ({ logger = console, preHook, postHook, ...cliOptio
34312
34333
  if (rawOptions.debug)
34313
34334
  logger.log('\n*** raw cli options ***\n', { rawOptions });
34314
34335
  // Load options.
34315
- const { command, debugOff, excludeAll, excludeAllOff, excludeDynamicOff, excludeEnvOff, excludeGlobalOff, excludePrivateOff, excludePublicOff, loadProcessOff, logOff, ...cliOptions } = rawOptions;
34336
+ const { command, debugOff, excludeAll, excludeAllOff, excludeDynamicOff, excludeEnvOff, excludeGlobalOff, excludePrivateOff, excludePublicOff, loadProcessOff, logOff, ...cliOptions } = {
34337
+ ...rawOptions,
34338
+ shellScripts: rawOptions.shellScripts
34339
+ ? JSON.parse(rawOptions.shellScripts)
34340
+ : undefined,
34341
+ };
34316
34342
  // Resolve flags.
34317
34343
  const resolveExclusion = (exclude, excludeOff, defaultValue) => exclude
34318
34344
  ? true
@@ -34351,10 +34377,7 @@ const generateGetDotenvCli = ({ logger = console, preHook, postHook, ...cliOptio
34351
34377
  ? JSON.parse(process.env.getDotenvOptions)
34352
34378
  : {});
34353
34379
  const cliGetDotenvOptions = getDotenvCliOptions2Options(cliOptions);
34354
- const getDotenvOptions = {
34355
- ...parentGetdotenvOptions,
34356
- ...cliGetDotenvOptions,
34357
- };
34380
+ const getDotenvOptions = mergeGetDotenvOptions(cliGetDotenvOptions, parentGetdotenvOptions);
34358
34381
  if (cliOptions.debug)
34359
34382
  logger.log('\n*** getdotenv option resolution ***\n', {
34360
34383
  parentGetdotenvOptions,
@@ -34362,9 +34385,9 @@ const generateGetDotenvCli = ({ logger = console, preHook, postHook, ...cliOptio
34362
34385
  getDotenvOptions,
34363
34386
  });
34364
34387
  // Execute getdotenv.
34365
- const getDotenvOptionsWithLogger = { ...getDotenvOptions, logger };
34366
- _.set(thisCommand, 'getDotenvOptions', getDotenvOptionsWithLogger);
34367
- const dotenv = await getDotenv(getDotenvOptionsWithLogger);
34388
+ const getDotenvOptionsProp = { ...getDotenvOptions, logger };
34389
+ _.set(thisCommand, 'getDotenvOptions', getDotenvOptionsProp);
34390
+ const dotenv = await getDotenv(getDotenvOptionsProp);
34368
34391
  if (cliOptions.debug)
34369
34392
  logger.log('\n*** resulting dotenv values ***\n', { dotenv });
34370
34393
  // Execute post-hook.
@@ -34376,9 +34399,10 @@ const generateGetDotenvCli = ({ logger = console, preHook, postHook, ...cliOptio
34376
34399
  process.exit(0);
34377
34400
  }
34378
34401
  if (command) {
34402
+ const shellCommand = getDotenvOptionsProp.shellScripts?.[command] ?? command;
34379
34403
  if (cliOptions.debug)
34380
- logger.log('\n*** shell command ***\n', command);
34381
- await execaCommand(command, {
34404
+ logger.log('\n*** shell command ***\n', shellCommand);
34405
+ await execaCommand(shellCommand, {
34382
34406
  env: {
34383
34407
  ...process.env,
34384
34408
  getDotenvOptions: JSON.stringify(getDotenvOptions),
package/dist/index.cjs CHANGED
@@ -25766,6 +25766,7 @@ const defaultGetDotenvCliOptionsGlobal = {
25766
25766
  paths: './',
25767
25767
  pathsDelimiter: ' ',
25768
25768
  privateToken: 'local',
25769
+ shellScripts: {},
25769
25770
  vars: '',
25770
25771
  varsAssignor: '=',
25771
25772
  varsDelimiter: ' ',
@@ -25802,6 +25803,10 @@ const defaultGetDotenvCliOptionsLocal = (fs$a.existsSync(defaultGetDotenvCliOpti
25802
25803
  const mergeGetDotenvOptions = (target = {}, source = {}) => ({
25803
25804
  ...source,
25804
25805
  ...target,
25806
+ shellScripts: {
25807
+ ...(source.shellScripts ?? {}),
25808
+ ...(target.shellScripts ?? {}),
25809
+ },
25805
25810
  vars: _.pickBy({
25806
25811
  ...(source.vars ?? {}),
25807
25812
  ...(target.vars ?? {}),
@@ -25834,6 +25839,10 @@ const getDotenvCliOptions2Options = ({ paths, pathsDelimiter, pathsDelimiterPatt
25834
25839
  const getDotenvDefaultOptions = getDotenvCliOptions2Options({
25835
25840
  ...defaultGetDotenvCliOptionsGlobal,
25836
25841
  ...defaultGetDotenvCliOptionsLocal,
25842
+ shellScripts: {
25843
+ ...(defaultGetDotenvCliOptionsGlobal.shellScripts ?? {}),
25844
+ ...(defaultGetDotenvCliOptionsLocal.shellScripts ?? {}),
25845
+ },
25837
25846
  });
25838
25847
 
25839
25848
  var main$1 = {exports: {}};
@@ -34185,18 +34194,21 @@ const cmdCommand$1 = new Command()
34185
34194
  throw new Error(`unable to resolve parent command`);
34186
34195
  if (!thisCommand.parent.parent)
34187
34196
  throw new Error(`unable to resolve root command`);
34188
- const { getDotenvOptions: { logger = console }, } = thisCommand.parent.parent;
34197
+ const { getDotenvOptions: { logger = console, shellScripts }, } = thisCommand.parent.parent;
34189
34198
  const { ignoreErrors, globs, list, pkgCwd, rootPath } = thisCommand.parent.opts();
34190
34199
  // Execute shell command.
34191
- await execShellCommandBatch({
34192
- command: thisCommand.args.join(' '),
34193
- globs,
34194
- ignoreErrors,
34195
- list,
34196
- logger,
34197
- pkgCwd,
34198
- rootPath,
34199
- });
34200
+ {
34201
+ const command = thisCommand.args.join(' ');
34202
+ await execShellCommandBatch({
34203
+ command: shellScripts?.[command] ?? command,
34204
+ globs,
34205
+ ignoreErrors,
34206
+ list,
34207
+ logger,
34208
+ pkgCwd,
34209
+ rootPath,
34210
+ });
34211
+ }
34200
34212
  });
34201
34213
 
34202
34214
  const batchCommand = new Command()
@@ -34213,7 +34225,7 @@ const batchCommand = new Command()
34213
34225
  .hook('preSubcommand', async (thisCommand) => {
34214
34226
  if (!thisCommand.parent)
34215
34227
  throw new Error(`unable to resolve root command`);
34216
- const { getDotenvOptions: { logger = console }, } = thisCommand.parent;
34228
+ const { getDotenvOptions: { logger = console, shellScripts }, } = thisCommand.parent;
34217
34229
  const { command, ignoreErrors, globs, list, pkgCwd, rootPath } = thisCommand.opts();
34218
34230
  if (command && thisCommand.args.length) {
34219
34231
  logger.error(`--command option conflicts with cmd subcommand.`);
@@ -34222,7 +34234,7 @@ const batchCommand = new Command()
34222
34234
  // Execute shell command.
34223
34235
  if (command)
34224
34236
  await execShellCommandBatch({
34225
- command,
34237
+ command: shellScripts?.[command] ?? command,
34226
34238
  globs,
34227
34239
  ignoreErrors,
34228
34240
  list,
@@ -34242,8 +34254,9 @@ const cmdCommand = new Command()
34242
34254
  .action(async (options, thisCommand) => {
34243
34255
  if (!thisCommand.parent)
34244
34256
  throw new Error('parent command not found');
34245
- const { getDotenvOptions: { debug, logger = console }, } = thisCommand.parent;
34246
- const shellCommand = thisCommand.args.join(' ');
34257
+ const { getDotenvOptions: { debug, logger = console, shellScripts }, } = thisCommand.parent;
34258
+ const command = thisCommand.args.join(' ');
34259
+ const shellCommand = shellScripts?.[command] ?? command;
34247
34260
  if (debug)
34248
34261
  logger.log('\n*** shell command ***\n', shellCommand);
34249
34262
  await execaCommand(shellCommand, {
@@ -34256,10 +34269,15 @@ const cmdCommand = new Command()
34256
34269
  * Generate a Commander CLI Command for get-dotenv.
34257
34270
  */
34258
34271
  const generateGetDotenvCli = ({ logger = console, preHook, postHook, ...cliOptionsCustom } = {}) => {
34259
- const { alias = 'getdotenv', debug, defaultEnv, description = 'Base CLI.', dotenvToken, dynamicPath, env, excludeDynamic, excludeEnv, excludeGlobal, excludePrivate, excludePublic, loadProcess, log, outputPath, paths, pathsDelimiter, pathsDelimiterPattern, privateToken, varsAssignor, varsAssignorPattern, varsDelimiter, varsDelimiterPattern, } = {
34272
+ const { alias = 'getdotenv', debug, defaultEnv, description = 'Base CLI.', dotenvToken, dynamicPath, env, excludeDynamic, excludeEnv, excludeGlobal, excludePrivate, excludePublic, loadProcess, log, outputPath, paths, pathsDelimiter, pathsDelimiterPattern, privateToken, shellScripts, varsAssignor, varsAssignorPattern, varsDelimiter, varsDelimiterPattern, } = {
34260
34273
  ...defaultGetDotenvCliOptionsGlobal,
34261
34274
  ...cliOptionsCustom,
34262
34275
  ...defaultGetDotenvCliOptionsLocal,
34276
+ shellScripts: {
34277
+ ...(defaultGetDotenvCliOptionsGlobal.shellScripts ?? {}),
34278
+ ...(cliOptionsCustom.shellScripts ?? {}),
34279
+ ...(defaultGetDotenvCliOptionsLocal.shellScripts ?? {}),
34280
+ },
34263
34281
  };
34264
34282
  const excludeAll = !!excludeDynamic &&
34265
34283
  ((!!excludeEnv && !!excludeGlobal) ||
@@ -34307,6 +34325,9 @@ const generateGetDotenvCli = ({ logger = console, preHook, postHook, ...cliOptio
34307
34325
  .option('--vars-delimiter-pattern <string>', 'vars delimiter regex pattern', varsDelimiterPattern)
34308
34326
  .option('--vars-assignor <string>', 'vars assignment operator string', varsAssignor)
34309
34327
  .option('--vars-assignor-pattern <string>', 'vars assignment operator regex pattern', varsAssignorPattern)
34328
+ .addOption(new Option('--shell-scripts <string>')
34329
+ .default(JSON.stringify(shellScripts))
34330
+ .hideHelp())
34310
34331
  .addCommand(batchCommand)
34311
34332
  .addCommand(cmdCommand, { isDefault: true })
34312
34333
  .hook('preSubcommand', async (thisCommand) => {
@@ -34314,7 +34335,12 @@ const generateGetDotenvCli = ({ logger = console, preHook, postHook, ...cliOptio
34314
34335
  if (rawOptions.debug)
34315
34336
  logger.log('\n*** raw cli options ***\n', { rawOptions });
34316
34337
  // Load options.
34317
- const { command, debugOff, excludeAll, excludeAllOff, excludeDynamicOff, excludeEnvOff, excludeGlobalOff, excludePrivateOff, excludePublicOff, loadProcessOff, logOff, ...cliOptions } = rawOptions;
34338
+ const { command, debugOff, excludeAll, excludeAllOff, excludeDynamicOff, excludeEnvOff, excludeGlobalOff, excludePrivateOff, excludePublicOff, loadProcessOff, logOff, ...cliOptions } = {
34339
+ ...rawOptions,
34340
+ shellScripts: rawOptions.shellScripts
34341
+ ? JSON.parse(rawOptions.shellScripts)
34342
+ : undefined,
34343
+ };
34318
34344
  // Resolve flags.
34319
34345
  const resolveExclusion = (exclude, excludeOff, defaultValue) => exclude
34320
34346
  ? true
@@ -34353,10 +34379,7 @@ const generateGetDotenvCli = ({ logger = console, preHook, postHook, ...cliOptio
34353
34379
  ? JSON.parse(process.env.getDotenvOptions)
34354
34380
  : {});
34355
34381
  const cliGetDotenvOptions = getDotenvCliOptions2Options(cliOptions);
34356
- const getDotenvOptions = {
34357
- ...parentGetdotenvOptions,
34358
- ...cliGetDotenvOptions,
34359
- };
34382
+ const getDotenvOptions = mergeGetDotenvOptions(cliGetDotenvOptions, parentGetdotenvOptions);
34360
34383
  if (cliOptions.debug)
34361
34384
  logger.log('\n*** getdotenv option resolution ***\n', {
34362
34385
  parentGetdotenvOptions,
@@ -34364,9 +34387,9 @@ const generateGetDotenvCli = ({ logger = console, preHook, postHook, ...cliOptio
34364
34387
  getDotenvOptions,
34365
34388
  });
34366
34389
  // Execute getdotenv.
34367
- const getDotenvOptionsWithLogger = { ...getDotenvOptions, logger };
34368
- _.set(thisCommand, 'getDotenvOptions', getDotenvOptionsWithLogger);
34369
- const dotenv = await getDotenv(getDotenvOptionsWithLogger);
34390
+ const getDotenvOptionsProp = { ...getDotenvOptions, logger };
34391
+ _.set(thisCommand, 'getDotenvOptions', getDotenvOptionsProp);
34392
+ const dotenv = await getDotenv(getDotenvOptionsProp);
34370
34393
  if (cliOptions.debug)
34371
34394
  logger.log('\n*** resulting dotenv values ***\n', { dotenv });
34372
34395
  // Execute post-hook.
@@ -34378,9 +34401,10 @@ const generateGetDotenvCli = ({ logger = console, preHook, postHook, ...cliOptio
34378
34401
  process.exit(0);
34379
34402
  }
34380
34403
  if (command) {
34404
+ const shellCommand = getDotenvOptionsProp.shellScripts?.[command] ?? command;
34381
34405
  if (cliOptions.debug)
34382
- logger.log('\n*** shell command ***\n', command);
34383
- await execaCommand(command, {
34406
+ logger.log('\n*** shell command ***\n', shellCommand);
34407
+ await execaCommand(shellCommand, {
34384
34408
  env: {
34385
34409
  ...process.env,
34386
34410
  getDotenvOptions: JSON.stringify(getDotenvOptions),
package/dist/index.d.cts CHANGED
@@ -5,7 +5,7 @@ import { Command } from '@commander-js/extra-typings';
5
5
  */
6
6
  interface GetDotenvCliOptions extends Omit<GetDotenvOptions, 'paths' | 'vars'> {
7
7
  /**
8
- * Cli alias. Should align with the `bin` property in `package.json`.
8
+ * CLI alias. Should align with the `bin` property in `package.json`.
9
9
  */
10
10
  alias?: string;
11
11
  /**
@@ -129,6 +129,10 @@ interface GetDotenvOptions {
129
129
  * filename token indicating private variables
130
130
  */
131
131
  privateToken?: string;
132
+ /**
133
+ * Shell scripts that can be executed from the CLI, either individually or via the batch subcommand.
134
+ */
135
+ shellScripts?: Record<string, string>;
132
136
  /**
133
137
  * explicit variables to include
134
138
  */
package/dist/index.d.mts CHANGED
@@ -5,7 +5,7 @@ import { Command } from '@commander-js/extra-typings';
5
5
  */
6
6
  interface GetDotenvCliOptions extends Omit<GetDotenvOptions, 'paths' | 'vars'> {
7
7
  /**
8
- * Cli alias. Should align with the `bin` property in `package.json`.
8
+ * CLI alias. Should align with the `bin` property in `package.json`.
9
9
  */
10
10
  alias?: string;
11
11
  /**
@@ -129,6 +129,10 @@ interface GetDotenvOptions {
129
129
  * filename token indicating private variables
130
130
  */
131
131
  privateToken?: string;
132
+ /**
133
+ * Shell scripts that can be executed from the CLI, either individually or via the batch subcommand.
134
+ */
135
+ shellScripts?: Record<string, string>;
132
136
  /**
133
137
  * explicit variables to include
134
138
  */
package/dist/index.d.ts CHANGED
@@ -5,7 +5,7 @@ import { Command } from '@commander-js/extra-typings';
5
5
  */
6
6
  interface GetDotenvCliOptions extends Omit<GetDotenvOptions, 'paths' | 'vars'> {
7
7
  /**
8
- * Cli alias. Should align with the `bin` property in `package.json`.
8
+ * CLI alias. Should align with the `bin` property in `package.json`.
9
9
  */
10
10
  alias?: string;
11
11
  /**
@@ -129,6 +129,10 @@ interface GetDotenvOptions {
129
129
  * filename token indicating private variables
130
130
  */
131
131
  privateToken?: string;
132
+ /**
133
+ * Shell scripts that can be executed from the CLI, either individually or via the batch subcommand.
134
+ */
135
+ shellScripts?: Record<string, string>;
132
136
  /**
133
137
  * explicit variables to include
134
138
  */
package/dist/index.mjs CHANGED
@@ -25763,6 +25763,7 @@ const defaultGetDotenvCliOptionsGlobal = {
25763
25763
  paths: './',
25764
25764
  pathsDelimiter: ' ',
25765
25765
  privateToken: 'local',
25766
+ shellScripts: {},
25766
25767
  vars: '',
25767
25768
  varsAssignor: '=',
25768
25769
  varsDelimiter: ' ',
@@ -25799,6 +25800,10 @@ const defaultGetDotenvCliOptionsLocal = (fs$a.existsSync(defaultGetDotenvCliOpti
25799
25800
  const mergeGetDotenvOptions = (target = {}, source = {}) => ({
25800
25801
  ...source,
25801
25802
  ...target,
25803
+ shellScripts: {
25804
+ ...(source.shellScripts ?? {}),
25805
+ ...(target.shellScripts ?? {}),
25806
+ },
25802
25807
  vars: _.pickBy({
25803
25808
  ...(source.vars ?? {}),
25804
25809
  ...(target.vars ?? {}),
@@ -25831,6 +25836,10 @@ const getDotenvCliOptions2Options = ({ paths, pathsDelimiter, pathsDelimiterPatt
25831
25836
  const getDotenvDefaultOptions = getDotenvCliOptions2Options({
25832
25837
  ...defaultGetDotenvCliOptionsGlobal,
25833
25838
  ...defaultGetDotenvCliOptionsLocal,
25839
+ shellScripts: {
25840
+ ...(defaultGetDotenvCliOptionsGlobal.shellScripts ?? {}),
25841
+ ...(defaultGetDotenvCliOptionsLocal.shellScripts ?? {}),
25842
+ },
25834
25843
  });
25835
25844
 
25836
25845
  var main$1 = {exports: {}};
@@ -34182,18 +34191,21 @@ const cmdCommand$1 = new Command()
34182
34191
  throw new Error(`unable to resolve parent command`);
34183
34192
  if (!thisCommand.parent.parent)
34184
34193
  throw new Error(`unable to resolve root command`);
34185
- const { getDotenvOptions: { logger = console }, } = thisCommand.parent.parent;
34194
+ const { getDotenvOptions: { logger = console, shellScripts }, } = thisCommand.parent.parent;
34186
34195
  const { ignoreErrors, globs, list, pkgCwd, rootPath } = thisCommand.parent.opts();
34187
34196
  // Execute shell command.
34188
- await execShellCommandBatch({
34189
- command: thisCommand.args.join(' '),
34190
- globs,
34191
- ignoreErrors,
34192
- list,
34193
- logger,
34194
- pkgCwd,
34195
- rootPath,
34196
- });
34197
+ {
34198
+ const command = thisCommand.args.join(' ');
34199
+ await execShellCommandBatch({
34200
+ command: shellScripts?.[command] ?? command,
34201
+ globs,
34202
+ ignoreErrors,
34203
+ list,
34204
+ logger,
34205
+ pkgCwd,
34206
+ rootPath,
34207
+ });
34208
+ }
34197
34209
  });
34198
34210
 
34199
34211
  const batchCommand = new Command()
@@ -34210,7 +34222,7 @@ const batchCommand = new Command()
34210
34222
  .hook('preSubcommand', async (thisCommand) => {
34211
34223
  if (!thisCommand.parent)
34212
34224
  throw new Error(`unable to resolve root command`);
34213
- const { getDotenvOptions: { logger = console }, } = thisCommand.parent;
34225
+ const { getDotenvOptions: { logger = console, shellScripts }, } = thisCommand.parent;
34214
34226
  const { command, ignoreErrors, globs, list, pkgCwd, rootPath } = thisCommand.opts();
34215
34227
  if (command && thisCommand.args.length) {
34216
34228
  logger.error(`--command option conflicts with cmd subcommand.`);
@@ -34219,7 +34231,7 @@ const batchCommand = new Command()
34219
34231
  // Execute shell command.
34220
34232
  if (command)
34221
34233
  await execShellCommandBatch({
34222
- command,
34234
+ command: shellScripts?.[command] ?? command,
34223
34235
  globs,
34224
34236
  ignoreErrors,
34225
34237
  list,
@@ -34239,8 +34251,9 @@ const cmdCommand = new Command()
34239
34251
  .action(async (options, thisCommand) => {
34240
34252
  if (!thisCommand.parent)
34241
34253
  throw new Error('parent command not found');
34242
- const { getDotenvOptions: { debug, logger = console }, } = thisCommand.parent;
34243
- const shellCommand = thisCommand.args.join(' ');
34254
+ const { getDotenvOptions: { debug, logger = console, shellScripts }, } = thisCommand.parent;
34255
+ const command = thisCommand.args.join(' ');
34256
+ const shellCommand = shellScripts?.[command] ?? command;
34244
34257
  if (debug)
34245
34258
  logger.log('\n*** shell command ***\n', shellCommand);
34246
34259
  await execaCommand(shellCommand, {
@@ -34253,10 +34266,15 @@ const cmdCommand = new Command()
34253
34266
  * Generate a Commander CLI Command for get-dotenv.
34254
34267
  */
34255
34268
  const generateGetDotenvCli = ({ logger = console, preHook, postHook, ...cliOptionsCustom } = {}) => {
34256
- const { alias = 'getdotenv', debug, defaultEnv, description = 'Base CLI.', dotenvToken, dynamicPath, env, excludeDynamic, excludeEnv, excludeGlobal, excludePrivate, excludePublic, loadProcess, log, outputPath, paths, pathsDelimiter, pathsDelimiterPattern, privateToken, varsAssignor, varsAssignorPattern, varsDelimiter, varsDelimiterPattern, } = {
34269
+ const { alias = 'getdotenv', debug, defaultEnv, description = 'Base CLI.', dotenvToken, dynamicPath, env, excludeDynamic, excludeEnv, excludeGlobal, excludePrivate, excludePublic, loadProcess, log, outputPath, paths, pathsDelimiter, pathsDelimiterPattern, privateToken, shellScripts, varsAssignor, varsAssignorPattern, varsDelimiter, varsDelimiterPattern, } = {
34257
34270
  ...defaultGetDotenvCliOptionsGlobal,
34258
34271
  ...cliOptionsCustom,
34259
34272
  ...defaultGetDotenvCliOptionsLocal,
34273
+ shellScripts: {
34274
+ ...(defaultGetDotenvCliOptionsGlobal.shellScripts ?? {}),
34275
+ ...(cliOptionsCustom.shellScripts ?? {}),
34276
+ ...(defaultGetDotenvCliOptionsLocal.shellScripts ?? {}),
34277
+ },
34260
34278
  };
34261
34279
  const excludeAll = !!excludeDynamic &&
34262
34280
  ((!!excludeEnv && !!excludeGlobal) ||
@@ -34304,6 +34322,9 @@ const generateGetDotenvCli = ({ logger = console, preHook, postHook, ...cliOptio
34304
34322
  .option('--vars-delimiter-pattern <string>', 'vars delimiter regex pattern', varsDelimiterPattern)
34305
34323
  .option('--vars-assignor <string>', 'vars assignment operator string', varsAssignor)
34306
34324
  .option('--vars-assignor-pattern <string>', 'vars assignment operator regex pattern', varsAssignorPattern)
34325
+ .addOption(new Option('--shell-scripts <string>')
34326
+ .default(JSON.stringify(shellScripts))
34327
+ .hideHelp())
34307
34328
  .addCommand(batchCommand)
34308
34329
  .addCommand(cmdCommand, { isDefault: true })
34309
34330
  .hook('preSubcommand', async (thisCommand) => {
@@ -34311,7 +34332,12 @@ const generateGetDotenvCli = ({ logger = console, preHook, postHook, ...cliOptio
34311
34332
  if (rawOptions.debug)
34312
34333
  logger.log('\n*** raw cli options ***\n', { rawOptions });
34313
34334
  // Load options.
34314
- const { command, debugOff, excludeAll, excludeAllOff, excludeDynamicOff, excludeEnvOff, excludeGlobalOff, excludePrivateOff, excludePublicOff, loadProcessOff, logOff, ...cliOptions } = rawOptions;
34335
+ const { command, debugOff, excludeAll, excludeAllOff, excludeDynamicOff, excludeEnvOff, excludeGlobalOff, excludePrivateOff, excludePublicOff, loadProcessOff, logOff, ...cliOptions } = {
34336
+ ...rawOptions,
34337
+ shellScripts: rawOptions.shellScripts
34338
+ ? JSON.parse(rawOptions.shellScripts)
34339
+ : undefined,
34340
+ };
34315
34341
  // Resolve flags.
34316
34342
  const resolveExclusion = (exclude, excludeOff, defaultValue) => exclude
34317
34343
  ? true
@@ -34350,10 +34376,7 @@ const generateGetDotenvCli = ({ logger = console, preHook, postHook, ...cliOptio
34350
34376
  ? JSON.parse(process.env.getDotenvOptions)
34351
34377
  : {});
34352
34378
  const cliGetDotenvOptions = getDotenvCliOptions2Options(cliOptions);
34353
- const getDotenvOptions = {
34354
- ...parentGetdotenvOptions,
34355
- ...cliGetDotenvOptions,
34356
- };
34379
+ const getDotenvOptions = mergeGetDotenvOptions(cliGetDotenvOptions, parentGetdotenvOptions);
34357
34380
  if (cliOptions.debug)
34358
34381
  logger.log('\n*** getdotenv option resolution ***\n', {
34359
34382
  parentGetdotenvOptions,
@@ -34361,9 +34384,9 @@ const generateGetDotenvCli = ({ logger = console, preHook, postHook, ...cliOptio
34361
34384
  getDotenvOptions,
34362
34385
  });
34363
34386
  // Execute getdotenv.
34364
- const getDotenvOptionsWithLogger = { ...getDotenvOptions, logger };
34365
- _.set(thisCommand, 'getDotenvOptions', getDotenvOptionsWithLogger);
34366
- const dotenv = await getDotenv(getDotenvOptionsWithLogger);
34387
+ const getDotenvOptionsProp = { ...getDotenvOptions, logger };
34388
+ _.set(thisCommand, 'getDotenvOptions', getDotenvOptionsProp);
34389
+ const dotenv = await getDotenv(getDotenvOptionsProp);
34367
34390
  if (cliOptions.debug)
34368
34391
  logger.log('\n*** resulting dotenv values ***\n', { dotenv });
34369
34392
  // Execute post-hook.
@@ -34375,9 +34398,10 @@ const generateGetDotenvCli = ({ logger = console, preHook, postHook, ...cliOptio
34375
34398
  process.exit(0);
34376
34399
  }
34377
34400
  if (command) {
34401
+ const shellCommand = getDotenvOptionsProp.shellScripts?.[command] ?? command;
34378
34402
  if (cliOptions.debug)
34379
- logger.log('\n*** shell command ***\n', command);
34380
- await execaCommand(command, {
34403
+ logger.log('\n*** shell command ***\n', shellCommand);
34404
+ await execaCommand(shellCommand, {
34381
34405
  env: {
34382
34406
  ...process.env,
34383
34407
  getDotenvOptions: JSON.stringify(getDotenvOptions),
package/package.json CHANGED
@@ -131,5 +131,5 @@
131
131
  },
132
132
  "type": "module",
133
133
  "types": "dist/index.d.ts",
134
- "version": "4.1.0"
134
+ "version": "4.2.0"
135
135
  }