diff --git a/bin/cli.js b/bin/cli.js index 66cf1d431..be657879a 100755 --- a/bin/cli.js +++ b/bin/cli.js @@ -12,7 +12,9 @@ const { getAndLoadConfigIfNeeded, configFileExists, getConfigPath, + validateConfig: isValidConfig, } = require('@hubspot/local-dev-lib/config'); +const { NO_VALIDATE_LIST } = require('../lib/constants'); const { logError } = require('../lib/errorHandlers/index'); const { setLogLevel, @@ -149,6 +151,17 @@ const setRequestHeaders = () => { }; const loadConfigMiddleware = async options => { + const validateConfig = () => { + const shouldValidate = options._.every( + item => !NO_VALIDATE_LIST.includes(item) + ); + if (shouldValidate) { + if (!isValidConfig()) { + process.exit(EXIT_CODES.ERROR); + } + } + }; + // Load the new config and check for the conflicting config flag if (configFileExists(true)) { loadConfig('', options); @@ -161,6 +174,7 @@ const loadConfigMiddleware = async options => { ); process.exit(EXIT_CODES.ERROR); } + validateConfig(); return; } @@ -169,11 +183,13 @@ const loadConfigMiddleware = async options => { if (options.config && fs.existsSync(options.config)) { const { config: configPath } = options; await loadConfig(configPath, options); + validateConfig(); return; } // Load deprecated config without a config flag and with no warnings getAndLoadConfigIfNeeded(options); + validateConfig(); return; }; diff --git a/lib/constants.ts b/lib/constants.ts index 754a41d85..9ed95ecd0 100644 --- a/lib/constants.ts +++ b/lib/constants.ts @@ -80,3 +80,12 @@ export const PLATFORM_VERSION_ERROR_TYPES = { PLATFORM_VERSION_SPECIFIED_DOES_NOT_EXIST: 'PlatformVersionErrorType.PLATFORM_VERSION_SPECIFIED_DOES_NOT_EXIST', } as const; + +export const NO_VALIDATE_LIST = [ + 'init', + 'clean', + 'list', + 'remove', + 'use', + 'delete', +] as const;