From 4b83acc896477dc6fe80578224d3d62e36ef6754 Mon Sep 17 00:00:00 2001 From: Joe Yeager Date: Wed, 18 Dec 2024 13:21:14 -0800 Subject: [PATCH] Refactor --- commands/project/upload.ts | 39 ++++++++------------------------------ lib/projects/upload.ts | 23 +++++++++++++++++++++- 2 files changed, 30 insertions(+), 32 deletions(-) diff --git a/commands/project/upload.ts b/commands/project/upload.ts index 715705e3d..3b8c4f2e6 100644 --- a/commands/project/upload.ts +++ b/commands/project/upload.ts @@ -27,12 +27,6 @@ const { PROJECT_ERROR_TYPES } = require('../../lib/constants'); const { logError, ApiErrorContext } = require('../../lib/errorHandlers/index'); const { EXIT_CODES } = require('../../lib/enums/exitCodes'); -const { - translate, - isTranslationError, -} = require('@hubspot/project-parsing-lib'); -const path = require('path'); - const i18nKey = 'commands.project.subcommands.upload'; exports.command = 'upload'; @@ -49,24 +43,6 @@ exports.handler = async options => { const { projectConfig, projectDir } = await getProjectConfig(); - let intermediateRepresentation; - if (options.translate) { - try { - intermediateRepresentation = await translate({ - projectSourceDir: path.join(projectDir, projectConfig.srcDir), - platformVersion: projectConfig.platformVersion, - accountId: derivedAccountId, - }); - } catch (e) { - if (isTranslationError(e)) { - logger.error(e.toString()); - } else { - logError(e); - } - return process.exit(EXIT_CODES.ERROR); - } - } - trackCommandUsage('project-upload', { type: accountType }, derivedAccountId); validateProjectConfig(projectConfig, projectDir); @@ -83,9 +59,11 @@ exports.handler = async options => { projectDir, pollProjectBuildAndDeploy, message, - intermediateRepresentation + options.translate ); + console.log(result); + if (result.uploadError) { if ( isSpecifiedError(result.uploadError, { @@ -155,12 +133,11 @@ exports.builder = yargs => { type: 'string', default: '', }, - }); - - yargs.option('translate', { - hidden: true, - type: 'boolean', - default: false, + translate: { + hidden: true, + type: 'boolean', + default: false, + }, }); yargs.example([['$0 project upload', i18n(`${i18nKey}.examples.default`)]]); diff --git a/lib/projects/upload.ts b/lib/projects/upload.ts index 586b2e9ea..566766d75 100644 --- a/lib/projects/upload.ts +++ b/lib/projects/upload.ts @@ -11,6 +11,8 @@ import { uiAccountDescription } from '../ui'; import { i18n } from '../lang'; import { EXIT_CODES } from '../enums/exitCodes'; import { ProjectConfig } from '../../types/Projects'; +import { isTranslationError, translate } from '@hubspot/project-parsing-lib'; +import { logError } from '../errorHandlers'; const i18nKey = 'lib.projectUpload'; @@ -92,7 +94,7 @@ export async function handleProjectUpload( projectDir: string, callbackFunc: ProjectUploadCallbackFunction, uploadMessage: string, - intermediateRepresentation: unknown + sendIR: boolean = false ) { const srcDir = path.resolve(projectDir, projectConfig.srcDir); @@ -127,6 +129,25 @@ export async function handleProjectUpload( }) ); + let intermediateRepresentation; + + if (sendIR) { + try { + intermediateRepresentation = await translate({ + projectSourceDir: path.join(projectDir, projectConfig.srcDir), + platformVersion: projectConfig.platformVersion, + accountId, + }); + } catch (e) { + if (isTranslationError(e)) { + logger.error(e.toString()); + } else { + logError(e); + } + return process.exit(EXIT_CODES.ERROR); + } + } + const { buildId, error } = await uploadProjectFiles( accountId, projectConfig.name,