diff --git a/commands/project/__tests__/deploy.test.ts b/commands/project/__tests__/deploy.test.ts index 124c71a45..fe8f3dbe5 100644 --- a/commands/project/__tests__/deploy.test.ts +++ b/commands/project/__tests__/deploy.test.ts @@ -18,11 +18,9 @@ const { addUseEnvironmentOptions, } = require('../../../lib/commonOpts'); const { loadAndValidateOptions } = require('../../../lib/validation'); -const { - getProjectConfig, - pollDeployStatus, - getProjectDetailUrl, -} = require('../../../lib/projects'); +const { getProjectConfig } = require('../../../lib/projects'); +const { getProjectDetailUrl } = require('../../../lib/projects/urls'); +const { pollDeployStatus } = require('../../../lib/projects/buildAndDeploy'); const { projectNamePrompt } = require('../../../lib/prompts/projectNamePrompt'); const { promptUser } = require('../../../lib/prompts/promptUtils'); const { trackCommandUsage } = require('../../../lib/usageTracking'); @@ -35,6 +33,8 @@ jest.mock('@hubspot/local-dev-lib/config'); jest.mock('../../../lib/commonOpts'); jest.mock('../../../lib/validation'); jest.mock('../../../lib/projects'); +jest.mock('../../../lib/projects/urls'); +jest.mock('../../../lib/projects/buildAndDeploy'); jest.mock('../../../lib/prompts/projectNamePrompt'); jest.mock('../../../lib/prompts/promptUtils'); jest.mock('../../../lib/usageTracking'); diff --git a/commands/project/deploy.ts b/commands/project/deploy.ts index 1114b61a4..0e3831b2e 100644 --- a/commands/project/deploy.ts +++ b/commands/project/deploy.ts @@ -13,11 +13,9 @@ const { fetchProject, } = require('@hubspot/local-dev-lib/api/projects'); const { loadAndValidateOptions } = require('../../lib/validation'); -const { - getProjectConfig, - pollDeployStatus, - getProjectDetailUrl, -} = require('../../lib/projects'); +const { getProjectConfig } = require('../../lib/projects'); +const { pollDeployStatus } = require('../../lib/projects/buildAndDeploy'); +const { getProjectDetailUrl } = require('../../lib/projects/urls'); const { projectNamePrompt } = require('../../lib/prompts/projectNamePrompt'); const { promptUser } = require('../../lib/prompts/promptUtils'); const { i18n } = require('../../lib/lang'); diff --git a/commands/project/listBuilds.ts b/commands/project/listBuilds.ts index b949f619f..956c34033 100644 --- a/commands/project/listBuilds.ts +++ b/commands/project/listBuilds.ts @@ -17,9 +17,9 @@ const { uiBetaTag, uiLink } = require('../../lib/ui'); const { loadAndValidateOptions } = require('../../lib/validation'); const { getProjectConfig, - getProjectDetailUrl, validateProjectConfig, } = require('../../lib/projects'); +const { getProjectDetailUrl } = require('../../lib/projects/urls'); const moment = require('moment'); const { promptUser } = require('../../lib/prompts/promptUtils'); const { isHubSpotHttpError } = require('@hubspot/local-dev-lib/errors/index'); diff --git a/commands/project/open.ts b/commands/project/open.ts index 63c01d45b..370eacf94 100644 --- a/commands/project/open.ts +++ b/commands/project/open.ts @@ -10,11 +10,8 @@ const { trackCommandUsage } = require('../../lib/usageTracking'); const { loadAndValidateOptions } = require('../../lib/validation'); const { i18n } = require('../../lib/lang'); const { logger } = require('@hubspot/local-dev-lib/logger'); -const { - getProjectConfig, - getProjectDetailUrl, - ensureProjectExists, -} = require('../../lib/projects'); +const { getProjectConfig, ensureProjectExists } = require('../../lib/projects'); +const { getProjectDetailUrl } = require('../../lib/projects/urls'); const { projectNamePrompt } = require('../../lib/prompts/projectNamePrompt'); const { uiBetaTag } = require('../../lib/ui'); const { EXIT_CODES } = require('../../lib/enums/exitCodes'); diff --git a/commands/project/upload.ts b/commands/project/upload.ts index cad644610..a67293d0e 100644 --- a/commands/project/upload.ts +++ b/commands/project/upload.ts @@ -15,9 +15,11 @@ const { handleProjectUpload, logFeedbackMessage, validateProjectConfig, - pollProjectBuildAndDeploy, - displayWarnLogs, } = require('../../lib/projects'); +const { + displayWarnLogs, + pollProjectBuildAndDeploy, +} = require('../../lib/projects/buildAndDeploy'); const { i18n } = require('../../lib/lang'); const { getAccountConfig } = require('@hubspot/local-dev-lib/config'); const { isSpecifiedError } = require('@hubspot/local-dev-lib/errors/index'); diff --git a/commands/project/watch.ts b/commands/project/watch.ts index 818e20ac3..d2ab74e68 100644 --- a/commands/project/watch.ts +++ b/commands/project/watch.ts @@ -15,11 +15,13 @@ const { ensureProjectExists, getProjectConfig, handleProjectUpload, - pollDeployStatus, validateProjectConfig, logFeedbackMessage, } = require('../../lib/projects'); -const { pollBuildStatus } = require('../../lib/projectTasks'); +const { + pollBuildStatus, + pollDeployStatus, +} = require('../../lib/projects/buildAndDeploy'); const { cancelStagedBuild, fetchProjectBuilds, diff --git a/lang/en.lyaml b/lang/en.lyaml index d5196b058..c1d8cdd95 100644 --- a/lang/en.lyaml +++ b/lang/en.lyaml @@ -1116,10 +1116,6 @@ en: notFound: "Your project {{#bold}}{{ projectName }}{{/bold}} could not be found in {{#bold}}{{ accountIdentifier }}{{/bold}}." pollFetchProject: checkingProject: "Checking if project exists in {{ accountIdentifier }}" - pollProjectBuildAndDeploy: - buildSucceededAutomaticallyDeploying: "Build #{{ buildId }} succeeded. {{#bold}}Automatically deploying{{/bold}} to {{ accountIdentifier }}\n" - cleanedUpTempFile: "Cleaned up temporary file {{ path }}" - viewDeploys: "View all deploys for this project in HubSpot" unableToFindAutodeployStatus: "Unable to find the auto deploy for build #{{ buildId }}. This deploy may have been skipped. {{ viewDeploysLink }}." logFeedbackMessage: feedbackHeader: "We'd love to hear your feedback!" @@ -1132,6 +1128,10 @@ en: failedStatusText: "FAILED" errorFetchingTaskStatus: "Error fetching {{ taskType }} status" pollBuildAutodeployStatusError: "Error fetching autodeploy status for build #{{ buildId }}" + pollProjectBuildAndDeploy: + buildSucceededAutomaticallyDeploying: "Build #{{ buildId }} succeeded. {{#bold}}Automatically deploying{{/bold}} to {{ accountIdentifier }}\n" + cleanedUpTempFile: "Cleaned up temporary file {{ path }}" + viewDeploys: "View all deploys for this project in HubSpot" ui: betaTag: "{{#bold}}[BETA]{{/bold}}" betaWarning: diff --git a/lib/LocalDevManager.ts b/lib/LocalDevManager.ts index 4d7bf0274..5503f6c10 100644 --- a/lib/LocalDevManager.ts +++ b/lib/LocalDevManager.ts @@ -20,7 +20,7 @@ const { PROJECT_CONFIG_FILE } = require('./constants'); const SpinniesManager = require('./ui/SpinniesManager'); const DevServerManager = require('./DevServerManager'); const { EXIT_CODES } = require('./enums/exitCodes'); -const { getProjectDetailUrl } = require('./projects'); +const { getProjectDetailUrl } = require('./projects/urls'); const { getAccountHomeUrl } = require('./localDev'); const { CONFIG_FILES, diff --git a/lib/doctor/__tests__/Diagnosis.test.ts b/lib/doctor/__tests__/Diagnosis.test.ts index 6fe6ebc1f..a9985c4a4 100644 --- a/lib/doctor/__tests__/Diagnosis.test.ts +++ b/lib/doctor/__tests__/Diagnosis.test.ts @@ -28,6 +28,8 @@ describe('lib/doctor/Diagnosis', () => { projectDir: 'project-dir', projectConfig: { name: 'Super cool project', + srcDir: 'project-dir', + platformVersion: 'test', }, }, }, diff --git a/lib/doctor/__tests__/DiagnosticInfoBuilder.test.ts b/lib/doctor/__tests__/DiagnosticInfoBuilder.test.ts index 34e90cb70..ac741a807 100644 --- a/lib/doctor/__tests__/DiagnosticInfoBuilder.test.ts +++ b/lib/doctor/__tests__/DiagnosticInfoBuilder.test.ts @@ -26,7 +26,7 @@ import { AccessToken, CLIAccount } from '@hubspot/local-dev-lib/types/Accounts'; import { getProjectConfig as _getProjectConfig } from '../../projects'; import { fetchProject as _fetchProject } from '@hubspot/local-dev-lib/api/projects'; import { Project } from '@hubspot/local-dev-lib/types/Project'; -import { AxiosPromise } from 'axios'; +import { HubSpotPromise } from '@hubspot/local-dev-lib/types/Http'; const walk = _walk as jest.MockedFunction; const getAccessToken = _getAccessToken as jest.MockedFunction< @@ -124,6 +124,8 @@ describe('lib/doctor/DiagnosticInfo', () => { projectDir, projectConfig: { name: 'My project', + srcDir: 'project-dir', + platformVersion: 'test', }, }; @@ -133,7 +135,7 @@ describe('lib/doctor/DiagnosticInfo', () => { deployedBuildId: 1, id: 8989898, isLocked: false, - name: projectConfig.projectConfig.name, + name: projectConfig!.projectConfig!.name, portalId: accountId, updatedAt: 12345, }; @@ -143,16 +145,16 @@ describe('lib/doctor/DiagnosticInfo', () => { accountType: 'STANDARD', encodedOAuthRefreshToken: '', expiresAt: '', - hubName: projectConfig.projectConfig.name, + hubName: projectConfig!.projectConfig!.name, portalId: accountId, scopeGroups: [], enabledFeatures: {}, }; getProjectConfig.mockResolvedValue(projectConfig); - fetchProject.mockResolvedValue(({ + fetchProject.mockResolvedValue({ data: projectDetails, - } as unknown) as AxiosPromise); + } as unknown as HubSpotPromise); getAccessToken.mockResolvedValue(accessToken); getConfigPath.mockReturnValue(configPath); utilPromisify.mockReturnValue(jest.fn().mockResolvedValue(npmVersion)); @@ -166,7 +168,7 @@ describe('lib/doctor/DiagnosticInfo', () => { expect(fetchProject).toHaveBeenCalledTimes(1); expect(fetchProject).toHaveBeenCalledWith( accountId, - projectConfig!.projectConfig.name + projectConfig!.projectConfig!.name ); expect(getAccessToken).toHaveBeenCalledTimes(1); diff --git a/lib/doctor/__tests__/Doctor.test.ts b/lib/doctor/__tests__/Doctor.test.ts index cf6fc19ef..18977976e 100644 --- a/lib/doctor/__tests__/Doctor.test.ts +++ b/lib/doctor/__tests__/Doctor.test.ts @@ -28,17 +28,19 @@ jest.mock('util', () => ({ const hasMissingPackages = _hasMissingPackages as jest.MockedFunction< typeof _hasMissingPackages >; -const isPortManagerPortAvailable = _isPortManagerPortAvailable as jest.MockedFunction< - typeof _isPortManagerPortAvailable ->; +const isPortManagerPortAvailable = + _isPortManagerPortAvailable as jest.MockedFunction< + typeof _isPortManagerPortAvailable + >; const utilPromisify = util.promisify as jest.MockedFunction< typeof util.promisify >; -const accessTokenForPersonalAccessKey = _accessTokenForPersonalAccessKey as jest.MockedFunction< - typeof _accessTokenForPersonalAccessKey ->; +const accessTokenForPersonalAccessKey = + _accessTokenForPersonalAccessKey as jest.MockedFunction< + typeof _accessTokenForPersonalAccessKey + >; const isSpecifiedError = _isSpecifiedError as jest.MockedFunction< typeof _isSpecifiedError @@ -64,7 +66,11 @@ describe('lib/doctor/Doctor', () => { project: { config: { projectDir: '/path/to/project', - projectConfig: {}, + projectConfig: { + name: 'my-project', + srcDir: '/path/to/project', + platformVersion: 'test', + }, }, }, versions: { @@ -75,11 +81,11 @@ describe('lib/doctor/Doctor', () => { }; beforeEach(() => { - doctor = new Doctor(({ + doctor = new Doctor({ generateDiagnosticInfo: jest.fn().mockResolvedValue({ ...diagnosticInfo, }), - } as unknown) as DiagnosticInfoBuilder); + } as unknown as DiagnosticInfoBuilder); utilPromisify.mockReturnValue( jest.fn().mockImplementationOnce((filename: string) => { @@ -104,12 +110,12 @@ describe('lib/doctor/Doctor', () => { }); it('should add error section if node version is not available', async () => { - doctor = new Doctor(({ + doctor = new Doctor({ generateDiagnosticInfo: jest.fn().mockResolvedValue({ ...diagnosticInfo, versions: {}, }), - } as unknown) as DiagnosticInfoBuilder); + } as unknown as DiagnosticInfoBuilder); await doctor.diagnose(); @@ -121,12 +127,12 @@ describe('lib/doctor/Doctor', () => { }); it('should add error section if minimum node version is not met', async () => { - doctor = new Doctor(({ + doctor = new Doctor({ generateDiagnosticInfo: jest.fn().mockResolvedValue({ ...diagnosticInfo, versions: { node: '1.0.0' }, }), - } as unknown) as DiagnosticInfoBuilder); + } as unknown as DiagnosticInfoBuilder); await doctor.diagnose(); @@ -149,12 +155,12 @@ describe('lib/doctor/Doctor', () => { }); it('should add error section if npm is not installed', async () => { - doctor = new Doctor(({ + doctor = new Doctor({ generateDiagnosticInfo: jest.fn().mockResolvedValue({ ...diagnosticInfo, versions: {}, }), - } as unknown) as DiagnosticInfoBuilder); + } as unknown as DiagnosticInfoBuilder); await doctor.diagnose(); diff --git a/lib/doctor/__tests__/__snapshots__/DiagnosticInfoBuilder.test.ts.snap b/lib/doctor/__tests__/__snapshots__/DiagnosticInfoBuilder.test.ts.snap index 46dcb2477..4bef91f57 100644 --- a/lib/doctor/__tests__/__snapshots__/DiagnosticInfoBuilder.test.ts.snap +++ b/lib/doctor/__tests__/__snapshots__/DiagnosticInfoBuilder.test.ts.snap @@ -58,6 +58,8 @@ exports[`lib/doctor/DiagnosticInfo generateDiagnosticInfo should gather the requ "config": { "projectConfig": { "name": "My project", + "platformVersion": "test", + "srcDir": "project-dir", }, "projectDir": "/Users/test/project", }, diff --git a/lib/localDev.ts b/lib/localDev.ts index d983cad74..d24c188c6 100644 --- a/lib/localDev.ts +++ b/lib/localDev.ts @@ -38,10 +38,8 @@ const { isAppDeveloperAccount, isDeveloperTestAccount, } = require('./accountTypes'); -const { - handleProjectUpload, - pollProjectBuildAndDeploy, -} = require('./projects'); +const { handleProjectUpload } = require('./projects'); +const { pollProjectBuildAndDeploy } = require('./projects/buildAndDeploy'); const { PROJECT_ERROR_TYPES, PROJECT_BUILD_TEXT, @@ -248,9 +246,8 @@ const createDeveloperTestAccountForLocalDev = async ( let currentPortalCount = 0; let maxTestPortals = 10; try { - const validateResult = await validateDevTestAccountUsageLimits( - accountConfig - ); + const validateResult = + await validateDevTestAccountUsageLimits(accountConfig); if (validateResult) { currentPortalCount = validateResult.results ? validateResult.results.length @@ -306,9 +303,8 @@ const createDeveloperTestAccountForLocalDev = async ( // Prompt user to confirm usage of an existing developer test account that is not currently in the config const useExistingDevTestAccount = async (env, account) => { - const useExistingDevTestAcct = await confirmUseExistingDeveloperTestAccountPrompt( - account - ); + const useExistingDevTestAcct = + await confirmUseExistingDeveloperTestAccountPrompt(account); if (!useExistingDevTestAcct) { logger.log(''); logger.log( diff --git a/lib/projects/buildAndDeploy.ts b/lib/projects/buildAndDeploy.ts index 84d88a94c..99cd2265e 100644 --- a/lib/projects/buildAndDeploy.ts +++ b/lib/projects/buildAndDeploy.ts @@ -370,7 +370,7 @@ function makePollTaskStatusFunc({ }; } -export function pollBuildAutodeployStatus( +function pollBuildAutodeployStatus( accountId: number, taskName: string, buildId: number @@ -430,7 +430,7 @@ export const pollBuildStatus = makePollTaskStatusFunc({ }, }); -const pollDeployStatus = makePollTaskStatusFunc({ +export const pollDeployStatus = makePollTaskStatusFunc({ linkToHubSpot: (accountId, taskName, taskId, deployedBuildId) => uiLink( `View deploy of build #${deployedBuildId} in HubSpot`, diff --git a/lib/projects/index.ts b/lib/projects/index.ts index c22b61db3..c2b19abcb 100644 --- a/lib/projects/index.ts +++ b/lib/projects/index.ts @@ -443,8 +443,10 @@ export async function handleProjectUpload( ); if (error) { + console.log(error); uploadResult = { uploadError: error }; } else if (callbackFunc) { + console.log('callbackfunc'); uploadResult = await callbackFunc( accountId, projectConfig, diff --git a/lib/projects/watch.ts b/lib/projects/watch.ts index 95ea171b1..a67104526 100644 --- a/lib/projects/watch.ts +++ b/lib/projects/watch.ts @@ -3,8 +3,8 @@ const chokidar = require('chokidar'); const path = require('path'); const chalk = require('chalk'); const { default: PQueue } = require('p-queue'); -const { logError, ApiErrorContext } = require('./errorHandlers/index'); -const { i18n } = require('./lang'); +const { logError, ApiErrorContext } = require('../errorHandlers/index'); +const { i18n } = require('../lang'); const { logger } = require('@hubspot/local-dev-lib/logger'); const { isAllowedExtension } = require('@hubspot/local-dev-lib/path'); const { shouldIgnoreFile } = require('@hubspot/local-dev-lib/ignoreRules'); @@ -16,7 +16,7 @@ const { queueBuild, } = require('@hubspot/local-dev-lib/api/projects'); const { isSpecifiedError } = require('@hubspot/local-dev-lib/errors/index'); -const { PROJECT_ERROR_TYPES } = require('./constants'); +const { PROJECT_ERROR_TYPES } = require('../constants'); const i18nKey = 'commands.project.subcommands.watch';