Skip to content

Commit

Permalink
Merge branch 'main' of github.com:HubSpot/hubspot-cli into jy/add-pro…
Browse files Browse the repository at this point in the history
…ject-translation
  • Loading branch information
joe-yeager committed Jan 23, 2025
2 parents 8960c66 + 04942cf commit 98df6bf
Show file tree
Hide file tree
Showing 48 changed files with 1,347 additions and 789 deletions.
8 changes: 4 additions & 4 deletions acceptance-tests/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -368,10 +368,10 @@ concat-stream@^2.0.0:
readable-stream "^3.0.2"
typedarray "^0.0.6"

cross-spawn@^7.0.3:
version "7.0.3"
resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-7.0.3.tgz#f73a85b9d5d41d045551c177e2882d4ac85728a6"
integrity sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==
cross-spawn@^7.0.5:
version "7.0.6"
resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-7.0.6.tgz#8a58fe78f00dcd70c370451759dfbfaf03e8ee9f"
integrity sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA==
dependencies:
path-key "^3.1.0"
shebang-command "^2.0.0"
Expand Down
2 changes: 1 addition & 1 deletion commands/__tests__/accounts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import yargs from 'yargs';
import list from '../account/list';
import rename from '../account/rename';
import use from '../account/use';
import info from '../account/info';
import * as info from '../account/info';
import remove from '../account/remove';
import clean from '../account/clean';

Expand Down
35 changes: 35 additions & 0 deletions commands/account/__tests__/info.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import yargs, { Argv } from 'yargs';
import { addConfigOptions } from '../../../lib/commonOpts';

jest.mock('yargs');
jest.mock('../../../lib/commonOpts');

// Import this last so mocks apply
import * as accountInfoCommand from '../info';

describe('commands/account/info', () => {
const yargsMock = yargs as Argv;

describe('command', () => {
it('should have the correct command structure', () => {
expect(accountInfoCommand.command).toEqual('info [account]');
});
});

describe('describe', () => {
it('should provide a description', () => {
expect(accountInfoCommand.describe).toBeDefined();
});
});

describe('builder', () => {
it('should support the correct options', () => {
accountInfoCommand.builder(yargsMock);

expect(yargsMock.example).toHaveBeenCalledTimes(1);

expect(addConfigOptions).toHaveBeenCalledTimes(1);
expect(addConfigOptions).toHaveBeenCalledWith(yargsMock);
});
});
});
42 changes: 24 additions & 18 deletions commands/account/info.ts
Original file line number Diff line number Diff line change
@@ -1,41 +1,47 @@
// @ts-nocheck
const { logger } = require('@hubspot/local-dev-lib/logger');
const { getAccountConfig } = require('@hubspot/local-dev-lib/config');
const { getAccessToken } = require('@hubspot/local-dev-lib/personalAccessKey');
const { addConfigOptions } = require('../../lib/commonOpts');
const { i18n } = require('../../lib/lang');
const { getTableContents } = require('../../lib/ui/table');
import { Argv, ArgumentsCamelCase } from 'yargs';
import { logger } from '@hubspot/local-dev-lib/logger';
import { getAccountConfig } from '@hubspot/local-dev-lib/config';
import { getAccessToken } from '@hubspot/local-dev-lib/personalAccessKey';
import { addConfigOptions } from '../../lib/commonOpts';
import { i18n } from '../../lib/lang';
import { getTableContents } from '../../lib/ui/table';
import { CommonArgs, ConfigArgs } from '../../types/Yargs';

const i18nKey = 'commands.account.subcommands.info';
exports.describe = i18n(`${i18nKey}.describe`);

exports.command = 'info [account]';
export const describe = i18n(`${i18nKey}.describe`);
export const command = 'info [account]';

exports.handler = async options => {
const { derivedAccountId } = options;
type AccountInfoArgs = CommonArgs & ConfigArgs;

export async function handler(
args: ArgumentsCamelCase<AccountInfoArgs>
): Promise<void> {
const { derivedAccountId } = args;
const config = getAccountConfig(derivedAccountId);
// check if the provided account is using a personal access key, if not, show an error
if (config && config.authType === 'personalaccesskey') {
const { name, personalAccessKey, env } = config;
let scopeGroups: string[][] = [];

const response = await getAccessToken(
personalAccessKey,
personalAccessKey!,
env,
derivedAccountId
);

const scopeGroups = response.scopeGroups.map(s => [s]);
scopeGroups = response.scopeGroups.map(s => [s]);

logger.log(i18n(`${i18nKey}.name`, { name }));
logger.log(i18n(`${i18nKey}.name`, { name: name! }));
logger.log(i18n(`${i18nKey}.accountId`, { accountId: derivedAccountId }));
logger.log(i18n(`${i18nKey}.scopeGroups`));
logger.log(getTableContents(scopeGroups, { border: { bodyLeft: ' ' } }));
} else {
logger.log(i18n(`${i18nKey}.errors.notUsingPersonalAccessKey`));
}
};
}

exports.builder = yargs => {
export function builder(yargs: Argv): Argv<AccountInfoArgs> {
addConfigOptions(yargs);

yargs.example([
Expand All @@ -44,5 +50,5 @@ exports.builder = yargs => {
['$0 accounts info 1234567', i18n(`${i18nKey}.examples.idBased`)],
]);

return yargs;
};
return yargs as Argv<AccountInfoArgs>;
}
12 changes: 4 additions & 8 deletions commands/account/remove.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const {
getConfigPath,
deleteAccount,
getConfigDefaultAccount,
getAccountId: getAccountIdFromConfig,
getAccountId,
updateDefaultAccount,
} = require('@hubspot/local-dev-lib/config');

Expand All @@ -23,7 +23,7 @@ exports.handler = async options => {
const { account } = options;
let accountToRemove = account;

if (accountToRemove && !getAccountIdFromConfig(accountToRemove)) {
if (accountToRemove && !getAccountId(accountToRemove)) {
logger.error(
i18n(`${i18nKey}.errors.accountNotFound`, {
specifiedAccount: accountToRemove,
Expand All @@ -32,17 +32,13 @@ exports.handler = async options => {
);
}

if (!accountToRemove || !getAccountIdFromConfig(accountToRemove)) {
if (!accountToRemove || !getAccountId(accountToRemove)) {
accountToRemove = await selectAccountFromConfig(
i18n(`${i18nKey}.prompts.selectAccountToRemove`)
);
}

trackCommandUsage(
'accounts-remove',
null,
getAccountIdFromConfig(accountToRemove)
);
trackCommandUsage('accounts-remove', null, getAccountId(accountToRemove));

const currentDefaultAccount = getConfigDefaultAccount();

Expand Down
10 changes: 3 additions & 7 deletions commands/account/use.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const { logger } = require('@hubspot/local-dev-lib/logger');
const {
getConfigPath,
updateDefaultAccount,
getAccountId: getAccountIdFromConfig,
getAccountId,
} = require('@hubspot/local-dev-lib/config');

const { trackCommandUsage } = require('../../lib/usageTracking');
Expand All @@ -20,7 +20,7 @@ exports.handler = async options => {

if (!newDefaultAccount) {
newDefaultAccount = await selectAccountFromConfig();
} else if (!getAccountIdFromConfig(newDefaultAccount)) {
} else if (!getAccountId(newDefaultAccount)) {
logger.error(
i18n(`${i18nKey}.errors.accountNotFound`, {
specifiedAccount: newDefaultAccount,
Expand All @@ -30,11 +30,7 @@ exports.handler = async options => {
newDefaultAccount = await selectAccountFromConfig();
}

trackCommandUsage(
'accounts-use',
null,
getAccountIdFromConfig(newDefaultAccount)
);
trackCommandUsage('accounts-use', null, getAccountId(newDefaultAccount));

updateDefaultAccount(newDefaultAccount);

Expand Down
4 changes: 2 additions & 2 deletions commands/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const {
getConfigPath,
loadConfig,
getConfigDefaultAccount,
getAccountId,
} = require('@hubspot/local-dev-lib/config');
const {
commaSeparatedValues,
Expand All @@ -39,7 +40,6 @@ const {
const {
addConfigOptions,
setLogLevel,
getAccountId,
addTestingOptions,
addGlobalOptions,
} = require('../lib/commonOpts');
Expand Down Expand Up @@ -197,7 +197,7 @@ exports.handler = async options => {
'accountsListCommand',
]);

const accountId = getAccountId({ account: accountName });
const accountId = getAccountId(accountName);
await trackAuthAction('auth', authType, TRACKING_STATUS.COMPLETE, accountId);

process.exit(EXIT_CODES.SUCCESS);
Expand Down
8 changes: 1 addition & 7 deletions commands/logs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,7 @@ const endpointLog = async (accountId, functionPath, options) => {
}
};

await tailLogs({
accountId,
compact,
tailCall,
fetchLatest,
name: functionPath,
});
await tailLogs(accountId, functionPath, fetchLatest, tailCall, compact);
} else if (latest) {
try {
const { data } = await getLatestFunctionLog(accountId, functionPath);
Expand Down
5 changes: 1 addition & 4 deletions commands/project/__tests__/installDeps.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ const { logger } = require('@hubspot/local-dev-lib/logger');
const { getProjectConfig } = require('../../../lib/projects');
const { EXIT_CODES } = require('../../../lib/enums/exitCodes');
const { trackCommandUsage } = require('../../../lib/usageTracking');
const { getAccountId } = require('../../../lib/commonOpts');
const {
installPackages,
getProjectPackageJsonLocations,
Expand Down Expand Up @@ -56,10 +55,8 @@ describe('commands/project/installDeps', () => {

it('should track the command usage', async () => {
const accountId = 999999;
getAccountId.mockReturnValue(accountId);
await installDepsCommand.handler({});
await installDepsCommand.handler({ derivedAccountId: accountId });

expect(getAccountId).toHaveBeenCalledTimes(1);
expect(trackCommandUsage).toHaveBeenCalledTimes(1);
expect(trackCommandUsage).toHaveBeenCalledWith(
'project-install-deps',
Expand Down
6 changes: 6 additions & 0 deletions commands/project/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ exports.builder = yargs => {
});

yargs.example([['$0 project create', i18n(`${i18nKey}.examples.default`)]]);
yargs.example([
[
'$0 project create --template-source HubSpot/ui-extensions-examples',
i18n(`${i18nKey}.examples.templateSource`),
],
]);

addConfigOptions(yargs);
addAccountOptions(yargs);
Expand Down
6 changes: 2 additions & 4 deletions commands/project/installDeps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ const { promptUser } = require('../../lib/prompts/promptUtils');
const path = require('path');
const { i18n } = require('../../lib/lang');
const { trackCommandUsage } = require('../../lib/usageTracking');
const { getAccountId } = require('../../lib/commonOpts');
const { uiBetaTag } = require('../../lib/ui');

const i18nKey = `commands.project.subcommands.installDeps`;
Expand All @@ -19,10 +18,9 @@ exports.command = 'install-deps [packages..]';
exports.describe = uiBetaTag(i18n(`${i18nKey}.help.describe`), false);

exports.handler = async options => {
const { packages } = options || {};
const { derivedAccountId, packages } = options || {};
try {
const accountId = getAccountId(options);
trackCommandUsage('project-install-deps', null, accountId);
trackCommandUsage('project-install-deps', null, derivedAccountId);

const projectConfig = await getProjectConfig();
if (!projectConfig || !projectConfig.projectDir) {
Expand Down
8 changes: 4 additions & 4 deletions commands/project/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ exports.handler = async options => {
});

try {
const result = await handleProjectUpload(
const { result, uploadError } = await handleProjectUpload(
derivedAccountId,
projectConfig,
projectDir,
Expand All @@ -57,9 +57,9 @@ exports.handler = async options => {
options.translate
);

if (result.uploadError) {
if (uploadError) {
if (
isSpecifiedError(result.uploadError, {
isSpecifiedError(uploadError, {
subCategory: PROJECT_ERROR_TYPES.PROJECT_LOCKED,
})
) {
Expand All @@ -68,7 +68,7 @@ exports.handler = async options => {
logger.log();
} else {
logError(
result.uploadError,
uploadError,
new ApiErrorContext({
accountId: derivedAccountId,
request: 'project upload',
Expand Down
8 changes: 4 additions & 4 deletions commands/project/watch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,16 +113,16 @@ exports.handler = async options => {

// Upload all files if no build exists for this project yet
if (initialUpload || hasNoBuilds) {
const result = await handleProjectUpload(
const { uploadError } = await handleProjectUpload(
derivedAccountId,
projectConfig,
projectDir,
startWatching
);

if (result.uploadError) {
if (uploadError) {
if (
isSpecifiedError(result.uploadError, {
isSpecifiedError(uploadError, {
subCategory: PROJECT_ERROR_TYPES.PROJECT_LOCKED,
})
) {
Expand All @@ -131,7 +131,7 @@ exports.handler = async options => {
logger.log();
} else {
logError(
result.uploadError,
uploadError,
new ApiErrorContext({
accountId: derivedAccountId,
request: 'project upload',
Expand Down
12 changes: 6 additions & 6 deletions commands/sandbox/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const {
HUBSPOT_ACCOUNT_TYPES,
HUBSPOT_ACCOUNT_TYPE_STRINGS,
} = require('@hubspot/local-dev-lib/constants/config');
const { buildNewAccount } = require('../../lib/buildAccount');
const { buildSandbox } = require('../../lib/buildAccount');
const {
hubspotAccountNamePrompt,
} = require('../../lib/prompts/accountNamePrompt');
Expand Down Expand Up @@ -130,13 +130,13 @@ exports.handler = async options => {
}

try {
const { result } = await buildNewAccount({
name: sandboxName,
accountType: sandboxType,
const result = await buildSandbox(
sandboxName,
accountConfig,
sandboxType,
env,
force,
});
force
);

const sandboxAccountConfig = getAccountConfig(result.sandbox.sandboxHubId);
// For v1 sandboxes, keep sync here. Once we migrate to v2, this will be handled by BE automatically
Expand Down
Loading

0 comments on commit 98df6bf

Please sign in to comment.