Skip to content

Add util for getting account description #592

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Nov 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/cli/commands/project/listBuilds.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ const {
getTableHeader,
} = require('@hubspot/cli-lib/lib/table');
const { getCwd } = require('@hubspot/cli-lib/path');
const { link } = require('../../lib/ui');
const { loadAndValidateOptions } = require('../../lib/validation');
const { link } = require('../../lib/links');
const {
getProjectConfig,
getProjectDetailUrl,
Expand Down
17 changes: 9 additions & 8 deletions packages/cli/commands/project/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const {
logApiErrorInstance,
ApiErrorContext,
} = require('@hubspot/cli-lib/errorHandlers');
const { getAccountDescription } = require('../../lib/ui');
const { logger } = require('@hubspot/cli-lib/logger');
const { uploadProject } = require('@hubspot/cli-lib/api/dfs');
const { shouldIgnoreFile } = require('@hubspot/cli-lib/ignoreRules');
Expand All @@ -36,9 +37,9 @@ const uploadProjectFiles = async (accountId, projectName, filePath) => {
});

spinnies.add('upload', {
text: `Uploading ${chalk.bold(projectName)} project files to ${chalk.bold(
accountId
)}`,
text: `Uploading ${chalk.bold(
projectName
)} project files to ${getAccountDescription(accountId)}`,
});

let buildId;
Expand All @@ -49,9 +50,9 @@ const uploadProjectFiles = async (accountId, projectName, filePath) => {
buildId = upload.buildId;

spinnies.succeed('upload', {
text: `Uploaded ${chalk.bold(projectName)} project files to ${chalk.bold(
accountId
)}`,
text: `Uploaded ${chalk.bold(
projectName
)} project files to ${getAccountDescription(accountId)}`,
});

logger.debug(
Expand All @@ -61,7 +62,7 @@ const uploadProjectFiles = async (accountId, projectName, filePath) => {
spinnies.fail('upload', {
text: `Failed to upload ${chalk.bold(
projectName
)} project files to ${chalk.bold(accountId)}`,
)} project files to ${getAccountDescription(accountId)}`,
});

logApiErrorInstance(
Expand Down Expand Up @@ -143,7 +144,7 @@ exports.handler = async options => {
logger.log(
`Build #${buildId} succeeded. ${chalk.bold(
'Automatically deploying'
)} to ${accountId}`
)} to ${getAccountDescription(accountId)}`
);
const { status } = await pollDeployStatus(
accountId,
Expand Down
10 changes: 0 additions & 10 deletions packages/cli/lib/links.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const supportsHyperlinks = require('supports-hyperlinks');
const { getEnv } = require('@hubspot/cli-lib/lib/config');
const { ENVIRONMENTS } = require('@hubspot/cli-lib/lib/constants');
const { getHubSpotWebsiteOrigin } = require('@hubspot/cli-lib/lib/urls');
Expand Down Expand Up @@ -121,18 +120,9 @@ const openLink = (accountId, shortcut) => {
logger.success(`We opened ${match.url} in your browser`);
};

const link = (linkText, url, options = {}) => {
if (supportsHyperlinks.stdout) {
return ['\u001B]8;;', url, '\u0007', linkText, '\u001B]8;;\u0007'].join('');
} else {
return options.fallback ? `${linkText}: ${url}` : linkText;
}
};

module.exports = {
getSiteLinks,
getSiteLinksAsArray,
logSiteLinks,
openLink,
link,
};
6 changes: 4 additions & 2 deletions packages/cli/lib/projects.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ const {
createProject: createProjectTemplate,
} = require('@hubspot/cli-lib/projects');
const { getHubSpotWebsiteOrigin } = require('@hubspot/cli-lib/lib/urls');

const {
ENVIRONMENTS,
POLLING_DELAY,
Expand All @@ -30,6 +29,7 @@ const {
ApiErrorContext,
} = require('@hubspot/cli-lib/errorHandlers');
const { getCwd } = require('@hubspot/cli-lib/path');
const { getAccountDescription } = require('../lib/ui');

const PROJECT_STRINGS = {
BUILD: {
Expand Down Expand Up @@ -176,7 +176,9 @@ const ensureProjectExists = async (accountId, projectName, forceCreate) => {
const promptResult = await prompt([
{
name: 'shouldCreateProject',
message: `The project ${projectName} does not exist in ${accountId}. Would you like to create it?`,
message: `The project ${projectName} does not exist in ${getAccountDescription(
accountId
)}. Would you like to create it?`,
type: 'confirm',
},
]);
Expand Down
37 changes: 37 additions & 0 deletions packages/cli/lib/ui.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
const chalk = require('chalk');
const supportsHyperlinks = require('supports-hyperlinks');
const { getAccountConfig } = require('@hubspot/cli-lib/lib/config');

/**
* Returns a hyperlink or link and description
*
* @param {string} linkText
* @param {string} url
* @param {object} options
* @returns {string}
*/
const link = (linkText, url, options = {}) => {
if (supportsHyperlinks.stdout) {
return ['\u001B]8;;', url, '\u0007', linkText, '\u001B]8;;\u0007'].join('');
} else {
return options.fallback ? `${linkText}: ${url}` : linkText;
}
};

/**
* Returns formatted account name and ID
*
* @param {number} accountId
* @returns {string}
*/
const getAccountDescription = accountId => {
const account = getAccountConfig(accountId);
return chalk.bold(
account.name ? `${account.name} (${account.portalId})` : account.portalId
);
};

module.exports = {
link,
getAccountDescription,
};
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@brandenrodgers I requested another review because I thought it might make sense to pull these "ui" related utils together in the CLI package but wanted to get your 👍 first

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it 👍