Skip to content

Commit

Permalink
remove log callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
brandenrodgers committed Feb 1, 2024
1 parent 6475cf3 commit ed89864
Show file tree
Hide file tree
Showing 10 changed files with 8 additions and 159 deletions.
18 changes: 1 addition & 17 deletions packages/cli/commands/create/function.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,13 @@ const {
} = require('../../lib/prompts/createFunctionPrompt');
const { logErrorInstance } = require('../../lib/errorHandlers/standardErrors');
const { EXIT_CODES } = require('../../lib/enums/exitCodes');
const { buildLogCallbacks } = require('../../lib/logCallbacks');

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

const createFunctionLogCallbacks = buildLogCallbacks({
destPathAlreadyExists: `${i18nKey}.logCallbacks.destPathAlreadyExists`,
createdDest: `${i18nKey}.logCallbacks.createdDest`,
createdFunctionFile: `${i18nKey}.logCallbacks.createdFunctionFile`,
createdConfigFile: `${i18nKey}.logCallbacks.createdConfigFile`,
success: `${i18nKey}.logCallbacks.success`,
});

module.exports = {
dest: ({ name }) => name,
execute: async ({ dest }) => {
const functionDefinition = await createFunctionPrompt();
try {
await createFunction(
functionDefinition,
dest,
{},
createFunctionLogCallbacks
);
await createFunction(functionDefinition, dest);
} catch (e) {
logErrorInstance(e);
process.exit(EXIT_CODES.ERROR);
Expand Down
15 changes: 1 addition & 14 deletions packages/cli/commands/create/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,9 @@ const { i18n } = require('../../lib/lang');
const { createModulePrompt } = require('../../lib/prompts/createModulePrompt');
const { logErrorInstance } = require('../../lib/errorHandlers/standardErrors');
const { EXIT_CODES } = require('../../lib/enums/exitCodes');
const { buildLogCallbacks } = require('../../lib/logCallbacks');

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

const createModuleLogCallbacks = buildLogCallbacks({
creatingPath: `${i18nKey}.logCallbacks.creatingPath`,
creatingModule: `${i18nKey}.logCallbacks.creatingModule`,
});

module.exports = {
dest: ({ dest }) => dest,
validate: ({ name }) => {
Expand All @@ -25,14 +19,7 @@ module.exports = {
execute: async ({ name, dest }) => {
const moduleDefinition = await createModulePrompt();
try {
await createModule(
moduleDefinition,
name,
dest,
false,
{},
createModuleLogCallbacks
);
await createModule(moduleDefinition, name, dest);
} catch (e) {
logErrorInstance(e);
process.exit(EXIT_CODES.ERROR);
Expand Down
13 changes: 1 addition & 12 deletions packages/cli/commands/create/template.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,9 @@ const {
} = require('../../lib/prompts/createTemplatePrompt');
const { i18n } = require('../../lib/lang');
const { EXIT_CODES } = require('../../lib/enums/exitCodes');
const { buildLogCallbacks } = require('../../lib/logCallbacks');

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

const createTemplateLogCallbacks = buildLogCallbacks({
creatingFile: `${i18nKey}.logCallbacks.creatingFile`,
});

module.exports = {
dest: ({ dest }) => dest,
validate: ({ name }) => {
Expand All @@ -27,13 +22,7 @@ module.exports = {
execute: async ({ name, dest }) => {
const { templateType } = await createTemplatePrompt();
try {
await createTemplate(
name,
dest,
templateType,
{},
createTemplateLogCallbacks
);
await createTemplate(name, dest, templateType);
} catch (e) {
logErrorInstance(e);
process.exit(EXIT_CODES.ERROR);
Expand Down
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('@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 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('@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`);

Expand All @@ -57,8 +41,7 @@ exports.handler = async options => {
src,
dest,
false,
includeArchived || false,
downloadLogCallbacks
includeArchived || false
);
} catch (err) {
logErrorInstance(err);
Expand Down
7 changes: 1 addition & 6 deletions packages/cli/commands/filemanager/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,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 @@ -128,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
34 changes: 0 additions & 34 deletions packages/cli/lang/en.lyaml
Original file line number Diff line number Diff line change
Expand Up @@ -171,23 +171,10 @@ en:
apiSamples: "Loading available API samples"
success:
sampleCreated: "Please, follow {{ filePath }}/README.md to find out how to run the sample"
function:
logCallbacks:
destPathAlreadyExists: "The {{ path }} path already exists"
createdDest: "Created {{ path }}"
failedToCreateFile: "The file {{ configFilePath }} could not be created"
createdFunctionFile: "Created {{ path }}"
createdConfigFile: "Created {{ path }}"
success: "A function for the endpoint '/_hcms/api/{{ endpointPath }}' has been created. Upload {{ folderName }} to try it out"
module:
logCallbacks:
creatingModule: "Creating module at {{ path }}"
creatingPath: "Creating {{ path }}"
errors:
nameRequired: "The \"name\" argument is required when creating a Custom Module."
template:
logCallbacks:
creatingFile: "Creating file at {{ path }}"
errors:
nameRequired: "The \"name\" argument is required when creating a Template."
customObject:
Expand Down Expand Up @@ -287,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 @@ -308,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 @@ -332,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 @@ -658,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 @@ -948,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
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

0 comments on commit ed89864

Please sign in to comment.