Skip to content

Commit

Permalink
Merge pull request #1171 from HubSpot/account-flag-test-account-bug-fix
Browse files Browse the repository at this point in the history
Handle case where account flag test account parent isn't authed on hs project dev
  • Loading branch information
camden11 authored Sep 11, 2024
2 parents d01e7f7 + b37cec0 commit 8e73e2d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 26 deletions.
22 changes: 3 additions & 19 deletions packages/cli/commands/project/dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,7 @@ const {
validateProjectConfig,
} = require('../../lib/projects');
const { EXIT_CODES } = require('../../lib/enums/exitCodes');
const {
uiAccountDescription,
uiBetaTag,
uiCommandReference,
uiLink,
} = require('../../lib/ui');
const { uiBetaTag, uiCommandReference, uiLink } = require('../../lib/ui');
const SpinniesManager = require('../../lib/ui/SpinniesManager');
const LocalDevManager = require('../../lib/LocalDevManager');
const {
Expand All @@ -52,6 +47,7 @@ const {
createInitialBuildForNewProject,
useExistingDevTestAccount,
validateAccountOption,
checkIfParentAccountIsAuthed,
} = require('../../lib/localDev');

const i18nKey = 'commands.project.subcommands.dev';
Expand Down Expand Up @@ -130,19 +126,7 @@ exports.handler = async options => {
await confirmDefaultAccountIsTarget(accountConfig, hasPublicApps);

if (hasPublicApps) {
// Exit if the user has not authed the parent account in the config
if (!getAccountConfig(accountConfig.parentAccountId)) {
logger.error(
i18n(`${i18nKey}.errors.parentAccountNotConfigured`, {
accountId: accountConfig.parentAccountId,
accountIdentifier: uiAccountDescription(targetTestingAccountId),
authCommand: uiCommandReference(
`hs auth --account=${accountConfig.parentAccountId}`
),
})
);
process.exit(EXIT_CODES.ERROR);
}
checkIfParentAccountIsAuthed(accountConfig);
targetProjectAccountId = accountConfig.parentAccountId;
} else {
targetProjectAccountId = accountId;
Expand Down
3 changes: 2 additions & 1 deletion packages/cli/lang/en.lyaml
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,6 @@ en:
noProjectConfig: "No project detected. Please run this command again from a project directory."
invalidProjectComponents: "Projects cannot contain both private and public apps. Move your apps to separate projects before attempting local development."
noRunnableComponents: "No supported components were found in this project. Run {{ command }} to see a list of available components and add one to your project."
parentAccountNotConfigured: "To develop this project locally, run {{ authCommand }} to authenticate the App Developer Account {{ accountId }} associated with {{ accountIdentifier }}."
examples:
default: "Start local dev for the current project"
create:
Expand Down Expand Up @@ -1023,6 +1022,8 @@ en:
createInitialBuildForNewProject:
initialUploadMessage: "HubSpot Local Dev Server Startup"
projectLockedError: "Your project is locked. This may mean that another user is running the {{#bold}}`hs project watch`{{/bold}} command for this project. If this is you, unlock the project in Projects UI."
checkIfParentAccountIsAuthed:
notAuthedError: "To develop this project locally, run {{ authCommand }} to authenticate the App Developer Account {{ accountId }} associated with {{ accountIdentifier }}."
projects:
config:
srcOutsideProjectDir: "Invalid value for 'srcDir' in {{ projectConfig }}: {{#bold}}srcDir: \"{{ srcDir }}\"{{/bold}}\n\t'srcDir' must be a relative path to a folder under the project root, such as \".\" or \"./src\""
Expand Down
31 changes: 25 additions & 6 deletions packages/cli/lib/localDev.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,34 @@ const checkIfAppDeveloperAccount = accountConfig => {
}
};

// Confirm the default account is a developer account if developing public apps
const validateAccountOption = (accountConfig, hasPublicApps) => {
if (hasPublicApps && !isDeveloperTestAccount(accountConfig)) {
const checkIfParentAccountIsAuthed = accountConfig => {
if (!getAccountConfig(accountConfig.parentAccountId)) {
logger.error(
i18n(`${i18nKey}.validateAccountOption.invalidPublicAppAccount`, {
useCommand: uiCommandReference('hs accounts use'),
devCommand: uiCommandReference('hs project dev'),
i18n(`${i18nKey}.checkIfParentAccountIsAuthed.notAuthedError`, {
accountId: accountConfig.parentAccountId,
accountIdentifier: uiAccountDescription(accountConfig.portalId),
authCommand: uiCommandReference(
`hs auth --account=${accountConfig.parentAccountId}`
),
})
);
process.exit(EXIT_CODES.SUCCESS);
}
};

// Confirm the default account is a developer account if developing public apps
const validateAccountOption = (accountConfig, hasPublicApps) => {
if (hasPublicApps) {
if (!isDeveloperTestAccount) {
logger.error(
i18n(`${i18nKey}.validateAccountOption.invalidPublicAppAccount`, {
useCommand: uiCommandReference('hs accounts use'),
devCommand: uiCommandReference('hs project dev'),
})
);
process.exit(EXIT_CODES.SUCCESS);
}
checkIfParentAccountIsAuthed(accountConfig);
} else if (isAppDeveloperAccount(accountConfig)) {
logger.error(
i18n(`${i18nKey}.validateAccountOption.invalidPrivateAppAccount`, {
Expand Down Expand Up @@ -456,4 +474,5 @@ module.exports = {
createNewProjectForLocalDev,
createInitialBuildForNewProject,
getAccountHomeUrl,
checkIfParentAccountIsAuthed,
};

0 comments on commit 8e73e2d

Please sign in to comment.