chore(package): update dependencies

This commit is contained in:
Todd Bluhm 2020-03-20 17:20:18 -05:00
parent 7af4005431
commit e66cfc10f1
No known key found for this signature in database
GPG Key ID: 9CF312607477B8AB
11 changed files with 40 additions and 32 deletions

View File

@ -1,17 +1,19 @@
# Changelog # Changelog
## 10.1.1 - Pending ## 10.1.1 - In Development
- **Upgrade**: Updated devDependencies `ts-standard`
- **Upgrade**: Upgraded dependency `commander` to `5.x`
- **Upgrade**: Upgraded devDependencies `ts-standard`, `sinon`
## 10.1.0 ## 10.1.0
- **Feature**: Added support for expanding vars using the `-x` flag. - **Feature**: Added support for expanding vars using the `-x` flag.
Note: only supports `$var` syntax Note: only supports `$var` syntax
- **Feature**: Added support for `--silent` flag that ignores env-cmd errors and missing files and - **Feature**: Added support for `--silent` flag that ignores env-cmd errors and missing files and
only terminates on caught signals only terminates on caught signals
- **Feature**: Added a new `--verbose` flag that prints additional debugging info to `console.info` - **Feature**: Added a new `--verbose` flag that prints additional debugging info to `console.info`
- **Upgrade**: Updated dependency `commander` to `v4` - **Upgrade**: Upgraded dependency `commander` to `4.x`
- **Upgrade**: Updated devDependencies `sinon`, `nyc`, and `ts-standard` - **Upgrade**: Upgraded devDependencies `sinon`, `nyc`, and `ts-standard`
- **Fix**: Handle case where the termination signal is the termination code - **Fix**: Handle case where the termination signal is the termination code
## 10.0.1 ## 10.0.1

2
dist/env-cmd.js vendored
View File

@ -39,7 +39,7 @@ async function EnvCmd({ command, commandArgs, envFile, rc, options = {} }) {
env = await get_env_vars_1.getEnvVars({ envFile, rc, verbose: options.verbose }); env = await get_env_vars_1.getEnvVars({ envFile, rc, verbose: options.verbose });
} }
catch (e) { catch (e) {
if (!(_a = options.silent, (_a !== null && _a !== void 0 ? _a : false))) { if (!((_a = options.silent) !== null && _a !== void 0 ? _a : false)) {
throw e; throw e;
} }
} }

View File

@ -8,13 +8,13 @@ async function getEnvVars(options = {}) {
options.envFile = options.envFile !== undefined ? options.envFile : {}; options.envFile = options.envFile !== undefined ? options.envFile : {};
// Check for rc file usage // Check for rc file usage
if (options.rc !== undefined) { if (options.rc !== undefined) {
return getRCFile({ return await getRCFile({
environments: options.rc.environments, environments: options.rc.environments,
filePath: options.rc.filePath, filePath: options.rc.filePath,
verbose: options.verbose verbose: options.verbose
}); });
} }
return getEnvFile({ return await getEnvFile({
filePath: options.envFile.filePath, filePath: options.envFile.filePath,
fallback: options.envFile.fallback, fallback: options.envFile.fallback,
verbose: options.verbose verbose: options.verbose

View File

@ -1,7 +1,7 @@
import { Command } from 'commander'; import * as commander from 'commander';
import { EnvCmdOptions } from './types'; import { EnvCmdOptions } from './types';
/** /**
* Parses the arguments passed into the cli * Parses the arguments passed into the cli
*/ */
export declare function parseArgs(args: string[]): EnvCmdOptions; export declare function parseArgs(args: string[]): EnvCmdOptions;
export declare function parseArgsUsingCommander(args: string[]): Command; export declare function parseArgsUsingCommander(args: string[]): commander.Command;

11
dist/parse-args.js vendored
View File

@ -1,6 +1,6 @@
"use strict"; "use strict";
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
const commander_1 = require("commander"); const commander = require("commander");
const utils_1 = require("./utils"); const utils_1 = require("./utils");
// Use commonjs require to prevent a weird folder hierarchy in dist // Use commonjs require to prevent a weird folder hierarchy in dist
const packageJson = require('../package.json'); /* eslint-disable-line */ const packageJson = require('../package.json'); /* eslint-disable-line */
@ -8,11 +8,13 @@ const packageJson = require('../package.json'); /* eslint-disable-line */
* Parses the arguments passed into the cli * Parses the arguments passed into the cli
*/ */
function parseArgs(args) { function parseArgs(args) {
// Get the command and command args // Run the initial arguments through commander in order to determine
// which value in the args array is the `command` to execute
let program = parseArgsUsingCommander(args); let program = parseArgsUsingCommander(args);
const command = program.args[0]; const command = program.args[0];
// Grab all arguments after the `command` in the args array
const commandArgs = args.splice(args.indexOf(command) + 1); const commandArgs = args.splice(args.indexOf(command) + 1);
// Reprocess the args with the command and command args removed // Reprocess the args with the command and command arguments removed
program = parseArgsUsingCommander(args.slice(0, args.indexOf(command))); program = parseArgsUsingCommander(args.slice(0, args.indexOf(command)));
// Set values for provided options // Set values for provided options
let noOverride = false; let noOverride = false;
@ -70,7 +72,7 @@ function parseArgs(args) {
} }
exports.parseArgs = parseArgs; exports.parseArgs = parseArgs;
function parseArgsUsingCommander(args) { function parseArgsUsingCommander(args) {
const program = new commander_1.Command(); const program = new commander.Command();
return program return program
.version(packageJson.version, '-v, --version') .version(packageJson.version, '-v, --version')
.usage('[options] <command> [...args]') .usage('[options] <command> [...args]')
@ -83,6 +85,7 @@ function parseArgsUsingCommander(args) {
.option('--use-shell', 'Execute the command in a new shell with the given environment') .option('--use-shell', 'Execute the command in a new shell with the given environment')
.option('--verbose', 'Print helpful debugging information') .option('--verbose', 'Print helpful debugging information')
.option('-x, --expand-envs', 'Replace $var in args and command with environment variables') .option('-x, --expand-envs', 'Replace $var in args and command with environment variables')
.allowUnknownOption(true)
.parse(['_', '_', ...args]); .parse(['_', '_', ...args]);
} }
exports.parseArgsUsingCommander = parseArgsUsingCommander; exports.parseArgsUsingCommander = parseArgsUsingCommander;

View File

@ -27,7 +27,7 @@ class TermSignals {
// Use the signal code if it is an error code // Use the signal code if it is an error code
let correctSignal; let correctSignal;
if (typeof signal === 'number') { if (typeof signal === 'number') {
if (signal > ((code !== null && code !== void 0 ? code : 0))) { if (signal > (code !== null && code !== void 0 ? code : 0)) {
code = signal; code = signal;
correctSignal = 'SIGINT'; correctSignal = 'SIGINT';
} }
@ -36,7 +36,7 @@ class TermSignals {
correctSignal = signal; correctSignal = signal;
} }
// Kill the child process // Kill the child process
proc.kill((correctSignal !== null && correctSignal !== void 0 ? correctSignal : code)); proc.kill(correctSignal !== null && correctSignal !== void 0 ? correctSignal : code);
// Terminate the parent process // Terminate the parent process
this._terminateProcess(code, correctSignal); this._terminateProcess(code, correctSignal);
} }
@ -49,8 +49,8 @@ class TermSignals {
this._removeProcessListeners(); this._removeProcessListeners();
if (!this._exitCalled) { if (!this._exitCalled) {
if (this.verbose) { if (this.verbose) {
console.info(`Child process exited with code: ${((code !== null && code !== void 0 ? code : '')).toString()} and signal:` + console.info(`Child process exited with code: ${(code !== null && code !== void 0 ? code : '').toString()} and signal:` +
((signal !== null && signal !== void 0 ? signal : '')).toString() + (signal !== null && signal !== void 0 ? signal : '').toString() +
'. Terminating parent process...'); '. Terminating parent process...');
} }
// Mark shared state so we do not run into a signal/exit loop // Mark shared state so we do not run into a signal/exit loop
@ -58,13 +58,13 @@ class TermSignals {
// Use the signal code if it is an error code // Use the signal code if it is an error code
let correctSignal; let correctSignal;
if (typeof signal === 'number') { if (typeof signal === 'number') {
if (signal > ((code !== null && code !== void 0 ? code : 0))) { if (signal > (code !== null && code !== void 0 ? code : 0)) {
code = signal; code = signal;
correctSignal = 'SIGINT'; correctSignal = 'SIGINT';
} }
} }
else { else {
correctSignal = (signal !== null && signal !== void 0 ? signal : undefined); correctSignal = signal !== null && signal !== void 0 ? signal : undefined;
} }
// Terminate the parent process // Terminate the parent process
this._terminateProcess(code, correctSignal); this._terminateProcess(code, correctSignal);

View File

@ -47,7 +47,7 @@
}, },
"homepage": "https://github.com/toddbluhm/env-cmd#readme", "homepage": "https://github.com/toddbluhm/env-cmd#readme",
"dependencies": { "dependencies": {
"commander": "^4.0.0", "commander": "^5.0.0",
"cross-spawn": "^7.0.0" "cross-spawn": "^7.0.0"
}, },
"devDependencies": { "devDependencies": {
@ -63,9 +63,9 @@
"husky": "^4.0.0", "husky": "^4.0.0",
"mocha": "^7.0.0", "mocha": "^7.0.0",
"nyc": "^15.0.0", "nyc": "^15.0.0",
"sinon": "^8.0.0", "sinon": "^9.0.0",
"ts-node": "^8.0.0", "ts-node": "^8.0.0",
"ts-standard": "^5.0.0", "ts-standard": "^7.0.0",
"typescript": "^3.7.0" "typescript": "^3.7.0"
}, },
"nyc": { "nyc": {

View File

@ -17,7 +17,7 @@ export async function CLI (args: string[]): Promise<{ [key: string]: any }> {
// Run EnvCmd // Run EnvCmd
try { try {
return await exports.EnvCmd(parsedArgs) return await (exports.EnvCmd(parsedArgs) as Promise<{ [key: string]: any }>)
} catch (e) { } catch (e) {
console.error(e) console.error(e)
return process.exit(1) return process.exit(1)

View File

@ -9,13 +9,13 @@ export async function getEnvVars (options: GetEnvVarOptions = {}): Promise<{ [ke
options.envFile = options.envFile !== undefined ? options.envFile : {} options.envFile = options.envFile !== undefined ? options.envFile : {}
// Check for rc file usage // Check for rc file usage
if (options.rc !== undefined) { if (options.rc !== undefined) {
return getRCFile({ return await getRCFile({
environments: options.rc.environments, environments: options.rc.environments,
filePath: options.rc.filePath, filePath: options.rc.filePath,
verbose: options.verbose verbose: options.verbose
}) })
} }
return getEnvFile({ return await getEnvFile({
filePath: options.envFile.filePath, filePath: options.envFile.filePath,
fallback: options.envFile.fallback, fallback: options.envFile.fallback,
verbose: options.verbose verbose: options.verbose

View File

@ -1,4 +1,4 @@
import { Command } from 'commander' import * as commander from 'commander'
import { EnvCmdOptions } from './types' import { EnvCmdOptions } from './types'
import { parseArgList } from './utils' import { parseArgList } from './utils'
@ -9,12 +9,14 @@ const packageJson = require('../package.json') /* eslint-disable-line */
* Parses the arguments passed into the cli * Parses the arguments passed into the cli
*/ */
export function parseArgs (args: string[]): EnvCmdOptions { export function parseArgs (args: string[]): EnvCmdOptions {
// Get the command and command args // Run the initial arguments through commander in order to determine
// which value in the args array is the `command` to execute
let program = parseArgsUsingCommander(args) let program = parseArgsUsingCommander(args)
const command = program.args[0] const command = program.args[0]
// Grab all arguments after the `command` in the args array
const commandArgs = args.splice(args.indexOf(command) + 1) const commandArgs = args.splice(args.indexOf(command) + 1)
// Reprocess the args with the command and command args removed // Reprocess the args with the command and command arguments removed
program = parseArgsUsingCommander(args.slice(0, args.indexOf(command))) program = parseArgsUsingCommander(args.slice(0, args.indexOf(command)))
// Set values for provided options // Set values for provided options
@ -75,8 +77,8 @@ export function parseArgs (args: string[]): EnvCmdOptions {
return options return options
} }
export function parseArgsUsingCommander (args: string[]): Command { export function parseArgsUsingCommander (args: string[]): commander.Command {
const program = new Command() const program = new commander.Command()
return program return program
.version(packageJson.version, '-v, --version') .version(packageJson.version, '-v, --version')
.usage('[options] <command> [...args]') .usage('[options] <command> [...args]')
@ -89,5 +91,6 @@ export function parseArgsUsingCommander (args: string[]): Command {
.option('--use-shell', 'Execute the command in a new shell with the given environment') .option('--use-shell', 'Execute the command in a new shell with the given environment')
.option('--verbose', 'Print helpful debugging information') .option('--verbose', 'Print helpful debugging information')
.option('-x, --expand-envs', 'Replace $var in args and command with environment variables') .option('-x, --expand-envs', 'Replace $var in args and command with environment variables')
.allowUnknownOption(true)
.parse(['_', '_', ...args]) .parse(['_', '_', ...args])
} }

View File

@ -5,7 +5,7 @@ import { parseArgs } from '../src/parse-args'
describe('parseArgs', (): void => { describe('parseArgs', (): void => {
const command = 'command' const command = 'command'
const commandArgs = ['cmda1', 'cmda2', '--cmda3', '-4', 'cmda4'] const commandArgs = ['cmda1', 'cmda2', '--cmda3', '-4', 'cmda4', '--fallback']
const environments = ['development', 'production'] const environments = ['development', 'production']
const rcFilePath = './.env-cmdrc' const rcFilePath = './.env-cmdrc'
const envFilePath = './.env' const envFilePath = './.env'