From 4f10b9721079631c7dc9cc868f9e05ac229b2adf Mon Sep 17 00:00:00 2001 From: Camden Phalen Date: Thu, 16 Nov 2023 14:44:04 -0500 Subject: [PATCH 1/4] Wip archive --- packages/cli/commands/project/download.js | 11 +++++++++-- packages/cli/lib/logCallbacks.js | 13 +++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 packages/cli/lib/logCallbacks.js diff --git a/packages/cli/commands/project/download.js b/packages/cli/commands/project/download.js index b768d5aea..6216c341f 100644 --- a/packages/cli/commands/project/download.js +++ b/packages/cli/commands/project/download.js @@ -12,7 +12,7 @@ const { ApiErrorContext, } = require('../../lib/errorHandlers/apiErrors'); const { logger } = require('@hubspot/cli-lib/logger'); -const { extractZipArchive } = require('@hubspot/cli-lib/archive'); +const { extractZipArchive } = require('@hubspot/local-dev-lib/archive'); const { downloadProject, fetchProjectBuilds, @@ -24,10 +24,16 @@ const { } = require('../../lib/prompts/downloadProjectPrompt'); const { i18n } = require('../../lib/lang'); const { uiBetaTag } = require('../../lib/ui'); +const { buildLogCallbacks } = require('../../lib/logCallbacks'); const i18nKey = 'cli.commands.project.subcommands.download'; const { EXIT_CODES } = require('../../lib/enums/exitCodes'); +const archiveLogCallbacks = buildLogCallbacks({ + init: 'Extracting project source...', + copy: 'Copying project source...', +}); + exports.command = 'download [--project]'; exports.describe = uiBetaTag(i18n(`${i18nKey}.describe`), false); @@ -93,7 +99,8 @@ exports.handler = async options => { zippedProject, projectName, path.resolve(absoluteDestPath), - { includesRootDir: false } + { includesRootDir: false }, + archiveLogCallbacks ); logger.log( diff --git a/packages/cli/lib/logCallbacks.js b/packages/cli/lib/logCallbacks.js new file mode 100644 index 000000000..28b376b8d --- /dev/null +++ b/packages/cli/lib/logCallbacks.js @@ -0,0 +1,13 @@ +const { logger } = require('@hubspot/cli-lib/logger'); + +function buildLogCallbacks(logData) { + const callbacksObject = {}; + for (let key in logData) { + callbacksObject[key] = () => logger.log(logData[key]); + } + return callbacksObject; +} + +module.exports = { + buildLogCallbacks, +}; From 546e5b956ce565217430e42ee868f04cb9bb7383 Mon Sep 17 00:00:00 2001 From: Camden Phalen Date: Tue, 28 Nov 2023 14:53:35 -0500 Subject: [PATCH 2/4] Update debugErrorAndContext --- packages/cli/lang/en.lyaml | 1 + packages/cli/lib/errorHandlers/standardErrors.js | 14 +++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/packages/cli/lang/en.lyaml b/packages/cli/lang/en.lyaml index 676978750..0501affd0 100644 --- a/packages/cli/lang/en.lyaml +++ b/packages/cli/lang/en.lyaml @@ -1271,6 +1271,7 @@ en: standardErrors: errorOccurred: "Error: {{ error }}" errorContext: "Context: {{ context }}" + errorCause: "Cause: {{ cause }}" systemErrorOccurred: "A system error has occurred: {{ errorMessage }}" genericErrorOccurred: "A {{ name }} has occurred." unknownErrorOccurred: "An unknown error has occurred" diff --git a/packages/cli/lib/errorHandlers/standardErrors.js b/packages/cli/lib/errorHandlers/standardErrors.js index 92751b67e..66995c5fb 100644 --- a/packages/cli/lib/errorHandlers/standardErrors.js +++ b/packages/cli/lib/errorHandlers/standardErrors.js @@ -1,3 +1,4 @@ +const util = require('util'); const { HubSpotAuthError } = require('@hubspot/cli-lib/lib/models/Errors'); const { logger } = require('@hubspot/cli-lib/logger'); const { i18n } = require('../lang'); @@ -40,7 +41,18 @@ function debugErrorAndContext(error, context) { } else { logger.debug(i18n(`${i18nKey}.errorOccurred`, { error })); } - logger.debug(i18n(`${i18nKey}.errorContext`, { context })); + if (error.cause) { + logger.debug( + i18n(`${i18nKey}.errorCause`, { + cause: util.inspect(error.cause, false, null, true), + }) + ); + } + logger.debug( + i18n(`${i18nKey}.errorContext`, { + context: util.inspect(context, false, null, true), + }) + ); } /** From 6dea74bf16889c43bf422bae5f1e92d4191639b9 Mon Sep 17 00:00:00 2001 From: Camden Phalen Date: Tue, 28 Nov 2023 15:02:17 -0500 Subject: [PATCH 3/4] port init --- packages/cli/commands/init.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/cli/commands/init.js b/packages/cli/commands/init.js index 247673dba..a857562b7 100644 --- a/packages/cli/commands/init.js +++ b/packages/cli/commands/init.js @@ -8,7 +8,9 @@ const { } = require('@hubspot/local-dev-lib/config'); const { addConfigOptions } = require('../lib/commonOpts'); const { handleExit } = require('../lib/process'); -const { checkAndUpdateGitignore } = require('@hubspot/cli-lib/lib/git'); +const { + checkAndAddConfigToGitignore, +} = require('@hubspot/local-dev-lib/gitignore'); const { logErrorInstance } = require('../lib/errorHandlers/standardErrors'); const { DEFAULT_HUBSPOT_CONFIG_YAML_FILE_NAME, @@ -117,7 +119,7 @@ exports.handler = async options => { ); const configPath = getConfigPath(); - checkAndUpdateGitignore(configPath); + checkAndAddConfigToGitignore(configPath); logger.log(''); logger.success( From 6661e303a03172b7c42df7bf0717df120101959e Mon Sep 17 00:00:00 2001 From: Camden Phalen Date: Mon, 4 Dec 2023 11:43:34 -0500 Subject: [PATCH 4/4] Clean up things, use i18n in buildLogCallbacks --- packages/cli/commands/init.js | 11 +++++++++-- packages/cli/commands/project/download.js | 4 ++-- packages/cli/lang/en.lyaml | 3 +++ packages/cli/lib/logCallbacks.js | 3 ++- 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/packages/cli/commands/init.js b/packages/cli/commands/init.js index a857562b7..199a10185 100644 --- a/packages/cli/commands/init.js +++ b/packages/cli/commands/init.js @@ -11,7 +11,10 @@ const { handleExit } = require('../lib/process'); const { checkAndAddConfigToGitignore, } = require('@hubspot/local-dev-lib/gitignore'); -const { logErrorInstance } = require('../lib/errorHandlers/standardErrors'); +const { + logErrorInstance, + debugErrorAndContext, +} = require('../lib/errorHandlers/standardErrors'); const { DEFAULT_HUBSPOT_CONFIG_YAML_FILE_NAME, PERSONAL_ACCESS_KEY_AUTH_METHOD, @@ -119,7 +122,11 @@ exports.handler = async options => { ); const configPath = getConfigPath(); - checkAndAddConfigToGitignore(configPath); + try { + checkAndAddConfigToGitignore(configPath); + } catch (e) { + debugErrorAndContext(e); + } logger.log(''); logger.success( diff --git a/packages/cli/commands/project/download.js b/packages/cli/commands/project/download.js index 6216c341f..36a5d8b12 100644 --- a/packages/cli/commands/project/download.js +++ b/packages/cli/commands/project/download.js @@ -30,8 +30,8 @@ const i18nKey = 'cli.commands.project.subcommands.download'; const { EXIT_CODES } = require('../../lib/enums/exitCodes'); const archiveLogCallbacks = buildLogCallbacks({ - init: 'Extracting project source...', - copy: 'Copying project source...', + init: `${i18nKey}.archiveLogCallbacks.init`, + copy: `${i18nKey}.archiveLogCallbacks.copy`, }); exports.command = 'download [--project]'; diff --git a/packages/cli/lang/en.lyaml b/packages/cli/lang/en.lyaml index 0501affd0..c603cb476 100644 --- a/packages/cli/lang/en.lyaml +++ b/packages/cli/lang/en.lyaml @@ -631,6 +631,9 @@ en: describe: "The name of the project to download" dest: describe: "Destination folder for the project" + archiveLogCallbacks: + init: "Extracting project source..." + copy: "Copying project source..." open: describe: "Open the specified project's details page in the browser" options: diff --git a/packages/cli/lib/logCallbacks.js b/packages/cli/lib/logCallbacks.js index 28b376b8d..9608c95cc 100644 --- a/packages/cli/lib/logCallbacks.js +++ b/packages/cli/lib/logCallbacks.js @@ -1,9 +1,10 @@ const { logger } = require('@hubspot/cli-lib/logger'); +const { i18n } = require('./lang'); function buildLogCallbacks(logData) { const callbacksObject = {}; for (let key in logData) { - callbacksObject[key] = () => logger.log(logData[key]); + callbacksObject[key] = () => logger.log(i18n(logData[key])); } return callbacksObject; }