Skip to content

Commit

Permalink
Merge branch 'main' of github.com:HubSpot/hubspot-cli into next
Browse files Browse the repository at this point in the history
  • Loading branch information
joe-yeager committed Aug 16, 2024
2 parents 2b85d3b + f55582b commit b2c6f92
Show file tree
Hide file tree
Showing 13 changed files with 262 additions and 138 deletions.
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"npmClient": "yarn",
"useWorkspaces": true,
"packages": ["packages/*", "acceptance-tests"],
"version": "5.2.1-beta.13"
"version": "5.3.0"
}
21 changes: 11 additions & 10 deletions packages/cli/commands/project/__tests__/deploy.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ jest.mock('@hubspot/local-dev-lib/api/projects');
jest.mock('../../../lib/validation');
jest.mock('../../../lib/projects');
jest.mock('../../../lib/prompts/projectNamePrompt');
jest.mock('../../../lib/prompts/buildIdPrompt');
jest.mock('../../../lib/prompts/deployBuildIdPrompt');
jest.mock('@hubspot/local-dev-lib/config');
jest.mock('../../../lib/usageTracking');
jest.mock('../../../lib/ui');
Expand Down Expand Up @@ -45,7 +45,9 @@ const {
getProjectDetailUrl,
} = require('../../../lib/projects');
const { projectNamePrompt } = require('../../../lib/prompts/projectNamePrompt');
const { buildIdPrompt } = require('../../../lib/prompts/buildIdPrompt');
const {
deployBuildIdPrompt,
} = require('../../../lib/prompts/deployBuildIdPrompt');
const { getAccountConfig } = require('@hubspot/local-dev-lib/config');

const yargs = require('yargs');
Expand All @@ -61,8 +63,8 @@ const {

describe('commands/project/deploy', () => {
const projectFlag = 'project';
const buildFlag = 'buildId';
const buildAliases = ['build'];
const buildFlag = 'build';
const buildAliases = ['buildId'];

describe('describe', () => {
it('should contain the beta tag', () => {
Expand Down Expand Up @@ -166,7 +168,7 @@ describe('commands/project/deploy', () => {
getAccountConfig.mockReturnValue({ accountType });
fetchProject.mockResolvedValue({ data: projectDetails });
deployProject.mockResolvedValue({ data: deployDetails });
buildIdPrompt.mockResolvedValue({
deployBuildIdPrompt.mockResolvedValue({
buildId: projectDetails.latestBuild.buildId,
});

Expand Down Expand Up @@ -297,22 +299,21 @@ describe('commands/project/deploy', () => {
it('should prompt for build id if no option is provided', async () => {
delete options.buildId;
await handler(options);
expect(buildIdPrompt).toHaveBeenCalledTimes(1);
expect(buildIdPrompt).toHaveBeenCalledWith(
expect(deployBuildIdPrompt).toHaveBeenCalledTimes(1);
expect(deployBuildIdPrompt).toHaveBeenCalledWith(
projectDetails.latestBuild.buildId,
projectDetails.deployedBuildId,
options.project,
expect.any(Function)
);
});

it('should log an error and exit if the prompted value is invalid', async () => {
delete options.buildId;
buildIdPrompt.mockReturnValue({});
deployBuildIdPrompt.mockReturnValue({});

await handler(options);

expect(buildIdPrompt).toHaveBeenCalledTimes(1);
expect(deployBuildIdPrompt).toHaveBeenCalledTimes(1);
expect(logger.error).toHaveBeenCalledTimes(1);
expect(logger.error).toHaveBeenCalledWith(
'You must specify a build to deploy'
Expand Down
34 changes: 33 additions & 1 deletion packages/cli/commands/project/cloneApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ const {
getAccountId,
addUseEnvironmentOptions,
} = require('../../lib/commonOpts');
const { trackCommandUsage } = require('../../lib/usageTracking');
const {
trackCommandUsage,
trackCommandMetadataUsage,
} = require('../../lib/usageTracking');
const { loadAndValidateOptions } = require('../../lib/validation');
const { i18n } = require('../../lib/lang');
const {
Expand Down Expand Up @@ -36,6 +39,9 @@ const { getCwd } = require('@hubspot/local-dev-lib/path');
const { logger } = require('@hubspot/local-dev-lib/logger');
const { getAccountConfig } = require('@hubspot/local-dev-lib/config');
const { extractZipArchive } = require('@hubspot/local-dev-lib/archive');
const {
fetchPublicAppMetadata,
} = require('@hubspot/local-dev-lib/api/appsDev');

const i18nKey = 'commands.project.subcommands.cloneApp';

Expand Down Expand Up @@ -67,6 +73,8 @@ exports.handler = async options => {
let appId;
let name;
let location;
let preventProjectMigrations;
let listingInfo;
try {
appId = options.appId;
if (!appId) {
Expand All @@ -78,6 +86,11 @@ exports.handler = async options => {
});
appId = appIdResponse.appId;
}
const selectedApp = await fetchPublicAppMetadata(appId, accountId);
// preventProjectMigrations returns true if we have not added app to allowlist config.
// listingInfo will only exist for marketplace apps
preventProjectMigrations = selectedApp.preventProjectMigrations;
listingInfo = selectedApp.listingInfo;

const projectResponse = await createProjectPrompt('', options, true);
name = projectResponse.name;
Expand Down Expand Up @@ -124,6 +137,19 @@ exports.handler = async options => {
};
const success = writeProjectConfig(configPath, configContent);

const isListed = Boolean(listingInfo);
trackCommandMetadataUsage(
'clone-app',
{
projectName: name,
appId,
status,
preventProjectMigrations,
isListed,
},
accountId
);

SpinniesManager.succeed('cloneApp', {
text: i18n(`${i18nKey}.cloneStatus.done`),
succeedColor: 'white',
Expand All @@ -141,6 +167,12 @@ exports.handler = async options => {
process.exit(EXIT_CODES.SUCCESS);
}
} catch (error) {
trackCommandMetadataUsage(
'clone-app',
{ projectName: name, appId, status: 'FAILURE', error },
accountId
);

SpinniesManager.fail('cloneApp', {
text: i18n(`${i18nKey}.cloneStatus.failure`),
failColor: 'white',
Expand Down
19 changes: 10 additions & 9 deletions packages/cli/commands/project/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ const {
getProjectDetailUrl,
} = require('../../lib/projects');
const { projectNamePrompt } = require('../../lib/prompts/projectNamePrompt');
const { buildIdPrompt } = require('../../lib/prompts/buildIdPrompt');
const {
deployBuildIdPrompt,
} = require('../../lib/prompts/deployBuildIdPrompt');
const { i18n } = require('../../lib/lang');
const { uiBetaTag, uiLink } = require('../../lib/ui');
const { getAccountConfig } = require('@hubspot/local-dev-lib/config');
Expand Down Expand Up @@ -112,20 +114,19 @@ exports.handler = async options => {
return process.exit(EXIT_CODES.ERROR);
}
} else {
const buildIdPromptResponse = await buildIdPrompt(
const deployBuildIdPromptResponse = await deployBuildIdPrompt(
latestBuild.buildId,
deployedBuildId,
projectName,
buildId =>
validateBuildId(
buildId,
latestBuild.buildId,
deployedBuildId,
latestBuild.buildId,
projectName,
accountId
)
);
buildIdToDeploy = buildIdPromptResponse.buildId;
buildIdToDeploy = deployBuildIdPromptResponse.buildId;
}

if (!buildIdToDeploy) {
Expand Down Expand Up @@ -178,17 +179,17 @@ exports.builder = yargs => {
describe: i18n(`${i18nKey}.options.project.describe`),
type: 'string',
},
buildId: {
alias: ['build'],
describe: i18n(`${i18nKey}.options.buildId.describe`),
build: {
alias: ['buildId'],
describe: i18n(`${i18nKey}.options.build.describe`),
type: 'number',
},
});

yargs.example([
['$0 project deploy', i18n(`${i18nKey}.examples.default`)],
[
'$0 project deploy --project="my-project" --buildId=5',
'$0 project deploy --project="my-project" --build=5',
i18n(`${i18nKey}.examples.withOptions`),
],
]);
Expand Down
22 changes: 20 additions & 2 deletions packages/cli/commands/project/migrateApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ const {
getAccountId,
addUseEnvironmentOptions,
} = require('../../lib/commonOpts');
const { trackCommandUsage } = require('../../lib/usageTracking');
const {
trackCommandUsage,
trackCommandMetadataUsage,
} = require('../../lib/usageTracking');
const { loadAndValidateOptions } = require('../../lib/validation');
const {
createProjectPrompt,
Expand Down Expand Up @@ -80,14 +83,17 @@ exports.handler = async options => {
});

let appName;
let preventProjectMigrations;
let listingInfo;
try {
const { data: selectedApp } = await fetchPublicAppMetadata(
appId,
accountId
);
// preventProjectMigrations returns true if we have not added app to allowlist config.
// listingInfo will only exist for marketplace apps
const { preventProjectMigrations, listingInfo } = selectedApp;
preventProjectMigrations = selectedApp.preventProjectMigrations;
listingInfo = selectedApp.listingInfo;
if (preventProjectMigrations && listingInfo) {
logger.error(i18n(`${i18nKey}.errors.invalidApp`, { appId }));
process.exit(EXIT_CODES.ERROR);
Expand Down Expand Up @@ -193,6 +199,13 @@ exports.handler = async options => {
{ includesRootDir: true, hideLogs: true }
);

const isListed = Boolean(listingInfo);
trackCommandMetadataUsage(
'migrate-app',
{ projectName, appId, status, preventProjectMigrations, isListed },
accountId
);

SpinniesManager.succeed('migrateApp', {
text: i18n(`${i18nKey}.migrationStatus.done`),
succeedColor: 'white',
Expand All @@ -210,6 +223,11 @@ exports.handler = async options => {
process.exit(EXIT_CODES.SUCCESS);
}
} catch (error) {
trackCommandMetadataUsage(
'migrate-app',
{ projectName, appId, status: 'FAILURE', error },
accountId
);
SpinniesManager.fail('migrateApp', {
text: i18n(`${i18nKey}.migrationStatus.failure`),
failColor: 'white',
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/commands/project/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ exports.handler = async options => {
logger.log(
i18n(`${i18nKey}.logs.autoDeployDisabled`, {
deployCommand: uiCommandReference(
`hs project deploy --buildId=${result.buildId}`
`hs project deploy --build=${result.buildId}`
),
})
);
Expand Down
9 changes: 6 additions & 3 deletions packages/cli/lang/en.lyaml
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ en:
default: "Deploy the latest build of the current project"
withOptions: "Deploy build 5 of the project my-project"
options:
buildId:
build:
describe: "Project build ID to be deployed"
project:
describe: "Project name"
Expand Down Expand Up @@ -1052,9 +1052,12 @@ en:
successStatusText: "DONE"
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"
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!"
feedbackMessage: "How are you liking the new projects and developer tools? \n > Run `{{#yellow}}hs feedback{{/yellow}}` to let us know what you think!\n"
Expand Down Expand Up @@ -1293,8 +1296,8 @@ en:
general: "[--general] Tell us about your experience with HubSpot's developer tools"
bugPrompt: "Create an issue on Github in your browser?"
generalPrompt: "Create an issue on Github in your browser?"
buildIdPrompt:
enterBuildId: "[--buildId] Deploy which build?"
deployBuildIdPrompt:
enterBuildId: "[--build] Deploy which build?"
previewPrompt:
enterSrc: "[--src] Enter a local theme directory to preview."
enterDest: "[--dest] Enter the destination path for the src theme in HubSpot Design Tools."
Expand Down
Loading

0 comments on commit b2c6f92

Please sign in to comment.