Skip to content

Commit

Permalink
Merge branch 'next' into cp/convert-ts-lib-3
Browse files Browse the repository at this point in the history
  • Loading branch information
camden11 committed Dec 16, 2024
2 parents aa9eb07 + 9422cfe commit 6b290e1
Show file tree
Hide file tree
Showing 10 changed files with 227 additions and 83 deletions.
2 changes: 1 addition & 1 deletion acceptance-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"devDependencies": {
"@types/js-yaml": "^4.0.9",
"concat-stream": "^2.0.0",
"cross-spawn": "^7.0.3",
"cross-spawn": "^7.0.5",
"dotenv": "^16.4.5",
"js-yaml": "^4.0.0",
"rimraf": "^3.0.2",
Expand Down
14 changes: 14 additions & 0 deletions bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const { logger } = require('@hubspot/local-dev-lib/logger');
const { addUserAgentHeader } = require('@hubspot/local-dev-lib/http');
const {
loadConfig,
getAndLoadConfigIfNeeded,
configFileExists,
getConfigPath,
} = require('@hubspot/local-dev-lib/config');
Expand All @@ -27,6 +28,7 @@ const pkg = require('../package.json');
const { i18n } = require('../lib/lang');
const { EXIT_CODES } = require('../lib/enums/exitCodes');
const { UI_COLORS, uiCommandReference } = require('../lib/ui');
const { checkAndWarnGitInclusion } = require('../lib/ui/git');

const removeCommand = require('../commands/remove');
const initCommand = require('../commands/init');
Expand Down Expand Up @@ -147,6 +149,7 @@ const setRequestHeaders = () => {
};

const loadConfigMiddleware = async options => {
// Load the new config and check for the conflicting config flag
if (configFileExists(true)) {
loadConfig('', options);

Expand All @@ -158,14 +161,24 @@ const loadConfigMiddleware = async options => {
);
process.exit(EXIT_CODES.ERROR);
}
return;
}

// We need to load the config when options.config exists,
// so that getAccountIdFromConfig() in injectAccountIdMiddleware reads from the right config
if (options.config && fs.existsSync(options.config)) {
const { config: configPath } = options;
await loadConfig(configPath, options);
return;
}

// Load deprecated config without a config flag and with no warnings
getAndLoadConfigIfNeeded(options);
return;
};

const checkAndWarnGitInclusionMiddleware = () => {
checkAndWarnGitInclusion(getConfigPath());
};

const argv = yargs
Expand All @@ -176,6 +189,7 @@ const argv = yargs
setRequestHeaders,
loadConfigMiddleware,
injectAccountIdMiddleware,
checkAndWarnGitInclusionMiddleware,
])
.exitProcess(false)
.fail(handleFailure)
Expand Down
2 changes: 1 addition & 1 deletion commands/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ exports.handler = async options => {
const { derivedAccountId } = options;
const cmsPublishMode = getCmsPublishMode(options);

trackCommandUsage('fetch', { mode: cmsPublishMode }, accountId);
trackCommandUsage('fetch', { mode: cmsPublishMode }, derivedAccountId);

try {
// Fetch and write file/folder.
Expand Down
11 changes: 6 additions & 5 deletions commands/project/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ exports.describe = uiBetaTag(i18n(`${i18nKey}.describe`), false);

exports.handler = async options => {
await loadAndValidateOptions(options);
const { derivedAccountId } = options;
const { derivedAccountId, providedAccountId } = options;
const accountConfig = getAccountConfig(derivedAccountId);
const env = getValidEnv(getEnv(derivedAccountId));

Expand Down Expand Up @@ -106,13 +106,14 @@ exports.handler = async options => {
isDeveloperTestAccount(accountConfig) ||
(!hasPublicApps && isSandbox(accountConfig));

// The account that the project must exist in
let targetProjectAccountId = derivedAccountId;
// targetProjectAccountId and targetTestingAccountId are set to null if --account flag is not provided.
// By setting them to null, we can later check if they need to be assigned based on the default account configuration and the type of app.
let targetProjectAccountId = providedAccountId ? derivedAccountId : null;
// The account that we are locally testing against
let targetTestingAccountId = derivedAccountId;
let targetTestingAccountId = providedAccountId ? derivedAccountId : null;

// Check that the default account or flag option is valid for the type of app in this project
if (derivedAccountId) {
if (providedAccountId) {
checkIfAccountFlagIsSupported(accountConfig, hasPublicApps);

if (hasPublicApps) {
Expand Down
1 change: 0 additions & 1 deletion lib/commonOpts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ export function addUseEnvironmentOptions(yargs: Argv): Argv {
.option('use-env', {
describe: i18n(`${i18nKey}.options.useEnv.describe`),
type: 'boolean',
default: false,
})
.conflicts('use-env', 'account');
}
Expand Down
12 changes: 7 additions & 5 deletions lib/localDev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ const checkIfParentAccountIsAuthed = accountConfig => {
// Confirm the default account is a developer account if developing public apps
const checkIfAccountFlagIsSupported = (accountConfig, hasPublicApps) => {
if (hasPublicApps) {
if (!isDeveloperTestAccount) {
if (!isDeveloperTestAccount(accountConfig)) {
logger.error(
i18n(`${i18nKey}.validateAccountOption.invalidPublicAppAccount`, {
useCommand: uiCommandReference('hs accounts use'),
Expand Down Expand Up @@ -248,8 +248,9 @@ const createDeveloperTestAccountForLocalDev = async (
let currentPortalCount = 0;
let maxTestPortals = 10;
try {
const validateResult =
await validateDevTestAccountUsageLimits(accountConfig);
const validateResult = await validateDevTestAccountUsageLimits(
accountConfig
);
if (validateResult) {
currentPortalCount = validateResult.results
? validateResult.results.length
Expand Down Expand Up @@ -305,8 +306,9 @@ const createDeveloperTestAccountForLocalDev = async (

// Prompt user to confirm usage of an existing developer test account that is not currently in the config
const useExistingDevTestAccount = async (env, account) => {
const useExistingDevTestAcct =
await confirmUseExistingDeveloperTestAccountPrompt(account);
const useExistingDevTestAcct = await confirmUseExistingDeveloperTestAccountPrompt(
account
);
if (!useExistingDevTestAcct) {
logger.log('');
logger.log(
Expand Down
Loading

0 comments on commit 6b290e1

Please sign in to comment.