diff --git a/commands/project/upload.ts b/commands/project/upload.ts index 29b349e32..eb7aa4791 100644 --- a/commands/project/upload.ts +++ b/commands/project/upload.ts @@ -43,6 +43,8 @@ exports.handler = async options => { const { projectConfig, projectDir } = await getProjectConfig(); + trackCommandUsage('project-upload', { type: accountType }, derivedAccountId); + validateProjectConfig(projectConfig, projectDir); await ensureProjectExists(derivedAccountId, projectConfig.name, { @@ -56,7 +58,8 @@ exports.handler = async options => { projectConfig, projectDir, pollProjectBuildAndDeploy, - message + message, + options.translate ); if (result.uploadError) { @@ -128,6 +131,11 @@ exports.builder = yargs => { type: 'string', default: '', }, + 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 2f2efb5d7..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'; @@ -19,7 +21,8 @@ async function uploadProjectFiles( projectName: string, filePath: string, uploadMessage: string, - platformVersion: string + platformVersion: string, + intermediateRepresentation?: unknown ): Promise<{ buildId?: number; error: unknown }> { SpinniesManager.init({}); const accountIdentifier = uiAccountDescription(accountId); @@ -41,10 +44,11 @@ async function uploadProjectFiles( projectName, filePath, uploadMessage, - platformVersion + platformVersion, + intermediateRepresentation ); - buildId = upload.buildId; + buildId = upload.buildId!; SpinniesManager.succeed('upload', { text: i18n(`${i18nKey}.uploadProjectFiles.succeed`, { @@ -89,7 +93,8 @@ export async function handleProjectUpload( projectConfig: ProjectConfig, projectDir: string, callbackFunc: ProjectUploadCallbackFunction, - uploadMessage: string + uploadMessage: string, + sendIR: boolean = false ) { const srcDir = path.resolve(projectDir, projectConfig.srcDir); @@ -124,12 +129,32 @@ 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, tempFile.name, uploadMessage, - projectConfig.platformVersion + projectConfig.platformVersion, + intermediateRepresentation ); if (error) { diff --git a/package.json b/package.json index 0d9943aae..7f38148c8 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,8 @@ "license": "Apache-2.0", "repository": "https://github.com/HubSpot/hubspot-cli", "dependencies": { - "@hubspot/local-dev-lib": "3.0.2", + "@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 d0ed5ab61..5ec1ac4ae 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", "@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"