From 59b1e42b344351d68ec56bb72c8a8203965222ef Mon Sep 17 00:00:00 2001 From: Joe Yeager Date: Wed, 20 Nov 2024 15:20:29 -0800 Subject: [PATCH 01/10] feat: Add translation to IR --- commands/project/upload.ts | 17 +++++++++++++++-- package.json | 1 + yarn.lock | 7 ++++++- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/commands/project/upload.ts b/commands/project/upload.ts index 745c195b4..31c00d50b 100644 --- a/commands/project/upload.ts +++ b/commands/project/upload.ts @@ -26,6 +26,8 @@ const { PROJECT_ERROR_TYPES } = require('../../lib/constants'); const { logError, ApiErrorContext } = require('../../lib/errorHandlers/index'); const { EXIT_CODES } = require('../../lib/enums/exitCodes'); +const { translate } = require('@hubspot/project-parsing-lib'); + const i18nKey = 'commands.project.subcommands.upload'; exports.command = 'upload [path] [--forceCreate] [--message]'; @@ -39,10 +41,15 @@ exports.handler = async options => { const accountConfig = getAccountConfig(accountId); const accountType = accountConfig && accountConfig.accountType; - trackCommandUsage('project-upload', { type: accountType }, accountId); - const { projectConfig, projectDir } = await getProjectConfig(projectPath); + if (options.translate) { + console.log(await translate(projectDir, projectConfig)); + return process.exit(EXIT_CODES.SUCCESS); + } + + trackCommandUsage('project-upload', { type: accountType }, accountId); + validateProjectConfig(projectConfig, projectDir); await ensureProjectExists(accountId, projectConfig.name, { @@ -124,6 +131,12 @@ exports.builder = yargs => { default: '', }); + yargs.option('translate', { + describe: 'Translate the project files', + type: 'boolean', + default: false, + }); + yargs.example([ ['$0 project upload myProjectFolder', i18n(`${i18nKey}.examples.default`)], ]); diff --git a/package.json b/package.json index 111957b33..a1dc27cb4 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,7 @@ "repository": "https://github.com/HubSpot/hubspot-cli", "dependencies": { "@hubspot/local-dev-lib": "2.3.0", + "@hubspot/project-parsing-lib": "file:../project-translation-layer", "@hubspot/serverless-dev-runtime": "7.0.0", "@hubspot/theme-preview-dev-server": "0.0.9", "@hubspot/ui-extensions-dev-server": "0.8.33", diff --git a/yarn.lock b/yarn.lock index 86240780f..daf9eba2a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -457,7 +457,7 @@ express "^4.18.2" uuid "^9.0.1" -"@hubspot/local-dev-lib@2.3.0": +"@hubspot/local-dev-lib@2.3.0", "@hubspot/local-dev-lib@^2.3.0": version "2.3.0" resolved "https://registry.yarnpkg.com/@hubspot/local-dev-lib/-/local-dev-lib-2.3.0.tgz#3350b9902adb00b1b927d049197e7333501d90fe" integrity sha512-ovWE0XjuzzdyJoQ9rFXIYLotNCfowfMbN+8eIlBUu89uzBcWUZj+VQudU6GN15RlPS8ZTSSvVFnCcMxNJv1IKw== @@ -481,6 +481,11 @@ semver "^6.3.0" unixify "^1.0.0" +"@hubspot/project-parsing-lib@file:../project-translation-layer": + version "0.0.1" + dependencies: + "@hubspot/local-dev-lib" "^2.3.0" + "@hubspot/serverless-dev-runtime@7.0.0": version "7.0.0" resolved "https://registry.yarnpkg.com/@hubspot/serverless-dev-runtime/-/serverless-dev-runtime-7.0.0.tgz#dffe8101e3a9b79fa768691daa2c9ba1f86c25d6" From eec83c253e3933e1ccf6c501fa849b5b83b9638d Mon Sep 17 00:00:00 2001 From: Joe Yeager Date: Thu, 21 Nov 2024 14:24:22 -0800 Subject: [PATCH 02/10] Move the project loading to the CLI --- commands/project/upload.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/commands/project/upload.ts b/commands/project/upload.ts index 31c00d50b..6e14ba1a1 100644 --- a/commands/project/upload.ts +++ b/commands/project/upload.ts @@ -27,6 +27,7 @@ const { logError, ApiErrorContext } = require('../../lib/errorHandlers/index'); const { EXIT_CODES } = require('../../lib/enums/exitCodes'); const { translate } = require('@hubspot/project-parsing-lib'); +const path = require('path'); const i18nKey = 'commands.project.subcommands.upload'; @@ -44,7 +45,7 @@ exports.handler = async options => { const { projectConfig, projectDir } = await getProjectConfig(projectPath); if (options.translate) { - console.log(await translate(projectDir, projectConfig)); + console.log(await translate(path.join(projectDir, projectConfig.srcDir))); return process.exit(EXIT_CODES.SUCCESS); } From 1dffb6e35fd28600ce295e857bbd5bf7decc10f2 Mon Sep 17 00:00:00 2001 From: Joe Yeager Date: Mon, 9 Dec 2024 13:22:31 -0800 Subject: [PATCH 03/10] Add error handling --- commands/project/upload.ts | 24 ++++++++++++++++++++++-- yarn.lock | 3 ++- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/commands/project/upload.ts b/commands/project/upload.ts index 6e14ba1a1..99ea6cebb 100644 --- a/commands/project/upload.ts +++ b/commands/project/upload.ts @@ -1,4 +1,6 @@ // @ts-nocheck +import util from 'util'; + const { addAccountOptions, addConfigOptions, @@ -26,7 +28,10 @@ const { PROJECT_ERROR_TYPES } = require('../../lib/constants'); const { logError, ApiErrorContext } = require('../../lib/errorHandlers/index'); const { EXIT_CODES } = require('../../lib/enums/exitCodes'); -const { translate } = require('@hubspot/project-parsing-lib'); +const { + translate, + isTranslationError, +} = require('@hubspot/project-parsing-lib'); const path = require('path'); const i18nKey = 'commands.project.subcommands.upload'; @@ -45,7 +50,22 @@ exports.handler = async options => { const { projectConfig, projectDir } = await getProjectConfig(projectPath); if (options.translate) { - console.log(await translate(path.join(projectDir, projectConfig.srcDir))); + try { + console.log( + util.inspect( + await translate(path.join(projectDir, projectConfig.srcDir)), + true, + 3, + true + ) + ); + } catch (e) { + if (isTranslationError(e)) { + return logger.error(e.toString()); + } + logError(e); + return process.exit(EXIT_CODES.ERROR); + } return process.exit(EXIT_CODES.SUCCESS); } diff --git a/yarn.lock b/yarn.lock index daf9eba2a..ab15ff3bf 100644 --- a/yarn.lock +++ b/yarn.lock @@ -485,6 +485,7 @@ version "0.0.1" dependencies: "@hubspot/local-dev-lib" "^2.3.0" + ajv "^8.17.1" "@hubspot/serverless-dev-runtime@7.0.0": version "7.0.0" @@ -1275,7 +1276,7 @@ ajv@^6.12.4: json-schema-traverse "^0.4.1" uri-js "^4.2.2" -ajv@^8.0.1: +ajv@^8.0.1, ajv@^8.17.1: version "8.17.1" resolved "https://registry.yarnpkg.com/ajv/-/ajv-8.17.1.tgz#37d9a5c776af6bc92d7f4f9510eba4c0a60d11a6" integrity sha512-B/gBuNg5SiMTrPkC+A2+cW0RszwxYmn6VYxB/inlBStS5nx6xHIt/ehKRhIMhqusl7a8LjQoZnjCs5vhwxOQ1g== From 7448eb6f17d78051837555b475ee18a3637c4aae Mon Sep 17 00:00:00 2001 From: Joe Yeager Date: Wed, 11 Dec 2024 11:43:30 -0800 Subject: [PATCH 04/10] Add logging for now --- commands/project/upload.ts | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/commands/project/upload.ts b/commands/project/upload.ts index 99ea6cebb..0f9f036d2 100644 --- a/commands/project/upload.ts +++ b/commands/project/upload.ts @@ -51,14 +51,10 @@ exports.handler = async options => { if (options.translate) { try { - console.log( - util.inspect( - await translate(path.join(projectDir, projectConfig.srcDir)), - true, - 3, - true - ) + const translation = await translate( + path.join(projectDir, projectConfig.srcDir) ); + console.log(util.inspect(translation, false, null, true)); } catch (e) { if (isTranslationError(e)) { return logger.error(e.toString()); From 0c855dbfe231c4dac0092d69daa14a175d6ae0ce Mon Sep 17 00:00:00 2001 From: Joe Yeager Date: Fri, 13 Dec 2024 11:26:34 -0800 Subject: [PATCH 05/10] Update upload flow --- commands/project/upload.ts | 15 +++++++++------ lib/projects.ts | 37 ++++++++++++++++++++++++++----------- yarn.lock | 34 ++++++++++++++++++++++++++++++++-- 3 files changed, 67 insertions(+), 19 deletions(-) diff --git a/commands/project/upload.ts b/commands/project/upload.ts index 0f9f036d2..d993a5af0 100644 --- a/commands/project/upload.ts +++ b/commands/project/upload.ts @@ -49,12 +49,15 @@ exports.handler = async options => { const { projectConfig, projectDir } = await getProjectConfig(projectPath); + let intermediateRepresentation; if (options.translate) { try { - const translation = await translate( - path.join(projectDir, projectConfig.srcDir) - ); - console.log(util.inspect(translation, false, null, true)); + intermediateRepresentation = await translate({ + projectSourceDir: path.join(projectDir, projectConfig.srcDir), + platformVersion: projectConfig.platformVersion, + accountId, + }); + console.log(util.inspect(intermediateRepresentation, false, null, true)); } catch (e) { if (isTranslationError(e)) { return logger.error(e.toString()); @@ -62,7 +65,6 @@ exports.handler = async options => { logError(e); return process.exit(EXIT_CODES.ERROR); } - return process.exit(EXIT_CODES.SUCCESS); } trackCommandUsage('project-upload', { type: accountType }, accountId); @@ -80,7 +82,8 @@ exports.handler = async options => { projectConfig, projectDir, pollProjectBuildAndDeploy, - message + message, + intermediateRepresentation ); if (result.uploadError) { diff --git a/lib/projects.ts b/lib/projects.ts index 658df28f7..8b3ddcbef 100644 --- a/lib/projects.ts +++ b/lib/projects.ts @@ -342,7 +342,8 @@ const uploadProjectFiles = async ( projectName, filePath, uploadMessage, - platformVersion + platformVersion, + intermediateRepresentation ) => { SpinniesManager.init({}); const accountIdentifier = uiAccountDescription(accountId); @@ -359,15 +360,27 @@ const uploadProjectFiles = async ( let error; try { - const { data: upload } = await uploadProject( - accountId, - projectName, - filePath, - uploadMessage, - platformVersion - ); + if (intermediateRepresentation) { + const { data: upload } = await uploadProject( + accountId, + projectName, + filePath, + uploadMessage, + platformVersion, + intermediateRepresentation + ); + buildId = upload.buildId; + } else { + const { data: upload } = await uploadProject( + accountId, + projectName, + filePath, + uploadMessage, + platformVersion + ); - buildId = upload.buildId; + buildId = upload.buildId; + } SpinniesManager.succeed('upload', { text: i18n(`${i18nKey}.uploadProjectFiles.succeed`, { @@ -511,7 +524,8 @@ const handleProjectUpload = async ( projectConfig, projectDir, callbackFunc, - uploadMessage + uploadMessage, + intermediateRepresentation ) => { const srcDir = path.resolve(projectDir, projectConfig.srcDir); @@ -551,7 +565,8 @@ const handleProjectUpload = async ( projectConfig.name, tempFile.name, uploadMessage, - projectConfig.platformVersion + projectConfig.platformVersion, + intermediateRepresentation ); if (error) { diff --git a/yarn.lock b/yarn.lock index 8981759f0..6a9b29ce0 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1463,7 +1463,7 @@ semver "^6.3.0" unixify "^1.0.0" -"@hubspot/local-dev-lib@2.3.0", "@hubspot/local-dev-lib@^2.3.0": +"@hubspot/local-dev-lib@2.3.0": version "2.3.0" resolved "https://registry.yarnpkg.com/@hubspot/local-dev-lib/-/local-dev-lib-2.3.0.tgz#3350b9902adb00b1b927d049197e7333501d90fe" integrity sha512-ovWE0XjuzzdyJoQ9rFXIYLotNCfowfMbN+8eIlBUu89uzBcWUZj+VQudU6GN15RlPS8ZTSSvVFnCcMxNJv1IKw== @@ -1487,11 +1487,36 @@ semver "^6.3.0" unixify "^1.0.0" +"@hubspot/local-dev-lib@^3.0.1": + version "3.0.1" + resolved "https://registry.yarnpkg.com/@hubspot/local-dev-lib/-/local-dev-lib-3.0.1.tgz#1dd22f439d6e262353f14915a354115bbc1f5f76" + integrity sha512-h1jOmZJNdHZFbrOA5Gn815YCsix8eY81A4dkrUuDZI4MzVaJH3o4RoRalMl+Hr2e35nDrbrbcIR1RMQADPSmwg== + dependencies: + address "^2.0.1" + axios "^1.3.5" + chalk "^2.4.2" + chokidar "^3.5.3" + content-disposition "^0.5.4" + cors "^2.8.5" + debounce "^1.2.0" + express "^4.18.2" + extract-zip "^2.0.1" + findup-sync "^5.0.0" + fs-extra "^11.1.0" + ignore "^5.1.4" + js-yaml "^4.1.0" + moment "^2.29.4" + p-queue "^6.0.2" + prettier "^3.3.0" + semver "^6.3.0" + unixify "^1.0.0" + "@hubspot/project-parsing-lib@file:../project-translation-layer": version "0.0.1" dependencies: - "@hubspot/local-dev-lib" "^2.3.0" + "@hubspot/local-dev-lib" "^3.0.1" ajv "^8.17.1" + ajv-draft-04 "^1.0.0" "@hubspot/serverless-dev-runtime@7.0.0": version "7.0.0" @@ -3862,6 +3887,11 @@ aggregate-error@^3.0.0: clean-stack "^2.0.0" indent-string "^4.0.0" +ajv-draft-04@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/ajv-draft-04/-/ajv-draft-04-1.0.0.tgz#3b64761b268ba0b9e668f0b41ba53fce0ad77fc8" + integrity sha512-mv00Te6nmYbRp5DCwclxtt7yV/joXJPGS7nM+97GdxvuttCOfgI3K4U25zboyeX0O+myI8ERluxQe5wljMmVIw== + ajv@^6.12.3, ajv@^6.12.4: version "6.12.6" resolved "https://registry.yarnpkg.com/ajv/-/ajv-6.12.6.tgz#baf5a62e802b07d977034586f8c3baf5adf26df4" From 34b23c643fb920d11c1c1e30b69322cdd395a871 Mon Sep 17 00:00:00 2001 From: Joe Yeager Date: Wed, 18 Dec 2024 12:46:20 -0800 Subject: [PATCH 06/10] clean up --- commands/project/upload.ts | 14 ++++---- lib/projects.ts | 35 +++++++------------ package.json | 4 +-- yarn.lock | 70 +++++++------------------------------- 4 files changed, 32 insertions(+), 91 deletions(-) diff --git a/commands/project/upload.ts b/commands/project/upload.ts index 26aacb356..9a0ae0507 100644 --- a/commands/project/upload.ts +++ b/commands/project/upload.ts @@ -1,6 +1,4 @@ // @ts-nocheck -import util from 'util'; - const { addAccountOptions, addConfigOptions, @@ -55,19 +53,19 @@ exports.handler = async options => { intermediateRepresentation = await translate({ projectSourceDir: path.join(projectDir, projectConfig.srcDir), platformVersion: projectConfig.platformVersion, - accountId, + accountId: derivedAccountId, }); - console.log(util.inspect(intermediateRepresentation, false, null, true)); } catch (e) { if (isTranslationError(e)) { - return logger.error(e.toString()); + logger.error(e.toString()); + } else { + logError(e); } - logError(e); return process.exit(EXIT_CODES.ERROR); } } - trackCommandUsage('project-upload', { type: accountType }, accountId); + trackCommandUsage('project-upload', { type: accountType }, derivedAccountId); validateProjectConfig(projectConfig, projectDir); @@ -158,7 +156,7 @@ exports.builder = yargs => { }); yargs.option('translate', { - describe: 'Translate the project files', + hidden: true, type: 'boolean', default: false, }); diff --git a/lib/projects.ts b/lib/projects.ts index dcd6041da..6fbeb9ad4 100644 --- a/lib/projects.ts +++ b/lib/projects.ts @@ -369,27 +369,15 @@ const uploadProjectFiles = async ( let error; try { - if (intermediateRepresentation) { - const { data: upload } = await uploadProject( - accountId, - projectName, - filePath, - uploadMessage, - platformVersion, - intermediateRepresentation - ); - buildId = upload.buildId; - } else { - const { data: upload } = await uploadProject( - accountId, - projectName, - filePath, - uploadMessage, - platformVersion - ); - - buildId = upload.buildId; - } + const { data: upload } = await uploadProject( + accountId, + projectName, + filePath, + uploadMessage, + platformVersion, + intermediateRepresentation + ); + buildId = upload.buildId; SpinniesManager.succeed('upload', { text: i18n(`${i18nKey}.uploadProjectFiles.succeed`, { @@ -411,7 +399,6 @@ const uploadProjectFiles = async ( projectName, }), }); - error = err; } @@ -569,7 +556,7 @@ const handleProjectUpload = async ( }) ); - const { buildId, error } = await uploadProjectFiles( + const data = await uploadProjectFiles( accountId, projectConfig.name, tempFile.name, @@ -578,6 +565,8 @@ const handleProjectUpload = async ( intermediateRepresentation ); + const { buildId, error } = data; + if (error) { uploadResult.uploadError = error; } else if (callbackFunc) { diff --git a/package.json b/package.json index 2353a0103..feebca16d 100644 --- a/package.json +++ b/package.json @@ -5,8 +5,8 @@ "license": "Apache-2.0", "repository": "https://github.com/HubSpot/hubspot-cli", "dependencies": { - "@hubspot/local-dev-lib": "3.0.1", - "@hubspot/project-parsing-lib": "file:../project-translation-layer", + "@hubspot/local-dev-lib": "^3.1.0", + "@hubspot/project-parsing-lib": "^0.0.1", "@hubspot/serverless-dev-runtime": "7.0.0", "@hubspot/theme-preview-dev-server": "0.0.10", "@hubspot/ui-extensions-dev-server": "0.8.33", diff --git a/yarn.lock b/yarn.lock index a6b21b715..88e0a90e7 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1463,34 +1463,10 @@ semver "^6.3.0" unixify "^1.0.0" -"@hubspot/local-dev-lib@3.0.1": - version "3.0.1" - resolved "https://registry.yarnpkg.com/@hubspot/local-dev-lib/-/local-dev-lib-3.0.1.tgz#1dd22f439d6e262353f14915a354115bbc1f5f76" - integrity sha512-h1jOmZJNdHZFbrOA5Gn815YCsix8eY81A4dkrUuDZI4MzVaJH3o4RoRalMl+Hr2e35nDrbrbcIR1RMQADPSmwg== - dependencies: - address "^2.0.1" - axios "^1.3.5" - chalk "^2.4.2" - chokidar "^3.5.3" - content-disposition "^0.5.4" - cors "^2.8.5" - debounce "^1.2.0" - express "^4.18.2" - extract-zip "^2.0.1" - findup-sync "^5.0.0" - fs-extra "^11.1.0" - ignore "^5.1.4" - js-yaml "^4.1.0" - moment "^2.29.4" - p-queue "^6.0.2" - prettier "^3.3.0" - semver "^6.3.0" - unixify "^1.0.0" - -"@hubspot/local-dev-lib@^3.0.1": - version "3.0.1" - resolved "https://registry.yarnpkg.com/@hubspot/local-dev-lib/-/local-dev-lib-3.0.1.tgz#1dd22f439d6e262353f14915a354115bbc1f5f76" - integrity sha512-h1jOmZJNdHZFbrOA5Gn815YCsix8eY81A4dkrUuDZI4MzVaJH3o4RoRalMl+Hr2e35nDrbrbcIR1RMQADPSmwg== +"@hubspot/local-dev-lib@^3.1.0": + version "3.1.0" + resolved "https://registry.yarnpkg.com/@hubspot/local-dev-lib/-/local-dev-lib-3.1.0.tgz#76b5d524aa694aad2bfc6e199ee1dac314f15774" + integrity sha512-iop3PgZ0ZWejCH6PmSeYnnGwV8vGIuA4F+w7SxukdX3QfhivlczClATWPaZanv1CYJHdflqoItq1kdF8ASJJmA== dependencies: address "^2.0.1" axios "^1.3.5" @@ -1511,10 +1487,12 @@ semver "^6.3.0" unixify "^1.0.0" -"@hubspot/project-parsing-lib@file:../project-translation-layer": +"@hubspot/project-parsing-lib@^0.0.1": version "0.0.1" + resolved "https://registry.yarnpkg.com/@hubspot/project-parsing-lib/-/project-parsing-lib-0.0.1.tgz#fd1f823abbe410d97446bd5fc804b2e9bf40402e" + integrity sha512-7Qqc6YplKTYG2skswVtNc02iCIuPd816vZT3I4HTYzJRQ9EqYTPZ7QLrL9VSTkLNkUyHw0AJE1qeQJqye1eAfQ== dependencies: - "@hubspot/local-dev-lib" "^3.0.1" + "@hubspot/local-dev-lib" "^3.1.0" ajv "^8.17.1" ajv-draft-04 "^1.0.0" @@ -10463,16 +10441,7 @@ string-length@^4.0.1: char-regex "^1.0.2" strip-ansi "^6.0.0" -"string-width-cjs@npm:string-width@^4.2.0": - version "4.2.3" - resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010" - integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g== - dependencies: - emoji-regex "^8.0.0" - is-fullwidth-code-point "^3.0.0" - strip-ansi "^6.0.1" - -string-width@^4.0.0, string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.2, string-width@^4.2.3: +"string-width-cjs@npm:string-width@^4.2.0", string-width@^4.0.0, string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.2, string-width@^4.2.3: version "4.2.3" resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010" integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g== @@ -10541,7 +10510,7 @@ stringify-object@^3.2.1, stringify-object@^3.3.0: is-obj "^1.0.1" is-regexp "^1.0.0" -"strip-ansi-cjs@npm:strip-ansi@^6.0.1": +"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1: version "6.0.1" resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9" integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A== @@ -10555,13 +10524,6 @@ strip-ansi@^5.2.0: dependencies: ansi-regex "^4.1.0" -strip-ansi@^6.0.0, strip-ansi@^6.0.1: - version "6.0.1" - resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9" - integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A== - dependencies: - ansi-regex "^5.0.1" - strip-ansi@^7.0.1: version "7.1.0" resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-7.1.0.tgz#d5b6568ca689d8561370b0707685d22434faff45" @@ -11548,7 +11510,8 @@ wordwrap@^1.0.0: resolved "https://registry.yarnpkg.com/wordwrap/-/wordwrap-1.0.0.tgz#27584810891456a4171c8d0226441ade90cbcaeb" integrity sha512-gvVzJFlPycKc5dZN4yPkP8w7Dc37BtP1yczEneOb4uq34pXZcvrtRTmWV8W+Ume+XCxKgbjM+nevkyFPMybd4Q== -"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0": +"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0: + name wrap-ansi-cjs version "7.0.0" resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43" integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q== @@ -11566,15 +11529,6 @@ wrap-ansi@^6.2.0: string-width "^4.1.0" strip-ansi "^6.0.0" -wrap-ansi@^7.0.0: - version "7.0.0" - resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43" - integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q== - dependencies: - ansi-styles "^4.0.0" - string-width "^4.1.0" - strip-ansi "^6.0.0" - wrap-ansi@^8.1.0: version "8.1.0" resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-8.1.0.tgz#56dc22368ee570face1b49819975d9b9a5ead214" From 61f2845ba38a1613f915756abbc0d1ac466e8aed Mon Sep 17 00:00:00 2001 From: Joe Yeager Date: Wed, 18 Dec 2024 12:57:24 -0800 Subject: [PATCH 07/10] Fix lockfile --- package.json | 2 +- yarn.lock | 56 +++++++++++++++++++++------------------------------- 2 files changed, 24 insertions(+), 34 deletions(-) diff --git a/package.json b/package.json index 3dd3ca245..2189b80d7 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "repository": "https://github.com/HubSpot/hubspot-cli", "dependencies": { "@hubspot/local-dev-lib": "^3.1.0", - "@hubspot/project-parsing-lib": "^0.0.2", + "@hubspot/project-parsing-lib": "^0.0.1", "@hubspot/serverless-dev-runtime": "7.0.0", "@hubspot/theme-preview-dev-server": "0.0.10", "@hubspot/ui-extensions-dev-server": "0.8.33", diff --git a/yarn.lock b/yarn.lock index d0ed5ab61..8e38168d4 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1463,10 +1463,10 @@ semver "^6.3.0" unixify "^1.0.0" -"@hubspot/local-dev-lib@3.0.2": - version "3.0.2" - resolved "https://registry.yarnpkg.com/@hubspot/local-dev-lib/-/local-dev-lib-3.0.2.tgz#8412c26c51d26cdb015312f5c5ac2daeced5e30f" - integrity sha512-brpFWcQIdP71YzwQ2ZMKqChzIEo4cCLJYPCTTVmMUwmuXtL35T/7vL06OukNEND5+B8VlmZeJ4PMrvsAT4YuWA== +"@hubspot/local-dev-lib@^3.1.0": + version "3.1.0" + resolved "https://registry.yarnpkg.com/@hubspot/local-dev-lib/-/local-dev-lib-3.1.0.tgz#76b5d524aa694aad2bfc6e199ee1dac314f15774" + integrity sha512-iop3PgZ0ZWejCH6PmSeYnnGwV8vGIuA4F+w7SxukdX3QfhivlczClATWPaZanv1CYJHdflqoItq1kdF8ASJJmA== dependencies: address "^2.0.1" axios "^1.3.5" @@ -1487,6 +1487,15 @@ semver "^6.3.0" unixify "^1.0.0" +"@hubspot/project-parsing-lib@^0.0.1": + version "0.0.1" + resolved "https://registry.yarnpkg.com/@hubspot/project-parsing-lib/-/project-parsing-lib-0.0.1.tgz#fd1f823abbe410d97446bd5fc804b2e9bf40402e" + integrity sha512-7Qqc6YplKTYG2skswVtNc02iCIuPd816vZT3I4HTYzJRQ9EqYTPZ7QLrL9VSTkLNkUyHw0AJE1qeQJqye1eAfQ== + dependencies: + "@hubspot/local-dev-lib" "^3.1.0" + ajv "^8.17.1" + ajv-draft-04 "^1.0.0" + "@hubspot/serverless-dev-runtime@7.0.0": version "7.0.0" resolved "https://registry.yarnpkg.com/@hubspot/serverless-dev-runtime/-/serverless-dev-runtime-7.0.0.tgz#dffe8101e3a9b79fa768691daa2c9ba1f86c25d6" @@ -3914,6 +3923,11 @@ aggregate-error@^3.0.0: clean-stack "^2.0.0" indent-string "^4.0.0" +ajv-draft-04@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/ajv-draft-04/-/ajv-draft-04-1.0.0.tgz#3b64761b268ba0b9e668f0b41ba53fce0ad77fc8" + integrity sha512-mv00Te6nmYbRp5DCwclxtt7yV/joXJPGS7nM+97GdxvuttCOfgI3K4U25zboyeX0O+myI8ERluxQe5wljMmVIw== + ajv@^6.12.3, ajv@^6.12.4: version "6.12.6" resolved "https://registry.yarnpkg.com/ajv/-/ajv-6.12.6.tgz#baf5a62e802b07d977034586f8c3baf5adf26df4" @@ -3924,7 +3938,7 @@ ajv@^6.12.3, ajv@^6.12.4: json-schema-traverse "^0.4.1" uri-js "^4.2.2" -ajv@^8.0.1: +ajv@^8.0.1, ajv@^8.17.1: version "8.17.1" resolved "https://registry.yarnpkg.com/ajv/-/ajv-8.17.1.tgz#37d9a5c776af6bc92d7f4f9510eba4c0a60d11a6" integrity sha512-B/gBuNg5SiMTrPkC+A2+cW0RszwxYmn6VYxB/inlBStS5nx6xHIt/ehKRhIMhqusl7a8LjQoZnjCs5vhwxOQ1g== @@ -10485,16 +10499,7 @@ string-length@^4.0.1: char-regex "^1.0.2" strip-ansi "^6.0.0" -"string-width-cjs@npm:string-width@^4.2.0": - version "4.2.3" - resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010" - integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g== - dependencies: - emoji-regex "^8.0.0" - is-fullwidth-code-point "^3.0.0" - strip-ansi "^6.0.1" - -string-width@^4.0.0, string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.2, string-width@^4.2.3: +"string-width-cjs@npm:string-width@^4.2.0", string-width@^4.0.0, string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.2, string-width@^4.2.3: version "4.2.3" resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010" integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g== @@ -10563,7 +10568,7 @@ stringify-object@^3.2.1, stringify-object@^3.3.0: is-obj "^1.0.1" is-regexp "^1.0.0" -"strip-ansi-cjs@npm:strip-ansi@^6.0.1": +"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1: version "6.0.1" resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9" integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A== @@ -10577,13 +10582,6 @@ strip-ansi@^5.2.0: dependencies: ansi-regex "^4.1.0" -strip-ansi@^6.0.0, strip-ansi@^6.0.1: - version "6.0.1" - resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9" - integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A== - dependencies: - ansi-regex "^5.0.1" - strip-ansi@^7.0.1: version "7.1.0" resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-7.1.0.tgz#d5b6568ca689d8561370b0707685d22434faff45" @@ -11570,7 +11568,8 @@ wordwrap@^1.0.0: resolved "https://registry.yarnpkg.com/wordwrap/-/wordwrap-1.0.0.tgz#27584810891456a4171c8d0226441ade90cbcaeb" integrity sha512-gvVzJFlPycKc5dZN4yPkP8w7Dc37BtP1yczEneOb4uq34pXZcvrtRTmWV8W+Ume+XCxKgbjM+nevkyFPMybd4Q== -"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0": +"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0: + name wrap-ansi-cjs version "7.0.0" resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43" integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q== @@ -11588,15 +11587,6 @@ wrap-ansi@^6.2.0: string-width "^4.1.0" strip-ansi "^6.0.0" -wrap-ansi@^7.0.0: - version "7.0.0" - resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43" - integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q== - dependencies: - ansi-styles "^4.0.0" - string-width "^4.1.0" - strip-ansi "^6.0.0" - wrap-ansi@^8.1.0: version "8.1.0" resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-8.1.0.tgz#56dc22368ee570face1b49819975d9b9a5ead214" From 42a3fed4dfb18e43e32794940beca33d7cb2cd78 Mon Sep 17 00:00:00 2001 From: Joe Yeager Date: Wed, 18 Dec 2024 12:58:09 -0800 Subject: [PATCH 08/10] Lock deps --- package.json | 4 ++-- yarn.lock | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 2189b80d7..7f38148c8 100644 --- a/package.json +++ b/package.json @@ -5,8 +5,8 @@ "license": "Apache-2.0", "repository": "https://github.com/HubSpot/hubspot-cli", "dependencies": { - "@hubspot/local-dev-lib": "^3.1.0", - "@hubspot/project-parsing-lib": "^0.0.1", + "@hubspot/local-dev-lib": "3.1.0", + "@hubspot/project-parsing-lib": "0.0.1", "@hubspot/serverless-dev-runtime": "7.0.0", "@hubspot/theme-preview-dev-server": "0.0.10", "@hubspot/ui-extensions-dev-server": "0.8.33", diff --git a/yarn.lock b/yarn.lock index 8e38168d4..5ec1ac4ae 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1463,7 +1463,7 @@ semver "^6.3.0" unixify "^1.0.0" -"@hubspot/local-dev-lib@^3.1.0": +"@hubspot/local-dev-lib@3.1.0", "@hubspot/local-dev-lib@^3.1.0": version "3.1.0" resolved "https://registry.yarnpkg.com/@hubspot/local-dev-lib/-/local-dev-lib-3.1.0.tgz#76b5d524aa694aad2bfc6e199ee1dac314f15774" integrity sha512-iop3PgZ0ZWejCH6PmSeYnnGwV8vGIuA4F+w7SxukdX3QfhivlczClATWPaZanv1CYJHdflqoItq1kdF8ASJJmA== @@ -1487,7 +1487,7 @@ semver "^6.3.0" unixify "^1.0.0" -"@hubspot/project-parsing-lib@^0.0.1": +"@hubspot/project-parsing-lib@0.0.1": version "0.0.1" resolved "https://registry.yarnpkg.com/@hubspot/project-parsing-lib/-/project-parsing-lib-0.0.1.tgz#fd1f823abbe410d97446bd5fc804b2e9bf40402e" integrity sha512-7Qqc6YplKTYG2skswVtNc02iCIuPd816vZT3I4HTYzJRQ9EqYTPZ7QLrL9VSTkLNkUyHw0AJE1qeQJqye1eAfQ== From 4b83acc896477dc6fe80578224d3d62e36ef6754 Mon Sep 17 00:00:00 2001 From: Joe Yeager Date: Wed, 18 Dec 2024 13:21:14 -0800 Subject: [PATCH 09/10] 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, From 3c28d8cedab7f529654a5adcf783408381da655f Mon Sep 17 00:00:00 2001 From: Joe Yeager Date: Wed, 18 Dec 2024 16:00:20 -0800 Subject: [PATCH 10/10] Remove console.log --- commands/project/upload.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/commands/project/upload.ts b/commands/project/upload.ts index 3b8c4f2e6..eb7aa4791 100644 --- a/commands/project/upload.ts +++ b/commands/project/upload.ts @@ -62,8 +62,6 @@ exports.handler = async options => { options.translate ); - console.log(result); - if (result.uploadError) { if ( isSpecifiedError(result.uploadError, {