Skip to content

Commit

Permalink
Merge branch 'master' into ts/159-JSR-list-modules
Browse files Browse the repository at this point in the history
# Conflicts:
#	packages/cli/commands/create/module.js
#	yarn.lock
  • Loading branch information
TanyaScales committed Feb 6, 2024
2 parents b0880e6 + e094a05 commit f7c50fb
Show file tree
Hide file tree
Showing 40 changed files with 280 additions and 290 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('../lib/errorHandlers/standardErrors');

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
2 changes: 1 addition & 1 deletion packages/cli/commands/cms/convertFields.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const {
} = require('@hubspot/cli-lib/lib/handleFieldsJs');

const { trackConvertFieldsUsage } = require('../../lib/usageTracking');
const { logErrorInstance } = require('@hubspot/cli-lib/errorHandlers');
const { logErrorInstance } = require('../../lib/errorHandlers/standardErrors');
const i18nKey = 'cli.commands.convertFields';

exports.command = 'convert-fields';
Expand Down
11 changes: 9 additions & 2 deletions packages/cli/commands/create/function.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
const { createFunction } = require('@hubspot/cli-lib/functions');
const { createFunction } = require('@hubspot/local-dev-lib/cms/functions');
const {
createFunctionPrompt,
} = require('../../lib/prompts/createFunctionPrompt');
const { logErrorInstance } = require('../../lib/errorHandlers/standardErrors');
const { EXIT_CODES } = require('../../lib/enums/exitCodes');

module.exports = {
dest: ({ name }) => name,
execute: async ({ dest }) => {
const functionDefinition = await createFunctionPrompt();
createFunction(functionDefinition, dest);
try {
await createFunction(functionDefinition, dest);
} catch (e) {
logErrorInstance(e);
process.exit(EXIT_CODES.ERROR);
}
},
};
15 changes: 10 additions & 5 deletions packages/cli/commands/create/module.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
const { createModulePrompt } = require('../../lib/prompts/createModulePrompt');
const { logger } = require('@hubspot/cli-lib/logger');
const { createModule } = require('@hubspot/local-dev-lib/cms/modules');
const { i18n } = require('../../lib/lang');
const { createModule } = require('@hubspot/cli-lib/modules');
const { createModulePrompt } = require('../../lib/prompts/createModulePrompt');
const { logErrorInstance } = require('../../lib/errorHandlers/standardErrors');
const { EXIT_CODES } = require('../../lib/enums/exitCodes');

const i18nKey = 'cli.commands.create.subcommands.module';

Expand All @@ -12,12 +14,15 @@ module.exports = {
logger.error(i18n(`${i18nKey}.errors.nameRequired`));
return false;
}

return true;
},
execute: async ({ name, dest, getInternalVersion }) => {
const moduleDefinition = await createModulePrompt();

await createModule(moduleDefinition, name, dest, getInternalVersion);
try {
await createModule(moduleDefinition, name, dest, getInternalVersion);
} catch (e) {
logErrorInstance(e);
process.exit(EXIT_CODES.ERROR);
}
},
};
13 changes: 10 additions & 3 deletions packages/cli/commands/create/template.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
const { createTemplate } = require('@hubspot/local-dev-lib/cms/templates');
const { logger } = require('@hubspot/cli-lib/logger');
const { logErrorInstance } = require('../../lib/errorHandlers/standardErrors');
const {
createTemplatePrompt,
} = require('../../lib/prompts/createTemplatePrompt');
const { logger } = require('@hubspot/cli-lib/logger');
const { i18n } = require('../../lib/lang');
const { createTemplate } = require('@hubspot/cli-lib/templates');
const { EXIT_CODES } = require('../../lib/enums/exitCodes');

const i18nKey = 'cli.commands.create.subcommands.template';

Expand All @@ -19,7 +21,12 @@ module.exports = {
},
execute: async ({ name, dest }) => {
const { templateType } = await createTemplatePrompt();
await createTemplate(name, dest, templateType);
try {
await createTemplate(name, dest, templateType);
} catch (e) {
logErrorInstance(e);
process.exit(EXIT_CODES.ERROR);
}
return { templateType };
},
};
21 changes: 2 additions & 19 deletions packages/cli/commands/fetch.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const { downloadFileOrFolder } = require('@hubspot/local-dev-lib/fileMapper');
const { logger } = require('@hubspot/cli-lib/logger');

const {
addConfigOptions,
addAccountOptions,
Expand All @@ -17,22 +16,7 @@ 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,
},
});
const { logErrorInstance } = require('../lib/errorHandlers/standardErrors');

exports.command = 'fetch <src> [dest]';
exports.describe = i18n(`${i18nKey}.describe`);
Expand Down Expand Up @@ -63,8 +47,7 @@ exports.handler = async options => {
src,
resolveLocalPath(dest),
mode,
options,
fileMapperLogCallbacks
options
);
} catch (err) {
logErrorInstance(err);
Expand Down
21 changes: 2 additions & 19 deletions packages/cli/commands/filemanager/fetch.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
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,
addAccountOptions,
Expand All @@ -15,21 +13,7 @@ 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,
},
});
const { logErrorInstance } = require('../../lib/errorHandlers/standardErrors');

exports.command = 'fetch <src> [dest]';
exports.describe = i18n(`${i18nKey}.describe`);
Expand Down Expand Up @@ -57,8 +41,7 @@ exports.handler = async options => {
src,
dest,
false,
includeArchived || false,
downloadLogCallbacks
includeArchived || false
);
} catch (err) {
logErrorInstance(err);
Expand Down
17 changes: 7 additions & 10 deletions packages/cli/commands/filemanager/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@ const fs = require('fs');
const path = require('path');

const { uploadFolder } = require('@hubspot/local-dev-lib/fileManager');
const { uploadFile } = require('@hubspot/cli-lib/api/fileManager');
const { uploadFile } = require('@hubspot/local-dev-lib/api/fileManager');
const { getCwd, convertToUnixPath } = require('@hubspot/local-dev-lib/path');
const { logger } = require('@hubspot/cli-lib/logger');
const {
validateSrcAndDestPaths,
} = require('@hubspot/local-dev-lib/cms/modules');
const { shouldIgnoreFile } = require('@hubspot/local-dev-lib/ignoreRules');

const {
ApiErrorContext,
logApiUploadErrorInstance,
} = require('../../lib/errorHandlers/apiErrors');
const { logErrorInstance } = require('../../lib/errorHandlers/standardErrors');
const { validateSrcAndDestPaths } = require('@hubspot/cli-lib/modules');
const { shouldIgnoreFile } = require('@hubspot/local-dev-lib/ignoreRules');

const {
addConfigOptions,
addAccountOptions,
Expand All @@ -25,11 +27,6 @@ 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 @@ -126,7 +123,7 @@ exports.handler = async options => {
src,
})
);
uploadFolder(accountId, absoluteSrcPath, dest, uploadLogCallbacks)
uploadFolder(accountId, absoluteSrcPath, dest)
.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
2 changes: 1 addition & 1 deletion packages/cli/commands/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const {
} = require('../lib/errorHandlers/apiErrors');
const {
getDirectoryContentsByPath,
} = require('@hubspot/cli-lib/api/fileMapper');
} = require('@hubspot/local-dev-lib/api/fileMapper');
const {
HUBSPOT_FOLDER,
MARKETPLACE_FOLDER,
Expand Down
3 changes: 1 addition & 2 deletions packages/cli/commands/mv.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
const { moveFile } = require('@hubspot/cli-lib/api/fileMapper');
const { moveFile } = require('@hubspot/local-dev-lib/api/fileMapper');
const { logger } = require('@hubspot/cli-lib/logger');
const {
logApiErrorInstance,
ApiErrorContext,
} = require('../lib/errorHandlers/apiErrors');

const {
addConfigOptions,
addAccountOptions,
Expand Down
6 changes: 4 additions & 2 deletions packages/cli/commands/project/dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,11 @@ const { getHubSpotWebsiteOrigin } = require('@hubspot/local-dev-lib/urls');
const {
logApiErrorInstance,
ApiErrorContext,
isMissingScopeError,
isSpecifiedError,
isSpecifiedError, // Migrate isSpecifiedError to local-dev-lib version only after uploadProject is migrated to local-dev-lib
} = require('../../lib/errorHandlers/apiErrors');
const {
isMissingScopeError,
} = require('@hubspot/local-dev-lib/errors/apiErrors');
const { logErrorInstance } = require('../../lib/errorHandlers/standardErrors');

const i18nKey = 'cli.commands.project.subcommands.dev';
Expand Down
Loading

0 comments on commit f7c50fb

Please sign in to comment.