Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
joe-yeager committed Dec 18, 2024
1 parent 42a3fed commit 4b83acc
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 32 deletions.
39 changes: 8 additions & 31 deletions commands/project/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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);
Expand All @@ -83,9 +59,11 @@ exports.handler = async options => {
projectDir,
pollProjectBuildAndDeploy,
message,
intermediateRepresentation
options.translate
);

console.log(result);

if (result.uploadError) {
if (
isSpecifiedError(result.uploadError, {
Expand Down Expand Up @@ -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`)]]);
Expand Down
23 changes: 22 additions & 1 deletion lib/projects/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -92,7 +94,7 @@ export async function handleProjectUpload<T = ProjectUploadDefaultResult>(
projectDir: string,
callbackFunc: ProjectUploadCallbackFunction<T>,
uploadMessage: string,
intermediateRepresentation: unknown
sendIR: boolean = false
) {
const srcDir = path.resolve(projectDir, projectConfig.srcDir);

Expand Down Expand Up @@ -127,6 +129,25 @@ export async function handleProjectUpload<T = ProjectUploadDefaultResult>(
})
);

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,
Expand Down

0 comments on commit 4b83acc

Please sign in to comment.