@keg-hub/args-parse
Advanced tools
Comparing version 7.1.0 to 8.0.0
{ | ||
"name": "@keg-hub/args-parse", | ||
"version": "7.1.0", | ||
"version": "8.0.0", | ||
"description": "Parse command line arguments", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
const path = require('path') | ||
const parseRoot = path.join(__dirname, '../../') | ||
const appRoot = require('app-root-path').path | ||
const defConfig = require('../../configs/parse.config.js') | ||
const { deepMerge } = require('@keg-hub/jsutils') | ||
const { deepMerge, get, noOpObj } = require('@keg-hub/jsutils') | ||
@@ -14,8 +13,62 @@ /** | ||
/** | ||
* Builds the environment object for the parse config | ||
* Values with higher priority override lower priority | ||
* @function | ||
* @param {Object} - Custom environment from the custom config | ||
* @param {Object} - inline environment from the inline config | ||
* | ||
* @returns {Object} - Built environment config object | ||
*/ | ||
const buildEnvironment = (customEnv=noOpObj, inlineEnv=noOpObj) => { | ||
return { | ||
...defConfig.environment, | ||
...customEnv, | ||
...inlineEnv, | ||
options: inlineEnv.options || customEnv.options || defConfig.environment.options, | ||
map: inlineEnv.map || customEnv.map || defConfig.environment.map | ||
} | ||
} | ||
/** | ||
* Builds the default args object for the parse config | ||
* Values with higher priority override lower priority | ||
* @function | ||
* @param {Object} - Custom defaultArgs from the custom config | ||
* @param {Object} - inline defaultArgs from the inline config | ||
* | ||
* @returns {Object} - Built defaultArgs config object | ||
*/ | ||
const buildDefArgs = (customArgs=noOpObj, inlineArgs=noOpObj) => { | ||
return { | ||
...defConfig.defaultArgs, | ||
...customArgs, | ||
...inlineArgs | ||
} | ||
} | ||
/** | ||
* Builds the default bools object for the parse config | ||
* Values with higher priority override lower priority | ||
* @function | ||
* @param {Object} - Custom bools from the custom config | ||
* @param {Object} - inline bools from the inline config | ||
* | ||
* @returns {Object} - Built bools config object | ||
*/ | ||
const buildBools = (customBools=noOpObj, inlineBools=noOpObj) => { | ||
return { | ||
...defConfig.bools, | ||
...customBools, | ||
...inlineBools | ||
} | ||
} | ||
/** | ||
* Loads the config object based on PARSE_CONFIG_PATH env or the default | ||
* @function | ||
* @param {Object} - inline config passed from the caller of args-parse | ||
* | ||
* @returns {Object} - Loaded config object | ||
*/ | ||
const loadConfig = inlineConfig => { | ||
const loadConfig = (inlineConfig=noOpObj) => { | ||
const { PARSE_CONFIG_PATH } = process.env | ||
@@ -26,6 +79,26 @@ const configPath = path.join(appRoot, PARSE_CONFIG_PATH || 'configs/parse.config.js') | ||
try { customConfig = require(configPath) } | ||
catch(err){ customConfig = {} } | ||
catch(err){ customConfig = noOpObj } | ||
return deepMerge(defConfig, customConfig, inlineConfig) | ||
return { | ||
...defConfig, | ||
...inlineConfig, | ||
...customConfig, | ||
settings: deepMerge( | ||
defConfig.settings, | ||
get(customConfig, 'settings'), | ||
get(inlineConfig, 'settings') | ||
), | ||
bools: buildBools( | ||
get(customConfig, 'bools'), | ||
get(inlineConfig, 'bools') | ||
), | ||
environment: buildEnvironment( | ||
get(customConfig, 'environment'), | ||
get(inlineConfig, 'environment') | ||
), | ||
defaultArgs: buildDefArgs( | ||
get(customConfig, 'defaultArgs'), | ||
get(inlineConfig, 'defaultArgs') | ||
) | ||
} | ||
} | ||
@@ -32,0 +105,0 @@ |
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
52654
1475
28