Skip to content

Commit

Permalink
Merge pull request #960 from HubSpot/swap-cli-lib-deps-4
Browse files Browse the repository at this point in the history
Use local-dev-lib for archive and gitignore
  • Loading branch information
camden11 authored Dec 4, 2023
2 parents 16cc4bd + 6661e30 commit 5c92038
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 6 deletions.
15 changes: 12 additions & 3 deletions packages/cli/commands/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,13 @@ const {
} = require('@hubspot/local-dev-lib/config');
const { addConfigOptions } = require('../lib/commonOpts');
const { handleExit } = require('../lib/process');
const { checkAndUpdateGitignore } = require('@hubspot/cli-lib/lib/git');
const { logErrorInstance } = require('../lib/errorHandlers/standardErrors');
const {
checkAndAddConfigToGitignore,
} = require('@hubspot/local-dev-lib/gitignore');
const {
logErrorInstance,
debugErrorAndContext,
} = require('../lib/errorHandlers/standardErrors');
const {
DEFAULT_HUBSPOT_CONFIG_YAML_FILE_NAME,
PERSONAL_ACCESS_KEY_AUTH_METHOD,
Expand Down Expand Up @@ -117,7 +122,11 @@ exports.handler = async options => {
);
const configPath = getConfigPath();

checkAndUpdateGitignore(configPath);
try {
checkAndAddConfigToGitignore(configPath);
} catch (e) {
debugErrorAndContext(e);
}

logger.log('');
logger.success(
Expand Down
11 changes: 9 additions & 2 deletions packages/cli/commands/project/download.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const {
ApiErrorContext,
} = require('../../lib/errorHandlers/apiErrors');
const { logger } = require('@hubspot/cli-lib/logger');
const { extractZipArchive } = require('@hubspot/cli-lib/archive');
const { extractZipArchive } = require('@hubspot/local-dev-lib/archive');
const {
downloadProject,
fetchProjectBuilds,
Expand All @@ -24,10 +24,16 @@ 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 @@ -93,7 +99,8 @@ exports.handler = async options => {
zippedProject,
projectName,
path.resolve(absoluteDestPath),
{ includesRootDir: false }
{ includesRootDir: false },
archiveLogCallbacks
);

logger.log(
Expand Down
4 changes: 4 additions & 0 deletions packages/cli/lang/en.lyaml
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,9 @@ 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 @@ -1271,6 +1274,7 @@ en:
standardErrors:
errorOccurred: "Error: {{ error }}"
errorContext: "Context: {{ context }}"
errorCause: "Cause: {{ cause }}"
systemErrorOccurred: "A system error has occurred: {{ errorMessage }}"
genericErrorOccurred: "A {{ name }} has occurred."
unknownErrorOccurred: "An unknown error has occurred"
Expand Down
14 changes: 13 additions & 1 deletion packages/cli/lib/errorHandlers/standardErrors.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const util = require('util');
const { HubSpotAuthError } = require('@hubspot/cli-lib/lib/models/Errors');
const { logger } = require('@hubspot/cli-lib/logger');
const { i18n } = require('../lang');
Expand Down Expand Up @@ -40,7 +41,18 @@ function debugErrorAndContext(error, context) {
} else {
logger.debug(i18n(`${i18nKey}.errorOccurred`, { error }));
}
logger.debug(i18n(`${i18nKey}.errorContext`, { context }));
if (error.cause) {
logger.debug(
i18n(`${i18nKey}.errorCause`, {
cause: util.inspect(error.cause, false, null, true),
})
);
}
logger.debug(
i18n(`${i18nKey}.errorContext`, {
context: util.inspect(context, false, null, true),
})
);
}

/**
Expand Down
14 changes: 14 additions & 0 deletions packages/cli/lib/logCallbacks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const { logger } = require('@hubspot/cli-lib/logger');
const { i18n } = require('./lang');

function buildLogCallbacks(logData) {
const callbacksObject = {};
for (let key in logData) {
callbacksObject[key] = () => logger.log(i18n(logData[key]));
}
return callbacksObject;
}

module.exports = {
buildLogCallbacks,
};

0 comments on commit 5c92038

Please sign in to comment.