Skip to content

Commit

Permalink
Merge branch 'master' into br-update-cms-imports
Browse files Browse the repository at this point in the history
  • Loading branch information
brandenrodgers committed Feb 1, 2024
2 parents 8098829 + 0ef5da3 commit f124a23
Show file tree
Hide file tree
Showing 19 changed files with 253 additions and 177 deletions.
2 changes: 1 addition & 1 deletion acceptance-tests/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "acceptance-tests",
"version": "5.1.1",
"version": "5.1.2",
"description": "Acceptance tests for cli",
"private": true,
"author": "Mike Talley <[email protected]>",
Expand Down
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.1.1"
"version": "5.1.3-beta.0"
}
32 changes: 24 additions & 8 deletions packages/cli/commands/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ const {
} = require('@hubspot/cli-lib/lib/constants');
const { i18n } = require('../lib/lang');
const {
updateConfigWithPersonalAccessKey,
getAccessToken,
updateConfigWithAccessToken,
} = require('@hubspot/local-dev-lib/personalAccessKey');
const {
updateAccountConfig,
Expand All @@ -17,7 +18,10 @@ const {
getConfigPath,
loadConfig,
} = require('@hubspot/local-dev-lib/config');
const { commaSeparatedValues } = require('@hubspot/local-dev-lib/text');
const {
commaSeparatedValues,
toKebabCase,
} = require('@hubspot/local-dev-lib/text');
const { promptUser } = require('../lib/prompts/promptUtils');
const {
personalAccessKeyPrompt,
Expand All @@ -40,6 +44,7 @@ const { trackAuthAction, trackCommandUsage } = require('../lib/usageTracking');
const { authenticateWithOauth } = require('../lib/oauth');
const { EXIT_CODES } = require('../lib/enums/exitCodes');
const { uiFeatureHighlight } = require('../lib/ui');
const { logErrorInstance } = require('@hubspot/cli-lib/errorHandlers');

const i18nKey = 'cli.commands.auth';

Expand Down Expand Up @@ -85,6 +90,8 @@ exports.handler = async options => {
let updatedConfig;
let validName;
let successAuthMethod;
let token;
let defaultName;

switch (authType) {
case OAUTH_AUTH_METHOD.value:
Expand All @@ -98,10 +105,18 @@ exports.handler = async options => {
case PERSONAL_ACCESS_KEY_AUTH_METHOD.value:
configData = await personalAccessKeyPrompt({ env, account });

updatedConfig = await updateConfigWithPersonalAccessKey(
configData.personalAccessKey,
env
);
try {
token = await getAccessToken(configData.personalAccessKey, env);
defaultName = toKebabCase(token.hubName);

updatedConfig = await updateConfigWithAccessToken(
token,
configData.personalAccessKey,
env
);
} catch (e) {
logErrorInstance(e);
}

if (!updatedConfig) {
break;
Expand All @@ -110,7 +125,7 @@ exports.handler = async options => {
validName = updatedConfig.name;

if (!validName) {
const { name: namePrompt } = await enterAccountNamePrompt();
const { name: namePrompt } = await enterAccountNamePrompt(defaultName);
validName = namePrompt;
}

Expand Down Expand Up @@ -139,7 +154,8 @@ exports.handler = async options => {
process.exit(EXIT_CODES.ERROR);
}

const accountName = updatedConfig.name || validName;
const accountName =
(updatedConfig && updatedConfig.name) || validName || configData.name;

const setAsDefault = await setAsDefaultAccountPrompt(accountName);

Expand Down
40 changes: 31 additions & 9 deletions packages/cli/commands/fetch.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { downloadFileOrFolder } = require('@hubspot/cli-lib/fileMapper');
const { downloadFileOrFolder } = require('@hubspot/local-dev-lib/fileMapper');
const { logger } = require('@hubspot/cli-lib/logger');

const {
Expand All @@ -17,6 +17,22 @@ const { i18n } = require('../lib/lang');

const i18nKey = 'cli.commands.fetch';
const { EXIT_CODES } = require('../lib/enums/exitCodes');
const { buildLogCallbacks } = require('../lib/logCallbacks');
const { logErrorInstance } = require('@hubspot/cli-lib/errorHandlers');

const fileMapperLogCallbacks = buildLogCallbacks({
skippedExisting: `${i18nKey}.fileMapperLogCallbacks.skippedExisting`,
wroteFolder: `${i18nKey}.fileMapperLogCallbacks.wroteFolder`,
completedFetch: {
key: `${i18nKey}.fileMapperLogCallbacks.completedFetch`,
logger: logger.success,
},
folderFetch: `${i18nKey}.fileMapperLogCallbacks.folderFetch`,
completedFolderFetch: {
key: `${i18nKey}.fileMapperLogCallbacks.completedFolderFetch`,
logger: logger.success,
},
});

exports.command = 'fetch <src> [dest]';
exports.describe = i18n(`${i18nKey}.describe`);
Expand All @@ -40,14 +56,20 @@ exports.handler = async options => {

trackCommandUsage('fetch', { mode }, accountId);

// Fetch and write file/folder.
downloadFileOrFolder({
accountId,
src,
dest: resolveLocalPath(dest),
mode,
options,
});
try {
// Fetch and write file/folder.
await downloadFileOrFolder(
accountId,
src,
resolveLocalPath(dest),
mode,
options,
fileMapperLogCallbacks
);
} catch (err) {
logErrorInstance(err);
process.exit(EXIT_CODES.ERROR);
}
};

exports.builder = yargs => {
Expand Down
36 changes: 32 additions & 4 deletions packages/cli/commands/filemanager/fetch.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const { downloadFileOrFolder } = require('@hubspot/cli-lib/fileManager');
const { downloadFileOrFolder } = require('@hubspot/local-dev-lib/fileManager');
const { logger } = require('@hubspot/cli-lib/logger');
const { resolveLocalPath } = require('../../lib/filesystem');
const { buildLogCallbacks } = require('../../lib/logCallbacks');

const {
addConfigOptions,
Expand All @@ -14,12 +15,27 @@ const { i18n } = require('../../lib/lang');

const i18nKey = 'cli.commands.filemanager.subcommands.fetch';
const { EXIT_CODES } = require('../../lib/enums/exitCodes');
const { logErrorInstance } = require('@hubspot/cli-lib/errorHandlers');

const downloadLogCallbacks = buildLogCallbacks({
skippedExisting: `${i18nKey}.downloadLogCallbacks.skippedExisting`,
fetchFolderStarted: `${i18nKey}.downloadLogCallbacks.fetchFolderStarted`,
fetchFolderSuccess: {
key: `${i18nKey}.downloadLogCallbacks.fetchFolderSuccess`,
logger: logger.success,
},
fetchFileStarted: `${i18nKey}.downloadLogCallbacks.fetchFileStarted`,
fetchFileSuccess: {
key: `${i18nKey}.downloadLogCallbacks.fetchFileSuccess`,
logger: logger.success,
},
});

exports.command = 'fetch <src> [dest]';
exports.describe = i18n(`${i18nKey}.describe`);

exports.handler = async options => {
let { src, dest } = options;
let { src, dest, includeArchived } = options;

await loadAndValidateOptions(options);

Expand All @@ -34,8 +50,20 @@ exports.handler = async options => {

trackCommandUsage('filemanager-fetch', null, accountId);

// Fetch and write file/folder.
await downloadFileOrFolder(accountId, src, dest, options);
try {
// Fetch and write file/folder.
await downloadFileOrFolder(
accountId,
src,
dest,
false,
includeArchived || false,
downloadLogCallbacks
);
} catch (err) {
logErrorInstance(err);
process.exit(EXIT_CODES.ERROR);
}
};

exports.builder = yargs => {
Expand Down
9 changes: 7 additions & 2 deletions packages/cli/commands/filemanager/upload.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const fs = require('fs');
const path = require('path');

const { uploadFolder } = require('@hubspot/cli-lib/fileManager');
const { uploadFolder } = require('@hubspot/local-dev-lib/fileManager');
const { uploadFile } = require('@hubspot/cli-lib/api/fileManager');
const { getCwd, convertToUnixPath } = require('@hubspot/local-dev-lib/path');
const { logger } = require('@hubspot/cli-lib/logger');
Expand All @@ -27,6 +27,11 @@ const { i18n } = require('../../lib/lang');

const i18nKey = 'cli.commands.filemanager.subcommands.upload';
const { EXIT_CODES } = require('../../lib/enums/exitCodes');
const { buildLogCallbacks } = require('../../lib/logCallbacks');

const uploadLogCallbacks = buildLogCallbacks({
uploadSuccess: `${i18nKey}.uploadLogCallbacks.uploadSuccess`,
});

exports.command = 'upload <src> <dest>';
exports.describe = i18n(`${i18nKey}.describe`);
Expand Down Expand Up @@ -123,7 +128,7 @@ exports.handler = async options => {
src,
})
);
uploadFolder(accountId, absoluteSrcPath, dest)
uploadFolder(accountId, absoluteSrcPath, dest, uploadLogCallbacks)
.then(() => {
logger.success(
i18n(`${i18nKey}.success.uploadComplete`, {
Expand Down
13 changes: 9 additions & 4 deletions packages/cli/commands/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ const {
const { i18n } = require('../lib/lang');
const { logger } = require('@hubspot/cli-lib/logger');
const {
updateConfigWithPersonalAccessKey,
getAccessToken,
updateConfigWithAccessToken,
} = require('@hubspot/local-dev-lib/personalAccessKey');
const { getCwd } = require('@hubspot/local-dev-lib/path');
const { toKebabCase } = require('@hubspot/local-dev-lib/text');
const { trackCommandUsage, trackAuthAction } = require('../lib/usageTracking');
const { setLogLevel, addTestingOptions } = require('../lib/commonOpts');
const { promptUser } = require('../lib/prompts/promptUtils');
Expand All @@ -52,12 +54,15 @@ const TRACKING_STATUS = {

const personalAccessKeyConfigCreationFlow = async (env, account) => {
const { personalAccessKey } = await personalAccessKeyPrompt({ env, account });
const { name } = await enterAccountNamePrompt();

let updatedConfig;

try {
updatedConfig = updateConfigWithPersonalAccessKey(
const token = await getAccessToken(personalAccessKey, env);
const defaultName = toKebabCase(token.hubName);
const { name } = await enterAccountNamePrompt(defaultName);

updatedConfig = updateConfigWithAccessToken(
token,
personalAccessKey,
env,
name,
Expand Down
6 changes: 4 additions & 2 deletions packages/cli/commands/upload.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
const fs = require('fs');
const path = require('path');
const { uploadFolder, hasUploadErrors } = require('@hubspot/cli-lib');
const { getFileMapperQueryValues } = require('@hubspot/cli-lib/fileMapper');
const {
getFileMapperQueryValues,
} = require('@hubspot/local-dev-lib/fileMapper');
const { upload, deleteFile } = require('@hubspot/cli-lib/api/fileMapper');
const {
getCwd,
Expand Down Expand Up @@ -158,7 +160,7 @@ exports.handler = async options => {
accountId,
absoluteSrcPath,
normalizedDest,
getFileMapperQueryValues({ mode, options })
getFileMapperQueryValues(mode, options)
)
.then(() => {
logger.success(
Expand Down
18 changes: 18 additions & 0 deletions packages/cli/lang/en.lyaml
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,12 @@ en:
describe: "Local directory you would like the files to be placed in, relative to your current working directory"
src:
describe: "Path in HubSpot Design Tools"
fileMapperLogCallbacks:
skippedExisting: 'Skipped existing "{{ filepath }}"'
wroteFolder: 'Wrote folder "{{ filepath }}"'
completedFetch: 'Completed fetch of file "{{ src }}"{{ version }} to "{{ dest }}" from the Design Manager'
folderFetch: 'Fetched "{{ src }}" from account {{ accountId }} from the Design Manager successfully'
completedFolderFetch: 'Completed fetch of folder "{{ src }}"{{ version }} to "{{ dest }}" from the Design Manager'
filemanager:
describe: "Commands for working with the File Manager."
subcommands:
Expand All @@ -289,6 +295,12 @@ en:
describe: "Path in HubSpot Design Tools"
src:
describe: "Path to the local directory you would like the files to be placed, relative to your current working directory. If omitted, this argument will default to your current working directory"
downloadLogCallbacks:
skippedExisting: "Skipped existing {{ filepath }}"
fetchFolderStarted: 'Fetching folder from "{{ src }}" to "{{ dest }}" in the File Manager of account {{ accountId }}'
fetchFolderSuccess: "Completed fetch of folder \"{{ src }}\" to \"{{ dest }}\" from the File Manager"
fetchFileStarted: "Fetching file from \"{{ src }}\" to \"{{ dest }}\" in the File Manager of account {{ accountId }}"
fetchFileSuccess: "Completed fetch of file \"{{ src }}\" to \"{{ dest }}\" from the File Manager"
upload:
describe: "Upload a folder or file from your computer to the HubSpot File Manager"
errors:
Expand All @@ -307,6 +319,8 @@ en:
success:
upload: "Uploaded file from \"{{ src }}\" to \"{{ dest }}\" in the File Manager of account {{ accountId }}"
uploadComplete: "Uploading files to \"{{ dest }}\" in the File Manager is complete"
uploadLogCallbacks:
uploadSuccess: 'Uploaded file "{{ file }}" to "{{ destPath }}"'
functions:
describe: "Commands for working with functions."
subcommands:
Expand Down Expand Up @@ -921,6 +935,10 @@ en:
setupError: "Failed to setup local dev server: {{ message }}"
startError: "Failed to start local dev server: {{ message }}"
fileChangeError: "Failed to notify local dev server of file change: {{ message }}"
oauth:
logCallbacks:
init: "Updating configuration"
success: "Configuration updated"
projects:
config:
srcOutsideProjectDir: "Invalid value for 'srcDir' in {{ projectConfig }}: {{#bold}}srcDir: \"{{ srcDir }}\"{{/bold}}\n\t'srcDir' must be a relative path to a folder under the project root, such as \".\" or \"./src\""
Expand Down
2 changes: 0 additions & 2 deletions packages/cli/lib/DevServerManager.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const httpClient = require('@hubspot/cli-lib/http');
const { logger } = require('@hubspot/cli-lib/logger');
const { COMPONENT_TYPES } = require('./projectStructure');
const { i18n } = require('./lang');
Expand Down Expand Up @@ -91,7 +90,6 @@ class DevServerManager {
await serverInterface.start({
accountId,
debug: this.debug,
httpClient,
projectConfig,
requestPorts,
});
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/lib/__tests__/validation.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { getAccountConfig } = require('@hubspot/local-dev-lib/config');
const { getOauthManager } = require('@hubspot/cli-lib/oauth');
const { getOauthManager } = require('@hubspot/local-dev-lib/oauth');
const {
accessTokenForPersonalAccessKey,
} = require('@hubspot/local-dev-lib/personalAccessKey');
Expand All @@ -10,7 +10,7 @@ const { validateAccount } = require('../validation');
jest.mock('@hubspot/cli-lib');
jest.mock('@hubspot/local-dev-lib/config');
jest.mock('@hubspot/cli-lib/logger');
jest.mock('@hubspot/cli-lib/oauth');
jest.mock('@hubspot/local-dev-lib/oauth');
jest.mock('@hubspot/local-dev-lib/personalAccessKey');
jest.mock('../commonOpts');

Expand Down
8 changes: 7 additions & 1 deletion packages/cli/lib/logCallbacks.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ const { i18n } = require('./lang');
function buildLogCallbacks(logData) {
const callbacksObject = {};
for (let key in logData) {
callbacksObject[key] = () => logger.log(i18n(logData[key]));
if (typeof logData[key] === 'string') {
callbacksObject[key] = interpolationData =>
logger.log(i18n(logData[key], interpolationData));
} else {
callbacksObject[key] = interpolationData =>
logData[key].logger(i18n(logData[key].key, interpolationData));
}
}
return callbacksObject;
}
Expand Down
Loading

0 comments on commit f124a23

Please sign in to comment.