diff --git a/bin/cli.js b/bin/cli.js index 1644f7ed0..017485619 100755 --- a/bin/cli.js +++ b/bin/cli.js @@ -8,16 +8,13 @@ const { logger } = require('@hubspot/local-dev-lib/logger'); const { addUserAgentHeader } = require('@hubspot/local-dev-lib/http'); const { loadConfig, + getAccountId, configFileExists, getConfigPath, validateConfig, } = require('@hubspot/local-dev-lib/config'); const { logError } = require('../lib/errorHandlers/index'); -const { - setLogLevel, - getCommandName, - injectAccountIdMiddleware, -} = require('../lib/commonOpts'); +const { setLogLevel, getCommandName } = require('../lib/commonOpts'); const { validateAccount } = require('../lib/validation'); const { trackHelpUsage, @@ -27,7 +24,7 @@ const { getIsInProject } = require('../lib/projects'); const pkg = require('../package.json'); const { i18n } = require('../lib/lang'); const { EXIT_CODES } = require('../lib/enums/exitCodes'); -const { UI_COLORS, uiCommandReference } = require('../lib/ui'); +const { UI_COLORS, uiCommandReference, uiDeprecatedTag } = require('../lib/ui'); const { checkAndWarnGitInclusion } = require('../lib/ui/git'); const removeCommand = require('../commands/remove'); @@ -176,6 +173,39 @@ const SKIP_CONFIG_VALIDATION = { auth: { target: true }, }; +const handleDeprecatedEnvVariables = options => { + // HUBSPOT_PORTAL_ID is deprecated, but we'll still support it for now + // The HubSpot GH Deploy Action still uses HUBSPOT_PORTAL_ID + if ( + options.useEnv && + process.env.HUBSPOT_PORTAL_ID && + !process.env.HUBSPOT_ACCOUNT_ID + ) { + uiDeprecatedTag( + i18n(`${i18nKey}.handleDeprecatedEnvVariables.portalEnvVarDeprecated`, { + configPath: getConfigPath(), + }) + ); + process.env.HUBSPOT_ACCOUNT_ID = process.env.HUBSPOT_PORTAL_ID; + } +}; + +/** + * Auto-injects the derivedAccountId flag into all commands + */ +const injectAccountIdMiddleware = async options => { + const { account } = options; + + // Preserves the original --account flag for certain commands. + options.providedAccountId = account; + + if (options.useEnv && process.env.HUBSPOT_ACCOUNT_ID) { + options.derivedAccountId = parseInt(process.env.HUBSPOT_ACCOUNT_ID, 10); + } else { + options.derivedAccountId = getAccountId(account); + } +}; + const loadConfigMiddleware = async options => { // Skip this when no command is provided if (!options._.length) { @@ -261,6 +291,7 @@ const argv = yargs .middleware([ setLogLevel, setRequestHeaders, + handleDeprecatedEnvVariables, loadConfigMiddleware, injectAccountIdMiddleware, checkAndWarnGitInclusionMiddleware, diff --git a/lang/en.lyaml b/lang/en.lyaml index 3ce2a43d3..295c67f75 100644 --- a/lang/en.lyaml +++ b/lang/en.lyaml @@ -7,6 +7,8 @@ en: cliUpdateNotification: "HubSpot CLI version {{#cyan}}{{#bold}}{currentVersion}{{/bold}}{{/cyan}} is outdated.\nRun {{ updateCommand }} to upgrade to version {{#cyan}}{{#bold}}{latestVersion}{{/bold}}{{/cyan}}" srcIsProject: "\"{{ src }}\" is in a project folder. Did you mean \"hs project {{command}}\"?" setDefaultAccountMoved: "This command has moved. Try `hs accounts use` instead" + handleDeprecatedEnvVariables: + portalEnvVarDeprecated: "The HUBSPOT_PORTAL_ID environment variable is deprecated. Please use HUBSPOT_ACCOUNT_ID instead." loadConfigMiddleware: configFileExists: "A configuration file already exists at {{ configPath }}. To specify a new configuration file, delete the existing one and try again." completion: diff --git a/lib/commonOpts.ts b/lib/commonOpts.ts index ba6caf0d7..c2d37d152 100644 --- a/lib/commonOpts.ts +++ b/lib/commonOpts.ts @@ -117,28 +117,6 @@ export function getAccountId( return getAccountIdFromConfig(account); } -/** - * Auto-injects the derivedAccountId flag into all commands - */ -export async function injectAccountIdMiddleware( - options: Arguments<{ - derivedAccountId?: number | null; - account?: number | string; - }> -): Promise { - const { account } = options; - - // Preserves the original --account flag for certain commands. - options.providedAccountId = account; - - if (options.useEnv && process.env.HUBSPOT_ACCOUNT_ID) { - options.derivedAccountId = parseInt(process.env.HUBSPOT_ACCOUNT_ID, 10); - return; - } - - options.derivedAccountId = getAccountIdFromConfig(account); -} - export function getCmsPublishMode( options: Arguments<{ cmsPublishMode?: CmsPublishMode }> ): CmsPublishMode { diff --git a/package.json b/package.json index a51a207e1..e2a8bb558 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "license": "Apache-2.0", "repository": "https://github.com/HubSpot/hubspot-cli", "dependencies": { - "@hubspot/local-dev-lib": "3.1.0", + "@hubspot/local-dev-lib": "3.1.1", "@hubspot/serverless-dev-runtime": "7.0.1", "@hubspot/theme-preview-dev-server": "0.0.10", "@hubspot/ui-extensions-dev-server": "0.8.40", diff --git a/yarn.lock b/yarn.lock index 8d8182926..065849c51 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1446,10 +1446,10 @@ semver "^6.3.0" unixify "^1.0.0" -"@hubspot/local-dev-lib@3.1.0": - version "3.1.0" - resolved "https://registry.yarnpkg.com/@hubspot/local-dev-lib/-/local-dev-lib-3.1.0.tgz#76b5d524aa694aad2bfc6e199ee1dac314f15774" - integrity sha512-iop3PgZ0ZWejCH6PmSeYnnGwV8vGIuA4F+w7SxukdX3QfhivlczClATWPaZanv1CYJHdflqoItq1kdF8ASJJmA== +"@hubspot/local-dev-lib@3.1.1": + version "3.1.1" + resolved "https://registry.yarnpkg.com/@hubspot/local-dev-lib/-/local-dev-lib-3.1.1.tgz#b67646d7a7b399cebc5d74f62c389c13554e950c" + integrity sha512-/SIKBuC3ORkKMXityS6tCz2sNU7OY96slJtLM0CxRlKDCiwEGb08Lf0Ruf1PMBJnAu8iHbw/6SprefFEHEQOpw== dependencies: address "^2.0.1" axios "^1.3.5" @@ -10709,7 +10709,16 @@ string-length@^4.0.1: char-regex "^1.0.2" strip-ansi "^6.0.0" -"string-width-cjs@npm:string-width@^4.2.0", string-width@^4.0.0, string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.2, string-width@^4.2.3: +"string-width-cjs@npm:string-width@^4.2.0": + version "4.2.3" + resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010" + integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g== + dependencies: + emoji-regex "^8.0.0" + is-fullwidth-code-point "^3.0.0" + strip-ansi "^6.0.1" + +string-width@^4.0.0, string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.2, string-width@^4.2.3: version "4.2.3" resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010" integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g== @@ -10791,7 +10800,7 @@ stringify-object@^3.2.1, stringify-object@^3.3.0: is-obj "^1.0.1" is-regexp "^1.0.0" -"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1: +"strip-ansi-cjs@npm:strip-ansi@^6.0.1": version "6.0.1" resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9" integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A== @@ -10805,6 +10814,13 @@ strip-ansi@^5.2.0: dependencies: ansi-regex "^4.1.0" +strip-ansi@^6.0.0, strip-ansi@^6.0.1: + version "6.0.1" + resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9" + integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A== + dependencies: + ansi-regex "^5.0.1" + strip-ansi@^7.0.1, strip-ansi@^7.1.0: version "7.1.0" resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-7.1.0.tgz#d5b6568ca689d8561370b0707685d22434faff45" @@ -11829,8 +11845,7 @@ wordwrap@^1.0.0: resolved "https://registry.yarnpkg.com/wordwrap/-/wordwrap-1.0.0.tgz#27584810891456a4171c8d0226441ade90cbcaeb" integrity sha512-gvVzJFlPycKc5dZN4yPkP8w7Dc37BtP1yczEneOb4uq34pXZcvrtRTmWV8W+Ume+XCxKgbjM+nevkyFPMybd4Q== -"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0: - name wrap-ansi-cjs +"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0": version "7.0.0" resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43" integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q== @@ -11848,6 +11863,15 @@ wrap-ansi@^6.2.0: string-width "^4.1.0" strip-ansi "^6.0.0" +wrap-ansi@^7.0.0: + version "7.0.0" + resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43" + integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q== + dependencies: + ansi-styles "^4.0.0" + string-width "^4.1.0" + strip-ansi "^6.0.0" + wrap-ansi@^8.1.0: version "8.1.0" resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-8.1.0.tgz#56dc22368ee570face1b49819975d9b9a5ead214"