From 3f1041e3419cfdbbfe72cce9824068ae59052ccf Mon Sep 17 00:00:00 2001 From: Joe Yeager Date: Mon, 28 Apr 2025 13:48:37 -0700 Subject: [PATCH 1/5] chore: Inline the remaining files --- commands/cms/lighthouseScore.ts | 2 +- lib/buildAccount.ts | 10 +- lib/commonOpts.ts | 16 +-- lib/configOptions.ts | 32 +++-- lib/doctor/Diagnosis.ts | 24 ++-- lib/doctor/Doctor.ts | 144 ++++++++++--------- lib/errorHandlers/index.ts | 15 +- lib/errorHandlers/suppressError.ts | 25 ++-- lib/generateSelectors.ts | 3 +- lib/oauth.ts | 4 +- lib/process.ts | 4 +- lib/prompts/accountNamePrompt.ts | 39 ++--- lib/prompts/accountsPrompt.ts | 4 +- lib/prompts/cmsFieldPrompt.ts | 3 +- lib/prompts/createApiSamplePrompt.ts | 16 ++- lib/prompts/createFunctionPrompt.ts | 28 ++-- lib/prompts/createModulePrompt.ts | 18 ++- lib/prompts/createProjectPrompt.ts | 22 +-- lib/prompts/createTemplatePrompt.ts | 4 +- lib/prompts/downloadProjectPrompt.ts | 10 +- lib/prompts/installPublicAppPrompt.ts | 12 +- lib/prompts/personalAccessKeyPrompt.ts | 63 +++++--- lib/prompts/previewPrompt.ts | 12 +- lib/prompts/projectAddPrompt.ts | 10 +- lib/prompts/projectDevTargetAccountPrompt.ts | 71 +++++---- lib/prompts/projectNamePrompt.ts | 17 +-- lib/prompts/projectsLogsPrompt.ts | 6 +- lib/prompts/sandboxesPrompt.ts | 12 +- lib/prompts/secretPrompt.ts | 6 +- lib/prompts/selectHubDBTablePrompt.ts | 26 ++-- lib/prompts/selectPublicAppPrompt.ts | 25 ++-- lib/prompts/setAsDefaultAccountPrompt.ts | 6 +- lib/prompts/uploadPrompt.ts | 10 +- lib/sandboxSync.ts | 30 ++-- lib/sandboxes.ts | 26 ++-- lib/serverlessLogs.ts | 10 +- lib/ui/git.ts | 18 ++- lib/ui/index.ts | 58 ++++---- lib/ui/serverlessFunctionLogs.ts | 6 +- 39 files changed, 453 insertions(+), 394 deletions(-) diff --git a/commands/cms/lighthouseScore.ts b/commands/cms/lighthouseScore.ts index ecd32c4ca..32b1753f4 100644 --- a/commands/cms/lighthouseScore.ts +++ b/commands/cms/lighthouseScore.ts @@ -28,7 +28,7 @@ const DEFAULT_TABLE_HEADER = [ ]; exports.command = 'lighthouse-score [--theme]'; -exports.describe = false; // i18n(`${i18nKey}.describe`); +exports.describe = false; const selectTheme = async accountId => { const { theme: selectedTheme } = await promptUser([ diff --git a/lib/buildAccount.ts b/lib/buildAccount.ts index e46f91bce..685000bad 100644 --- a/lib/buildAccount.ts +++ b/lib/buildAccount.ts @@ -91,13 +91,11 @@ export async function buildDeveloperTestAccount( env: Environment, portalLimit: number ): Promise { - const i18nKey = 'lib.developerTestAccount.create.loading'; - const id = getAccountIdentifier(parentAccountConfig); const parentAccountId = getAccountId(id); if (!parentAccountId) { - throw new Error(i18n(`${i18nKey}.fail`)); + throw new Error(i18n(`lib.developerTestAccount.create.loading.fail`)); } SpinniesManager.init({ @@ -106,7 +104,7 @@ export async function buildDeveloperTestAccount( logger.log(''); SpinniesManager.add('buildDeveloperTestAccount', { - text: i18n(`${i18nKey}.add`, { + text: i18n(`lib.developerTestAccount.create.loading.add`, { accountName: testAccountName, }), }); @@ -124,7 +122,7 @@ export async function buildDeveloperTestAccount( developerTestAccountPersonalAccessKey = data.personalAccessKey; SpinniesManager.succeed('buildDeveloperTestAccount', { - text: i18n(`${i18nKey}.succeed`, { + text: i18n(`lib.developerTestAccount.create.loading.succeed`, { accountName: testAccountName, accountId: developerTestAccountId, }), @@ -133,7 +131,7 @@ export async function buildDeveloperTestAccount( debugError(e); SpinniesManager.fail('buildDeveloperTestAccount', { - text: i18n(`${i18nKey}.fail`, { + text: i18n(`lib.developerTestAccount.create.loading.fail`, { accountName: testAccountName, }), }); diff --git a/lib/commonOpts.ts b/lib/commonOpts.ts index 8da81d22d..1f0691179 100644 --- a/lib/commonOpts.ts +++ b/lib/commonOpts.ts @@ -21,14 +21,12 @@ import { debugError } from './errorHandlers'; import { EXIT_CODES } from './enums/exitCodes'; import { uiCommandReference } from './ui'; -const i18nKey = 'lib.commonOpts'; - export function addGlobalOptions(yargs: Argv) { yargs.version(false); yargs.option('debug', { alias: 'd', default: false, - describe: i18n(`${i18nKey}.options.debug.describe`), + describe: i18n(`lib.commonOpts.options.debug.describe`), type: 'boolean', }); yargs.option('network-debug', { @@ -42,7 +40,7 @@ export function addGlobalOptions(yargs: Argv) { export function addAccountOptions(yargs: Argv): Argv { return yargs.option('account', { alias: 'a', - describe: i18n(`${i18nKey}.options.account.describe`), + describe: i18n(`lib.commonOpts.options.account.describe`), type: 'string', }); } @@ -50,7 +48,7 @@ export function addAccountOptions(yargs: Argv): Argv { export function addConfigOptions(yargs: Argv): Argv { return yargs.option('config', { alias: 'c', - describe: i18n(`${i18nKey}.options.config.describe`), + describe: i18n(`lib.commonOpts.options.config.describe`), type: 'string', }); } @@ -58,7 +56,7 @@ export function addConfigOptions(yargs: Argv): Argv { export function addOverwriteOptions(yargs: Argv): Argv { return yargs.option('overwrite', { alias: 'o', - describe: i18n(`${i18nKey}.options.overwrite.describe`), + describe: i18n(`lib.commonOpts.options.overwrite.describe`), type: 'boolean', default: false, }); @@ -73,7 +71,7 @@ export function addCmsPublishModeOptions( return yargs.option('cms-publish-mode', { alias: 'm', describe: i18n( - `${i18nKey}.options.modes.describe.${ + `lib.commonOpts.options.modes.describe.${ read ? 'read' : write ? 'write' : 'default' }`, { modes: cmsPublishModes } @@ -84,7 +82,7 @@ export function addCmsPublishModeOptions( export function addTestingOptions(yargs: Argv): Argv { return yargs.option('qa', { - describe: i18n(`${i18nKey}.options.qa.describe`), + describe: i18n(`lib.commonOpts.options.qa.describe`), type: 'boolean', default: false, hidden: true, @@ -93,7 +91,7 @@ export function addTestingOptions(yargs: Argv): Argv { export function addUseEnvironmentOptions(yargs: Argv): Argv { yargs.option('use-env', { - describe: i18n(`${i18nKey}.options.useEnv.describe`), + describe: i18n(`lib.commonOpts.options.useEnv.describe`), type: 'boolean', }); yargs.conflicts('use-env', 'account'); diff --git a/lib/configOptions.ts b/lib/configOptions.ts index 180601620..d658f70c8 100644 --- a/lib/configOptions.ts +++ b/lib/configOptions.ts @@ -11,22 +11,26 @@ import { trackCommandUsage } from './usageTracking'; import { promptUser } from './prompts/promptUtils'; import { i18n } from '../lib/lang'; -const i18nKey = 'commands.config.subcommands.set.options'; - async function enableOrDisableUsageTracking(): Promise { const { isEnabled } = await promptUser<{ isEnabled: boolean }>([ { type: 'list', name: 'isEnabled', pageSize: 20, - message: i18n(`${i18nKey}.allowUsageTracking.promptMessage`), + message: i18n( + `commands.config.subcommands.set.options.allowUsageTracking.promptMessage` + ), choices: [ { - name: i18n(`${i18nKey}.allowUsageTracking.labels.enabled`), + name: i18n( + `commands.config.subcommands.set.options.allowUsageTracking.labels.enabled` + ), value: true, }, { - name: i18n(`${i18nKey}.allowUsageTracking.labels.disabled`), + name: i18n( + `commands.config.subcommands.set.options.allowUsageTracking.labels.disabled` + ), value: false, }, ], @@ -57,7 +61,7 @@ export async function setAllowUsageTracking({ updateAllowUsageTracking(isEnabled); logger.success( - i18n(`${i18nKey}.allowUsageTracking.success`, { + i18n(`commands.config.subcommands.set.options.allowUsageTracking.success`, { isEnabled: isEnabled.toString(), }) ); @@ -73,7 +77,9 @@ async function selectCmsPublishMode(): Promise { type: 'list', name: 'cmsPublishMode', pageSize: 20, - message: i18n(`${i18nKey}.defaultMode.promptMessage`), + message: i18n( + `commands.config.subcommands.set.options.defaultMode.promptMessage` + ), choices: ALL_CMS_PUBLISH_MODES, default: CMS_PUBLISH_MODE.publish, }, @@ -102,7 +108,7 @@ export async function setDefaultCmsPublishMode({ newDefault = defaultCmsPublishMode; } else { logger.error( - i18n(`${i18nKey}.defaultMode.error`, { + i18n(`commands.config.subcommands.set.options.defaultMode.error`, { validModes: commaSeparatedValues(ALL_CMS_PUBLISH_MODES), }) ); @@ -112,7 +118,7 @@ export async function setDefaultCmsPublishMode({ updateDefaultCmsPublishMode(newDefault); logger.success( - i18n(`${i18nKey}.defaultMode.success`, { + i18n(`commands.config.subcommands.set.options.defaultMode.success`, { mode: newDefault, }) ); @@ -122,7 +128,9 @@ async function enterTimeout(): Promise { const { timeout } = await promptUser<{ timeout: string }>([ { name: 'timeout', - message: i18n(`${i18nKey}.httpTimeout.promptMessage`), + message: i18n( + `commands.config.subcommands.set.options.httpTimeout.promptMessage` + ), type: 'input', default: 30000, }, @@ -151,6 +159,8 @@ export async function setHttpTimeout({ updateHttpTimeout(newHttpTimeout); logger.success( - i18n(`${i18nKey}.httpTimeout.success`, { timeout: newHttpTimeout }) + i18n(`commands.config.subcommands.set.options.httpTimeout.success`, { + timeout: newHttpTimeout, + }) ); } diff --git a/lib/doctor/Diagnosis.ts b/lib/doctor/Diagnosis.ts index 4197eed6a..f116abdd6 100644 --- a/lib/doctor/Diagnosis.ts +++ b/lib/doctor/Diagnosis.ts @@ -34,8 +34,6 @@ interface DiagnosisCategories { defaultAccountOverrideFile: DiagnosisCategory; } -const i18nKey = `lib.doctor.diagnosis`; - export class Diagnosis { private readonly prefixes: prefixes; private readonly diagnosis: DiagnosisCategories; @@ -53,24 +51,26 @@ export class Diagnosis { this.diagnosis = { cli: { - header: i18n(`${i18nKey}.cli.header`), + header: i18n(`${`lib.doctor.diagnosis`}.cli.header`), sections: [], }, cliConfig: { - header: i18n(`${i18nKey}.cliConfig.header`), + header: i18n(`${`lib.doctor.diagnosis`}.cliConfig.header`), sections: [], }, defaultAccountOverrideFile: { - header: i18n(`${i18nKey}.defaultAccountOverrideFile.header`), + header: i18n( + `${`lib.doctor.diagnosis`}.defaultAccountOverrideFile.header` + ), sections: [], }, project: { - header: i18n(`${i18nKey}.projectConfig.header`), + header: i18n(`${`lib.doctor.diagnosis`}.projectConfig.header`), subheaders: [ - i18n(`${i18nKey}.projectConfig.projectDirSubHeader`, { + i18n(`${`lib.doctor.diagnosis`}.projectConfig.projectDirSubHeader`, { projectDir: diagnosticInfo.project?.config?.projectDir, }), - i18n(`${i18nKey}.projectConfig.projectNameSubHeader`, { + i18n(`${`lib.doctor.diagnosis`}.projectConfig.projectNameSubHeader`, { projectName: diagnosticInfo.project?.config?.projectConfig?.name, }), ], @@ -80,10 +80,10 @@ export class Diagnosis { if (diagnosticInfo.config) { this.diagnosis.cliConfig.subheaders = [ - i18n(`${i18nKey}.cliConfig.configFileSubHeader`, { + i18n(`${`lib.doctor.diagnosis`}.cliConfig.configFileSubHeader`, { filename: diagnosticInfo.config, }), - i18n(`${i18nKey}.cliConfig.defaultAccountSubHeader`, { + i18n(`${`lib.doctor.diagnosis`}.cliConfig.defaultAccountSubHeader`, { accountDetails: uiAccountDescription(accountId!), }), ]; @@ -129,12 +129,12 @@ export class Diagnosis { output.push(''); output.push( - i18n(`${i18nKey}.counts.errors`, { + i18n(`${`lib.doctor.diagnosis`}.counts.errors`, { count: this.errorCount, }) ); output.push( - i18n(`${i18nKey}.counts.warnings`, { + i18n(`${`lib.doctor.diagnosis`}.counts.warnings`, { count: this.warningCount, }) ); diff --git a/lib/doctor/Doctor.ts b/lib/doctor/Doctor.ts index 7f0b3d59a..bee369c67 100644 --- a/lib/doctor/Doctor.ts +++ b/lib/doctor/Doctor.ts @@ -35,8 +35,6 @@ const { i18n } = require('../lang'); const { uiLink } = require('../ui'); const minMajorNodeVersion = 18; -const i18nKey = `lib.doctor`; - export class Doctor { accountId: number | null; private diagnosis?: Diagnosis; @@ -56,7 +54,7 @@ export class Doctor { async diagnose(): Promise { SpinniesManager.add('runningDiagnostics', { - text: i18n(`${i18nKey}.runningDiagnostics`), + text: i18n(`lib.doctor.runningDiagnostics`), }); this.diagnosticInfo = @@ -79,7 +77,7 @@ export class Doctor { this.performCliConfigSettingsChecks(); SpinniesManager.succeed('runningDiagnostics', { - text: i18n(`${i18nKey}.diagnosticsComplete`), + text: i18n(`lib.doctor.diagnosticsComplete`), succeedColor: 'white', }); @@ -110,9 +108,9 @@ export class Doctor { if (!this.diagnosticInfo?.config) { this.diagnosis?.addCLIConfigSection({ type: 'error', - message: i18n(`${i18nKey}.diagnosis.cliConfig.noConfigFile`), + message: i18n(`lib.doctor.diagnosis.cliConfig.noConfigFile`), secondaryMessaging: i18n( - `${i18nKey}.diagnosis.cliConfig.noConfigFileSecondary`, + `lib.doctor.diagnosis.cliConfig.noConfigFileSecondary`, { command: uiCommandReference('hs init'), } @@ -125,20 +123,25 @@ export class Doctor { } private performDefaultAccountOverrideFileChecks(): void { - const localI18nKey = `${i18nKey}.defaultAccountOverrideFileChecks`; if (this.diagnosticInfo?.defaultAccountOverrideFile) { this.diagnosis?.addDefaultAccountOverrideFileSection({ type: 'warning', - message: i18n(`${localI18nKey}.overrideActive`, { - defaultAccountOverrideFile: - this.diagnosticInfo.defaultAccountOverrideFile, - }), + message: i18n( + `lib.doctor.defaultAccountOverrideFileChecks.overrideActive`, + { + defaultAccountOverrideFile: + this.diagnosticInfo.defaultAccountOverrideFile, + } + ), }); this.diagnosis?.addDefaultAccountOverrideFileSection({ type: 'warning', - message: i18n(`${localI18nKey}.overrideAccountId`, { - overrideAccountId: getCWDAccountOverride(), - }), + message: i18n( + `lib.doctor.defaultAccountOverrideFileChecks.overrideAccountId`, + { + overrideAccountId: getCWDAccountOverride(), + } + ), }); } } @@ -148,17 +151,16 @@ export class Doctor { this.diagnosis?.addCLIConfigSection({ type: 'warning', message: i18n( - `${i18nKey}.diagnosis.cliConfig.settings.httpUseLocalhost` + `lib.doctor.diagnosis.cliConfig.settings.httpUseLocalhost` ), secondaryMessaging: i18n( - `${i18nKey}.diagnosis.cliConfig.settings.httpUseLocalhostSecondary` + `lib.doctor.diagnosis.cliConfig.settings.httpUseLocalhostSecondary` ), }); } } private async checkIfAccessTokenValid(): Promise { - const localI18nKey = `${i18nKey}.accountChecks`; try { await accessTokenForPersonalAccessKey(this.accountId!, true); @@ -172,11 +174,11 @@ export class Doctor { this.diagnosis?.addCLIConfigSection({ type: 'success', - message: i18n(`${localI18nKey}.active`), + message: i18n(`lib.doctor.accountChecks.active`), }); const linkToPakUI = uiLink( - i18n(`${localI18nKey}.pak.viewScopes`), + i18n(`${`lib.doctor.accountChecks`}.pak.viewScopes`), `${getHubSpotWebsiteOrigin( this.diagnosticInfoBuilder?.env || 'PROD' )}/personal-access-key/${this.diagnosticInfo?.account.accountId}` @@ -185,16 +187,21 @@ export class Doctor { if (missingScopes.length > 0) { this.diagnosis?.addCLIConfigSection({ type: 'warning', - message: i18n(`${localI18nKey}.pak.incomplete`), - secondaryMessaging: i18n(`${localI18nKey}.pak.incompleteSecondary`, { - command: uiCommandReference(`hs auth`), - link: linkToPakUI, - }), + message: i18n(`lib.doctor.accountChecks.pak.incomplete`), + secondaryMessaging: i18n( + `lib.doctor.accountChecks.pak.incompleteSecondary`, + { + command: uiCommandReference(`hs auth`), + link: linkToPakUI, + } + ), }); } else { this.diagnosis?.addCLIConfigSection({ type: 'success', - message: i18n(`${localI18nKey}.pak.valid`, { link: linkToPakUI }), + message: i18n(`lib.doctor.accountChecks.pak.valid`, { + link: linkToPakUI, + }), }); } } catch (error) { @@ -212,10 +219,13 @@ export class Doctor { if (portalNotActive) { this.diagnosis?.addCLIConfigSection({ type: 'error', - message: i18n(`${localI18nKey}.inactive`), - secondaryMessaging: i18n(`${localI18nKey}.inactiveSecondary`, { - command: uiCommandReference(`hs accounts clean`), - }), + message: i18n(`${`lib.doctor.accountChecks`}.inactive`), + secondaryMessaging: i18n( + `${`lib.doctor.accountChecks`}.inactiveSecondary`, + { + command: uiCommandReference(`hs accounts clean`), + } + ), }); } else if ( isSpecifiedError(error, { @@ -227,30 +237,32 @@ export class Doctor { ) { this.diagnosis?.addCLIConfigSection({ type: 'success', - message: i18n(`${localI18nKey}.active`), + message: i18n(`${`lib.doctor.accountChecks`}.active`), }); this.diagnosis?.addCLIConfigSection({ type: 'error', - message: i18n(`${localI18nKey}.pak.invalid`), - secondaryMessaging: i18n(`${localI18nKey}.pak.invalidSecondary`, { - command: uiCommandReference(`hs auth`), - }), + message: i18n(`${`lib.doctor.accountChecks`}.pak.invalid`), + secondaryMessaging: i18n( + `${`lib.doctor.accountChecks`}.pak.invalidSecondary`, + { + command: uiCommandReference(`hs auth`), + } + ), }); } else { this.diagnosis?.addCLIConfigSection({ type: 'error', - message: i18n(`${localI18nKey}.unableToDetermine`), + message: i18n(`lib.doctor.accountChecks.unableToDetermine`), }); } } } private async checkIfNodeIsInstalled(): Promise { - const localI18nKey = `${i18nKey}.nodeChecks`; if (!this.diagnosticInfo?.versions.node) { return this.diagnosis?.addCliSection({ type: 'error', - message: i18n(`${localI18nKey}.unableToDetermine`), + message: i18n(`lib.doctor.nodeChecks.unableToDetermine`), }); } @@ -260,32 +272,31 @@ export class Doctor { if (!currentNodeMajor || parseInt(currentNodeMajor) < minMajorNodeVersion) { return this.diagnosis?.addCliSection({ type: 'warning', - message: i18n(`${localI18nKey}.minimumNotMet`, { + message: i18n(`lib.doctor.nodeChecks.minimumNotMet`, { nodeVersion: this.diagnosticInfo?.versions.node, }), }); } this.diagnosis?.addCliSection({ type: 'success', - message: i18n(`${localI18nKey}.success`, { + message: i18n(`lib.doctor.nodeChecks.success`, { nodeVersion: this.diagnosticInfo?.versions.node, }), }); } private async checkIfNpmIsInstalled(): Promise { - const localI18nKey = `${i18nKey}.npmChecks`; const npmVersion = this.diagnosticInfo?.versions?.npm; if (!npmVersion) { return this.diagnosis?.addCliSection({ type: 'error', - message: i18n(`${localI18nKey}.notInstalled`), + message: i18n(`lib.doctor.npmChecks.notInstalled`), }); } this.diagnosis?.addCliSection({ type: 'success', - message: i18n(`${localI18nKey}.installed`, { + message: i18n(`lib.doctor.npmChecks.installed`, { npmVersion, }), }); @@ -302,13 +313,13 @@ export class Doctor { } catch (e) { return this.diagnosis?.addCliSection({ type: 'error', - message: i18n(`${i18nKey}.hsChecks.unableToDetermine`), + message: i18n(`lib.doctor.hsChecks.unableToDetermine`), secondaryMessaging: i18n( - `${i18nKey}.hsChecks.unableToDetermineSecondary`, + `lib.doctor.hsChecks.unableToDetermineSecondary`, { command: uiCommandReference(`hs --version`), link: uiLink( - i18n(`${i18nKey}.hsChecks.unableToDetermineSecondaryLink`), + i18n(`lib.doctor.hsChecks.unableToDetermineSecondaryLink`), `https://www.npmjs.com/package/${pkg.name}?activeTab=versions` ), } @@ -320,10 +331,10 @@ export class Doctor { const onNextTag = pkg.version.includes('beta'); this.diagnosis?.addCliSection({ type: 'warning', - message: i18n(`${i18nKey}.hsChecks.notLatest`, { + message: i18n(`lib.doctor.hsChecks.notLatest`, { hsVersion: pkg.version, }), - secondaryMessaging: i18n(`${i18nKey}.hsChecks.notLatestSecondary`, { + secondaryMessaging: i18n(`lib.doctor.hsChecks.notLatestSecondary`, { hsVersion: onNextTag ? nextCliVersion : latestCLIVersion, command: uiCommandReference(`npm install -g ${pkg.name}`), }), @@ -331,7 +342,7 @@ export class Doctor { } else { this.diagnosis?.addCliSection({ type: 'success', - message: i18n(`${i18nKey}.hsChecks.latest`, { + message: i18n(`lib.doctor.hsChecks.latest`, { hsVersion: latestCLIVersion, }), }); @@ -340,7 +351,6 @@ export class Doctor { private async checkIfNpmInstallRequired(): Promise { let foundError = false; - const localI18nKey = `${i18nKey}.projectDependenciesChecks`; for (const packageFile of this.diagnosticInfo?.packageFiles || []) { const packageDirName = path.dirname(packageFile); @@ -354,11 +364,14 @@ export class Doctor { this.diagnosis?.addProjectSection({ type: 'warning', - message: i18n(`${localI18nKey}.missingDependencies`, { - dir: packageDirName, - }), + message: i18n( + `lib.doctor.projectDependenciesChecks.missingDependencies`, + { + dir: packageDirName, + } + ), secondaryMessaging: i18n( - `${localI18nKey}.missingDependenciesSecondary`, + `lib.doctor.projectDependenciesChecks.missingDependenciesSecondary`, { command: uiCommandReference('hs project install-deps'), } @@ -371,16 +384,19 @@ export class Doctor { if (!(await this.isValidJsonFile(packageFile))) { this.diagnosis?.addProjectSection({ type: 'error', - message: i18n(`${i18nKey}.files.invalidJson`, { + message: i18n(`lib.doctor.files.invalidJson`, { filename: packageFile, }), }); } else { this.diagnosis?.addProjectSection({ type: 'error', - message: i18n(`${localI18nKey}.unableToDetermine`, { - dir: packageDirName, - }), + message: i18n( + `${`lib.doctor.projectDependenciesChecks`}.unableToDetermine`, + { + dir: packageDirName, + } + ), }); } @@ -391,7 +407,7 @@ export class Doctor { if (!foundError) { this.diagnosis?.addProjectSection({ type: 'success', - message: i18n(`${localI18nKey}.success`), + message: i18n(`${`lib.doctor.projectDependenciesChecks`}.success`), }); } } @@ -418,7 +434,7 @@ export class Doctor { foundError = true; this.diagnosis?.addProjectSection({ type: 'error', - message: i18n(`${i18nKey}.files.invalidJson`, { + message: i18n(`lib.doctor.files.invalidJson`, { filename: jsonFile, }), }); @@ -428,18 +444,16 @@ export class Doctor { if (!foundError) { this.diagnosis?.addProjectSection({ type: 'success', - message: i18n(`${i18nKey}.files.validJson`), + message: i18n(`lib.doctor.files.validJson`), }); } } private async checkIfPortsAreAvailable(): Promise { - const localI18nKey = `${i18nKey}.port`; - if (await isPortManagerPortAvailable()) { this.diagnosis?.addProjectSection({ type: 'success', - message: i18n(`${localI18nKey}.available`, { + message: i18n(`lib.doctor.port.available`, { port: PORT_MANAGER_SERVER_PORT, }), }); @@ -448,10 +462,10 @@ export class Doctor { this.diagnosis?.addProjectSection({ type: 'warning', - message: i18n(`${localI18nKey}.inUse`, { + message: i18n(`lib.doctor.port.inUse`, { port: PORT_MANAGER_SERVER_PORT, }), - secondaryMessaging: i18n(`${localI18nKey}.inUseSecondary`, { + secondaryMessaging: i18n(`lib.doctor.port.inUseSecondary`, { command: uiCommandReference('hs project dev'), }), }); diff --git a/lib/errorHandlers/index.ts b/lib/errorHandlers/index.ts index 3419d5af9..5e6356468 100644 --- a/lib/errorHandlers/index.ts +++ b/lib/errorHandlers/index.ts @@ -9,7 +9,6 @@ import { shouldSuppressError } from './suppressError'; import { i18n } from '../lang'; import util from 'util'; import { uiCommandReference } from '../ui'; -const i18nKey = 'lib.errorHandlers.index'; export function logError(error: unknown, context?: ApiErrorContext): void { debugError(error, context); @@ -41,7 +40,7 @@ export function logError(error: unknown, context?: ApiErrorContext): void { logger.error(message.join(' ')); } else { // Unknown errors - logger.error(i18n(`${i18nKey}.unknownErrorOccurred`)); + logger.error(i18n(`lib.errorHandlers.index.unknownErrorOccurred`)); } if (isHubSpotHttpError(error) && error.code === 'ETIMEDOUT') { @@ -51,7 +50,7 @@ export function logError(error: unknown, context?: ApiErrorContext): void { // Timeout was caused by the default timeout if (error.timeout && defaultTimeout === error.timeout) { logger.error( - i18n(`${i18nKey}.configTimeoutErrorOccurred`, { + i18n(`lib.errorHandlers.index.configTimeoutErrorOccurred`, { timeout: error.timeout, configSetCommand: uiCommandReference('hs config set'), }) @@ -59,7 +58,7 @@ export function logError(error: unknown, context?: ApiErrorContext): void { } // Timeout was caused by a custom timeout set by the CLI or LDL else { - logger.error(i18n(`${i18nKey}.genericTimeoutErrorOccurred`)); + logger.error(i18n(`lib.errorHandlers.index.genericTimeoutErrorOccurred`)); } } } @@ -68,19 +67,21 @@ export function debugError(error: unknown, context?: ApiErrorContext): void { if (isHubSpotHttpError(error)) { logger.debug(error.toString()); } else { - logger.debug(i18n(`${i18nKey}.errorOccurred`, { error: String(error) })); + logger.debug( + i18n(`lib.errorHandlers.index.errorOccurred`, { error: String(error) }) + ); } if (error instanceof Error && error.cause && !isHubSpotHttpError(error)) { logger.debug( - i18n(`${i18nKey}.errorCause`, { + i18n(`lib.errorHandlers.index.errorCause`, { cause: util.inspect(error.cause, false, null, true), }) ); } if (context) { logger.debug( - i18n(`${i18nKey}.errorContext`, { + i18n(`lib.errorHandlers.index.errorContext`, { context: util.inspect(context, false, null, true), }) ); diff --git a/lib/errorHandlers/suppressError.ts b/lib/errorHandlers/suppressError.ts index bacf0a878..735c67e04 100644 --- a/lib/errorHandlers/suppressError.ts +++ b/lib/errorHandlers/suppressError.ts @@ -14,8 +14,6 @@ import { import { ApiErrorContext } from './index'; import { HubSpotHttpError } from '@hubspot/local-dev-lib/models/HubSpotHttpError'; -const i18nKey = 'lib.errorHandlers.suppressErrors'; - function createPlatformVersionError( err: HubSpotHttpError, subCategory: string @@ -42,17 +40,24 @@ function createPlatformVersionError( } uiLine(); - logger.error(i18n(`${i18nKey}.platformVersionErrors.header`)); + logger.error( + i18n(`lib.errorHandlers.suppressErrors.platformVersionErrors.header`) + ); logger.log( - i18n(`${i18nKey}.platformVersionErrors.${translationKey}`, { - platformVersion, - }) + i18n( + `lib.errorHandlers.suppressErrors.platformVersionErrors.${translationKey}`, + { + platformVersion, + } + ) + ); + logger.log( + i18n(`lib.errorHandlers.suppressErrors.platformVersionErrors.updateProject`) ); - logger.log(i18n(`${i18nKey}.platformVersionErrors.updateProject`)); logger.log( - i18n(`${i18nKey}.platformVersionErrors.betaLink`, { + i18n(`lib.errorHandlers.suppressErrors.platformVersionErrors.betaLink`, { docsLink: uiLink( - i18n(`${i18nKey}.platformVersionErrors.docsLink`), + i18n(`lib.errorHandlers.suppressErrors.platformVersionErrors.docsLink`), 'https://developers.hubspot.com/docs/platform/platform-versioning' ), }) @@ -66,7 +71,7 @@ export function shouldSuppressError( ): boolean { if (isMissingScopeError(err)) { logger.error( - i18n(`${i18nKey}.missingScopeError`, { + i18n(`lib.errorHandlers.suppressErrors.missingScopeError`, { accountName: context?.accountId ? uiAccountDescription(context.accountId) : '', diff --git a/lib/generateSelectors.ts b/lib/generateSelectors.ts index 0427e9a08..5e2fc132f 100644 --- a/lib/generateSelectors.ts +++ b/lib/generateSelectors.ts @@ -9,7 +9,6 @@ const CSS_PSEUDO_CLASS_REGEX = new RegExp( /:active|:checked|:disabled|:empty|:enabled|:first-of-type|:focus|:hover|:in-range|:invalid|:link|:optional|:out-of-range|:read-only|:read-write|:required|:target|:valid|:visited/, 'g' ); -const i18nKey = 'commands.theme.subcommands.generateSelectors'; let maxFieldsDepth = 0; @@ -21,7 +20,7 @@ export function findFieldsJsonPath(basePath: string): string | null { const _path = basePath.endsWith('/') ? basePath.slice(0, -1) : basePath; if (!fs.existsSync(_path)) { logger.error( - i18n(`${i18nKey}.errors.invalidPath`, { + i18n(`commands.theme.subcommands.generateSelectors.errors.invalidPath`, { themePath: basePath, }) ); diff --git a/lib/oauth.ts b/lib/oauth.ts index 875ec08a4..1e315edc6 100644 --- a/lib/oauth.ts +++ b/lib/oauth.ts @@ -18,8 +18,6 @@ import { EXIT_CODES } from './enums/exitCodes'; const PORT = 3000; const redirectUri = `http://localhost:${PORT}/oauth-callback`; -const i18nKey = 'lib.oauth'; - function buildAuthUrl(oauthManager: OAuth2Manager): string { const { env: accountEnv, @@ -31,7 +29,7 @@ function buildAuthUrl(oauthManager: OAuth2Manager): string { const scopes = accountScopes || DEFAULT_OAUTH_SCOPES; if (!clientId) { - logger.error(i18n(`${i18nKey}.missingClientId`)); + logger.error(i18n(`lib.oauth.missingClientId`)); process.exit(EXIT_CODES.ERROR); } diff --git a/lib/process.ts b/lib/process.ts index f27e18c49..009390549 100644 --- a/lib/process.ts +++ b/lib/process.ts @@ -2,8 +2,6 @@ import readline from 'readline'; import { logger, setLogLevel, LOG_LEVEL } from '@hubspot/local-dev-lib/logger'; import { i18n } from './lang'; -const i18nKey = 'lib.process'; - interface KeyPress { ctrl?: boolean; shift?: boolean; @@ -41,7 +39,7 @@ export function handleExit( setLogLevel(LOG_LEVEL.NONE); } - logger.debug(i18n(`${i18nKey}.exitDebug`, { signal })); + logger.debug(i18n(`lib.process.exitDebug`, { signal })); await callback({ isSIGHUP }); } }); diff --git a/lib/prompts/accountNamePrompt.ts b/lib/prompts/accountNamePrompt.ts index ccc5d9786..b13f8f0d2 100644 --- a/lib/prompts/accountNamePrompt.ts +++ b/lib/prompts/accountNamePrompt.ts @@ -5,8 +5,6 @@ import { PromptConfig } from '../../types/Prompts'; import { HUBSPOT_ACCOUNT_TYPES } from '@hubspot/local-dev-lib/constants/config'; import { AccountType } from '@hubspot/local-dev-lib/types/Accounts'; -const i18nKey = 'lib.prompts.accountNamePrompt'; - export type AccountNamePromptResponse = { name: string; }; @@ -16,18 +14,20 @@ export function getCliAccountNamePromptConfig( ): PromptConfig { return { name: 'name', - message: i18n(`${i18nKey}.enterAccountName`), + message: i18n(`lib.prompts.accountNamePrompt.enterAccountName`), default: defaultName, validate(val?: string) { if (typeof val !== 'string') { - return i18n(`${i18nKey}.errors.invalidName`); + return i18n(`lib.prompts.accountNamePrompt.errors.invalidName`); } else if (!val.length) { - return i18n(`${i18nKey}.errors.nameRequired`); + return i18n(`lib.prompts.accountNamePrompt.errors.nameRequired`); } else if (val.indexOf(' ') >= 0) { - return i18n(`${i18nKey}.errors.spacesInName`); + return i18n(`lib.prompts.accountNamePrompt.errors.spacesInName`); } return accountNameExistsInConfig(val) - ? i18n(`${i18nKey}.errors.accountNameExists`, { name: val }) + ? i18n(`lib.prompts.accountNamePrompt.errors.accountNameExists`, { + name: val, + }) : true; }, }; @@ -60,13 +60,18 @@ export function hubspotAccountNamePrompt({ let defaultName: string | undefined; if (isSandbox) { promptMessageString = isDevelopmentSandbox - ? i18n(`${i18nKey}.enterDevelopmentSandboxName`) - : i18n(`${i18nKey}.enterStandardSandboxName`); + ? i18n(`lib.prompts.accountNamePrompt.enterDevelopmentSandboxName`) + : i18n(`lib.prompts.accountNamePrompt.enterStandardSandboxName`); } else if (isDeveloperTestAccount) { - promptMessageString = i18n(`${i18nKey}.enterDeveloperTestAccountName`); - defaultName = i18n(`${i18nKey}.developerTestAccountDefaultName`, { - count: currentPortalCount + 1, - }); + promptMessageString = i18n( + `lib.prompts.accountNamePrompt.enterDeveloperTestAccountName` + ); + defaultName = i18n( + `lib.prompts.accountNamePrompt.developerTestAccountDefaultName`, + { + count: currentPortalCount + 1, + } + ); } return promptUser([ @@ -75,12 +80,14 @@ export function hubspotAccountNamePrompt({ message: promptMessageString, validate(val?: string) { if (typeof val !== 'string') { - return i18n(`${i18nKey}.errors.invalidName`); + return i18n(`lib.prompts.accountNamePrompt.errors.invalidName`); } else if (!val.trim().length) { - return i18n(`${i18nKey}.errors.nameRequired`); + return i18n(`lib.prompts.accountNamePrompt.errors.nameRequired`); } return accountNameExistsInConfig(val) - ? i18n(`${i18nKey}.errors.accountNameExists`, { name: val }) + ? i18n(`lib.prompts.accountNamePrompt.errors.accountNameExists`, { + name: val, + }) : true; }, default: defaultName, diff --git a/lib/prompts/accountsPrompt.ts b/lib/prompts/accountsPrompt.ts index bee5ce10a..05e7ac076 100644 --- a/lib/prompts/accountsPrompt.ts +++ b/lib/prompts/accountsPrompt.ts @@ -20,8 +20,6 @@ function mapAccountChoices( ); } -const i18nKey = 'commands.account.subcommands.use'; - export async function selectAccountFromConfig(prompt = ''): Promise { const accountsList = getConfigAccounts(); const defaultAccount = getConfigDefaultAccount(); @@ -31,7 +29,7 @@ export async function selectAccountFromConfig(prompt = ''): Promise { type: 'list', name: 'default', pageSize: 20, - message: prompt || i18n(`${i18nKey}.promptMessage`), + message: prompt || i18n(`commands.account.subcommands.use.promptMessage`), choices: mapAccountChoices(accountsList), default: defaultAccount ?? undefined, }, diff --git a/lib/prompts/cmsFieldPrompt.ts b/lib/prompts/cmsFieldPrompt.ts index 3f6ecbde4..e1cd4a981 100644 --- a/lib/prompts/cmsFieldPrompt.ts +++ b/lib/prompts/cmsFieldPrompt.ts @@ -4,7 +4,6 @@ import { promptUser } from './promptUtils'; import { i18n } from '../lang'; import { escapeRegExp } from '@hubspot/local-dev-lib/escapeRegExp'; -const i18nKey = 'lib.prompts.uploadPrompt'; const FIELDS_FILES = ['fields.json', 'fields.js', 'fields.cjs', 'fields.mjs']; export async function fieldsJsPrompt( @@ -36,7 +35,7 @@ export async function fieldsJsPrompt( const promptVal = await promptUser<{ filePathChoice: string }>([ { - message: i18n(`${i18nKey}.fieldsPrompt`, { dir: fileDir }), + message: i18n(`lib.prompts.uploadPrompt.fieldsPrompt`, { dir: fileDir }), type: 'list', name: 'filePathChoice', choices: selection, diff --git a/lib/prompts/createApiSamplePrompt.ts b/lib/prompts/createApiSamplePrompt.ts index c8d78b6ef..a41551f3a 100644 --- a/lib/prompts/createApiSamplePrompt.ts +++ b/lib/prompts/createApiSamplePrompt.ts @@ -2,8 +2,6 @@ import { promptUser } from './promptUtils'; import { i18n } from '../lang'; import { PromptConfig } from '../../types/Prompts'; -const i18nKey = 'lib.prompts.createApiSamplePrompt'; - type SampleChoice = { name: string; description: string; @@ -32,7 +30,7 @@ function getSampleTypesPrompt( return { type: 'rawlist', name: 'sampleType', - message: i18n(`${i18nKey}.selectApiSampleApp`), + message: i18n(`lib.prompts.createApiSamplePrompt.selectApiSampleApp`), choices: choices.map(choice => ({ name: `${choice.name} - ${choice.description}`, value: choice.id, @@ -42,7 +40,11 @@ function getSampleTypesPrompt( if (input && input.length > 0) { resolve(true); } else { - reject(i18n(`${i18nKey}.errors.apiSampleAppRequired`)); + reject( + i18n( + `lib.prompts.createApiSamplePrompt.errors.apiSampleAppRequired` + ) + ); } }); }, @@ -55,7 +57,7 @@ function getLanguagesPrompt( return { type: 'rawlist', name: 'sampleLanguage', - message: i18n(`${i18nKey}.selectLanguage`), + message: i18n(`lib.prompts.createApiSamplePrompt.selectLanguage`), choices: choices.map(choice => ({ name: choice, value: choice, @@ -65,7 +67,9 @@ function getLanguagesPrompt( if (input && input.length > 0) { resolve(true); } - reject(i18n(`${i18nKey}.errors.languageRequired`)); + reject( + i18n(`lib.prompts.createApiSamplePrompt.errors.languageRequired`) + ); }); }, }; diff --git a/lib/prompts/createFunctionPrompt.ts b/lib/prompts/createFunctionPrompt.ts index 0ec6f1f46..968779fba 100644 --- a/lib/prompts/createFunctionPrompt.ts +++ b/lib/prompts/createFunctionPrompt.ts @@ -2,8 +2,6 @@ import { promptUser } from './promptUtils'; import { i18n } from '../lang'; import { PromptConfig } from '../../types/Prompts'; -const i18nKey = 'lib.prompts.createFunctionPrompt'; - type CreateFunctionPromptResponse = { functionsFolder: string; filename: string; @@ -13,14 +11,14 @@ type CreateFunctionPromptResponse = { const FUNCTIONS_FOLDER_PROMPT: PromptConfig = { name: 'functionsFolder', - message: i18n(`${i18nKey}.enterFolder`), + message: i18n(`lib.prompts.createFunctionPrompt.enterFolder`), validate(val?: string) { if (typeof val !== 'string') { - return i18n(`${i18nKey}.errors.invalid`); + return i18n(`lib.prompts.createFunctionPrompt.errors.invalid`); } else if (!val.length) { - return i18n(`${i18nKey}.errors.blank`); + return i18n(`lib.prompts.createFunctionPrompt.errors.blank`); } else if (val.indexOf(' ') >= 0) { - return i18n(`${i18nKey}.errors.space`); + return i18n(`lib.prompts.createFunctionPrompt.errors.space`); } return true; }, @@ -28,14 +26,14 @@ const FUNCTIONS_FOLDER_PROMPT: PromptConfig = { const FUNCTION_FILENAME_PROMPT: PromptConfig = { name: 'filename', - message: i18n(`${i18nKey}.enterFilename`), + message: i18n(`lib.prompts.createFunctionPrompt.enterFilename`), validate(val?: string) { if (typeof val !== 'string') { - return i18n(`${i18nKey}.errors.invalid`); + return i18n(`lib.prompts.createFunctionPrompt.errors.invalid`); } else if (!val.length) { - return i18n(`${i18nKey}.errors.blank`); + return i18n(`lib.prompts.createFunctionPrompt.errors.blank`); } else if (val.indexOf(' ') >= 0) { - return i18n(`${i18nKey}.errors.space`); + return i18n(`lib.prompts.createFunctionPrompt.errors.space`); } return true; }, @@ -44,21 +42,21 @@ const FUNCTION_FILENAME_PROMPT: PromptConfig = { const ENDPOINT_METHOD_PROMPT: PromptConfig = { type: 'list', name: 'endpointMethod', - message: i18n(`${i18nKey}.selectEndpointMethod`), + message: i18n(`lib.prompts.createFunctionPrompt.selectEndpointMethod`), default: 'GET', choices: ['DELETE', 'GET', 'PATCH', 'POST', 'PUT'], }; const ENDPOINT_PATH_PROMPT: PromptConfig = { name: 'endpointPath', - message: i18n(`${i18nKey}.enterEndpointPath`), + message: i18n(`lib.prompts.createFunctionPrompt.enterEndpointPath`), validate(val?: string) { if (typeof val !== 'string') { - return i18n(`${i18nKey}.errors.invalid`); + return i18n(`lib.prompts.createFunctionPrompt.errors.invalid`); } else if (!val.length) { - return i18n(`${i18nKey}.errors.blank`); + return i18n(`lib.prompts.createFunctionPrompt.errors.blank`); } else if (val.indexOf(' ') >= 0) { - return i18n(`${i18nKey}.errors.space`); + return i18n(`lib.prompts.createFunctionPrompt.errors.space`); } return true; }, diff --git a/lib/prompts/createModulePrompt.ts b/lib/prompts/createModulePrompt.ts index bd4e1cf3d..e2fd8fa7b 100644 --- a/lib/prompts/createModulePrompt.ts +++ b/lib/prompts/createModulePrompt.ts @@ -3,8 +3,6 @@ import { PromptConfig } from '../../types/Prompts'; import { promptUser } from './promptUtils'; import { i18n } from '../lang'; -const i18nKey = 'lib.prompts.createModulePrompt'; - type CreateModulePromptResponse = { moduleLabel: string; reactType: boolean; @@ -15,12 +13,12 @@ type CreateModulePromptResponse = { const MODULE_LABEL_PROMPT: PromptConfig = { name: 'moduleLabel', - message: i18n(`${i18nKey}.enterLabel`), + message: i18n(`lib.prompts.createModulePrompt.enterLabel`), validate(val?: string): boolean | string { if (typeof val !== 'string') { - return i18n(`${i18nKey}.errors.invalidLabel`); + return i18n(`lib.prompts.createModulePrompt.errors.invalidLabel`); } else if (!val.length) { - return i18n(`${i18nKey}.errors.labelRequired`); + return i18n(`lib.prompts.createModulePrompt.errors.labelRequired`); } return true; }, @@ -29,14 +27,14 @@ const MODULE_LABEL_PROMPT: PromptConfig = { const REACT_TYPE_PROMPT: PromptConfig = { type: 'confirm', name: 'reactType', - message: i18n(`${i18nKey}.selectReactType`), + message: i18n(`lib.prompts.createModulePrompt.selectReactType`), default: false, }; const CONTENT_TYPES_PROMPT: PromptConfig = { type: 'checkbox', name: 'contentTypes', - message: i18n(`${i18nKey}.selectContentType`), + message: i18n(`lib.prompts.createModulePrompt.selectContentType`), default: ['ANY'], choices: [ { name: 'Any', value: 'ANY' }, @@ -57,7 +55,7 @@ const CONTENT_TYPES_PROMPT: PromptConfig = { if (input.length > 0) { resolve(true); } - reject(i18n(`${i18nKey}.errors.contentTypeRequired`)); + reject(i18n(`lib.prompts.createModulePrompt.errors.contentTypeRequired`)); }); }, }; @@ -65,14 +63,14 @@ const CONTENT_TYPES_PROMPT: PromptConfig = { const GLOBAL_PROMPT: PromptConfig = { type: 'confirm', name: 'global', - message: i18n(`${i18nKey}.confirmGlobal`), + message: i18n(`lib.prompts.createModulePrompt.confirmGlobal`), default: false, }; const AVAILABLE_FOR_NEW_CONTENT: PromptConfig = { type: 'confirm', name: 'availableForNewContent', - message: i18n(`${i18nKey}.availableForNewContent`), + message: i18n(`lib.prompts.createModulePrompt.availableForNewContent`), default: true, }; diff --git a/lib/prompts/createProjectPrompt.ts b/lib/prompts/createProjectPrompt.ts index 719db0c5b..701a59183 100644 --- a/lib/prompts/createProjectPrompt.ts +++ b/lib/prompts/createProjectPrompt.ts @@ -11,19 +11,17 @@ import { i18n } from '../lang'; import { ProjectTemplate } from '../../types/Projects'; import { PROJECT_CONFIG_FILE } from '../constants'; -const i18nKey = 'lib.prompts.createProjectPrompt'; - function validateProjectDirectory(input?: string): string | boolean { if (!input) { - return i18n(`${i18nKey}.errors.destRequired`); + return i18n(`lib.prompts.createProjectPrompt.errors.destRequired`); } if ( fs.existsSync(path.resolve(getCwd(), path.join(input, PROJECT_CONFIG_FILE))) ) { - return i18n(`${i18nKey}.errors.invalidDest`); + return i18n(`lib.prompts.createProjectPrompt.errors.invalidDest`); } if (!isValidPath(input)) { - return i18n(`${i18nKey}.errors.invalidCharacters`); + return i18n(`lib.prompts.createProjectPrompt.errors.invalidCharacters`); } return true; } @@ -85,18 +83,18 @@ export async function createProjectPrompt( const result = await promptUser([ { name: 'name', - message: i18n(`${i18nKey}.enterName`), + message: i18n(`lib.prompts.createProjectPrompt.enterName`), when: !promptOptions.name, validate: (input?: string) => { if (!input) { - return i18n(`${i18nKey}.errors.nameRequired`); + return i18n(`lib.prompts.createProjectPrompt.errors.nameRequired`); } return true; }, }, { name: 'dest', - message: i18n(`${i18nKey}.enterDest`), + message: i18n(`lib.prompts.createProjectPrompt.enterDest`), when: !promptOptions.dest, default: answers => { const projectName = sanitizeFileName( @@ -113,10 +111,10 @@ export async function createProjectPrompt( name: 'projectTemplate', message: () => { return promptOptions.template && !providedTemplateIsValid - ? i18n(`${i18nKey}.errors.invalidTemplate`, { + ? i18n(`lib.prompts.createProjectPrompt.errors.invalidTemplate`, { template: promptOptions.template, }) - : i18n(`${i18nKey}.selectTemplate`); + : i18n(`lib.prompts.createProjectPrompt.selectTemplate`); }, when: createProjectFromTemplate && !providedTemplateIsValid, type: 'list', @@ -148,7 +146,9 @@ export async function createProjectPrompt( if (projectTemplates && projectTemplates.length > 0) { if (!result.projectTemplate) { - throw new Error(i18n(`${i18nKey}.errors.projectTemplateRequired`)); + throw new Error( + i18n(`lib.prompts.createProjectPrompt.errors.projectTemplateRequired`) + ); } return result; } diff --git a/lib/prompts/createTemplatePrompt.ts b/lib/prompts/createTemplatePrompt.ts index 7aa0b1a41..c49c99824 100644 --- a/lib/prompts/createTemplatePrompt.ts +++ b/lib/prompts/createTemplatePrompt.ts @@ -2,8 +2,6 @@ import { promptUser } from './promptUtils'; import { i18n } from '../lang'; import { PromptChoices, PromptConfig } from '../../types/Prompts'; -const i18nKey = 'lib.prompts.createTemplatePrompt'; - const templateTypeChoices = [ { name: 'page', value: 'page-template' }, { name: 'email', value: 'email-template' }, @@ -21,7 +19,7 @@ interface CreateTemplatePromptResponse { const TEMPLATE_TYPE_PROMPT: PromptConfig = { type: 'list', name: 'templateType', - message: i18n(`${i18nKey}.selectTemplate`), + message: i18n(`lib.prompts.createTemplatePrompt.selectTemplate`), default: 'page', choices: templateTypeChoices, }; diff --git a/lib/prompts/downloadProjectPrompt.ts b/lib/prompts/downloadProjectPrompt.ts index f3ad0f41b..6fa4e4d7d 100644 --- a/lib/prompts/downloadProjectPrompt.ts +++ b/lib/prompts/downloadProjectPrompt.ts @@ -7,8 +7,6 @@ import { EXIT_CODES } from '../enums/exitCodes'; import { i18n } from '../lang'; import { Project } from '@hubspot/local-dev-lib/types/Project'; -const i18nKey = 'lib.prompts.downloadProjectPrompt'; - type DownloadProjectPromptResponse = { project: string; }; @@ -21,7 +19,9 @@ async function createProjectsList( const { data: projects } = await fetchProjects(accountId); return projects.results; } - logger.error(i18n(`${i18nKey}.errors.accountIdRequired`)); + logger.error( + i18n(`lib.prompts.downloadProjectPrompt.errors.accountIdRequired`) + ); process.exit(EXIT_CODES.ERROR); } catch (e) { logError(e, accountId ? new ApiErrorContext({ accountId }) : undefined); @@ -43,11 +43,11 @@ export async function downloadProjectPrompt(promptOptions: { message: () => { return promptOptions.project && !projectsList.find(p => p.name === promptOptions.name) - ? i18n(`${i18nKey}.errors.projectNotFound`, { + ? i18n(`lib.prompts.downloadProjectPrompt.errors.projectNotFound`, { projectName: promptOptions.project, accountId: accountId || '', }) - : i18n(`${i18nKey}.selectProject`); + : i18n(`lib.prompts.downloadProjectPrompt.selectProject`); }, when: !promptOptions.project || diff --git a/lib/prompts/installPublicAppPrompt.ts b/lib/prompts/installPublicAppPrompt.ts index 33e5a527b..918fbf8bd 100644 --- a/lib/prompts/installPublicAppPrompt.ts +++ b/lib/prompts/installPublicAppPrompt.ts @@ -5,8 +5,6 @@ import { promptUser } from './promptUtils'; import { i18n } from '../lang'; import { EXIT_CODES } from '../enums/exitCodes'; -const i18nKey = 'lib.prompts.installPublicAppPrompt'; - export async function installPublicAppPrompt( env: string, targetAccountId: number, @@ -17,9 +15,9 @@ export async function installPublicAppPrompt( ): Promise { logger.log(''); if (isReinstall) { - logger.log(i18n(`${i18nKey}.reinstallExplanation`)); + logger.log(i18n(`lib.prompts.installPublicAppPrompt.reinstallExplanation`)); } else { - logger.log(i18n(`${i18nKey}.explanation`)); + logger.log(i18n(`lib.prompts.installPublicAppPrompt.explanation`)); } const { shouldOpenBrowser } = await promptUser<{ @@ -28,12 +26,14 @@ export async function installPublicAppPrompt( name: 'shouldOpenBrowser', type: 'confirm', message: i18n( - isReinstall ? `${i18nKey}.reinstallPrompt` : `${i18nKey}.prompt` + isReinstall + ? `lib.prompts.installPublicAppPrompt.reinstallPrompt` + : `lib.prompts.installPublicAppPrompt.prompt` ), }); if (!isReinstall && !shouldOpenBrowser) { - logger.log(i18n(`${i18nKey}.decline`)); + logger.log(i18n(`lib.prompts.installPublicAppPrompt.decline`)); process.exit(EXIT_CODES.SUCCESS); } else if (!shouldOpenBrowser) { return; diff --git a/lib/prompts/personalAccessKeyPrompt.ts b/lib/prompts/personalAccessKeyPrompt.ts index 2c37503da..79f4b27b0 100644 --- a/lib/prompts/personalAccessKeyPrompt.ts +++ b/lib/prompts/personalAccessKeyPrompt.ts @@ -16,8 +16,6 @@ import { uiInfoSection } from '../ui'; import { EXIT_CODES } from '../enums/exitCodes'; import { PromptConfig } from '../../types/Prompts'; -const i18nKey = 'lib.prompts.personalAccessKeyPrompt'; - export type PersonalAccessKeyPromptResponse = { personalAccessKey: string; env: string; @@ -63,9 +61,16 @@ export async function personalAccessKeyPrompt({ const websiteOrigin = getHubSpotWebsiteOrigin(env); let url = `${websiteOrigin}/l/personal-access-key`; if (process.env.BROWSER !== 'none') { - uiInfoSection(i18n(`${i18nKey}.personalAccessKeySetupTitle`), () => { - logger.log(i18n(`${i18nKey}.personalAccessKeyBrowserOpenPrep`)); - }); + uiInfoSection( + i18n(`lib.prompts.personalAccessKeyPrompt.personalAccessKeySetupTitle`), + () => { + logger.log( + i18n( + `lib.prompts.personalAccessKeyPrompt.personalAccessKeyBrowserOpenPrep` + ) + ); + } + ); if (account) { url = `${websiteOrigin}/personal-access-key/${account}`; } @@ -81,7 +86,9 @@ export async function personalAccessKeyPrompt({ } } - logger.log(i18n(`${i18nKey}.logs.openingWebBrowser`, { url })); + logger.log( + i18n(`lib.prompts.personalAccessKeyPrompt.logs.openingWebBrowser`, { url }) + ); const { personalAccessKey } = await promptUser(PERSONAL_ACCESS_KEY); @@ -93,24 +100,28 @@ export async function personalAccessKeyPrompt({ const ACCOUNT_ID: PromptConfig = { name: 'accountId', - message: i18n(`${i18nKey}.enterAccountId`), + message: i18n(`lib.prompts.personalAccessKeyPrompt.enterAccountId`), type: 'number', validate(val?: number) { if (!Number.isNaN(val) && val !== undefined && val > 0) { return true; } - return i18n(`${i18nKey}.errors.invalidAccountId`); + return i18n(`lib.prompts.personalAccessKeyPrompt.errors.invalidAccountId`); }, }; const CLIENT_ID: PromptConfig = { name: 'clientId', - message: i18n(`${i18nKey}.enterClientId`), + message: i18n(`lib.prompts.personalAccessKeyPrompt.enterClientId`), validate(val?: string) { if (typeof val !== 'string') { - return i18n(`${i18nKey}.errors.invalidOauthClientId`); + return i18n( + `lib.prompts.personalAccessKeyPrompt.errors.invalidOauthClientId` + ); } else if (val.length !== 36) { - return i18n(`${i18nKey}.errors.invalidOauthClientIdLength`); + return i18n( + `lib.prompts.personalAccessKeyPrompt.errors.invalidOauthClientIdLength` + ); } return true; }, @@ -118,14 +129,20 @@ const CLIENT_ID: PromptConfig = { const CLIENT_SECRET: PromptConfig = { name: 'clientSecret', - message: i18n(`${i18nKey}.enterClientSecret`), + message: i18n(`lib.prompts.personalAccessKeyPrompt.enterClientSecret`), validate(val?: string) { if (typeof val !== 'string') { - return i18n(`${i18nKey}.errors.invalidOauthClientSecret`); + return i18n( + `lib.prompts.personalAccessKeyPrompt.errors.invalidOauthClientSecret` + ); } else if (val.length !== 36) { - return i18n(`${i18nKey}.errors.invalidOauthClientSecretLength`); + return i18n( + `lib.prompts.personalAccessKeyPrompt.errors.invalidOauthClientSecretLength` + ); } else if (val[0] === '*') { - return i18n(`${i18nKey}.errors.invalidOauthClientSecretCopy`); + return i18n( + `lib.prompts.personalAccessKeyPrompt.errors.invalidOauthClientSecretCopy` + ); } return true; }, @@ -135,12 +152,14 @@ const PERSONAL_ACCESS_KEY_BROWSER_OPEN_PREP: PromptConfig = { name: 'personalAccessKey', - message: i18n(`${i18nKey}.enterPersonalAccessKey`), + message: i18n(`lib.prompts.personalAccessKeyPrompt.enterPersonalAccessKey`), transformer: (val?: string) => { if (!val) return val; let res = ''; @@ -151,9 +170,13 @@ const PERSONAL_ACCESS_KEY: PromptConfig = { }, validate(val?: string) { if (!val || typeof val !== 'string') { - return i18n(`${i18nKey}.errors.invalidPersonalAccessKey`); + return i18n( + `lib.prompts.personalAccessKeyPrompt.errors.invalidPersonalAccessKey` + ); } else if (val[0] === '•') { - return i18n(`${i18nKey}.errors.invalidPersonalAccessKeyCopy`); + return i18n( + `lib.prompts.personalAccessKeyPrompt.errors.invalidPersonalAccessKeyCopy` + ); } return true; }, @@ -162,7 +185,7 @@ const PERSONAL_ACCESS_KEY: PromptConfig = { const SCOPES: PromptConfig = { type: 'checkbox', name: 'scopes', - message: i18n(`${i18nKey}.selectScopes`), + message: i18n(`lib.prompts.personalAccessKeyPrompt.selectScopes`), default: [...DEFAULT_OAUTH_SCOPES], choices: [...OAUTH_SCOPES], }; diff --git a/lib/prompts/previewPrompt.ts b/lib/prompts/previewPrompt.ts index 00981368e..5075799f3 100644 --- a/lib/prompts/previewPrompt.ts +++ b/lib/prompts/previewPrompt.ts @@ -3,8 +3,6 @@ import { getCwd } from '@hubspot/local-dev-lib/path'; import { promptUser } from './promptUtils'; import { i18n } from '../lang'; -const i18nKey = 'lib.prompts.previewPrompt'; - type PreviewPromptResponse = { src: string; dest: string; @@ -20,24 +18,24 @@ export async function previewPrompt( return promptUser([ { name: 'src', - message: i18n(`${i18nKey}.enterSrc`), + message: i18n(`lib.prompts.previewPrompt.enterSrc`), when: !promptOptions.src, default: '.', validate: (input?: string) => { if (!input) { - return i18n(`${i18nKey}.errors.srcRequired`); + return i18n(`lib.prompts.previewPrompt.errors.srcRequired`); } return true; }, }, { name: 'dest', - message: i18n(`${i18nKey}.enterDest`), + message: i18n(`lib.prompts.previewPrompt.enterDest`), when: !promptOptions.dest, default: path.basename(getCwd()), validate: (input?: string) => { if (!input) { - return i18n(`${i18nKey}.errors.destRequired`); + return i18n(`lib.prompts.previewPrompt.errors.destRequired`); } return true; }, @@ -51,7 +49,7 @@ export async function previewProjectPrompt( return promptUser([ { name: 'themeComponentPath', - message: i18n(`${i18nKey}.themeProjectSelect`), + message: i18n(`lib.prompts.previewPrompt.themeProjectSelect`), type: 'list', choices: themeComponents.map(t => { const themeName = path.basename(t.path); diff --git a/lib/prompts/projectAddPrompt.ts b/lib/prompts/projectAddPrompt.ts index 855e402ef..d7c4e756f 100644 --- a/lib/prompts/projectAddPrompt.ts +++ b/lib/prompts/projectAddPrompt.ts @@ -2,8 +2,6 @@ import { promptUser } from './promptUtils'; import { ComponentTemplate } from '../../types/Projects'; import { i18n } from '../lang'; -const i18nKey = 'lib.prompts.projectAddPrompt'; - type ProjectAddPromptResponse = { componentTemplate: ComponentTemplate; name: string; @@ -31,10 +29,10 @@ export async function projectAddPrompt( name: 'componentTemplate', message: () => { return promptOptions.type && !providedTypeIsValid - ? i18n(`${i18nKey}.errors.invalidType`, { + ? i18n(`lib.prompts.projectAddPrompt.errors.invalidType`, { type: promptOptions.type, }) - : i18n(`${i18nKey}.selectType`); + : i18n(`lib.prompts.projectAddPrompt.selectType`); }, when: !providedTypeIsValid, type: 'list', @@ -47,11 +45,11 @@ export async function projectAddPrompt( }, { name: 'name', - message: i18n(`${i18nKey}.enterName`), + message: i18n(`lib.prompts.projectAddPrompt.enterName`), when: !promptOptions.name, validate: (input?: string) => { if (!input) { - return i18n(`${i18nKey}.errors.nameRequired`); + return i18n(`lib.prompts.projectAddPrompt.errors.nameRequired`); } return true; }, diff --git a/lib/prompts/projectDevTargetAccountPrompt.ts b/lib/prompts/projectDevTargetAccountPrompt.ts index 6597b54c0..0c0e36a80 100644 --- a/lib/prompts/projectDevTargetAccountPrompt.ts +++ b/lib/prompts/projectDevTargetAccountPrompt.ts @@ -23,8 +23,6 @@ import { } from '../../types/Prompts'; import { EXIT_CODES } from '../enums/exitCodes'; -const i18nKey = 'lib.prompts.projectDevTargetAccountPrompt'; - function mapNestedAccount(accountConfig: CLIAccount): { name: string; value: { @@ -67,7 +65,7 @@ export async function selectSandboxTargetAccountPrompt( const { data } = await getSandboxUsageLimits(defaultAccountId); sandboxUsage = data.usage; } else { - logger.error(`${i18nKey}.noAccountId`); + logger.error(`lib.prompts.projectDevTargetAccountPrompt.noAccountId`); process.exit(EXIT_CODES.ERROR); } } catch (err) { @@ -83,14 +81,20 @@ export async function selectSandboxTargetAccountPrompt( if (sandboxUsage['DEVELOPER'] && sandboxUsage['DEVELOPER'].available === 0) { if (sandboxAccounts.length < sandboxUsage['DEVELOPER'].limit) { - disabledMessage = i18n(`${i18nKey}.sandboxLimitWithSuggestion`, { - authCommand: uiCommandReference('hs auth'), - limit: sandboxUsage['DEVELOPER'].limit, - }); + disabledMessage = i18n( + `lib.prompts.projectDevTargetAccountPrompt.sandboxLimitWithSuggestion`, + { + authCommand: uiCommandReference('hs auth'), + limit: sandboxUsage['DEVELOPER'].limit, + } + ); } else { - disabledMessage = i18n(`${i18nKey}.sandboxLimit`, { - limit: sandboxUsage['DEVELOPER'].limit, - }); + disabledMessage = i18n( + `lib.prompts.projectDevTargetAccountPrompt.sandboxLimit`, + { + limit: sandboxUsage['DEVELOPER'].limit, + } + ); } } // Order choices by Developer Sandbox -> Standard Sandbox @@ -102,7 +106,9 @@ export async function selectSandboxTargetAccountPrompt( .filter(a => a.accountType === HUBSPOT_ACCOUNT_TYPES.STANDARD_SANDBOX) .map(mapNestedAccount), { - name: i18n(`${i18nKey}.createNewSandboxOption`), + name: i18n( + `lib.prompts.projectDevTargetAccountPrompt.createNewSandboxOption` + ), value: { targetAccountId: null, createNestedAccount: true, @@ -110,7 +116,9 @@ export async function selectSandboxTargetAccountPrompt( disabled: disabledMessage, }, { - name: i18n(`${i18nKey}.chooseDefaultAccountOption`), + name: i18n( + `lib.prompts.projectDevTargetAccountPrompt.chooseDefaultAccountOption` + ), value: { targetAccountId: defaultAccountId, createNestedAccount: false, @@ -136,7 +144,7 @@ export async function selectDeveloperTestTargetAccountPrompt( const { data } = await fetchDeveloperTestAccounts(defaultAccountId); devTestAccountsResponse = data; } else { - logger.error(`${i18nKey}.noAccountId`); + logger.error(`lib.prompts.projectDevTargetAccountPrompt.noAccountId`); process.exit(EXIT_CODES.ERROR); } } catch (err) { @@ -149,10 +157,13 @@ export async function selectDeveloperTestTargetAccountPrompt( devTestAccountsResponse.results.length >= devTestAccountsResponse.maxTestPortals ) { - disabledMessage = i18n(`${i18nKey}.developerTestAccountLimit`, { - authCommand: uiCommandReference('hs auth'), - limit: devTestAccountsResponse.maxTestPortals, - }); + disabledMessage = i18n( + `lib.prompts.projectDevTargetAccountPrompt.developerTestAccountLimit`, + { + authCommand: uiCommandReference('hs auth'), + limit: devTestAccountsResponse.maxTestPortals, + } + ); } const devTestAccounts: PromptChoices = []; @@ -176,7 +187,9 @@ export async function selectDeveloperTestTargetAccountPrompt( const choices = [ ...devTestAccounts, { - name: i18n(`${i18nKey}.createNewDeveloperTestAccountOption`), + name: i18n( + `lib.prompts.projectDevTargetAccountPrompt.createNewDeveloperTestAccountOption` + ), value: { targetAccountId: null, createNestedAccount: true, @@ -204,7 +217,7 @@ async function selectTargetAccountPrompt( { name: 'targetAccountInfo', type: 'list', - message: i18n(`${i18nKey}.promptMessage`, { + message: i18n(`lib.prompts.projectDevTargetAccountPrompt.promptMessage`, { accountIdentifier: uiAccountDescription(accountId), accountType, }), @@ -225,10 +238,13 @@ export async function confirmDefaultAccountPrompt( { name: 'useDefaultAccount', type: 'confirm', - message: i18n(`${i18nKey}.confirmDefaultAccount`, { - accountName, - accountType, - }), + message: i18n( + `lib.prompts.projectDevTargetAccountPrompt.confirmDefaultAccount`, + { + accountName, + accountType, + } + ), }, ]); return useDefaultAccount; @@ -243,9 +259,12 @@ export async function confirmUseExistingDeveloperTestAccountPrompt( { name: 'confirmUseExistingDeveloperTestAccount', type: 'confirm', - message: i18n(`${i18nKey}.confirmUseExistingDeveloperTestAccount`, { - accountName: getNonConfigDeveloperTestAccountName(account), - }), + message: i18n( + `lib.prompts.projectDevTargetAccountPrompt.confirmUseExistingDeveloperTestAccount`, + { + accountName: getNonConfigDeveloperTestAccountName(account), + } + ), }, ]); return confirmUseExistingDeveloperTestAccount; diff --git a/lib/prompts/projectNamePrompt.ts b/lib/prompts/projectNamePrompt.ts index 4aa5647c1..fc7241ed7 100644 --- a/lib/prompts/projectNamePrompt.ts +++ b/lib/prompts/projectNamePrompt.ts @@ -3,8 +3,6 @@ import { i18n } from '../lang'; import { ensureProjectExists } from '../projects/ensureProjectExists'; import { uiAccountDescription } from '../ui'; -const i18nKey = 'lib.prompts.projectNamePrompt'; - export type ProjectNamePromptResponse = { projectName: string; }; @@ -15,21 +13,24 @@ export async function projectNamePrompt( ) { const result = await promptUser({ name: 'projectName', - message: i18n(`${i18nKey}.enterName`), + message: i18n(`lib.prompts.projectNamePrompt.enterName`), when: !options.project, validate: async val => { if (typeof val !== 'string' || !val) { - return i18n(`${i18nKey}.errors.invalidName`); + return i18n(`lib.prompts.projectNamePrompt.errors.invalidName`); } const { projectExists } = await ensureProjectExists(accountId, val, { allowCreate: false, noLogs: true, }); if (!projectExists) { - return i18n(`${i18nKey}.errors.projectDoesNotExist`, { - projectName: val, - accountIdentifier: uiAccountDescription(accountId), - }); + return i18n( + `lib.prompts.projectNamePrompt.errors.projectDoesNotExist`, + { + projectName: val, + accountIdentifier: uiAccountDescription(accountId), + } + ); } return true; }, diff --git a/lib/prompts/projectsLogsPrompt.ts b/lib/prompts/projectsLogsPrompt.ts index f43d69f63..1b9304e8e 100644 --- a/lib/prompts/projectsLogsPrompt.ts +++ b/lib/prompts/projectsLogsPrompt.ts @@ -1,8 +1,6 @@ import { i18n } from '../lang'; import { promptUser } from './promptUtils'; -const i18nKey = 'lib.prompts.projectLogsPrompt'; - type ProjectLogsPromptOptions = { functionChoices?: string[]; promptOptions?: { function?: string }; @@ -29,7 +27,9 @@ export async function projectLogsPrompt({ { name: 'functionName', type: 'list', - message: i18n(`${i18nKey}.functionName`, { projectName }), + message: i18n(`lib.prompts.projectLogsPrompt.functionName`, { + projectName, + }), when: () => (!promptOptions || !promptOptions.function) && functionChoices.length > 0, diff --git a/lib/prompts/sandboxesPrompt.ts b/lib/prompts/sandboxesPrompt.ts index 10c0c3594..394b92f41 100644 --- a/lib/prompts/sandboxesPrompt.ts +++ b/lib/prompts/sandboxesPrompt.ts @@ -12,8 +12,6 @@ import { CLIAccount } from '@hubspot/local-dev-lib/types/Accounts'; import { PromptChoices } from '../../types/Prompts'; import { SandboxAccountType } from '../../types/Sandboxes'; -const i18nKey = 'lib.prompts.sandboxesPrompt'; - type SandboxTypePromptResponse = { type: SandboxAccountType; }; @@ -52,15 +50,15 @@ export async function sandboxTypePrompt(): Promise { return promptUser([ { name: 'type', - message: i18n(`${i18nKey}.type.message`), + message: i18n(`lib.prompts.sandboxesPrompt.type.message`), type: 'list', choices: [ { - name: i18n(`${i18nKey}.type.developer`), + name: i18n(`lib.prompts.sandboxesPrompt.type.developer`), value: HUBSPOT_ACCOUNT_TYPES.DEVELOPMENT_SANDBOX, }, { - name: i18n(`${i18nKey}.type.standard`), + name: i18n(`lib.prompts.sandboxesPrompt.type.standard`), value: HUBSPOT_ACCOUNT_TYPES.STANDARD_SANDBOX, }, ], @@ -84,8 +82,8 @@ export function deleteSandboxPrompt( name: 'account', message: i18n( promptParentAccount - ? `${i18nKey}.selectParentAccountName` - : `${i18nKey}.selectAccountName` + ? `lib.prompts.sandboxesPrompt.selectParentAccountName` + : `lib.prompts.sandboxesPrompt.selectAccountName` ), type: 'list', pageSize: 20, diff --git a/lib/prompts/secretPrompt.ts b/lib/prompts/secretPrompt.ts index a2604b086..1131eb2ec 100644 --- a/lib/prompts/secretPrompt.ts +++ b/lib/prompts/secretPrompt.ts @@ -1,8 +1,6 @@ import { promptUser } from './promptUtils'; import { i18n } from '../lang'; -const i18nKey = 'lib.prompts.secretPrompt'; - type SecretValuePromptResponse = { secretValue: string; }; @@ -13,7 +11,7 @@ export function secretValuePrompt(): Promise { name: 'secretValue', type: 'password', mask: '*', - message: i18n(`${i18nKey}.enterValue`), + message: i18n(`lib.prompts.secretPrompt.enterValue`), }, ]); } @@ -27,7 +25,7 @@ export function secretNamePrompt(): Promise { { name: 'secretName', type: 'input', - message: i18n(`${i18nKey}.enterName`), + message: i18n(`lib.prompts.secretPrompt.enterName`), }, ]); } diff --git a/lib/prompts/selectHubDBTablePrompt.ts b/lib/prompts/selectHubDBTablePrompt.ts index d443ed1ba..645534847 100644 --- a/lib/prompts/selectHubDBTablePrompt.ts +++ b/lib/prompts/selectHubDBTablePrompt.ts @@ -8,21 +8,27 @@ import { EXIT_CODES } from '../enums/exitCodes'; import { Table } from '@hubspot/local-dev-lib/types/Hubdb'; import { isValidPath, untildify } from '@hubspot/local-dev-lib/path'; -const i18nKey = 'lib.prompts.selectHubDBTablePrompt'; - async function fetchHubDBOptions(accountId: number) { try { const { data: { results: tables }, } = await fetchTables(accountId); if (tables.length === 0) { - logger.log(i18n(`${i18nKey}.errors.noTables`, { accountId })); + logger.log( + i18n(`lib.prompts.selectHubDBTablePrompt.errors.noTables`, { + accountId, + }) + ); process.exit(EXIT_CODES.SUCCESS); } return tables; } catch (error) { debugError(error, { accountId }); - logger.error(i18n(`${i18nKey}.errors.errorFetchingTables`, { accountId })); + logger.error( + i18n(`lib.prompts.selectHubDBTablePrompt.errors.errorFetchingTables`, { + accountId, + }) + ); process.exit(EXIT_CODES.ERROR); } } @@ -47,7 +53,7 @@ export async function selectHubDBTablePrompt({ return promptUser([ { name: 'tableId', - message: i18n(`${i18nKey}.selectTable`), + message: i18n(`lib.prompts.selectHubDBTablePrompt.selectTable`), when: !id && !isValidTable, type: 'list', choices: hubdbTables.map(table => { @@ -59,17 +65,19 @@ export async function selectHubDBTablePrompt({ }, { name: 'dest', - message: i18n(`${i18nKey}.enterDest`), + message: i18n(`lib.prompts.selectHubDBTablePrompt.enterDest`), when: !options.dest && !skipDestPrompt, validate: (input?: string) => { if (!input) { - return i18n(`${i18nKey}.errors.destRequired`); + return i18n(`lib.prompts.selectHubDBTablePrompt.errors.destRequired`); } if (fs.existsSync(input)) { - return i18n(`${i18nKey}.errors.invalidDest`); + return i18n(`lib.prompts.selectHubDBTablePrompt.errors.invalidDest`); } if (!isValidPath(input)) { - return i18n(`${i18nKey}.errors.invalidCharacters`); + return i18n( + `lib.prompts.selectHubDBTablePrompt.errors.invalidCharacters` + ); } return true; }, diff --git a/lib/prompts/selectPublicAppPrompt.ts b/lib/prompts/selectPublicAppPrompt.ts index eb1f62bba..5e522b747 100644 --- a/lib/prompts/selectPublicAppPrompt.ts +++ b/lib/prompts/selectPublicAppPrompt.ts @@ -7,8 +7,6 @@ import { fetchPublicAppsForPortal } from '@hubspot/local-dev-lib/api/appsDev'; import { EXIT_CODES } from '../enums/exitCodes'; import { PublicApp } from '@hubspot/local-dev-lib/types/Apps'; -const i18nKey = 'lib.prompts.selectPublicAppPrompt'; - type PublicAppPromptResponse = { appId: number; }; @@ -20,7 +18,9 @@ async function fetchPublicAppOptions( ): Promise { try { if (!accountId) { - logger.error(i18n(`${i18nKey}.errors.noAccountId`)); + logger.error( + i18n(`lib.prompts.selectPublicAppPrompt.errors.noAccountId`) + ); process.exit(EXIT_CODES.ERROR); } @@ -46,9 +46,14 @@ async function fetchPublicAppOptions( ? 'noAppsMigrationMessage' : 'noAppsCloneMessage'; uiLine(); - logger.error(i18n(`${i18nKey}.errors.${headerTranslationKey}`)); + logger.error( + i18n(`lib.prompts.selectPublicAppPrompt.errors.${headerTranslationKey}`) + ); logger.log( - i18n(`${i18nKey}.errors.${messageTranslationKey}`, { accountName }) + i18n( + `lib.prompts.selectPublicAppPrompt.errors.${messageTranslationKey}`, + { accountName } + ) ); uiLine(); process.exit(EXIT_CODES.SUCCESS); @@ -56,7 +61,9 @@ async function fetchPublicAppOptions( return filteredPublicApps; } catch (error) { logError(error, accountId ? { accountId } : undefined); - logger.error(i18n(`${i18nKey}.errors.errorFetchingApps`)); + logger.error( + i18n(`lib.prompts.selectPublicAppPrompt.errors.errorFetchingApps`) + ); process.exit(EXIT_CODES.ERROR); } } @@ -82,7 +89,7 @@ export async function selectPublicAppPrompt({ return promptUser([ { name: 'appId', - message: i18n(`${i18nKey}.${translationKey}`, { + message: i18n(`lib.prompts.selectPublicAppPrompt.${translationKey}`, { accountName, }), type: 'list', @@ -91,7 +98,9 @@ export async function selectPublicAppPrompt({ if (isMigratingApp && preventProjectMigrations && listingInfo) { return { name: `${app.name} (${app.id})`, - disabled: i18n(`${i18nKey}.errors.cannotBeMigrated`), + disabled: i18n( + `lib.prompts.selectPublicAppPrompt.errors.cannotBeMigrated` + ), }; } return { diff --git a/lib/prompts/setAsDefaultAccountPrompt.ts b/lib/prompts/setAsDefaultAccountPrompt.ts index 7f8ea61be..0fa026045 100644 --- a/lib/prompts/setAsDefaultAccountPrompt.ts +++ b/lib/prompts/setAsDefaultAccountPrompt.ts @@ -5,8 +5,6 @@ import { import { promptUser } from './promptUtils'; import { i18n } from '../lang'; -const i18nKey = 'lib.prompts.setAsDefaultAccountPrompt'; - export async function setAsDefaultAccountPrompt( accountName: string ): Promise { @@ -18,7 +16,9 @@ export async function setAsDefaultAccountPrompt( name: 'setAsDefault', type: 'confirm', when: defaultAccount !== accountName, - message: i18n(`${i18nKey}.setAsDefaultAccountMessage`), + message: i18n( + `lib.prompts.setAsDefaultAccountPrompt.setAsDefaultAccountMessage` + ), }, ]); diff --git a/lib/prompts/uploadPrompt.ts b/lib/prompts/uploadPrompt.ts index 9d021d2fc..12be6aead 100644 --- a/lib/prompts/uploadPrompt.ts +++ b/lib/prompts/uploadPrompt.ts @@ -3,8 +3,6 @@ import { getCwd } from '@hubspot/local-dev-lib/path'; import { promptUser } from './promptUtils'; import { i18n } from '../lang'; -const i18nKey = 'lib.prompts.uploadPrompt'; - type UploadPromptResponse = { src: string; dest: string; @@ -16,24 +14,24 @@ export async function uploadPrompt( return promptUser([ { name: 'src', - message: i18n(`${i18nKey}.enterSrc`), + message: i18n(`lib.prompts.uploadPrompt.enterSrc`), when: !promptOptions.src, default: '.', validate: (input?: string) => { if (!input) { - return i18n(`${i18nKey}.errors.srcRequired`); + return i18n(`lib.prompts.uploadPrompt.errors.srcRequired`); } return true; }, }, { name: 'dest', - message: i18n(`${i18nKey}.enterDest`), + message: i18n(`lib.prompts.uploadPrompt.enterDest`), when: !promptOptions.dest, default: path.basename(getCwd()), validate: (input?: string) => { if (!input) { - return i18n(`${i18nKey}.errors.destRequired`); + return i18n(`lib.prompts.uploadPrompt.errors.destRequired`); } return true; }, diff --git a/lib/sandboxSync.ts b/lib/sandboxSync.ts index 5f3a894ab..611e1ec36 100644 --- a/lib/sandboxSync.ts +++ b/lib/sandboxSync.ts @@ -21,8 +21,6 @@ import { import { isDevelopmentSandbox } from './accountTypes'; import { SandboxSyncTask } from '../types/Sandboxes'; -const i18nKey = 'lib.sandbox.sync'; - export async function syncSandbox( accountConfig: CLIAccount, parentAccountConfig: CLIAccount, @@ -38,7 +36,7 @@ export async function syncSandbox( if (!accountId || !parentAccountId) { throw new Error( - i18n(`${i18nKey}.failure.invalidUser`, { + i18n(`lib.sandbox.sync.failure.invalidUser`, { accountName: accountId ? uiAccountDescription(accountId) : id!.toString(), @@ -73,7 +71,7 @@ export async function syncSandbox( } SpinniesManager.add('sandboxSync', { - text: i18n(`${i18nKey}.loading.startSync`), + text: i18n(`lib.sandbox.sync.loading.startSync`), }); await initiateSync( @@ -83,15 +81,17 @@ export async function syncSandbox( accountId ); const spinniesText = isDevSandbox - ? `${i18nKey}.loading.succeedDevSb` - : `${i18nKey}.loading.succeed`; + ? `lib.sandbox.sync.loading.succeedDevSb` + : `lib.sandbox.sync.loading.succeed`; SpinniesManager.succeed('sandboxSync', { text: i18n( - slimInfoMessage ? `${i18nKey}.loading.successDevSbInfo` : spinniesText, + slimInfoMessage + ? `lib.sandbox.sync.loading.successDevSbInfo` + : spinniesText, { accountName: uiAccountDescription(accountId), url: uiLink( - i18n(`${i18nKey}.info.syncStatusDetailsLinkText`), + i18n(`lib.sandbox.sync.info.syncStatusDetailsLinkText`), syncStatusUrl ), } @@ -101,7 +101,7 @@ export async function syncSandbox( debugError(err); SpinniesManager.fail('sandboxSync', { - text: i18n(`${i18nKey}.loading.fail`), + text: i18n(`lib.sandbox.sync.loading.fail`), }); logger.log(''); @@ -113,7 +113,7 @@ export async function syncSandbox( }) ) { logger.error( - i18n(`${i18nKey}.failure.invalidUser`, { + i18n(`lib.sandbox.sync.failure.invalidUser`, { accountName: uiAccountDescription(accountId), parentAccountName: uiAccountDescription(parentAccountId), }) @@ -126,7 +126,7 @@ export async function syncSandbox( }) ) { logger.error( - i18n(`${i18nKey}.failure.syncInProgress`, { + i18n(`lib.sandbox.sync.failure.syncInProgress`, { url: `${baseUrl}/sandboxes-developer/${parentAccountId}/syncactivitylog`, }) ); @@ -139,7 +139,7 @@ export async function syncSandbox( ) { // This will only trigger if a user is not a super admin of the target account. logger.error( - i18n(`${i18nKey}.failure.notSuperAdmin`, { + i18n(`lib.sandbox.sync.failure.notSuperAdmin`, { account: uiAccountDescription(accountId), }) ); @@ -151,7 +151,7 @@ export async function syncSandbox( }) ) { logger.error( - i18n(`${i18nKey}.failure.objectNotFound`, { + i18n(`lib.sandbox.sync.failure.objectNotFound`, { account: uiAccountDescription(accountId), }) ); @@ -182,10 +182,10 @@ export async function syncSandbox( uiLine(); logger.info( i18n( - `${i18nKey}.info.${isDevSandbox ? 'syncMessageDevSb' : 'syncMessage'}`, + `lib.sandbox.sync.info.${isDevSandbox ? 'syncMessageDevSb' : 'syncMessage'}`, { url: uiLink( - i18n(`${i18nKey}.info.syncStatusDetailsLinkText`), + i18n(`lib.sandbox.sync.info.syncStatusDetailsLinkText`), syncStatusUrl ), } diff --git a/lib/sandboxes.ts b/lib/sandboxes.ts index 8ffa6412d..40eb68c5e 100644 --- a/lib/sandboxes.ts +++ b/lib/sandboxes.ts @@ -17,8 +17,6 @@ import { uiAccountDescription } from './ui'; import { logError } from './errorHandlers/index'; import { SandboxSyncTask, SandboxAccountType } from '../types/Sandboxes'; -const i18nKey = 'lib.sandbox'; - export const SYNC_TYPES = { OBJECT_RECORDS: 'object-records', } as const; @@ -75,14 +73,14 @@ export async function getAvailableSyncTypes( const portalId = getAccountId(id); if (!parentPortalId || !portalId) { - throw new Error(i18n(`${i18nKey}.sync.failure.syncTypeFetch`)); + throw new Error(i18n(`lib.sandbox.sync.failure.syncTypeFetch`)); } const { data: { results: syncTypes }, } = await fetchTypes(parentPortalId, portalId); if (!syncTypes) { - throw new Error(i18n(`${i18nKey}.sync.failure.syncTypeFetch`)); + throw new Error(i18n(`lib.sandbox.sync.failure.syncTypeFetch`)); } return syncTypes.map(t => ({ type: t.name })); } @@ -96,14 +94,14 @@ export async function validateSandboxUsageLimits( const accountId = getAccountId(id); if (!accountId) { - throw new Error(i18n(`${i18nKey}.create.failure.usageLimitFetch`)); + throw new Error(i18n(`lib.sandbox.create.failure.usageLimitFetch`)); } const { data: { usage }, } = await getSandboxUsageLimits(accountId); if (!usage) { - throw new Error(i18n(`${i18nKey}.create.failure.usageLimitFetch`)); + throw new Error(i18n(`lib.sandbox.create.failure.usageLimitFetch`)); } if (sandboxType === HUBSPOT_ACCOUNT_TYPES.DEVELOPMENT_SANDBOX) { if (usage['DEVELOPER'].available === 0) { @@ -116,7 +114,7 @@ export async function validateSandboxUsageLimits( if (hasDevelopmentSandboxes) { throw new Error( i18n( - `${i18nKey}.create.failure.alreadyInConfig.developer.${ + `lib.sandbox.create.failure.alreadyInConfig.developer.${ plural ? 'other' : 'one' }`, { @@ -129,7 +127,7 @@ export async function validateSandboxUsageLimits( const baseUrl = getHubSpotWebsiteOrigin(env); throw new Error( i18n( - `${i18nKey}.create.failure.limit.developer.${ + `lib.sandbox.create.failure.limit.developer.${ plural ? 'other' : 'one' }`, { @@ -153,7 +151,7 @@ export async function validateSandboxUsageLimits( if (hasStandardSandboxes) { throw new Error( i18n( - `${i18nKey}.create.failure.alreadyInConfig.standard.${ + `lib.sandbox.create.failure.alreadyInConfig.standard.${ plural ? 'other' : 'one' }`, { @@ -166,7 +164,7 @@ export async function validateSandboxUsageLimits( const baseUrl = getHubSpotWebsiteOrigin(env); throw new Error( i18n( - `${i18nKey}.create.failure.limit.standard.${ + `lib.sandbox.create.failure.limit.standard.${ plural ? 'other' : 'one' }`, { @@ -189,14 +187,14 @@ export function handleSandboxCreateError( ): never { if (isMissingScopeError(err)) { logger.error( - i18n(`${i18nKey}.create.failure.scopes.message`, { + i18n(`lib.sandbox.create.failure.scopes.message`, { accountName: uiAccountDescription(accountId), }) ); const websiteOrigin = getHubSpotWebsiteOrigin(env); const url = `${websiteOrigin}/personal-access-key/${accountId}`; logger.info( - i18n(`${i18nKey}.create.failure.scopes.instructions`, { + i18n(`lib.sandbox.create.failure.scopes.instructions`, { accountName: uiAccountDescription(accountId), url, }) @@ -210,7 +208,7 @@ export function handleSandboxCreateError( ) { logger.log(''); logger.error( - i18n(`${i18nKey}.create.failure.invalidUser`, { + i18n(`lib.sandbox.create.failure.invalidUser`, { accountName: name, parentAccountName: uiAccountDescription(accountId), }) @@ -225,7 +223,7 @@ export function handleSandboxCreateError( ) { logger.log(''); logger.error( - i18n(`${i18nKey}.create.failure.403Gating`, { + i18n(`lib.sandbox.create.failure.403Gating`, { accountName: name, parentAccountName: uiAccountDescription(accountId), accountId, diff --git a/lib/serverlessLogs.ts b/lib/serverlessLogs.ts index 476d4f4de..91d3a170b 100644 --- a/lib/serverlessLogs.ts +++ b/lib/serverlessLogs.ts @@ -60,8 +60,6 @@ async function verifyAccessKeyAndUserAccess( return; } - // TODO[JOE]: Update this i18n key - const i18nKey = 'lib.serverless'; const { authType } = accountConfig; if (authType !== PERSONAL_ACCESS_KEY_AUTH_METHOD.value) { return; @@ -73,7 +71,7 @@ async function verifyAccessKeyAndUserAccess( scopesData = resp.data; } catch (e) { logger.debug( - i18n(`${i18nKey}.verifyAccessKeyAndUserAccess.fetchScopeDataError`, { + i18n(`lib.serverless.verifyAccessKeyAndUserAccess.fetchScopeDataError`, { scopeGroup, }) ); @@ -84,18 +82,18 @@ async function verifyAccessKeyAndUserAccess( if (!portalScopesInGroup.length) { logger.error( - i18n(`${i18nKey}.verifyAccessKeyAndUserAccess.portalMissingScope`) + i18n(`lib.serverless.verifyAccessKeyAndUserAccess.portalMissingScope`) ); return; } if (!portalScopesInGroup.every(s => userScopesInGroup.includes(s))) { logger.error( - i18n(`${i18nKey}.verifyAccessKeyAndUserAccess.userMissingScope`) + i18n(`lib.serverless.verifyAccessKeyAndUserAccess.userMissingScope`) ); } else { logger.error( - i18n(`${i18nKey}.verifyAccessKeyAndUserAccess.genericMissingScope`) + i18n(`lib.serverless.verifyAccessKeyAndUserAccess.genericMissingScope`) ); } } diff --git a/lib/ui/git.ts b/lib/ui/git.ts index 5af2ad4a4..ab3521f3a 100644 --- a/lib/ui/git.ts +++ b/lib/ui/git.ts @@ -3,22 +3,20 @@ import { checkGitInclusion } from '@hubspot/local-dev-lib/gitignore'; import { logger } from '@hubspot/local-dev-lib/logger'; import { i18n } from '../lang'; -const i18nKey = 'lib.ui.git'; - export function checkAndWarnGitInclusion(configPath: string): void { try { const { inGit, configIgnored } = checkGitInclusion(configPath); if (!inGit || configIgnored) return; - logger.warn(i18n(`${i18nKey}.securityIssue`)); - logger.warn(i18n(`${i18nKey}.configFileTracked`)); - logger.warn(i18n(`${i18nKey}.fileName`, { configPath })); - logger.warn(i18n(`${i18nKey}.remediate`)); - logger.warn(i18n(`${i18nKey}.moveConfig`, { homeDir: os.homedir() })); - logger.warn(i18n(`${i18nKey}.addGitignore`, { configPath })); - logger.warn(i18n(`${i18nKey}.noRemote`)); + logger.warn(i18n(`lib.ui.git.securityIssue`)); + logger.warn(i18n(`lib.ui.git.configFileTracked`)); + logger.warn(i18n(`lib.ui.git.fileName`, { configPath })); + logger.warn(i18n(`lib.ui.git.remediate`)); + logger.warn(i18n(`lib.ui.git.moveConfig`, { homeDir: os.homedir() })); + logger.warn(i18n(`lib.ui.git.addGitignore`, { configPath })); + logger.warn(i18n(`lib.ui.git.noRemote`)); } catch (e) { // fail silently - logger.debug(i18n(`${i18nKey}.checkFailed`)); + logger.debug(i18n(`lib.ui.git.checkFailed`)); } } diff --git a/lib/ui/index.ts b/lib/ui/index.ts index 85bdf3a61..aa6d24be2 100644 --- a/lib/ui/index.ts +++ b/lib/ui/index.ts @@ -90,30 +90,32 @@ export function uiCommandReference(command: string, withQuotes = true): string { } export function uiFeatureHighlight(features: string[], title?: string): void { - const i18nKey = 'lib.ui.featureHighlight'; - - uiInfoSection(title ? title : i18n(`${i18nKey}.defaultTitle`), () => { - features.forEach((c, i) => { - const featureKey = `${i18nKey}.featureKeys.${c}`; - const message = i18n(`${featureKey}.message`, { - command: uiCommandReference(i18n(`${featureKey}.command`)), - link: uiLink(i18n(`${featureKey}.linkText`), i18n(`${featureKey}.url`)), + uiInfoSection( + title ? title : i18n(`lib.ui.featureHighlight.defaultTitle`), + () => { + features.forEach((c, i) => { + const featureKey = `lib.ui.featureHighlight.featureKeys.${c}`; + const message = i18n(`${featureKey}.message`, { + command: uiCommandReference(i18n(`${featureKey}.command`)), + link: uiLink( + i18n(`${featureKey}.linkText`), + i18n(`${featureKey}.url`) + ), + }); + if (i !== 0) { + logger.log(''); + } + logger.log(message); }); - if (i !== 0) { - logger.log(''); - } - logger.log(message); - }); - }); + } + ); } export function uiBetaTag(message: string, log?: true): undefined; export function uiBetaTag(message: string, log: false): string; export function uiBetaTag(message: string, log = true): string | undefined { - const i18nKey = 'lib.ui'; - const terminalUISupport = getTerminalUISupport(); - const tag = i18n(`${i18nKey}.betaTag`); + const tag = i18n(`lib.ui.betaTag`); const result = `${ terminalUISupport.color ? chalk.hex(UI_COLORS.SORBET)(tag) : tag @@ -132,10 +134,8 @@ export function uiDeprecatedTag( message: string, log = true ): string | undefined { - const i18nKey = 'lib.ui'; - const terminalUISupport = getTerminalUISupport(); - const tag = i18n(`${i18nKey}.deprecatedTag`); + const tag = i18n(`lib.ui.deprecatedTag`); const result = `${ terminalUISupport.color ? chalk.yellow(tag) : tag @@ -153,13 +153,11 @@ export function uiCommandDisabledBanner( url?: string, message?: string ): void { - const i18nKey = 'lib.ui'; - const tag = message || - i18n(`${i18nKey}.disabledMessage`, { + i18n(`lib.ui.disabledMessage`, { command: uiCommandReference(command), - url: url ? uiLink(i18n(`${i18nKey}.disabledUrlText`), url) : '', + url: url ? uiLink(i18n(`lib.ui.disabledUrlText`), url) : '', npmCommand: uiCommandReference('npm i -g @hubspot/cli@latest'), }); @@ -175,12 +173,10 @@ export function uiDeprecatedDescription( command: string, url?: string ) { - const i18nKey = 'lib.ui'; - - const tag = i18n(`${i18nKey}.deprecatedDescription`, { + const tag = i18n(`lib.ui.deprecatedDescription`, { message, command: uiCommandReference(command), - url: url ? uiLink(i18n(`${i18nKey}.deprecatedUrlText`), url) : '', + url: url ? uiLink(i18n(`lib.ui.deprecatedUrlText`), url) : '', }); return uiDeprecatedTag(tag); } @@ -190,13 +186,11 @@ export function uiDeprecatedMessage( url?: string, message?: string ): void { - const i18nKey = 'lib.ui'; - const tag = message || - i18n(`${i18nKey}.deprecatedMessage`, { + i18n(`lib.ui.deprecatedMessage`, { command: uiCommandReference(command), - url: url ? uiLink(i18n(`${i18nKey}.deprecatedUrlText`), url) : '', + url: url ? uiLink(i18n(`lib.ui.deprecatedUrlText`), url) : '', }); logger.log(); diff --git a/lib/ui/serverlessFunctionLogs.ts b/lib/ui/serverlessFunctionLogs.ts index f75a56a16..05add1b69 100644 --- a/lib/ui/serverlessFunctionLogs.ts +++ b/lib/ui/serverlessFunctionLogs.ts @@ -7,8 +7,6 @@ import { GetFunctionLogsResponse, } from '@hubspot/local-dev-lib/types/Functions'; -const i18nKey = 'lib.ui.serverlessFunctionLogs'; - const SEPARATOR = ' - '; const LOG_STATUS_COLORS: { [key: string]: (status: string) => string } = { SUCCESS: Styles.success, @@ -89,7 +87,7 @@ function processLog(log: FunctionLog, options: Options): string | void { return logHandler[log.status](log, options); } catch (e) { logger.error( - i18n(`${i18nKey}.unableToProcessLog`, { + i18n(`lib.ui.serverlessFunctionLogs.unableToProcessLog`, { log: JSON.stringify(log), }) ); @@ -114,7 +112,7 @@ function processLogs( const isLogsResp = isLogsResponse(logsResp); if (!logsResp || (isLogsResp && logsResp.results!.length === 0)) { - return i18n(`${i18nKey}.noLogsFound`); + return i18n(`lib.ui.serverlessFunctionLogs.noLogsFound`); } else if (isLogsResp) { return logsResp .results!.map(log => { From 92d5422ea1db1a00f10a7a6ccb84f574567095fd Mon Sep 17 00:00:00 2001 From: Joe Yeager Date: Mon, 28 Apr 2025 13:54:14 -0700 Subject: [PATCH 2/5] Fix cursors bad decisions --- lib/doctor/Diagnosis.ts | 22 ++++++++++------------ lib/doctor/Doctor.ts | 12 ++++++------ 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/lib/doctor/Diagnosis.ts b/lib/doctor/Diagnosis.ts index f116abdd6..0c363ce78 100644 --- a/lib/doctor/Diagnosis.ts +++ b/lib/doctor/Diagnosis.ts @@ -51,26 +51,24 @@ export class Diagnosis { this.diagnosis = { cli: { - header: i18n(`${`lib.doctor.diagnosis`}.cli.header`), + header: i18n(`lib.doctor.diagnosis.cli.header`), sections: [], }, cliConfig: { - header: i18n(`${`lib.doctor.diagnosis`}.cliConfig.header`), + header: i18n(`lib.doctor.diagnosis.cliConfig.header`), sections: [], }, defaultAccountOverrideFile: { - header: i18n( - `${`lib.doctor.diagnosis`}.defaultAccountOverrideFile.header` - ), + header: i18n(`lib.doctor.diagnosis.defaultAccountOverrideFile.header`), sections: [], }, project: { - header: i18n(`${`lib.doctor.diagnosis`}.projectConfig.header`), + header: i18n(`lib.doctor.diagnosis.projectConfig.header`), subheaders: [ - i18n(`${`lib.doctor.diagnosis`}.projectConfig.projectDirSubHeader`, { + i18n(`lib.doctor.diagnosis.projectConfig.projectDirSubHeader`, { projectDir: diagnosticInfo.project?.config?.projectDir, }), - i18n(`${`lib.doctor.diagnosis`}.projectConfig.projectNameSubHeader`, { + i18n(`lib.doctor.diagnosis.projectConfig.projectNameSubHeader`, { projectName: diagnosticInfo.project?.config?.projectConfig?.name, }), ], @@ -80,10 +78,10 @@ export class Diagnosis { if (diagnosticInfo.config) { this.diagnosis.cliConfig.subheaders = [ - i18n(`${`lib.doctor.diagnosis`}.cliConfig.configFileSubHeader`, { + i18n(`lib.doctor.diagnosis.cliConfig.configFileSubHeader`, { filename: diagnosticInfo.config, }), - i18n(`${`lib.doctor.diagnosis`}.cliConfig.defaultAccountSubHeader`, { + i18n(`lib.doctor.diagnosis.cliConfig.defaultAccountSubHeader`, { accountDetails: uiAccountDescription(accountId!), }), ]; @@ -129,12 +127,12 @@ export class Diagnosis { output.push(''); output.push( - i18n(`${`lib.doctor.diagnosis`}.counts.errors`, { + i18n(`lib.doctor.diagnosis.counts.errors`, { count: this.errorCount, }) ); output.push( - i18n(`${`lib.doctor.diagnosis`}.counts.warnings`, { + i18n(`lib.doctor.diagnosis.counts.warnings`, { count: this.warningCount, }) ); diff --git a/lib/doctor/Doctor.ts b/lib/doctor/Doctor.ts index bee369c67..651235d11 100644 --- a/lib/doctor/Doctor.ts +++ b/lib/doctor/Doctor.ts @@ -178,7 +178,7 @@ export class Doctor { }); const linkToPakUI = uiLink( - i18n(`${`lib.doctor.accountChecks`}.pak.viewScopes`), + i18n(`lib.doctor.accountChecks.pak.viewScopes`), `${getHubSpotWebsiteOrigin( this.diagnosticInfoBuilder?.env || 'PROD' )}/personal-access-key/${this.diagnosticInfo?.account.accountId}` @@ -219,9 +219,9 @@ export class Doctor { if (portalNotActive) { this.diagnosis?.addCLIConfigSection({ type: 'error', - message: i18n(`${`lib.doctor.accountChecks`}.inactive`), + message: i18n(`lib.doctor.accountChecks.inactive`), secondaryMessaging: i18n( - `${`lib.doctor.accountChecks`}.inactiveSecondary`, + `lib.doctor.accountChecks.inactiveSecondary`, { command: uiCommandReference(`hs accounts clean`), } @@ -237,13 +237,13 @@ export class Doctor { ) { this.diagnosis?.addCLIConfigSection({ type: 'success', - message: i18n(`${`lib.doctor.accountChecks`}.active`), + message: i18n(`lib.doctor.accountChecks.active`), }); this.diagnosis?.addCLIConfigSection({ type: 'error', - message: i18n(`${`lib.doctor.accountChecks`}.pak.invalid`), + message: i18n(`lib.doctor.accountChecks.pak.invalid`), secondaryMessaging: i18n( - `${`lib.doctor.accountChecks`}.pak.invalidSecondary`, + `lib.doctor.accountChecks.pak.invalidSecondary`, { command: uiCommandReference(`hs auth`), } From 14f6d0d5b31a2f029128950b0d836eae6bcb5497 Mon Sep 17 00:00:00 2001 From: Joe Yeager Date: Mon, 28 Apr 2025 13:55:19 -0700 Subject: [PATCH 3/5] more cursor jank --- lib/doctor/Doctor.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/doctor/Doctor.ts b/lib/doctor/Doctor.ts index 651235d11..437d92beb 100644 --- a/lib/doctor/Doctor.ts +++ b/lib/doctor/Doctor.ts @@ -392,7 +392,7 @@ export class Doctor { this.diagnosis?.addProjectSection({ type: 'error', message: i18n( - `${`lib.doctor.projectDependenciesChecks`}.unableToDetermine`, + `lib.doctor.projectDependenciesChecks.unableToDetermine`, { dir: packageDirName, } @@ -407,7 +407,7 @@ export class Doctor { if (!foundError) { this.diagnosis?.addProjectSection({ type: 'success', - message: i18n(`${`lib.doctor.projectDependenciesChecks`}.success`), + message: i18n(`lib.doctor.projectDependenciesChecks.success`), }); } } From 0caaa9bebfca22a9aa8eb7bbed0dbbb71d19d363 Mon Sep 17 00:00:00 2001 From: Joe Yeager Date: Wed, 30 Apr 2025 09:43:16 -0700 Subject: [PATCH 4/5] fix: Correct 'occured' to 'occurred' typo in sandbox error message --- lang/en.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lang/en.ts b/lang/en.ts index d012d4d9e..804eb7fc2 100644 --- a/lang/en.ts +++ b/lang/en.ts @@ -3248,7 +3248,7 @@ export const lib = { instructions: (accountName, url) => `To update CLI permissions for "${accountName}": \n- Go to ${url}, deactivate the existing personal access key, and create a new one that includes developer sandbox permissions. \n- Update the CLI config for this account by running ${chalk.bold('hs auth')} and entering the new key.\n`, }, - generic: 'An error occured while creating a developer sandbox', + generic: 'An error occurred while creating a developer sandbox', }, }, standard: { From 946f9ac90eb7ceb30a22e75504d70fc42bff399f Mon Sep 17 00:00:00 2001 From: Joe Yeager Date: Wed, 30 Apr 2025 09:49:37 -0700 Subject: [PATCH 5/5] fix: Fix additional typos and awkward phrasing in language file --- lang/en.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lang/en.ts b/lang/en.ts index 02f093dfa..3848e6d0f 100644 --- a/lang/en.ts +++ b/lang/en.ts @@ -274,7 +274,7 @@ export const commands = { }, success: { moduleDownloaded: (moduleName, path) => - `"${moduleName}" succesfully downloaded to "${path}"`, + `"${moduleName}" successfully downloaded to "${path}"`, }, errors: { pathExists: path => `Folder already exists at "${path}"`, @@ -3398,7 +3398,7 @@ export const lib = { port: { inUse: port => `Port ${port} is in use`, inUseSecondary: command => - `Make sure it is available if before running ${command}`, + `Make sure it is available before running ${command}`, available: port => `Port ${port} available for local development`, }, diagnosis: {