From a20161b0cb30c4f7692c37890e2d894045eb8afb Mon Sep 17 00:00:00 2001 From: kemmerle Date: Fri, 20 Dec 2024 16:50:48 -0500 Subject: [PATCH] Refactor `loadAndValidateOptions`: Add account middleware (Final part) (#1310) --- bin/cli.js | 76 ++++++++++++++++++++--- commands/account/clean.ts | 2 - commands/account/info.ts | 3 - commands/account/list.ts | 3 - commands/account/remove.ts | 2 - commands/account/rename.ts | 3 - commands/account/use.ts | 3 - commands/cms/lighthouseScore.ts | 2 - commands/config/set.ts | 3 - commands/customObject/create.ts | 7 +-- commands/customObject/schema/create.ts | 7 +-- commands/customObject/schema/delete.ts | 3 - commands/customObject/schema/fetch-all.ts | 3 - commands/customObject/schema/fetch.ts | 3 - commands/customObject/schema/list.ts | 3 - commands/customObject/schema/update.ts | 7 +-- commands/fetch.ts | 7 +-- commands/filemanager/fetch.ts | 3 - commands/filemanager/upload.ts | 3 - commands/function/deploy.ts | 3 - commands/function/list.ts | 3 - commands/function/server.ts | 3 - commands/hubdb/clear.ts | 3 - commands/hubdb/create.ts | 7 +-- commands/hubdb/delete.ts | 3 - commands/hubdb/fetch.ts | 3 - commands/lint.ts | 3 - commands/list.ts | 3 - commands/logs.ts | 3 - commands/module/marketplace-validate.ts | 3 - commands/mv.ts | 3 - commands/project/__tests__/deploy.test.ts | 7 --- commands/project/add.ts | 3 - commands/project/cloneApp.ts | 3 - commands/project/create.ts | 3 - commands/project/deploy.ts | 3 - commands/project/dev.ts | 2 - commands/project/download.ts | 8 +-- commands/project/listBuilds.ts | 3 - commands/project/logs.ts | 3 - commands/project/migrateApp.ts | 3 - commands/project/open.ts | 3 - commands/project/upload.ts | 3 - commands/project/watch.ts | 3 - commands/remove.ts | 3 - commands/sandbox/create.ts | 3 - commands/sandbox/delete.ts | 13 ++-- commands/secret/addSecret.ts | 4 -- commands/secret/deleteSecret.ts | 3 - commands/secret/listSecrets.ts | 3 - commands/secret/updateSecret.ts | 3 - commands/theme/marketplace-validate.ts | 3 - commands/theme/preview.ts | 3 - commands/upload.ts | 7 +-- commands/watch.ts | 7 +-- lib/validation.ts | 13 ---- 56 files changed, 81 insertions(+), 214 deletions(-) diff --git a/bin/cli.js b/bin/cli.js index 8ed71494c..85a013e38 100755 --- a/bin/cli.js +++ b/bin/cli.js @@ -18,6 +18,7 @@ const { getCommandName, injectAccountIdMiddleware, } = require('../lib/commonOpts'); +const { validateAccount } = require('../lib/validation'); const { trackHelpUsage, trackConvertFieldsUsage, @@ -147,18 +148,40 @@ const setRequestHeaders = () => { addUserAgentHeader('HubSpot CLI', pkg.version); }; -const NO_CONFIG_VALIDATION = { - init: { skip: true }, - auth: { skip: true }, +const isTargetedCommand = (options, commandMap) => { + const checkCommand = (options, commandMap) => { + const currentCommand = options._[0]; + + if (!commandMap[currentCommand]) { + return false; + } + + if (commandMap[currentCommand].target) { + return true; + } + + const subCommands = commandMap[currentCommand].subCommands || {}; + if (options._.length > 1) { + return checkCommand({ _: options._.slice(1) }, subCommands); + } + + return false; + }; + + return checkCommand(options, commandMap); +}; + +const SKIP_CONFIG_VALIDATION = { + init: { target: true }, + auth: { target: true }, }; const loadConfigMiddleware = async options => { const maybeValidateConfig = () => { - const shouldValidate = options._.every( - command => - !(NO_CONFIG_VALIDATION[command] && NO_CONFIG_VALIDATION[command].skip) - ); - if (shouldValidate && !validateConfig()) { + if ( + !isTargetedCommand(options, SKIP_CONFIG_VALIDATION) && + !validateConfig() + ) { process.exit(EXIT_CODES.ERROR); } }; @@ -182,6 +205,42 @@ const checkAndWarnGitInclusionMiddleware = () => { checkAndWarnGitInclusion(getConfigPath()); }; +const accountsSubCommands = { + target: false, + subCommands: { + clean: { target: true }, + list: { target: true }, + ls: { target: true }, + remove: { target: true }, + }, +}; +const sandboxesSubCommands = { + target: false, + subCommands: { + delete: { target: true }, + }, +}; + +const SKIP_ACCOUNT_VALIDATION = { + init: { target: true }, + auth: { target: true }, + account: accountsSubCommands, + accounts: accountsSubCommands, + sandbox: sandboxesSubCommands, + sandboxes: sandboxesSubCommands, +}; + +const validateAccountOptions = async options => { + let validAccount = true; + if (!isTargetedCommand(options, SKIP_ACCOUNT_VALIDATION)) { + validAccount = await validateAccount(options); + } + + if (!validAccount) { + process.exit(EXIT_CODES.ERROR); + } +}; + const argv = yargs .usage('The command line interface to interact with HubSpot.') // loadConfigMiddleware loads the new hidden config for all commands @@ -191,6 +250,7 @@ const argv = yargs loadConfigMiddleware, injectAccountIdMiddleware, checkAndWarnGitInclusionMiddleware, + validateAccountOptions, ]) .exitProcess(false) .fail(handleFailure) diff --git a/commands/account/clean.ts b/commands/account/clean.ts index e7673843f..708179c07 100644 --- a/commands/account/clean.ts +++ b/commands/account/clean.ts @@ -6,7 +6,6 @@ const { const { trackCommandUsage } = require('../../lib/usageTracking'); const { i18n } = require('../../lib/lang'); -const { loadAndValidateOptions } = require('../../lib/validation'); const { EXIT_CODES } = require('../../lib/enums/exitCodes'); const { addTestingOptions, addConfigOptions } = require('../../lib/commonOpts'); const { promptUser } = require('../../lib/prompts/promptUtils'); @@ -29,7 +28,6 @@ exports.describe = i18n(`${i18nKey}.describe`); exports.handler = async options => { const { qa } = options; - await loadAndValidateOptions(options, false); trackCommandUsage('accounts-clean', null); diff --git a/commands/account/info.ts b/commands/account/info.ts index f90a63c1e..4dd0b5aa9 100644 --- a/commands/account/info.ts +++ b/commands/account/info.ts @@ -3,7 +3,6 @@ const { logger } = require('@hubspot/local-dev-lib/logger'); const { getAccountConfig } = require('@hubspot/local-dev-lib/config'); const { getAccessToken } = require('@hubspot/local-dev-lib/personalAccessKey'); const { addConfigOptions } = require('../../lib/commonOpts'); -const { loadAndValidateOptions } = require('../../lib/validation'); const { i18n } = require('../../lib/lang'); const { getTableContents } = require('../../lib/ui/table'); @@ -13,8 +12,6 @@ exports.describe = i18n(`${i18nKey}.describe`); exports.command = 'info [account]'; exports.handler = async options => { - await loadAndValidateOptions(options); - const { derivedAccountId } = options; const config = getAccountConfig(derivedAccountId); // check if the provided account is using a personal access key, if not, show an error diff --git a/commands/account/list.ts b/commands/account/list.ts index f8e178fc2..d2a6cd4ec 100644 --- a/commands/account/list.ts +++ b/commands/account/list.ts @@ -12,7 +12,6 @@ const { addConfigOptions } = require('../../lib/commonOpts'); const { getTableContents, getTableHeader } = require('../../lib/ui/table'); const { trackCommandUsage } = require('../../lib/usageTracking'); -const { loadAndValidateOptions } = require('../../lib/validation'); const { isSandbox, isDeveloperTestAccount } = require('../../lib/accountTypes'); const { i18n } = require('../../lib/lang'); @@ -81,8 +80,6 @@ const getPortalData = mappedPortalData => { }; exports.handler = async options => { - await loadAndValidateOptions(options, false); - const { derivedAccountId } = options; trackCommandUsage('accounts-list', null, derivedAccountId); diff --git a/commands/account/remove.ts b/commands/account/remove.ts index 1ee5676eb..b0a11533f 100644 --- a/commands/account/remove.ts +++ b/commands/account/remove.ts @@ -13,7 +13,6 @@ const { const { trackCommandUsage } = require('../../lib/usageTracking'); const { i18n } = require('../../lib/lang'); const { selectAccountFromConfig } = require('../../lib/prompts/accountsPrompt'); -const { loadAndValidateOptions } = require('../../lib/validation'); const i18nKey = 'commands.account.subcommands.remove'; @@ -21,7 +20,6 @@ exports.command = 'remove [account]'; exports.describe = i18n(`${i18nKey}.describe`); exports.handler = async options => { - await loadAndValidateOptions(options, false); const { account } = options; let accountToRemove = account; diff --git a/commands/account/rename.ts b/commands/account/rename.ts index 6fdf6bb90..ca94e5d47 100644 --- a/commands/account/rename.ts +++ b/commands/account/rename.ts @@ -4,7 +4,6 @@ const { renameAccount } = require('@hubspot/local-dev-lib/config'); const { addConfigOptions, addAccountOptions } = require('../../lib/commonOpts'); const { trackCommandUsage } = require('../../lib/usageTracking'); -const { loadAndValidateOptions } = require('../../lib/validation'); const { i18n } = require('../../lib/lang'); const i18nKey = 'commands.account.subcommands.rename'; @@ -13,8 +12,6 @@ exports.command = 'rename '; exports.describe = i18n(`${i18nKey}.describe`); exports.handler = async options => { - loadAndValidateOptions(options); - const { accountName, newName, derivedAccountId } = options; trackCommandUsage('accounts-rename', null, derivedAccountId); diff --git a/commands/account/use.ts b/commands/account/use.ts index fa20ba942..df2ec0594 100644 --- a/commands/account/use.ts +++ b/commands/account/use.ts @@ -9,7 +9,6 @@ const { const { trackCommandUsage } = require('../../lib/usageTracking'); const { i18n } = require('../../lib/lang'); const { selectAccountFromConfig } = require('../../lib/prompts/accountsPrompt'); -const { loadAndValidateOptions } = require('../../lib/validation'); const i18nKey = 'commands.account.subcommands.use'; @@ -17,8 +16,6 @@ exports.command = 'use [account]'; exports.describe = i18n(`${i18nKey}.describe`); exports.handler = async options => { - await loadAndValidateOptions(options, false); - let newDefaultAccount = options.account; if (!newDefaultAccount) { diff --git a/commands/cms/lighthouseScore.ts b/commands/cms/lighthouseScore.ts index 7223f5da2..7f4bc4a37 100644 --- a/commands/cms/lighthouseScore.ts +++ b/commands/cms/lighthouseScore.ts @@ -7,7 +7,6 @@ const { } = require('../../lib/commonOpts'); const { logger } = require('@hubspot/local-dev-lib/logger'); const { getTableContents, getTableHeader } = require('../../lib/ui/table'); -const { loadAndValidateOptions } = require('../../lib/validation'); const { promptUser } = require('../../lib/prompts/promptUtils'); const { i18n } = require('../../lib/lang'); const { fetchThemes } = require('@hubspot/local-dev-lib/api/designManager'); @@ -67,7 +66,6 @@ const selectTheme = async accountId => { }; exports.handler = async options => { - await loadAndValidateOptions(options); const { target, verbose, theme, derivedAccountId } = options; const includeDesktopScore = target === 'desktop' || !verbose; diff --git a/commands/config/set.ts b/commands/config/set.ts index 783d9b8f4..75e6053e3 100644 --- a/commands/config/set.ts +++ b/commands/config/set.ts @@ -1,5 +1,4 @@ // @ts-nocheck -const { loadAndValidateOptions } = require('../../lib/validation'); const { i18n } = require('../../lib/lang'); const { trackCommandUsage } = require('../../lib/usageTracking'); const { promptUser } = require('../../lib/prompts/promptUtils'); @@ -55,8 +54,6 @@ const handleConfigUpdate = async (accountId, options) => { }; exports.handler = async options => { - await loadAndValidateOptions(options); - const { derivedAccountId } = options; trackCommandUsage('config-set', null, derivedAccountId); diff --git a/commands/customObject/create.ts b/commands/customObject/create.ts index ec32235e7..2e483dfde 100644 --- a/commands/customObject/create.ts +++ b/commands/customObject/create.ts @@ -4,10 +4,7 @@ import { inputPrompt } from '../../lib/prompts/promptUtils'; const { logger } = require('@hubspot/local-dev-lib/logger'); const { logError } = require('../../lib/errorHandlers/index'); const { getAbsoluteFilePath } = require('@hubspot/local-dev-lib/path'); -const { - checkAndConvertToJson, - loadAndValidateOptions, -} = require('../../lib/validation'); +const { checkAndConvertToJson } = require('../../lib/validation'); const { trackCommandUsage } = require('../../lib/usageTracking'); const { batchCreateObjects, @@ -24,8 +21,6 @@ exports.handler = async options => { const { path, name: providedName, derivedAccountId } = options; let definitionPath = path; - await loadAndValidateOptions(options); - trackCommandUsage('custom-object-batch-create', null, derivedAccountId); if (!definitionPath) { diff --git a/commands/customObject/schema/create.ts b/commands/customObject/schema/create.ts index 248bd2631..9037fe59b 100644 --- a/commands/customObject/schema/create.ts +++ b/commands/customObject/schema/create.ts @@ -2,10 +2,7 @@ const { logger } = require('@hubspot/local-dev-lib/logger'); const { logError } = require('../../../lib/errorHandlers/index'); const { getAbsoluteFilePath } = require('@hubspot/local-dev-lib/path'); -const { - checkAndConvertToJson, - loadAndValidateOptions, -} = require('../../../lib/validation'); +const { checkAndConvertToJson } = require('../../../lib/validation'); const { trackCommandUsage } = require('../../../lib/usageTracking'); const { addTestingOptions } = require('../../../lib/commonOpts'); const { @@ -34,8 +31,6 @@ exports.describe = i18n(`${i18nKey}.describe`); exports.handler = async options => { const { path, derivedAccountId } = options; - await loadAndValidateOptions(options); - trackCommandUsage('custom-object-schema-create', null, derivedAccountId); const filePath = getAbsoluteFilePath(path); diff --git a/commands/customObject/schema/delete.ts b/commands/customObject/schema/delete.ts index 427eb0a79..38fd9e738 100644 --- a/commands/customObject/schema/delete.ts +++ b/commands/customObject/schema/delete.ts @@ -4,7 +4,6 @@ import { confirmPrompt, listPrompt } from '../../../lib/prompts/promptUtils'; import { fetchObjectSchemas } from '@hubspot/local-dev-lib/api/customObjects'; const { logger } = require('@hubspot/local-dev-lib/logger'); -const { loadAndValidateOptions } = require('../../../lib/validation'); const { trackCommandUsage } = require('../../../lib/usageTracking'); const { deleteObjectSchema, @@ -20,8 +19,6 @@ exports.describe = i18n(`${i18nKey}.describe`); exports.handler = async options => { const { name: providedName, force, derivedAccountId } = options; - await loadAndValidateOptions(options); - trackCommandUsage('custom-object-schema-delete', null, derivedAccountId); let name; diff --git a/commands/customObject/schema/fetch-all.ts b/commands/customObject/schema/fetch-all.ts index e3e14d527..1a05a8af6 100644 --- a/commands/customObject/schema/fetch-all.ts +++ b/commands/customObject/schema/fetch-all.ts @@ -2,7 +2,6 @@ import { inputPrompt } from '../../../lib/prompts/promptUtils'; const { logger } = require('@hubspot/local-dev-lib/logger'); -const { loadAndValidateOptions } = require('../../../lib/validation'); const { trackCommandUsage } = require('../../../lib/usageTracking'); const { downloadSchemas, @@ -18,8 +17,6 @@ exports.command = 'fetch-all [dest]'; exports.describe = i18n(`${i18nKey}.describe`); exports.handler = async options => { - await loadAndValidateOptions(options); - const { derivedAccountId, dest: providedDest } = options; trackCommandUsage('custom-object-schema-fetch-all', null, derivedAccountId); diff --git a/commands/customObject/schema/fetch.ts b/commands/customObject/schema/fetch.ts index 73aba85e6..f32df58fe 100644 --- a/commands/customObject/schema/fetch.ts +++ b/commands/customObject/schema/fetch.ts @@ -13,7 +13,6 @@ const { const { fetchSchema } = require('@hubspot/local-dev-lib/api/fileTransport'); const { getCwd } = require('@hubspot/local-dev-lib/path'); -const { loadAndValidateOptions } = require('../../../lib/validation'); const { trackCommandUsage } = require('../../../lib/usageTracking'); const { i18n } = require('../../../lib/lang'); const { logError } = require('../../../lib/errorHandlers'); @@ -26,8 +25,6 @@ exports.describe = i18n(`${i18nKey}.describe`); exports.handler = async options => { const { name: providedName, dest: providedDest, derivedAccountId } = options; - await loadAndValidateOptions(options); - trackCommandUsage('custom-object-schema-fetch', null, derivedAccountId); let name; diff --git a/commands/customObject/schema/list.ts b/commands/customObject/schema/list.ts index 901489f9a..8f0c91d74 100644 --- a/commands/customObject/schema/list.ts +++ b/commands/customObject/schema/list.ts @@ -2,7 +2,6 @@ const { logger } = require('@hubspot/local-dev-lib/logger'); const { logError } = require('../../../lib/errorHandlers/index'); -const { loadAndValidateOptions } = require('../../../lib/validation'); const { trackCommandUsage } = require('../../../lib/usageTracking'); const { listSchemas } = require('../../../lib/schema'); const { i18n } = require('../../../lib/lang'); @@ -13,8 +12,6 @@ exports.command = 'list'; exports.describe = i18n(`${i18nKey}.describe`); exports.handler = async options => { - await loadAndValidateOptions(options); - const { derivedAccountId } = options; trackCommandUsage('custom-object-schema-list', null, derivedAccountId); diff --git a/commands/customObject/schema/update.ts b/commands/customObject/schema/update.ts index 577d58902..09951e8df 100644 --- a/commands/customObject/schema/update.ts +++ b/commands/customObject/schema/update.ts @@ -8,10 +8,7 @@ const { getAbsoluteFilePath } = require('@hubspot/local-dev-lib/path'); const { ENVIRONMENTS, } = require('@hubspot/local-dev-lib/constants/environments'); -const { - checkAndConvertToJson, - loadAndValidateOptions, -} = require('../../../lib/validation'); +const { checkAndConvertToJson } = require('../../../lib/validation'); const { trackCommandUsage } = require('../../../lib/usageTracking'); const { addTestingOptions } = require('../../../lib/commonOpts'); const { CONFIG_FLAGS } = require('../../../lib/constants'); @@ -37,8 +34,6 @@ exports.describe = i18n(`${i18nKey}.describe`); exports.handler = async options => { const { path, name: providedName, derivedAccountId } = options; - await loadAndValidateOptions(options); - trackCommandUsage('custom-object-schema-update', null, derivedAccountId); const filePath = getAbsoluteFilePath(path); diff --git a/commands/fetch.ts b/commands/fetch.ts index e852b76dc..6285dbe5a 100644 --- a/commands/fetch.ts +++ b/commands/fetch.ts @@ -11,10 +11,7 @@ const { addGlobalOptions, } = require('../lib/commonOpts'); const { resolveLocalPath } = require('../lib/filesystem'); -const { - validateCmsPublishMode, - loadAndValidateOptions, -} = require('../lib/validation'); +const { validateCmsPublishMode } = require('../lib/validation'); const { trackCommandUsage } = require('../lib/usageTracking'); const { i18n } = require('../lib/lang'); @@ -28,8 +25,6 @@ exports.describe = i18n(`${i18nKey}.describe`); exports.handler = async options => { const { src, dest } = options; - await loadAndValidateOptions(options); - if (!validateCmsPublishMode(options)) { process.exit(EXIT_CODES.ERROR); } diff --git a/commands/filemanager/fetch.ts b/commands/filemanager/fetch.ts index 5e4cd16f6..57d6098e8 100644 --- a/commands/filemanager/fetch.ts +++ b/commands/filemanager/fetch.ts @@ -9,7 +9,6 @@ const { addGlobalOptions, addUseEnvironmentOptions, } = require('../../lib/commonOpts'); -const { loadAndValidateOptions } = require('../../lib/validation'); const { trackCommandUsage } = require('../../lib/usageTracking'); const { i18n } = require('../../lib/lang'); @@ -23,8 +22,6 @@ exports.describe = i18n(`${i18nKey}.describe`); exports.handler = async options => { const { src, includeArchived, derivedAccountId, overwrite } = options; - await loadAndValidateOptions(options); - if (typeof src !== 'string') { logger.error(i18n(`${i18nKey}.errors.sourceRequired`)); process.exit(EXIT_CODES.ERROR); diff --git a/commands/filemanager/upload.ts b/commands/filemanager/upload.ts index 5676e6635..6ca6b0081 100644 --- a/commands/filemanager/upload.ts +++ b/commands/filemanager/upload.ts @@ -18,7 +18,6 @@ const { addAccountOptions, addUseEnvironmentOptions, } = require('../../lib/commonOpts'); -const { loadAndValidateOptions } = require('../../lib/validation'); const { trackCommandUsage } = require('../../lib/usageTracking'); const { i18n } = require('../../lib/lang'); @@ -31,8 +30,6 @@ exports.describe = i18n(`${i18nKey}.describe`); exports.handler = async options => { const { src, dest, derivedAccountId } = options; - await loadAndValidateOptions(options); - const absoluteSrcPath = path.resolve(getCwd(), src); let stats; diff --git a/commands/function/deploy.ts b/commands/function/deploy.ts index 4d23e05eb..11c2f1f92 100644 --- a/commands/function/deploy.ts +++ b/commands/function/deploy.ts @@ -14,7 +14,6 @@ const { buildPackage, getBuildStatus, } = require('@hubspot/local-dev-lib/api/functions'); -const { loadAndValidateOptions } = require('../../lib/validation'); const { outputBuildLog } = require('../../lib/serverlessLogs'); const { i18n } = require('../../lib/lang'); const { isHubSpotHttpError } = require('@hubspot/local-dev-lib/errors/index'); @@ -25,8 +24,6 @@ exports.command = 'deploy '; exports.describe = false; exports.handler = async options => { - await loadAndValidateOptions(options); - const { path: functionPath, derivedAccountId } = options; const splitFunctionPath = functionPath.split('.'); diff --git a/commands/function/list.ts b/commands/function/list.ts index b01c838bc..80be65a0b 100644 --- a/commands/function/list.ts +++ b/commands/function/list.ts @@ -10,7 +10,6 @@ const { addUseEnvironmentOptions, } = require('../../lib/commonOpts'); const { trackCommandUsage } = require('../../lib/usageTracking'); -const { loadAndValidateOptions } = require('../../lib/validation'); const { i18n } = require('../../lib/lang'); const i18nKey = 'commands.function.subcommands.list'; @@ -20,8 +19,6 @@ exports.command = ['list', 'ls']; exports.describe = i18n(`${i18nKey}.describe`); exports.handler = async options => { - loadAndValidateOptions(options); - const { derivedAccountId } = options; trackCommandUsage('functions-list', null, derivedAccountId); diff --git a/commands/function/server.ts b/commands/function/server.ts index aa4306ea9..bcb4709c9 100644 --- a/commands/function/server.ts +++ b/commands/function/server.ts @@ -7,7 +7,6 @@ const { const { trackCommandUsage } = require('../../lib/usageTracking'); const { logger } = require('@hubspot/local-dev-lib/logger'); const { start: startTestServer } = require('@hubspot/serverless-dev-runtime'); -const { loadAndValidateOptions } = require('../../lib/validation'); const { i18n } = require('../../lib/lang'); const i18nKey = 'commands.function.subcommands.server'; @@ -16,8 +15,6 @@ exports.command = 'server '; exports.describe = false; exports.handler = async options => { - await loadAndValidateOptions(options); - const { path: functionPath, derivedAccountId } = options; trackCommandUsage('functions-server', null, derivedAccountId); diff --git a/commands/hubdb/clear.ts b/commands/hubdb/clear.ts index b59126405..8894f8804 100644 --- a/commands/hubdb/clear.ts +++ b/commands/hubdb/clear.ts @@ -6,7 +6,6 @@ const { publishTable } = require('@hubspot/local-dev-lib/api/hubdb'); const { selectHubDBTablePrompt, } = require('../../lib/prompts/selectHubDBTablePrompt'); -const { loadAndValidateOptions } = require('../../lib/validation'); const { trackCommandUsage } = require('../../lib/usageTracking'); const { addConfigOptions, @@ -23,8 +22,6 @@ exports.describe = i18n(`${i18nKey}.describe`); exports.handler = async options => { const { derivedAccountId } = options; - await loadAndValidateOptions(options); - trackCommandUsage('hubdb-clear', null, derivedAccountId); try { diff --git a/commands/hubdb/create.ts b/commands/hubdb/create.ts index 3c9ac36db..bb77c8897 100644 --- a/commands/hubdb/create.ts +++ b/commands/hubdb/create.ts @@ -7,10 +7,7 @@ const { getCwd } = require('@hubspot/local-dev-lib/path'); const { createHubDbTable } = require('@hubspot/local-dev-lib/hubdb'); const { untildify, isValidPath } = require('@hubspot/local-dev-lib/path'); const { promptUser } = require('../../lib/prompts/promptUtils'); -const { - checkAndConvertToJson, - loadAndValidateOptions, -} = require('../../lib/validation'); +const { checkAndConvertToJson } = require('../../lib/validation'); const { trackCommandUsage } = require('../../lib/usageTracking'); const { addConfigOptions, @@ -50,8 +47,6 @@ function selectPathPrompt(options) { exports.handler = async options => { const { derivedAccountId } = options; - await loadAndValidateOptions(options); - trackCommandUsage('hubdb-create', null, derivedAccountId); let filePath; diff --git a/commands/hubdb/delete.ts b/commands/hubdb/delete.ts index 0b8df0258..c183ec73c 100644 --- a/commands/hubdb/delete.ts +++ b/commands/hubdb/delete.ts @@ -2,7 +2,6 @@ const { logger } = require('@hubspot/local-dev-lib/logger'); const { logError } = require('../../lib/errorHandlers/index'); const { deleteTable } = require('@hubspot/local-dev-lib/api/hubdb'); -const { loadAndValidateOptions } = require('../../lib/validation'); const { trackCommandUsage } = require('../../lib/usageTracking'); const { addConfigOptions, @@ -24,8 +23,6 @@ exports.describe = i18n(`${i18nKey}.describe`); exports.handler = async options => { const { force, derivedAccountId } = options; - await loadAndValidateOptions(options); - trackCommandUsage('hubdb-delete', null, derivedAccountId); try { diff --git a/commands/hubdb/fetch.ts b/commands/hubdb/fetch.ts index d2829d909..94e0cbda0 100644 --- a/commands/hubdb/fetch.ts +++ b/commands/hubdb/fetch.ts @@ -5,7 +5,6 @@ const { downloadHubDbTable } = require('@hubspot/local-dev-lib/hubdb'); const { selectHubDBTablePrompt, } = require('../../lib/prompts/selectHubDBTablePrompt'); -const { loadAndValidateOptions } = require('../../lib/validation'); const { trackCommandUsage } = require('../../lib/usageTracking'); const { @@ -23,8 +22,6 @@ exports.describe = i18n(`${i18nKey}.describe`); exports.handler = async options => { const { derivedAccountId } = options; - await loadAndValidateOptions(options); - trackCommandUsage('hubdb-fetch', null, derivedAccountId); try { diff --git a/commands/lint.ts b/commands/lint.ts index 1d99e3275..bddc727bc 100644 --- a/commands/lint.ts +++ b/commands/lint.ts @@ -14,7 +14,6 @@ const { } = require('../lib/commonOpts'); const { resolveLocalPath } = require('../lib/filesystem'); const { trackCommandUsage } = require('../lib/usageTracking'); -const { loadAndValidateOptions } = require('../lib/validation'); const { i18n } = require('../lib/lang'); const i18nKey = 'commands.lint'; @@ -64,8 +63,6 @@ function printHublValidationResult({ file, validation }: LintResult): number { export const handler = async options => { const { path: lintPath } = options; - await loadAndValidateOptions(options); - const { derivedAccountId } = options; const localPath = resolveLocalPath(lintPath); const groupName = i18n(`${i18nKey}.groupName`, { diff --git a/commands/list.ts b/commands/list.ts index 5ef4e52b8..9d3ad7f1e 100644 --- a/commands/list.ts +++ b/commands/list.ts @@ -15,7 +15,6 @@ const { getDirectoryContentsByPath, } = require('@hubspot/local-dev-lib/api/fileMapper'); const { HUBSPOT_FOLDER, MARKETPLACE_FOLDER } = require('../lib/constants'); -const { loadAndValidateOptions } = require('../lib/validation'); const { i18n } = require('../lib/lang'); const i18nKey = 'commands.list'; @@ -25,8 +24,6 @@ exports.command = 'list [path]'; exports.describe = i18n(`${i18nKey}.describe`); exports.handler = async options => { - await loadAndValidateOptions(options); - const { path, derivedAccountId } = options; const directoryPath = path || '/'; let contentsResp; diff --git a/commands/logs.ts b/commands/logs.ts index 3c67b2251..3570a1416 100644 --- a/commands/logs.ts +++ b/commands/logs.ts @@ -13,7 +13,6 @@ const { getLatestFunctionLog, } = require('@hubspot/local-dev-lib/api/functions'); const { tailLogs } = require('../lib/serverlessLogs'); -const { loadAndValidateOptions } = require('../lib/validation'); const { i18n } = require('../lib/lang'); const { promptUser } = require('../lib/prompts/promptUtils'); const { EXIT_CODES } = require('../lib/enums/exitCodes'); @@ -100,8 +99,6 @@ exports.command = 'logs [endpoint]'; exports.describe = i18n(`${i18nKey}.describe`); exports.handler = async options => { - await loadAndValidateOptions(options); - const { endpoint: endpointArgValue, latest, derivedAccountId } = options; trackCommandUsage('logs', { latest }, derivedAccountId); diff --git a/commands/module/marketplace-validate.ts b/commands/module/marketplace-validate.ts index 5f5df5bf2..1dc9f2bcd 100644 --- a/commands/module/marketplace-validate.ts +++ b/commands/module/marketplace-validate.ts @@ -5,7 +5,6 @@ const { addAccountOptions, addUseEnvironmentOptions, } = require('../../lib/commonOpts'); -const { loadAndValidateOptions } = require('../../lib/validation'); const { trackCommandUsage } = require('../../lib/usageTracking'); const { kickOffValidation, @@ -24,8 +23,6 @@ exports.describe = i18n(`${i18nKey}.describe`); exports.handler = async options => { const { src, derivedAccountId } = options; - await loadAndValidateOptions(options); - trackCommandUsage('validate', null, derivedAccountId); SpinniesManager.init(); diff --git a/commands/mv.ts b/commands/mv.ts index 9cb27bd49..771446e58 100644 --- a/commands/mv.ts +++ b/commands/mv.ts @@ -11,7 +11,6 @@ const { } = require('../lib/commonOpts'); const { trackCommandUsage } = require('../lib/usageTracking'); const { isPathFolder } = require('../lib/filesystem'); -const { loadAndValidateOptions } = require('../lib/validation'); const { i18n } = require('../lib/lang'); const { uiBetaTag } = require('../lib/ui'); @@ -30,8 +29,6 @@ exports.command = 'mv '; exports.describe = uiBetaTag(i18n(`${i18nKey}.describe`), false); exports.handler = async options => { - await loadAndValidateOptions(options); - const { srcPath, destPath, derivedAccountId } = options; trackCommandUsage('mv', null, derivedAccountId); diff --git a/commands/project/__tests__/deploy.test.ts b/commands/project/__tests__/deploy.test.ts index fe8f3dbe5..9e53acba4 100644 --- a/commands/project/__tests__/deploy.test.ts +++ b/commands/project/__tests__/deploy.test.ts @@ -17,7 +17,6 @@ const { addConfigOptions, addUseEnvironmentOptions, } = require('../../../lib/commonOpts'); -const { loadAndValidateOptions } = require('../../../lib/validation'); const { getProjectConfig } = require('../../../lib/projects'); const { getProjectDetailUrl } = require('../../../lib/projects/urls'); const { pollDeployStatus } = require('../../../lib/projects/buildAndDeploy'); @@ -135,12 +134,6 @@ describe('commands/project/deploy', () => { processExitSpy = jest.spyOn(process, 'exit').mockImplementation(() => {}); }); - it('should load and validate the options', async () => { - await deployCommand.handler(options); - expect(loadAndValidateOptions).toHaveBeenCalledTimes(1); - expect(loadAndValidateOptions).toHaveBeenCalledWith(options); - }); - it('should load the account config for the correct account id', async () => { await deployCommand.handler(options); expect(getAccountConfig).toHaveBeenCalledTimes(1); diff --git a/commands/project/add.ts b/commands/project/add.ts index add459234..d8767582f 100644 --- a/commands/project/add.ts +++ b/commands/project/add.ts @@ -10,7 +10,6 @@ const { createProjectComponent, getProjectComponentsByVersion, } = require('../../lib/projects'); -const { loadAndValidateOptions } = require('../../lib/validation'); const { uiBetaTag } = require('../../lib/ui'); const { HUBSPOT_PROJECT_COMPONENTS_GITHUB_PATH, @@ -22,8 +21,6 @@ exports.command = 'add'; exports.describe = uiBetaTag(i18n(`${i18nKey}.describe`), false); exports.handler = async options => { - await loadAndValidateOptions(options); - const { derivedAccountId } = options; logger.log(''); diff --git a/commands/project/cloneApp.ts b/commands/project/cloneApp.ts index 4e784e02d..5a8ec9535 100644 --- a/commands/project/cloneApp.ts +++ b/commands/project/cloneApp.ts @@ -10,7 +10,6 @@ const { trackCommandUsage, trackCommandMetadataUsage, } = require('../../lib/usageTracking'); -const { loadAndValidateOptions } = require('../../lib/validation'); const { i18n } = require('../../lib/lang'); const { selectPublicAppPrompt, @@ -47,8 +46,6 @@ exports.command = 'clone-app'; exports.describe = uiBetaTag(i18n(`${i18nKey}.describe`), false); exports.handler = async options => { - await loadAndValidateOptions(options); - const { derivedAccountId } = options; const accountConfig = getAccountConfig(derivedAccountId); const accountName = uiAccountDescription(derivedAccountId); diff --git a/commands/project/create.ts b/commands/project/create.ts index b322f79d6..4d4b25496 100644 --- a/commands/project/create.ts +++ b/commands/project/create.ts @@ -5,7 +5,6 @@ const { addUseEnvironmentOptions, } = require('../../lib/commonOpts'); const { trackCommandUsage } = require('../../lib/usageTracking'); -const { loadAndValidateOptions } = require('../../lib/validation'); const { getCwd } = require('@hubspot/local-dev-lib/path'); const path = require('path'); const chalk = require('chalk'); @@ -27,8 +26,6 @@ exports.command = 'create'; exports.describe = uiBetaTag(i18n(`${i18nKey}.describe`), false); exports.handler = async options => { - await loadAndValidateOptions(options); - const { derivedAccountId } = options; const hasCustomTemplateSource = Boolean(options.templateSource); diff --git a/commands/project/deploy.ts b/commands/project/deploy.ts index 0e3831b2e..1952c0af8 100644 --- a/commands/project/deploy.ts +++ b/commands/project/deploy.ts @@ -12,7 +12,6 @@ const { deployProject, fetchProject, } = require('@hubspot/local-dev-lib/api/projects'); -const { loadAndValidateOptions } = require('../../lib/validation'); const { getProjectConfig } = require('../../lib/projects'); const { pollDeployStatus } = require('../../lib/projects/buildAndDeploy'); const { getProjectDetailUrl } = require('../../lib/projects/urls'); @@ -60,8 +59,6 @@ const validateBuildId = ( }; exports.handler = async options => { - await loadAndValidateOptions(options); - const { derivedAccountId } = options; const accountConfig = getAccountConfig(derivedAccountId); const { project: projectOption, buildId: buildIdOption } = options; diff --git a/commands/project/dev.ts b/commands/project/dev.ts index 5b8843bee..762028634 100644 --- a/commands/project/dev.ts +++ b/commands/project/dev.ts @@ -6,7 +6,6 @@ const { addTestingOptions, } = require('../../lib/commonOpts'); const { trackCommandUsage } = require('../../lib/usageTracking'); -const { loadAndValidateOptions } = require('../../lib/validation'); const { handleExit } = require('../../lib/process'); const { i18n } = require('../../lib/lang'); const { logger } = require('@hubspot/local-dev-lib/logger'); @@ -56,7 +55,6 @@ exports.command = 'dev'; exports.describe = uiBetaTag(i18n(`${i18nKey}.describe`), false); exports.handler = async options => { - await loadAndValidateOptions(options); const { derivedAccountId, providedAccountId } = options; const accountConfig = getAccountConfig(derivedAccountId); const env = getValidEnv(getEnv(derivedAccountId)); diff --git a/commands/project/download.ts b/commands/project/download.ts index 57dff12ae..e770d20fe 100644 --- a/commands/project/download.ts +++ b/commands/project/download.ts @@ -17,7 +17,6 @@ const { fetchProjectBuilds, } = require('@hubspot/local-dev-lib/api/projects'); const { ensureProjectExists, getProjectConfig } = require('../../lib/projects'); -const { loadAndValidateOptions } = require('../../lib/validation'); const { downloadProjectPrompt, } = require('../../lib/prompts/downloadProjectPrompt'); @@ -31,8 +30,6 @@ exports.command = 'download'; exports.describe = uiBetaTag(i18n(`${i18nKey}.describe`), false); exports.handler = async options => { - await loadAndValidateOptions(options); - const { projectConfig } = await getProjectConfig(); if (projectConfig) { @@ -63,9 +60,8 @@ exports.handler = async options => { accountId: chalk.bold(derivedAccountId), }) ); - const { name: promptedProjectName } = await downloadProjectPrompt( - options - ); + const { name: promptedProjectName } = + await downloadProjectPrompt(options); projectName = promptedProjectName || project; } diff --git a/commands/project/listBuilds.ts b/commands/project/listBuilds.ts index 956c34033..edb41ff35 100644 --- a/commands/project/listBuilds.ts +++ b/commands/project/listBuilds.ts @@ -14,7 +14,6 @@ const { } = require('@hubspot/local-dev-lib/api/projects'); const { getTableContents, getTableHeader } = require('../../lib/ui/table'); const { uiBetaTag, uiLink } = require('../../lib/ui'); -const { loadAndValidateOptions } = require('../../lib/validation'); const { getProjectConfig, validateProjectConfig, @@ -30,8 +29,6 @@ exports.command = 'list-builds'; exports.describe = uiBetaTag(i18n(`${i18nKey}.describe`), false); exports.handler = async options => { - await loadAndValidateOptions(options); - const { project: projectFlagValue, limit, derivedAccountId } = options; trackCommandUsage('project-list-builds', null, derivedAccountId); diff --git a/commands/project/logs.ts b/commands/project/logs.ts index ecd2228d6..78ed0ee1e 100644 --- a/commands/project/logs.ts +++ b/commands/project/logs.ts @@ -10,7 +10,6 @@ const { logger } = require('@hubspot/local-dev-lib/logger'); const { getTableContents, getTableHeader } = require('../../lib/ui/table'); const { logError } = require('../../lib/errorHandlers/'); -const { loadAndValidateOptions } = require('../../lib/validation'); const { uiBetaTag, uiLine, uiLink } = require('../../lib/ui'); const { projectLogsPrompt } = require('../../lib/prompts/projectsLogsPrompt'); const { i18n } = require('../../lib/lang'); @@ -86,8 +85,6 @@ exports.handler = async options => { const { derivedAccountId } = options; trackCommandUsage('project-logs', null, derivedAccountId); - await loadAndValidateOptions(options); - try { await ProjectLogsManager.init(derivedAccountId); diff --git a/commands/project/migrateApp.ts b/commands/project/migrateApp.ts index 8044d4347..85b893d18 100644 --- a/commands/project/migrateApp.ts +++ b/commands/project/migrateApp.ts @@ -9,7 +9,6 @@ const { trackCommandUsage, trackCommandMetadataUsage, } = require('../../lib/usageTracking'); -const { loadAndValidateOptions } = require('../../lib/validation'); const { createProjectPrompt, } = require('../../lib/prompts/createProjectPrompt'); @@ -52,8 +51,6 @@ exports.command = 'migrate-app'; exports.describe = uiBetaTag(i18n(`${i18nKey}.describe`), false); exports.handler = async options => { - await loadAndValidateOptions(options); - const { derivedAccountId } = options; const accountConfig = getAccountConfig(derivedAccountId); const accountName = uiAccountDescription(derivedAccountId); diff --git a/commands/project/open.ts b/commands/project/open.ts index 370eacf94..351d5fed5 100644 --- a/commands/project/open.ts +++ b/commands/project/open.ts @@ -7,7 +7,6 @@ const { addTestingOptions, } = require('../../lib/commonOpts'); const { trackCommandUsage } = require('../../lib/usageTracking'); -const { loadAndValidateOptions } = require('../../lib/validation'); const { i18n } = require('../../lib/lang'); const { logger } = require('@hubspot/local-dev-lib/logger'); const { getProjectConfig, ensureProjectExists } = require('../../lib/projects'); @@ -22,8 +21,6 @@ exports.command = 'open'; exports.describe = uiBetaTag(i18n(`${i18nKey}.describe`), false); exports.handler = async options => { - await loadAndValidateOptions(options); - const { project, derivedAccountId } = options; trackCommandUsage('project-open', null, derivedAccountId); diff --git a/commands/project/upload.ts b/commands/project/upload.ts index 29b349e32..343e93d52 100644 --- a/commands/project/upload.ts +++ b/commands/project/upload.ts @@ -8,7 +8,6 @@ const chalk = require('chalk'); const { logger } = require('@hubspot/local-dev-lib/logger'); const { uiBetaTag, uiCommandReference } = require('../../lib/ui'); const { trackCommandUsage } = require('../../lib/usageTracking'); -const { loadAndValidateOptions } = require('../../lib/validation'); const { ensureProjectExists, getProjectConfig, @@ -33,8 +32,6 @@ exports.command = 'upload'; exports.describe = uiBetaTag(i18n(`${i18nKey}.describe`), false); exports.handler = async options => { - await loadAndValidateOptions(options); - const { forceCreate, message, derivedAccountId } = options; const accountConfig = getAccountConfig(derivedAccountId); const accountType = accountConfig && accountConfig.accountType; diff --git a/commands/project/watch.ts b/commands/project/watch.ts index 96c218303..ceac52615 100644 --- a/commands/project/watch.ts +++ b/commands/project/watch.ts @@ -27,7 +27,6 @@ const { fetchProjectBuilds, } = require('@hubspot/local-dev-lib/api/projects'); const { isSpecifiedError } = require('@hubspot/local-dev-lib/errors/index'); -const { loadAndValidateOptions } = require('../../lib/validation'); const { EXIT_CODES } = require('../../lib/enums/exitCodes'); const { handleKeypress, handleExit } = require('../../lib/process'); @@ -86,8 +85,6 @@ const handleUserInput = (accountId, projectName, currentBuildId) => { }; exports.handler = async options => { - await loadAndValidateOptions(options); - const { initialUpload, derivedAccountId } = options; trackCommandUsage('project-watch', null, derivedAccountId); diff --git a/commands/remove.ts b/commands/remove.ts index accf186d4..3d2c0a711 100644 --- a/commands/remove.ts +++ b/commands/remove.ts @@ -9,7 +9,6 @@ const { addUseEnvironmentOptions, addGlobalOptions, } = require('../lib/commonOpts'); -const { loadAndValidateOptions } = require('../lib/validation'); const { trackCommandUsage } = require('../lib/usageTracking'); const { i18n } = require('../lib/lang'); @@ -21,8 +20,6 @@ exports.describe = i18n(`${i18nKey}.describe`); exports.handler = async options => { const { path: hsPath, derivedAccountId } = options; - await loadAndValidateOptions(options); - trackCommandUsage('remove', null, derivedAccountId); try { diff --git a/commands/sandbox/create.ts b/commands/sandbox/create.ts index c6020e393..b516e307d 100644 --- a/commands/sandbox/create.ts +++ b/commands/sandbox/create.ts @@ -5,7 +5,6 @@ const { addUseEnvironmentOptions, addTestingOptions, } = require('../../lib/commonOpts'); -const { loadAndValidateOptions } = require('../../lib/validation'); const { i18n } = require('../../lib/lang'); const { EXIT_CODES } = require('../../lib/enums/exitCodes'); const { getAccountConfig, getEnv } = require('@hubspot/local-dev-lib/config'); @@ -40,8 +39,6 @@ exports.command = 'create'; exports.describe = uiBetaTag(i18n(`${i18nKey}.describe`), false); exports.handler = async options => { - await loadAndValidateOptions(options); - const { name, type, force, derivedAccountId } = options; const accountConfig = getAccountConfig(derivedAccountId); const env = getValidEnv(getEnv(derivedAccountId)); diff --git a/commands/sandbox/delete.ts b/commands/sandbox/delete.ts index 9886438f3..290acd49d 100644 --- a/commands/sandbox/delete.ts +++ b/commands/sandbox/delete.ts @@ -8,7 +8,6 @@ const { } = require('../../lib/commonOpts'); const { logger } = require('@hubspot/local-dev-lib/logger'); const { trackCommandUsage } = require('../../lib/usageTracking'); -const { loadAndValidateOptions } = require('../../lib/validation'); const { logError, debugError } = require('../../lib/errorHandlers/index'); const { isSpecifiedError } = require('@hubspot/local-dev-lib/errors/index'); const { deleteSandbox } = require('@hubspot/local-dev-lib/api/sandboxHubs'); @@ -41,8 +40,6 @@ exports.describe = exports.describe = uiBetaTag( ); exports.handler = async options => { - await loadAndValidateOptions(options, false); - const { providedAccountId, force } = options; trackCommandUsage('sandbox-delete', null); @@ -155,9 +152,8 @@ exports.handler = async options => { ); logger.log(''); - const promptDefaultAccount = removeSandboxAccountFromConfig( - sandboxAccountId - ); + const promptDefaultAccount = + removeSandboxAccountFromConfig(sandboxAccountId); if (promptDefaultAccount && !force) { const newDefaultAccount = await selectAccountFromConfig(); updateDefaultAccount(newDefaultAccount); @@ -208,9 +204,8 @@ exports.handler = async options => { ); logger.log(''); - const promptDefaultAccount = removeSandboxAccountFromConfig( - sandboxAccountId - ); + const promptDefaultAccount = + removeSandboxAccountFromConfig(sandboxAccountId); if (promptDefaultAccount && !force) { const newDefaultAccount = await selectAccountFromConfig(); updateDefaultAccount(newDefaultAccount); diff --git a/commands/secret/addSecret.ts b/commands/secret/addSecret.ts index f0d526c2d..1d57d7db9 100644 --- a/commands/secret/addSecret.ts +++ b/commands/secret/addSecret.ts @@ -7,9 +7,7 @@ const { logger } = require('@hubspot/local-dev-lib/logger'); const { logError, ApiErrorContext } = require('../../lib/errorHandlers/index'); const { addSecret } = require('@hubspot/local-dev-lib/api/secrets'); -const { loadAndValidateOptions } = require('../../lib/validation'); const { trackCommandUsage } = require('../../lib/usageTracking'); - const { addConfigOptions, addAccountOptions, @@ -31,8 +29,6 @@ exports.handler = async options => { const { name, derivedAccountId } = options; let secretName = name; - await loadAndValidateOptions(options); - trackCommandUsage('secrets-add', null, derivedAccountId); try { diff --git a/commands/secret/deleteSecret.ts b/commands/secret/deleteSecret.ts index ccd5604eb..4b2275747 100644 --- a/commands/secret/deleteSecret.ts +++ b/commands/secret/deleteSecret.ts @@ -10,7 +10,6 @@ const { fetchSecrets, } = require('@hubspot/local-dev-lib/api/secrets'); -const { loadAndValidateOptions } = require('../../lib/validation'); const { trackCommandUsage } = require('../../lib/usageTracking'); const { uiAccountDescription } = require('../../lib/ui'); @@ -30,8 +29,6 @@ exports.handler = async options => { const { name, derivedAccountId, force } = options; let secretName = name; - await loadAndValidateOptions(options); - trackCommandUsage('secrets-delete', null, derivedAccountId); try { diff --git a/commands/secret/listSecrets.ts b/commands/secret/listSecrets.ts index d7cc903a9..2f8f5d428 100644 --- a/commands/secret/listSecrets.ts +++ b/commands/secret/listSecrets.ts @@ -3,7 +3,6 @@ const { logger } = require('@hubspot/local-dev-lib/logger'); const { logError, ApiErrorContext } = require('../../lib/errorHandlers/index'); const { fetchSecrets } = require('@hubspot/local-dev-lib/api/secrets'); -const { loadAndValidateOptions } = require('../../lib/validation'); const { trackCommandUsage } = require('../../lib/usageTracking'); const { uiAccountDescription } = require('../../lib/ui'); @@ -20,8 +19,6 @@ exports.command = 'list'; exports.describe = i18n(`${i18nKey}.describe`); exports.handler = async options => { - await loadAndValidateOptions(options); - const { derivedAccountId } = options; trackCommandUsage('secrets-list', null, derivedAccountId); diff --git a/commands/secret/updateSecret.ts b/commands/secret/updateSecret.ts index 98348b017..51666fc36 100644 --- a/commands/secret/updateSecret.ts +++ b/commands/secret/updateSecret.ts @@ -8,7 +8,6 @@ const { fetchSecrets, } = require('@hubspot/local-dev-lib/api/secrets'); -const { loadAndValidateOptions } = require('../../lib/validation'); const { trackCommandUsage } = require('../../lib/usageTracking'); const { uiAccountDescription } = require('../../lib/ui'); @@ -30,9 +29,7 @@ exports.describe = i18n(`${i18nKey}.describe`); exports.handler = async options => { const { name, derivedAccountId } = options; - let secretName = name; - await loadAndValidateOptions(options); trackCommandUsage('secrets-update', null, derivedAccountId); diff --git a/commands/theme/marketplace-validate.ts b/commands/theme/marketplace-validate.ts index 94d969e26..8c12949f1 100644 --- a/commands/theme/marketplace-validate.ts +++ b/commands/theme/marketplace-validate.ts @@ -5,7 +5,6 @@ const { addAccountOptions, addUseEnvironmentOptions, } = require('../../lib/commonOpts'); -const { loadAndValidateOptions } = require('../../lib/validation'); const { trackCommandUsage } = require('../../lib/usageTracking'); const { kickOffValidation, @@ -24,8 +23,6 @@ exports.describe = i18n(`${i18nKey}.describe`); exports.handler = async options => { const { path, derivedAccountId } = options; - await loadAndValidateOptions(options); - trackCommandUsage('validate', null, derivedAccountId); SpinniesManager.init(); diff --git a/commands/theme/preview.ts b/commands/theme/preview.ts index a88625942..c82f6dd46 100644 --- a/commands/theme/preview.ts +++ b/commands/theme/preview.ts @@ -7,7 +7,6 @@ const { addAccountOptions, addConfigOptions } = require('../../lib/commonOpts'); const { getCwd } = require('@hubspot/local-dev-lib/path'); const { getUploadableFileList } = require('../../lib/upload'); const { trackCommandUsage } = require('../../lib/usageTracking'); -const { loadAndValidateOptions } = require('../../lib/validation'); const { previewPrompt, previewProjectPrompt, @@ -113,8 +112,6 @@ exports.handler = async options => { generateFieldsTypes, } = options; - await loadAndValidateOptions(options); - const { absoluteSrc, dest } = await determineSrcAndDest(options); const filePaths = await getUploadableFileList(absoluteSrc, false); diff --git a/commands/upload.ts b/commands/upload.ts index a21318717..feb37b63c 100644 --- a/commands/upload.ts +++ b/commands/upload.ts @@ -35,10 +35,7 @@ const { } = require('../lib/commonOpts'); const { uploadPrompt } = require('../lib/prompts/uploadPrompt'); const { confirmPrompt } = require('../lib/prompts/promptUtils'); -const { - validateCmsPublishMode, - loadAndValidateOptions, -} = require('../lib/validation'); +const { validateCmsPublishMode } = require('../lib/validation'); const { trackCommandUsage } = require('../lib/usageTracking'); const { getUploadableFileList } = require('../lib/upload'); @@ -67,8 +64,6 @@ const logThemePreview = (filePath, accountId) => { }; exports.handler = async options => { - await loadAndValidateOptions(options); - if (!validateCmsPublishMode(options)) { process.exit(EXIT_CODES.WARNING); } diff --git a/commands/watch.ts b/commands/watch.ts index 959c946af..ef75b0fea 100644 --- a/commands/watch.ts +++ b/commands/watch.ts @@ -15,10 +15,7 @@ const { getCmsPublishMode, } = require('../lib/commonOpts'); const { uploadPrompt } = require('../lib/prompts/uploadPrompt'); -const { - validateCmsPublishMode, - loadAndValidateOptions, -} = require('../lib/validation'); +const { validateCmsPublishMode } = require('../lib/validation'); const { trackCommandUsage } = require('../lib/usageTracking'); const { i18n } = require('../lib/lang'); const { getUploadableFileList } = require('../lib/upload'); @@ -34,8 +31,6 @@ exports.handler = async options => { const { remove, initialUpload, disableInitial, notify, derivedAccountId } = options; - await loadAndValidateOptions(options); - if (!validateCmsPublishMode(options)) { process.exit(EXIT_CODES.ERROR); } diff --git a/lib/validation.ts b/lib/validation.ts index d970c0fd3..5f66f6090 100644 --- a/lib/validation.ts +++ b/lib/validation.ts @@ -24,20 +24,8 @@ const { getExt, } = require('@hubspot/local-dev-lib/path'); const { getAccountId, getCmsPublishMode } = require('./commonOpts'); -const { EXIT_CODES } = require('./enums/exitCodes'); const { logError } = require('./errorHandlers/index'); -async function loadAndValidateOptions(options, shouldValidateAccount = true) { - let validAccount = true; - if (shouldValidateAccount) { - validAccount = await validateAccount(options); - } - - if (!validAccount) { - process.exit(EXIT_CODES.ERROR); - } -} - /** * Validate that an account was passed to the command and that the account's configuration is valid * @@ -227,5 +215,4 @@ module.exports = { validateAccount, checkAndConvertToJson, fileExists, - loadAndValidateOptions, };