Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions commands/account/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import { toKebabCase } from '@hubspot/local-dev-lib/text';
import { Environment } from '@hubspot/local-dev-lib/types/Config';
import { CLIAccount } from '@hubspot/local-dev-lib/types/Accounts';
import { PERSONAL_ACCESS_KEY_AUTH_METHOD } from '@hubspot/local-dev-lib/constants/auth';
import { GLOBAL_CONFIG_PATH } from '@hubspot/local-dev-lib/constants/config';

import { addGlobalOptions, addTestingOptions } from '../../lib/commonOpts';
import { handleMerge, handleMigration } from '../../lib/configMigrate';
import { handleExit } from '../../lib/process';
import { debugError } from '../../lib/errorHandlers/index';
Expand All @@ -37,6 +37,7 @@ import { trackCommandMetadataUsage } from '../../lib/usageTracking';
import { EXIT_CODES } from '../../lib/enums/exitCodes';
import { uiCommandReference, uiFeatureHighlight } from '../../lib/ui';
import { CommonArgs, ConfigArgs } from '../../types/Yargs';
import { makeYargsBuilder } from '../../lib/yargsUtils';

const TRACKING_STATUS = {
STARTED: 'started',
Expand Down Expand Up @@ -269,7 +270,7 @@ export async function handler(
);
}

export function builder(yargs: Argv): Argv<AccountAuthArgs> {
function accountAuthBuilder(yargs: Argv): Argv<AccountAuthArgs> {
yargs.options({
account: {
describe: i18n(
Expand All @@ -285,8 +286,18 @@ export function builder(yargs: Argv): Argv<AccountAuthArgs> {
},
});

addTestingOptions(yargs);
addGlobalOptions(yargs);

return yargs as Argv<AccountAuthArgs>;
}

export const builder = makeYargsBuilder<AccountAuthArgs>(
accountAuthBuilder,
command,
i18n('commands.account.subcommands.auth.verboseDescribe', {
authMethod: PERSONAL_ACCESS_KEY_AUTH_METHOD.value,
globalConfigPath: GLOBAL_CONFIG_PATH,
}),
{
useGlobalOptions: true,
useTestingOptions: true,
}
);
36 changes: 23 additions & 13 deletions commands/config/migrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@ import fs from 'fs';
import {
DEFAULT_HUBSPOT_CONFIG_YAML_FILE_NAME,
GLOBAL_CONFIG_PATH,
ARCHIVED_HUBSPOT_CONFIG_YAML_FILE_NAME,
} from '@hubspot/local-dev-lib/constants/config';
import { configFileExists } from '@hubspot/local-dev-lib/config/migrate';
import { logger } from '@hubspot/local-dev-lib/logger';

import { handleMigration, handleMerge } from '../../lib/configMigrate';
import { addConfigOptions } from '../../lib/commonOpts';
import { i18n } from '../../lib/lang';
import { CommonArgs, ConfigArgs } from '../../types/Yargs';
import { trackCommandMetadataUsage } from '../../lib/usageTracking';
import { logError } from '../../lib/errorHandlers/index';
import { EXIT_CODES } from '../../lib/enums/exitCodes';
import { makeYargsBuilder } from '../../lib/yargsUtils';

export const describe = i18n('commands.config.subcommands.migrate.describe', {
deprecatedConfigPath: DEFAULT_HUBSPOT_CONFIG_YAML_FILE_NAME,
Expand Down Expand Up @@ -71,15 +72,15 @@ export async function handler(
}
}

export function builder(yargs: Argv): Argv<ConfigMigrateArgs> {
addConfigOptions(yargs);

yargs
.option('force', {
alias: 'f',
type: 'boolean',
default: false,
description: i18n('commands.config.subcommands.migrate.options.force'),
function configMigrateBuilder(yargs: Argv): Argv<ConfigMigrateArgs> {
return yargs
.option({
force: {
alias: 'f',
type: 'boolean',
default: false,
description: i18n('commands.config.subcommands.migrate.options.force'),
},
})
.example([
[
Expand All @@ -95,7 +96,16 @@ export function builder(yargs: Argv): Argv<ConfigMigrateArgs> {
globalConfigPath: GLOBAL_CONFIG_PATH,
}),
],
]);

return yargs as Argv<ConfigMigrateArgs>;
]) as Argv<ConfigMigrateArgs>;
}

export const builder = makeYargsBuilder<ConfigMigrateArgs>(
configMigrateBuilder,
command,
i18n('commands.config.subcommands.migrate.verboseDescribe', {
archivedConfigPath: ARCHIVED_HUBSPOT_CONFIG_YAML_FILE_NAME,
}),
{
useConfigOptions: true,
}
);
12 changes: 10 additions & 2 deletions lang/en.lyaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ en:
subcommands:
auth:
describe: "Configure authentication for your HubSpot account."
verboseDescribe: "Configure authentication for a HubSpot account. This will create or update the global config file at {{ globalConfigPath }} that stores your account information.\n\nThe recommended authentication method is {{#bold}}{{ authMethod }}{{/bold}}, which uses an access token tied to a specific user account.\nIf a deprecated config file exists, you will be prompted to migrate it to the new global config file. If both deprecated and global config files exist, you will be prompted to merge them. If any conflicts exist between the two files, you will be prompted to reconcile them."
options:
account:
describe: "HubSpot account to authenticate"
Expand Down Expand Up @@ -168,6 +169,7 @@ en:
subcommands:
migrate:
describe: "Migrate from the deprecated {{ deprecatedConfigPath }} file to the new global config file at {{ globalConfigPath }}."
verboseDescribe: "This command will create a new global configuration file in your root directory and rename the deprecated config to {{ archivedConfigPath }}. If any conflicting values are detected, we will prompt you to reconcile them unless the \"--force\" flag is supplied."
migrationAlreadyCompleted: "No {{ deprecatedConfigPath }} deprecated configuration file found. No migration necessary."
errors:
configNotFound: "A configuration file at {{ configPath }} could not be found. Please try again with a valid file path."
Expand Down Expand Up @@ -1332,9 +1334,15 @@ en:
debug:
describe: "Set log level to debug"
configMigrate:
migrateConfigPrompt: "Migrate config?\n From deprecated config file: {{ deprecatedConfigPath }}\n To new global config file: {{ globalConfigPath }}\n (This action will delete the deprecated config file).\n"
migrationHeader: "Migrate your existing configuration file to the new global location?"
migrationDescription: "This action will create a new global configuration file in your root directory and rename the deprecated config to {{ archivedConfigPath}}. If any conflicting values are detected, we will prompt you to reconcile them unless the \"--force\" flag is supplied."
mergeHeader: "Merge your existing configuration file with the global config?"
mergeDescription: "This action will merge your deprecated config file with the global config file located in your root directory. It will also rename the deprecated config to {{ archivedConfigPath }}. If any conflicting values are detected, we will prompt you to reconcile them unless the \"--force\" flag is supplied."
migrateConfigPromptDescription: "From deprecated config file: {{ deprecatedConfigPath }}\nTo new global config file: {{ globalConfigPath }}"
migrateConfigPrompt: "Migrate to the new config?"
mergeConfigConflictPrompt: "Change the {{ property }} property in the global config from {{ newValue }} to {{ oldValue }}?"
mergeConfigsPrompt: "Two config files detected. Merge them?\n Deprecated config file: {{ deprecatedConfigPath }}\n Global config: {{ globalConfigPath }}\n (This action will delete the deprecated config file).\n"
mergeConfigsPromptDescription: "Two config files detected. \nDeprecated config file: {{ deprecatedConfigPath }}\nGlobal config: {{ globalConfigPath }}"
mergeConfigsPrompt: "Merge configs?"
migrationSuccess: "The deprecated config file has been migrated to the new global config file at {{ globalConfigPath }}."
mergeSuccess: "The deprecated config file has been merged with the global config file at {{ globalConfigPath }}."
skippedExistingAccounts: "\nThe following accounts were not merged, because they already exist in the global config: {{ skippedAccountIds }}.\n"
Expand Down
43 changes: 33 additions & 10 deletions lib/configMigrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
} from '@hubspot/local-dev-lib/config/migrate';
import {
DEFAULT_HUBSPOT_CONFIG_YAML_FILE_NAME,
ARCHIVED_HUBSPOT_CONFIG_YAML_FILE_NAME,
GLOBAL_CONFIG_PATH,
} from '@hubspot/local-dev-lib/constants/config';
import { logger } from '@hubspot/local-dev-lib/logger';
Expand All @@ -25,15 +26,26 @@ export async function handleMigration(
accountId: number | undefined,
configPath?: string
): Promise<boolean> {
const { shouldMigrateConfig } = await promptUser({
name: 'shouldMigrateConfig',
type: 'confirm',
message: i18n('lib.configMigrate.migrateConfigPrompt', {
logger.log(i18n('lib.configMigrate.migrationHeader'));
logger.log('');
logger.log(
i18n('lib.configMigrate.migrationDescription', {
archivedConfigPath: ARCHIVED_HUBSPOT_CONFIG_YAML_FILE_NAME,
})
);
logger.log('');
logger.log(
i18n('lib.configMigrate.migrateConfigPromptDescription', {
deprecatedConfigPath:
getConfigPath(configPath, false) ||
DEFAULT_HUBSPOT_CONFIG_YAML_FILE_NAME,
globalConfigPath: GLOBAL_CONFIG_PATH,
}),
})
);
const { shouldMigrateConfig } = await promptUser({
name: 'shouldMigrateConfig',
type: 'confirm',
message: i18n('lib.configMigrate.migrateConfigPrompt'),
});

if (!shouldMigrateConfig) {
Expand Down Expand Up @@ -107,15 +119,26 @@ export async function handleMerge(
configPath?: string,
force?: boolean
): Promise<boolean> {
const { shouldMergeConfigs } = await promptUser({
name: 'shouldMergeConfigs',
type: 'confirm',
message: i18n('lib.configMigrate.mergeConfigsPrompt', {
logger.log(i18n('lib.configMigrate.mergeHeader'));
logger.log('');
logger.log(
i18n('lib.configMigrate.mergeDescription', {
archivedConfigPath: ARCHIVED_HUBSPOT_CONFIG_YAML_FILE_NAME,
})
);
logger.log('');
logger.log(
i18n('lib.configMigrate.mergeConfigsPromptDescription', {
deprecatedConfigPath:
getConfigPath(configPath, false) ||
DEFAULT_HUBSPOT_CONFIG_YAML_FILE_NAME,
globalConfigPath: GLOBAL_CONFIG_PATH,
}),
})
);
const { shouldMergeConfigs } = await promptUser({
name: 'shouldMergeConfigs',
type: 'confirm',
message: i18n('lib.configMigrate.mergeConfigsPrompt'),
});

if (!shouldMergeConfigs) {
Expand Down
9 changes: 9 additions & 0 deletions lib/middleware/configMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export async function loadConfigMiddleware(
!configFileExists(true) &&
isTargetedCommand(argv._, {
account: { target: false, subCommands: { auth: { target: true } } },
config: { target: false, subCommands: { migrate: { target: true } } },
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the hs config migrate command is validated and there is no deprecated config present, we warn the user that they need to supply an account ID. That would be ok for any other command, but with this command, we want to tell the user that no further action is required because the migration has already taken place.

})
) {
return;
Expand Down Expand Up @@ -129,13 +130,21 @@ const sandboxesSubCommands = {
},
};

const configSubCommands = {
target: false,
subCommands: {
migrate: { target: true },
},
};

const SKIP_ACCOUNT_VALIDATION = {
init: { target: true },
auth: { target: true },
account: accountsSubCommands,
accounts: accountsSubCommands,
sandbox: sandboxesSubCommands,
sandboxes: sandboxesSubCommands,
config: configSubCommands,
};

export async function validateAccountOptions(argv: Arguments): Promise<void> {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"license": "Apache-2.0",
"repository": "https://github.com/HubSpot/hubspot-cli",
"dependencies": {
"@hubspot/local-dev-lib": "3.5.6",
"@hubspot/local-dev-lib": "3.6.0",
"@hubspot/project-parsing-lib": "0.1.11",
"@hubspot/serverless-dev-runtime": "7.0.2",
"@hubspot/theme-preview-dev-server": "0.0.10",
Expand Down