Skip to content

Commit

Permalink
Merge pull request #977 from HubSpot/br-update-cms-imports
Browse files Browse the repository at this point in the history
Update some more of the cms imports to use local-dev-lib
  • Loading branch information
brandenrodgers authored Feb 5, 2024
2 parents 1533a21 + a204498 commit 07e9b17
Show file tree
Hide file tree
Showing 15 changed files with 79 additions and 120 deletions.
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);
}
},
};
14 changes: 10 additions & 4 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,11 +14,15 @@ module.exports = {
logger.error(i18n(`${i18nKey}.errors.nameRequired`));
return false;
}

return true;
},
execute: async ({ name, dest }) => {
const moduleDefinition = await createModulePrompt();
await createModule(moduleDefinition, name, dest);
try {
await createModule(moduleDefinition, name, dest);
} 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 };
},
};
19 changes: 1 addition & 18 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,23 +16,8 @@ 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('../lib/errorHandlers/standardErrors');

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 Down Expand Up @@ -63,8 +47,7 @@ exports.handler = async options => {
src,
resolveLocalPath(dest),
mode,
options,
fileMapperLogCallbacks
options
);
} catch (err) {
logErrorInstance(err);
Expand Down
19 changes: 1 addition & 18 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 @@ -17,20 +15,6 @@ const i18nKey = 'cli.commands.filemanager.subcommands.fetch';
const { EXIT_CODES } = require('../../lib/enums/exitCodes');
const { logErrorInstance } = require('../../lib/errorHandlers/standardErrors');

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`);

Expand All @@ -57,8 +41,7 @@ exports.handler = async options => {
src,
dest,
false,
includeArchived || false,
downloadLogCallbacks
includeArchived || false
);
} catch (err) {
logErrorInstance(err);
Expand Down
15 changes: 6 additions & 9 deletions packages/cli/commands/filemanager/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@ 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');
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
9 changes: 1 addition & 8 deletions packages/cli/commands/project/download.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,10 @@ const {
} = require('../../lib/prompts/downloadProjectPrompt');
const { i18n } = require('../../lib/lang');
const { uiBetaTag } = require('../../lib/ui');
const { buildLogCallbacks } = require('../../lib/logCallbacks');

const i18nKey = 'cli.commands.project.subcommands.download';
const { EXIT_CODES } = require('../../lib/enums/exitCodes');

const archiveLogCallbacks = buildLogCallbacks({
init: `${i18nKey}.archiveLogCallbacks.init`,
copy: `${i18nKey}.archiveLogCallbacks.copy`,
});

exports.command = 'download [--project]';
exports.describe = uiBetaTag(i18n(`${i18nKey}.describe`), false);

Expand Down Expand Up @@ -99,8 +93,7 @@ exports.handler = async options => {
zippedProject,
projectName,
path.resolve(absoluteDestPath),
{ includesRootDir: false },
archiveLogCallbacks
{ includesRootDir: false }
);

logger.log(
Expand Down
13 changes: 8 additions & 5 deletions packages/cli/commands/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,14 @@ const {
logApiUploadErrorInstance,
} = require('../lib/errorHandlers/apiErrors');
const { logErrorInstance } = require('../lib/errorHandlers/standardErrors');
const { validateSrcAndDestPaths } = require('@hubspot/cli-lib/modules');
const {
validateSrcAndDestPaths,
} = require('@hubspot/local-dev-lib/cms/modules');
const { shouldIgnoreFile } = require('@hubspot/local-dev-lib/ignoreRules');
const {
getThemePreviewUrl,
getThemeJSONPath,
} = require('@hubspot/local-dev-lib/cms/themes');

const {
addConfigOptions,
Expand All @@ -32,10 +38,7 @@ const { cleanUploadPrompt } = require('../lib/prompts/cleanUploadPrompt');
const { validateMode, loadAndValidateOptions } = require('../lib/validation');
const { trackCommandUsage } = require('../lib/usageTracking');
const { getUploadableFileList } = require('../lib/upload');
const {
getThemePreviewUrl,
getThemeJSONPath,
} = require('@hubspot/local-dev-lib/cms/themes');

const { i18n } = require('../lib/lang');
const i18nKey = 'cli.commands.upload';
const { EXIT_CODES } = require('../lib/enums/exitCodes');
Expand Down
21 changes: 0 additions & 21 deletions packages/cli/lang/en.lyaml
Original file line number Diff line number Diff line change
Expand Up @@ -274,12 +274,6 @@ 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 @@ -295,12 +289,6 @@ 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 @@ -319,8 +307,6 @@ 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 @@ -645,9 +631,6 @@ en:
describe: "The name of the project to download"
dest:
describe: "Destination folder for the project"
archiveLogCallbacks:
init: "Extracting project source..."
copy: "Copying project source..."
open:
describe: "Open the specified project's details page in the browser"
options:
Expand Down Expand Up @@ -935,10 +918,6 @@ 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
11 changes: 11 additions & 0 deletions packages/cli/lib/commonOpts.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
const Logger = require('@hubspot/cli-lib/logger');
const {
setLogLevel: setLocalDevLibLogLevel,
} = require('@hubspot/local-dev-lib/logger');
const { DEFAULT_MODE, Mode } = require('@hubspot/cli-lib');
const {
getAccountId: getAccountIdFromConfig,
Expand Down Expand Up @@ -66,8 +69,16 @@ const setLogLevel = (options = {}) => {
const { debug } = options;
if (debug) {
Logger.setLogLevel(LOG_LEVEL.DEBUG);

// Update the log level in local-dev-lib's instance of the logger
// This will evenutally replace cli-lib's version of it
setLocalDevLibLogLevel(LOG_LEVEL.DEBUG);
} else {
Logger.setLogLevel(LOG_LEVEL.LOG);

// Update the log level in local-dev-lib's instance of the logger
// This will evenutally replace cli-lib's version of it
setLocalDevLibLogLevel(LOG_LEVEL.LOG);
}
};

Expand Down
20 changes: 0 additions & 20 deletions packages/cli/lib/logCallbacks.js

This file was deleted.

13 changes: 1 addition & 12 deletions packages/cli/lib/oauth.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,10 @@ const { handleExit } = require('./process');
const { getHubSpotWebsiteOrigin } = require('@hubspot/local-dev-lib/urls');
const { logger } = require('@hubspot/cli-lib/logger');
const { ENVIRONMENTS } = require('@hubspot/cli-lib/lib/constants');
const { buildLogCallbacks } = require('./logCallbacks');

const PORT = 3000;
const redirectUri = `http://localhost:${PORT}/oauth-callback`;

const i18nKey = 'cli.lib.oauth';

const oauthLogCallbacks = buildLogCallbacks({
init: `${i18nKey}.logCallbacks.init`,
success: {
key: `${i18nKey}.logCallbacks.success`,
logger: logger.success,
},
});

const buildAuthUrl = oauthManager => {
return (
`${getHubSpotWebsiteOrigin(oauthManager.account.env)}/oauth/${
Expand Down Expand Up @@ -107,7 +96,7 @@ const authenticateWithOauth = async configData => {
const oauthManager = setupOauth(configData);
logger.log('Authorizing');
await authorize(oauthManager);
addOauthToAccountConfig(oauthManager, oauthLogCallbacks);
addOauthToAccountConfig(oauthManager);
};

module.exports = {
Expand Down
Loading

0 comments on commit 07e9b17

Please sign in to comment.