chore(package): updated ts-standard version

- improved code readability of options parsing
- added missing code coverage test cases
This commit is contained in:
Todd Bluhm 2020-02-17 17:42:53 -06:00
parent 0498a0701d
commit c0ce28cb84
No known key found for this signature in database
GPG Key ID: 9CF312607477B8AB
7 changed files with 65 additions and 15 deletions

View File

@ -1,5 +1,8 @@
# Changelog
## 10.1.1 - Pending
- **Upgrade**: Updated devDependencies `ts-standard`
## 10.1.0
- **Feature**: Added support for expanding vars using the `-x` flag.

29
dist/parse-args.js vendored
View File

@ -14,11 +14,28 @@ function parseArgs(args) {
const commandArgs = args.splice(args.indexOf(command) + 1);
// Reprocess the args with the command and command args removed
program = parseArgsUsingCommander(args.slice(0, args.indexOf(command)));
const noOverride = !program.override;
const useShell = !!program.useShell;
const expandEnvs = !!program.expandEnvs;
const verbose = !!program.verbose;
const silent = !!program.silent;
// Set values for provided options
let noOverride = false;
// In commander `no-` negates the original value `override`
if (program.override === false) {
noOverride = true;
}
let useShell = false;
if (program.useShell === true) {
useShell = true;
}
let expandEnvs = false;
if (program.expandEnvs === true) {
expandEnvs = true;
}
let verbose = false;
if (program.verbose === true) {
verbose = true;
}
let silent = false;
if (program.silent === true) {
silent = true;
}
let rc;
if (program.environments !== undefined && program.environments.length !== 0) {
rc = {
@ -46,7 +63,7 @@ function parseArgs(args) {
verbose
}
};
if (verbose === true) {
if (verbose) {
console.info(`Options: ${JSON.stringify(options, null, 0)}`);
}
return options;

View File

@ -17,7 +17,7 @@ async function getEnvFileVars(envFilePath) {
// Get the file extension
const ext = path.extname(absolutePath).toLowerCase();
let env = {};
if (REQUIRE_HOOK_EXTENSIONS.indexOf(ext) > -1) {
if (REQUIRE_HOOK_EXTENSIONS.includes(ext)) {
const possiblePromise = require(absolutePath); /* eslint-disable-line */
env = utils_1.isPromise(possiblePromise) ? await possiblePromise : possiblePromise;
}

View File

@ -62,7 +62,7 @@
"nyc": "^15.0.0",
"sinon": "^8.0.0",
"ts-node": "^8.0.0",
"ts-standard": "^4.0.0",
"ts-standard": "^5.0.0",
"typescript": "^3.7.0"
},
"nyc": {

View File

@ -16,11 +16,29 @@ export function parseArgs (args: string[]): EnvCmdOptions {
// Reprocess the args with the command and command args removed
program = parseArgsUsingCommander(args.slice(0, args.indexOf(command)))
const noOverride = !(program.override as boolean)
const useShell = !!(program.useShell as boolean)
const expandEnvs = !!(program.expandEnvs as boolean)
const verbose = !!(program.verbose as boolean)
const silent = !!(program.silent as boolean)
// Set values for provided options
let noOverride = false
// In commander `no-` negates the original value `override`
if (program.override === false) {
noOverride = true
}
let useShell = false
if (program.useShell === true) {
useShell = true
}
let expandEnvs = false
if (program.expandEnvs === true) {
expandEnvs = true
}
let verbose = false
if (program.verbose === true) {
verbose = true
}
let silent = false
if (program.silent === true) {
silent = true
}
let rc: any
if (program.environments !== undefined && program.environments.length !== 0) {
@ -51,7 +69,7 @@ export function parseArgs (args: string[]): EnvCmdOptions {
verbose
}
}
if (verbose === true) {
if (verbose) {
console.info(`Options: ${JSON.stringify(options, null, 0)}`)
}
return options

View File

@ -18,7 +18,7 @@ export async function getEnvFileVars (envFilePath: string): Promise<{ [key: stri
// Get the file extension
const ext = path.extname(absolutePath).toLowerCase()
let env = {}
if (REQUIRE_HOOK_EXTENSIONS.indexOf(ext) > -1) {
if (REQUIRE_HOOK_EXTENSIONS.includes(ext)) {
const possiblePromise = require(absolutePath) /* eslint-disable-line */
env = isPromise(possiblePromise) ? await possiblePromise : possiblePromise
} else {

View File

@ -91,4 +91,16 @@ describe('parseArgs', (): void => {
assert.exists(res.options!.verbose)
assert.equal(logInfoStub.callCount, 1)
})
it('should parse expandEnvs option', (): void => {
const res = parseArgs(['-f', envFilePath, '-x', command, ...commandArgs])
assert.exists(res.envFile)
assert.isTrue(res.options!.expandEnvs)
})
it('should parse silent option', (): void => {
const res = parseArgs(['-f', envFilePath, '--silent', command, ...commandArgs])
assert.exists(res.envFile)
assert.isTrue(res.options!.silent)
})
})