@hubspot/cli 7.10.0 → 7.11.0-experimental.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/cli.js +5 -4
- package/commands/__tests__/getStarted.test.js +10 -0
- package/commands/__tests__/project.test.js +3 -0
- package/commands/account/__tests__/rename.test.js +10 -3
- package/commands/account/auth.js +10 -14
- package/commands/account/clean.js +11 -19
- package/commands/account/createOverride.js +15 -11
- package/commands/account/info.js +8 -5
- package/commands/account/list.js +15 -19
- package/commands/account/remove.js +23 -22
- package/commands/account/removeOverride.js +6 -6
- package/commands/account/rename.js +2 -2
- package/commands/account/use.js +19 -8
- package/commands/app/__tests__/migrate.test.js +8 -4
- package/commands/app/migrate.js +2 -2
- package/commands/auth.js +18 -14
- package/commands/config/migrate.js +5 -5
- package/commands/customObject/createSchema.js +2 -3
- package/commands/customObject/updateSchema.js +2 -3
- package/commands/getStarted.js +2 -3
- package/commands/hubdb/__tests__/list.test.js +1 -0
- package/commands/hubdb/list.js +2 -2
- package/commands/init.js +36 -32
- package/commands/project/__tests__/deploy.test.js +15 -10
- package/commands/project/__tests__/devUnifiedFlow.test.js +6 -4
- package/commands/project/__tests__/lint.test.js +709 -0
- package/commands/project/__tests__/logs.test.js +4 -0
- package/commands/project/__tests__/validate.test.js +2 -2
- package/commands/project/cloneApp.js +2 -2
- package/commands/project/create.js +20 -14
- package/commands/project/deploy.js +2 -2
- package/commands/project/dev/deprecatedFlow.js +4 -5
- package/commands/project/dev/index.js +6 -3
- package/commands/project/dev/unifiedFlow.js +11 -6
- package/commands/project/lint.d.ts +6 -0
- package/commands/project/lint.js +178 -0
- package/commands/project/logs.js +2 -3
- package/commands/project/migrate.js +4 -13
- package/commands/project/profile/add.js +6 -7
- package/commands/project/profile/delete.js +2 -2
- package/commands/project/upload.js +2 -2
- package/commands/project/validate.js +2 -2
- package/commands/project.js +2 -0
- package/commands/sandbox/__tests__/create.test.js +14 -5
- package/commands/sandbox/create.js +4 -5
- package/commands/sandbox/delete.js +23 -20
- package/commands/testAccount/create.js +2 -2
- package/commands/testAccount/delete.js +9 -8
- package/lang/en.d.ts +53 -12
- package/lang/en.js +63 -16
- package/lib/__tests__/buildAccount.test.js +22 -30
- package/lib/__tests__/commonOpts.test.js +9 -13
- package/lib/__tests__/developerTestAccounts.test.js +29 -17
- package/lib/__tests__/importData.test.js +20 -10
- package/lib/__tests__/oauth.test.js +19 -8
- package/lib/__tests__/sandboxSync.test.js +33 -11
- package/lib/__tests__/sandboxes.test.js +30 -19
- package/lib/__tests__/usageTracking.test.js +10 -10
- package/lib/__tests__/validation.test.js +32 -32
- package/lib/accountTypes.d.ts +9 -9
- package/lib/accountTypes.js +2 -4
- package/lib/app/__tests__/migrate.test.js +15 -0
- package/lib/app/__tests__/migrate_legacy.test.js +9 -0
- package/lib/app/migrate_legacy.d.ts +2 -2
- package/lib/buildAccount.d.ts +4 -4
- package/lib/buildAccount.js +7 -14
- package/lib/commonOpts.js +3 -3
- package/lib/configMigrate.d.ts +2 -2
- package/lib/configMigrate.js +42 -18
- package/lib/configOptions.js +3 -2
- package/lib/developerTestAccounts.d.ts +3 -3
- package/lib/developerTestAccounts.js +4 -7
- package/lib/doctor/DiagnosticInfoBuilder.d.ts +1 -1
- package/lib/doctor/DiagnosticInfoBuilder.js +9 -6
- package/lib/doctor/Doctor.js +4 -3
- package/lib/doctor/__tests__/Diagnosis.test.js +4 -3
- package/lib/doctor/__tests__/DiagnosticInfoBuilder.test.js +17 -9
- package/lib/doctor/__tests__/Doctor.test.js +14 -0
- package/lib/errorHandlers/index.js +8 -3
- package/lib/importData.js +8 -7
- package/lib/links.js +5 -5
- package/lib/middleware/{__test__ → __tests__}/commandTargetingUtils.test.js +3 -3
- package/lib/middleware/{__test__ → __tests__}/configMiddleware.test.js +23 -22
- package/lib/middleware/{__test__ → __tests__}/gitMiddleware.test.js +9 -7
- package/lib/middleware/autoUpdateMiddleware.js +34 -23
- package/lib/middleware/commandTargetingUtils.js +3 -2
- package/lib/middleware/configMiddleware.d.ts +6 -1
- package/lib/middleware/configMiddleware.js +36 -15
- package/lib/middleware/fireAlarmMiddleware.js +4 -15
- package/lib/middleware/gitMiddleware.js +8 -4
- package/lib/oauth.d.ts +2 -2
- package/lib/oauth.js +8 -10
- package/lib/projects/__tests__/AppDevModeInterface.test.js +17 -6
- package/lib/projects/__tests__/DevServerManager.test.js +1 -0
- package/lib/projects/__tests__/LocalDevProcess.test.js +1 -0
- package/lib/projects/__tests__/components.test.js +2 -22
- package/lib/projects/__tests__/deploy.test.js +16 -13
- package/lib/projects/__tests__/uieLinting.test.js +640 -0
- package/lib/projects/add/__tests__/legacyAddComponent.test.js +1 -1
- package/lib/projects/add/__tests__/v2AddComponent.test.js +30 -4
- package/lib/projects/add/legacyAddComponent.js +1 -1
- package/lib/projects/add/v2AddComponent.js +16 -5
- package/lib/projects/components.d.ts +8 -1
- package/lib/projects/components.js +91 -8
- package/lib/projects/create/__tests__/v2.test.js +11 -0
- package/lib/projects/deploy.js +21 -8
- package/lib/projects/localDev/AppDevModeInterface.js +2 -2
- package/lib/projects/localDev/DevServerManager_DEPRECATED.js +11 -3
- package/lib/projects/localDev/LocalDevLogger.js +4 -4
- package/lib/projects/localDev/LocalDevManager_DEPRECATED.js +3 -3
- package/lib/projects/localDev/helpers/account.d.ts +10 -10
- package/lib/projects/localDev/helpers/account.js +6 -11
- package/lib/projects/localDev/helpers/process.js +5 -3
- package/lib/projects/uieLinting.d.ts +33 -0
- package/lib/projects/uieLinting.js +222 -0
- package/lib/projects/urls.js +5 -6
- package/lib/prompts/__tests__/downloadProjectPrompt.test.js +7 -5
- package/lib/prompts/accountNamePrompt.js +3 -3
- package/lib/prompts/accountsPrompt.d.ts +1 -1
- package/lib/prompts/accountsPrompt.js +6 -7
- package/lib/prompts/confirmImportDataPrompt.js +2 -2
- package/lib/prompts/downloadProjectPrompt.d.ts +1 -0
- package/lib/prompts/downloadProjectPrompt.js +5 -2
- package/lib/prompts/importDataTestAccountSelectPrompt.js +4 -5
- package/lib/prompts/personalAccessKeyPrompt.js +2 -2
- package/lib/prompts/projectDevTargetAccountPrompt.d.ts +3 -3
- package/lib/prompts/projectDevTargetAccountPrompt.js +5 -7
- package/lib/prompts/sandboxesPrompt.js +7 -8
- package/lib/prompts/setAsDefaultAccountPrompt.js +7 -6
- package/lib/sandboxSync.d.ts +2 -2
- package/lib/sandboxSync.js +3 -9
- package/lib/sandboxes.d.ts +4 -4
- package/lib/sandboxes.js +6 -11
- package/lib/serverlessLogs.js +2 -2
- package/lib/theme/__tests__/migrate.test.js +15 -0
- package/lib/ui/SpinniesManager.d.ts +5 -7
- package/lib/ui/SpinniesManager.js +9 -12
- package/lib/ui/__tests__/SpinniesManager.test.d.ts +1 -0
- package/lib/ui/__tests__/SpinniesManager.test.js +489 -0
- package/lib/ui/index.js +6 -3
- package/lib/usageTracking.js +15 -8
- package/lib/validation.js +13 -11
- package/mcp-server/tools/cms/HsCreateFunctionTool.js +4 -2
- package/mcp-server/tools/cms/HsCreateModuleTool.js +4 -2
- package/mcp-server/tools/cms/HsCreateTemplateTool.js +4 -2
- package/mcp-server/tools/cms/HsFunctionLogsTool.js +4 -2
- package/mcp-server/tools/cms/HsListFunctionsTool.js +3 -1
- package/mcp-server/tools/cms/HsListTool.js +3 -1
- package/mcp-server/tools/cms/__tests__/HsCreateFunctionTool.test.js +1 -0
- package/mcp-server/tools/index.js +4 -0
- package/mcp-server/tools/project/AddFeatureToProjectTool.js +4 -2
- package/mcp-server/tools/project/CreateProjectTool.js +4 -2
- package/mcp-server/tools/project/CreateTestAccountTool.js +17 -7
- package/mcp-server/tools/project/DeployProjectTool.js +3 -1
- package/mcp-server/tools/project/DocFetchTool.js +6 -4
- package/mcp-server/tools/project/DocsSearchTool.d.ts +1 -1
- package/mcp-server/tools/project/DocsSearchTool.js +10 -8
- package/mcp-server/tools/project/GetApiUsagePatternsByAppIdTool.d.ts +1 -1
- package/mcp-server/tools/project/GetApiUsagePatternsByAppIdTool.js +9 -7
- package/mcp-server/tools/project/GetApplicationInfoTool.js +8 -6
- package/mcp-server/tools/project/GetBuildLogsTool.d.ts +26 -0
- package/mcp-server/tools/project/GetBuildLogsTool.js +125 -0
- package/mcp-server/tools/project/GetBuildStatusTool.d.ts +26 -0
- package/mcp-server/tools/project/GetBuildStatusTool.js +166 -0
- package/mcp-server/tools/project/GetConfigValuesTool.d.ts +1 -1
- package/mcp-server/tools/project/GetConfigValuesTool.js +9 -7
- package/mcp-server/tools/project/GuidedWalkthroughTool.d.ts +1 -1
- package/mcp-server/tools/project/GuidedWalkthroughTool.js +5 -3
- package/mcp-server/tools/project/UploadProjectTools.js +3 -1
- package/mcp-server/tools/project/ValidateProjectTool.js +4 -2
- package/mcp-server/tools/project/__tests__/CreateTestAccountTool.test.js +12 -2
- package/mcp-server/tools/project/__tests__/DocFetchTool.test.js +5 -1
- package/mcp-server/tools/project/__tests__/DocsSearchTool.test.js +23 -11
- package/mcp-server/tools/project/__tests__/GetApiUsagePatternsByAppIdTool.test.js +7 -5
- package/mcp-server/tools/project/__tests__/GetApplicationInfoTool.test.js +7 -5
- package/mcp-server/tools/project/__tests__/GetBuildLogsTool.test.d.ts +1 -0
- package/mcp-server/tools/project/__tests__/GetBuildLogsTool.test.js +305 -0
- package/mcp-server/tools/project/__tests__/GetBuildStatusTool.test.d.ts +1 -0
- package/mcp-server/tools/project/__tests__/GetBuildStatusTool.test.js +240 -0
- package/mcp-server/tools/project/__tests__/GetConfigValuesTool.test.js +8 -6
- package/mcp-server/utils/__tests__/content.test.js +21 -20
- package/mcp-server/utils/__tests__/feedbackTracking.test.js +34 -28
- package/mcp-server/utils/config.d.ts +1 -0
- package/mcp-server/utils/config.js +10 -0
- package/mcp-server/utils/content.d.ts +1 -1
- package/mcp-server/utils/content.js +2 -2
- package/mcp-server/utils/feedbackTracking.d.ts +1 -1
- package/mcp-server/utils/feedbackTracking.js +3 -3
- package/mcp-server/utils/toolUsageTracking.js +4 -3
- package/package.json +9 -9
- package/ui/components/BoxWithTitle.d.ts +2 -1
- package/ui/components/BoxWithTitle.js +2 -2
- package/ui/components/StatusMessageBoxes.d.ts +5 -4
- package/ui/components/StatusMessageBoxes.js +8 -8
- package/lib/middleware/__test__/notificationsMiddleware.test.js +0 -8
- package/lib/middleware/notificationsMiddleware.d.ts +0 -1
- package/lib/middleware/notificationsMiddleware.js +0 -28
- package/lib/ui/boxen.d.ts +0 -5
- package/lib/ui/boxen.js +0 -26
- package/mcp-server/utils/__tests__/cliConfig.test.js +0 -110
- package/mcp-server/utils/cliConfig.d.ts +0 -1
- package/mcp-server/utils/cliConfig.js +0 -12
- /package/{lib/middleware/__test__/commandTargetingUtils.test.d.ts → commands/project/__tests__/lint.test.d.ts} +0 -0
- /package/lib/middleware/{__test__/configMiddleware.test.d.ts → __tests__/commandTargetingUtils.test.d.ts} +0 -0
- /package/lib/middleware/{__test__/gitMiddleware.test.d.ts → __tests__/configMiddleware.test.d.ts} +0 -0
- /package/lib/middleware/{__test__/notificationsMiddleware.test.d.ts → __tests__/gitMiddleware.test.d.ts} +0 -0
- /package/lib/middleware/{__test__ → __tests__}/requestMiddleware.test.d.ts +0 -0
- /package/lib/middleware/{__test__ → __tests__}/requestMiddleware.test.js +0 -0
- /package/lib/middleware/{__test__ → __tests__}/yargsChecksMiddleware.test.d.ts +0 -0
- /package/lib/middleware/{__test__ → __tests__}/yargsChecksMiddleware.test.js +0 -0
- /package/{mcp-server/utils/__tests__/cliConfig.test.d.ts → lib/projects/__tests__/uieLinting.test.d.ts} +0 -0
package/bin/cli.js
CHANGED
|
@@ -4,7 +4,7 @@ import { logError } from '../lib/errorHandlers/index.js';
|
|
|
4
4
|
import { setCLILogLevel, getCommandName } from '../lib/commonOpts.js';
|
|
5
5
|
import { trackHelpUsage, trackConvertFieldsUsage, } from '../lib/usageTracking.js';
|
|
6
6
|
import { EXIT_CODES } from '../lib/enums/exitCodes.js';
|
|
7
|
-
import {
|
|
7
|
+
import { validateConfigMiddleware, injectAccountIdMiddleware, validateAccountOptions, handleDeprecatedEnvVariables, handleCustomConfigLocationMiddleware, } from '../lib/middleware/configMiddleware.js';
|
|
8
8
|
import { autoUpdateCLI } from '../lib/middleware/autoUpdateMiddleware.js';
|
|
9
9
|
import { checkAndWarnGitInclusionMiddleware } from '../lib/middleware/gitMiddleware.js';
|
|
10
10
|
import { performChecks } from '../lib/middleware/yargsChecksMiddleware.js';
|
|
@@ -55,7 +55,8 @@ function handleFailure(msg, err, yargs) {
|
|
|
55
55
|
else if (err) {
|
|
56
56
|
logError(err);
|
|
57
57
|
}
|
|
58
|
-
if (msg === null) {
|
|
58
|
+
if (msg === null && !err) {
|
|
59
|
+
// Required so running `hs` without a command shows the help
|
|
59
60
|
yargs.showHelp('log');
|
|
60
61
|
process.exit(EXIT_CODES.SUCCESS);
|
|
61
62
|
}
|
|
@@ -65,13 +66,13 @@ function handleFailure(msg, err, yargs) {
|
|
|
65
66
|
}
|
|
66
67
|
const argv = yargs(process.argv.slice(2))
|
|
67
68
|
.usage('The command line interface to interact with HubSpot.')
|
|
68
|
-
// loadConfigMiddleware loads the new hidden config for all commands
|
|
69
69
|
.middleware([
|
|
70
70
|
setCLILogLevel,
|
|
71
71
|
setRequestHeaders,
|
|
72
72
|
handleDeprecatedEnvVariables,
|
|
73
|
-
|
|
73
|
+
handleCustomConfigLocationMiddleware,
|
|
74
74
|
injectAccountIdMiddleware,
|
|
75
|
+
validateConfigMiddleware,
|
|
75
76
|
autoUpdateCLI,
|
|
76
77
|
checkAndWarnGitInclusionMiddleware,
|
|
77
78
|
validateAccountOptions,
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import getStartedCommand from '../getStarted.js';
|
|
2
2
|
import { trackCommandUsage } from '../../lib/usageTracking.js';
|
|
3
3
|
import { promptUser } from '../../lib/prompts/promptUtils.js';
|
|
4
|
+
import { getConfigAccountById } from '@hubspot/local-dev-lib/config';
|
|
4
5
|
import { projectNameAndDestPrompt } from '../../lib/prompts/projectNameAndDestPrompt.js';
|
|
5
6
|
import { cloneGithubRepo } from '@hubspot/local-dev-lib/github';
|
|
6
7
|
import { getProjectConfig, writeProjectConfig, } from '../../lib/projects/config.js';
|
|
@@ -16,6 +17,7 @@ vi.mock('../../lib/ui/logger');
|
|
|
16
17
|
vi.mock('../../lib/errorHandlers');
|
|
17
18
|
vi.mock('@hubspot/local-dev-lib/github');
|
|
18
19
|
vi.mock('../../lib/dependencyManagement');
|
|
20
|
+
vi.mock('@hubspot/local-dev-lib/config');
|
|
19
21
|
vi.mock('open');
|
|
20
22
|
vi.mock('fs-extra', () => ({
|
|
21
23
|
default: {
|
|
@@ -27,6 +29,14 @@ vi.mock('fs-extra', () => ({
|
|
|
27
29
|
describe('commands/get-started', () => {
|
|
28
30
|
beforeEach(() => {
|
|
29
31
|
vi.clearAllMocks();
|
|
32
|
+
// @TODO Revisit config mocking in tests
|
|
33
|
+
getConfigAccountById.mockReturnValue({
|
|
34
|
+
accountId: 12345,
|
|
35
|
+
name: 'Test Account',
|
|
36
|
+
authType: 'personalaccesskey',
|
|
37
|
+
personalAccessKey: 'test-key',
|
|
38
|
+
env: 'prod',
|
|
39
|
+
});
|
|
30
40
|
});
|
|
31
41
|
describe('command', () => {
|
|
32
42
|
it('should have the correct command structure', () => {
|
|
@@ -13,6 +13,7 @@ import migrateApp from '../project/migrateApp.js';
|
|
|
13
13
|
import migrate from '../project/migrate.js';
|
|
14
14
|
import cloneApp from '../project/cloneApp.js';
|
|
15
15
|
import installDeps from '../project/installDeps.js';
|
|
16
|
+
import lint from '../project/lint.js';
|
|
16
17
|
import updateDeps from '../project/updateDeps.js';
|
|
17
18
|
import validate from '../project/validate.js';
|
|
18
19
|
import profileCommands from '../project/profile.js';
|
|
@@ -38,6 +39,7 @@ vi.mock('../project/migrate', () => ({
|
|
|
38
39
|
default: {},
|
|
39
40
|
}));
|
|
40
41
|
vi.mock('../project/installDeps');
|
|
42
|
+
vi.mock('../project/lint');
|
|
41
43
|
vi.mock('../project/profile');
|
|
42
44
|
vi.mock('../../lib/commonOpts');
|
|
43
45
|
const commandSpy = vi
|
|
@@ -73,6 +75,7 @@ describe('commands/project', () => {
|
|
|
73
75
|
migrate,
|
|
74
76
|
cloneApp,
|
|
75
77
|
installDeps,
|
|
78
|
+
lint,
|
|
76
79
|
updateDeps,
|
|
77
80
|
profileCommands,
|
|
78
81
|
validate,
|
|
@@ -4,17 +4,20 @@ import accountRenameCommand from '../rename.js';
|
|
|
4
4
|
import * as config from '@hubspot/local-dev-lib/config';
|
|
5
5
|
import { logError } from '../../../lib/errorHandlers/index.js';
|
|
6
6
|
import { EXIT_CODES } from '../../../lib/enums/exitCodes.js';
|
|
7
|
+
import * as usageTracking from '../../../lib/usageTracking.js';
|
|
7
8
|
vi.mock('../../../lib/commonOpts');
|
|
8
9
|
vi.mock('@hubspot/local-dev-lib/config');
|
|
9
10
|
vi.mock('../../../lib/errorHandlers/index.js');
|
|
11
|
+
vi.mock('../../../lib/usageTracking.js');
|
|
10
12
|
const positionalSpy = vi
|
|
11
13
|
.spyOn(yargs, 'positional')
|
|
12
14
|
.mockReturnValue(yargs);
|
|
13
15
|
const exampleSpy = vi
|
|
14
16
|
.spyOn(yargs, 'example')
|
|
15
17
|
.mockReturnValue(yargs);
|
|
16
|
-
const renameAccountSpy = vi.spyOn(config, '
|
|
18
|
+
const renameAccountSpy = vi.spyOn(config, 'renameConfigAccount');
|
|
17
19
|
const processExitSpy = vi.spyOn(process, 'exit');
|
|
20
|
+
const trackCommandUsageSpy = vi.spyOn(usageTracking, 'trackCommandUsage');
|
|
18
21
|
describe('commands/account/rename', () => {
|
|
19
22
|
const yargsMock = yargs;
|
|
20
23
|
describe('command', () => {
|
|
@@ -31,7 +34,7 @@ describe('commands/account/rename', () => {
|
|
|
31
34
|
let args;
|
|
32
35
|
beforeEach(() => {
|
|
33
36
|
vi.clearAllMocks();
|
|
34
|
-
renameAccountSpy.
|
|
37
|
+
renameAccountSpy.mockReturnValue(undefined);
|
|
35
38
|
processExitSpy.mockImplementation(() => {
|
|
36
39
|
throw new Error('process.exit called');
|
|
37
40
|
});
|
|
@@ -42,13 +45,17 @@ describe('commands/account/rename', () => {
|
|
|
42
45
|
});
|
|
43
46
|
it('should rename the account', async () => {
|
|
44
47
|
await expect(accountRenameCommand.handler(args)).rejects.toThrow('process.exit called');
|
|
48
|
+
expect(trackCommandUsageSpy).toHaveBeenCalledWith('accounts-rename', undefined, undefined);
|
|
45
49
|
expect(renameAccountSpy).toHaveBeenCalledWith('myExistingAccountName', 'my-new-account-name');
|
|
46
50
|
expect(processExitSpy).toHaveBeenCalledWith(EXIT_CODES.SUCCESS);
|
|
47
51
|
});
|
|
48
52
|
it('should handle errors when renameAccount throws', async () => {
|
|
49
53
|
const error = new Error('Failed to rename account');
|
|
50
|
-
renameAccountSpy.
|
|
54
|
+
renameAccountSpy.mockImplementation(() => {
|
|
55
|
+
throw error;
|
|
56
|
+
});
|
|
51
57
|
await expect(accountRenameCommand.handler(args)).rejects.toThrow('process.exit called');
|
|
58
|
+
expect(trackCommandUsageSpy).toHaveBeenCalledWith('accounts-rename', undefined, undefined);
|
|
52
59
|
expect(renameAccountSpy).toHaveBeenCalledWith('myExistingAccountName', 'my-new-account-name');
|
|
53
60
|
expect(logError).toHaveBeenCalledTimes(1);
|
|
54
61
|
expect(logError).toHaveBeenCalledWith(error);
|
package/commands/account/auth.js
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { configFileExists, getConfigPath, } from '@hubspot/local-dev-lib/config/migrate';
|
|
3
|
-
import { getAccountIdentifier } from '@hubspot/local-dev-lib/config/getAccountIdentifier';
|
|
1
|
+
import { updateConfigAccount, createEmptyConfigFile, deleteConfigFileIfEmpty, getConfigFilePath, localConfigFileExists, globalConfigFileExists, } from '@hubspot/local-dev-lib/config';
|
|
4
2
|
import { getAccessToken, updateConfigWithAccessToken, } from '@hubspot/local-dev-lib/personalAccessKey';
|
|
5
3
|
import { ENVIRONMENTS } from '@hubspot/local-dev-lib/constants/environments';
|
|
6
4
|
import { toKebabCase } from '@hubspot/local-dev-lib/text';
|
|
@@ -46,10 +44,9 @@ async function updateConfigWithNewAccount(env, configAlreadyExists, providedPers
|
|
|
46
44
|
// Can happen if the user is re-authenticating an account with no name
|
|
47
45
|
if (configAlreadyExists && !updatedConfig.name) {
|
|
48
46
|
updatedConfig.name = (await cliAccountNamePrompt(defaultAccountName)).name;
|
|
49
|
-
|
|
47
|
+
updateConfigAccount({
|
|
50
48
|
...updatedConfig,
|
|
51
49
|
});
|
|
52
|
-
writeConfig();
|
|
53
50
|
}
|
|
54
51
|
return updatedConfig;
|
|
55
52
|
}
|
|
@@ -59,8 +56,8 @@ async function updateConfigWithNewAccount(env, configAlreadyExists, providedPers
|
|
|
59
56
|
}
|
|
60
57
|
}
|
|
61
58
|
async function handleConfigMigration() {
|
|
62
|
-
const deprecatedConfigExists =
|
|
63
|
-
const globalConfigExists =
|
|
59
|
+
const deprecatedConfigExists = localConfigFileExists();
|
|
60
|
+
const globalConfigExists = globalConfigFileExists();
|
|
64
61
|
// No deprecated config exists, so no migration is needed
|
|
65
62
|
if (!deprecatedConfigExists) {
|
|
66
63
|
return true;
|
|
@@ -117,12 +114,11 @@ async function handler(args) {
|
|
|
117
114
|
await trackAuthAction('account-auth', authType, TRACKING_STATUS.ERROR);
|
|
118
115
|
process.exit(EXIT_CODES.ERROR);
|
|
119
116
|
}
|
|
120
|
-
const configAlreadyExists =
|
|
117
|
+
const configAlreadyExists = globalConfigFileExists();
|
|
121
118
|
if (!configAlreadyExists) {
|
|
122
|
-
createEmptyConfigFile(
|
|
119
|
+
createEmptyConfigFile(true);
|
|
123
120
|
}
|
|
124
|
-
|
|
125
|
-
handleExit(deleteEmptyConfigFile);
|
|
121
|
+
handleExit(deleteConfigFileIfEmpty);
|
|
126
122
|
const updatedConfig = await updateConfigWithNewAccount(args.qa ? ENVIRONMENTS.QA : ENVIRONMENTS.PROD, configAlreadyExists, providedPersonalAccessKey, parsedUserProvidedAccountId);
|
|
127
123
|
if (!updatedConfig) {
|
|
128
124
|
if (!disableTracking) {
|
|
@@ -131,14 +127,14 @@ async function handler(args) {
|
|
|
131
127
|
uiLogger.error(commands.account.subcommands.auth.errors.failedToUpdateConfig);
|
|
132
128
|
process.exit(EXIT_CODES.ERROR);
|
|
133
129
|
}
|
|
134
|
-
const accountId =
|
|
130
|
+
const { accountId, name } = updatedConfig;
|
|
135
131
|
if (!configAlreadyExists) {
|
|
136
132
|
uiLogger.log('');
|
|
137
|
-
uiLogger.success(commands.account.subcommands.auth.success.configFileCreated(
|
|
133
|
+
uiLogger.success(commands.account.subcommands.auth.success.configFileCreated(getConfigFilePath()));
|
|
138
134
|
uiLogger.success(commands.account.subcommands.auth.success.configFileUpdated(accountId));
|
|
139
135
|
}
|
|
140
136
|
else {
|
|
141
|
-
await setAsDefaultAccountPrompt(
|
|
137
|
+
await setAsDefaultAccountPrompt(name);
|
|
142
138
|
}
|
|
143
139
|
uiFeatureHighlight([
|
|
144
140
|
'getStartedCommand',
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import fs from 'fs';
|
|
2
2
|
import { accessTokenForPersonalAccessKey } from '@hubspot/local-dev-lib/personalAccessKey';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { removeAccountFromConfig, getAllConfigAccounts, getConfigDefaultAccountIfExists, setConfigAccountAsDefault, } from '@hubspot/local-dev-lib/config';
|
|
4
|
+
import { getDefaultAccountOverrideAccountId, getDefaultAccountOverrideFilePath, } from '@hubspot/local-dev-lib/config/defaultAccountOverride';
|
|
5
5
|
import { isSpecifiedError } from '@hubspot/local-dev-lib/errors/index';
|
|
6
|
-
import { getCWDAccountOverride, getDefaultAccountOverrideFilePath, } from '@hubspot/local-dev-lib/config';
|
|
7
6
|
import { trackCommandUsage } from '../../lib/usageTracking.js';
|
|
8
7
|
import { EXIT_CODES } from '../../lib/enums/exitCodes.js';
|
|
9
8
|
import { promptUser } from '../../lib/prompts/promptUtils.js';
|
|
@@ -20,7 +19,7 @@ const describe = commands.account.subcommands.clean.describe;
|
|
|
20
19
|
async function handler(args) {
|
|
21
20
|
const { qa } = args;
|
|
22
21
|
trackCommandUsage('accounts-clean');
|
|
23
|
-
const accountsList =
|
|
22
|
+
const accountsList = getAllConfigAccounts();
|
|
24
23
|
const filteredTestAccounts = accountsList.filter(p => qa ? p.env === 'qa' : p.env !== 'qa');
|
|
25
24
|
if (filteredTestAccounts && filteredTestAccounts.length === 0) {
|
|
26
25
|
uiLogger.log(commands.account.subcommands.clean.noResults);
|
|
@@ -35,8 +34,7 @@ async function handler(args) {
|
|
|
35
34
|
});
|
|
36
35
|
for (const account of filteredTestAccounts) {
|
|
37
36
|
try {
|
|
38
|
-
|
|
39
|
-
await accessTokenForPersonalAccessKey(accountId, true);
|
|
37
|
+
await accessTokenForPersonalAccessKey(account.accountId, true);
|
|
40
38
|
}
|
|
41
39
|
catch (error) {
|
|
42
40
|
if (isSpecifiedError(error, {
|
|
@@ -60,17 +58,13 @@ async function handler(args) {
|
|
|
60
58
|
? commands.account.subcommands.clean.inactiveAccountsFound.one
|
|
61
59
|
: commands.account.subcommands.clean.inactiveAccountsFound.other(accountsToRemove.length),
|
|
62
60
|
});
|
|
63
|
-
uiLogger.log(getTableContents(accountsToRemove.map(p => [
|
|
64
|
-
uiAccountDescription(getAccountIdentifier(p)),
|
|
65
|
-
]), { border: { bodyLeft: ' ' } }));
|
|
61
|
+
uiLogger.log(getTableContents(accountsToRemove.map(p => [uiAccountDescription(p.accountId)]), { border: { bodyLeft: ' ' } }));
|
|
66
62
|
let promptMessage = oneAccountFound
|
|
67
63
|
? commands.account.subcommands.clean.confirm.one
|
|
68
64
|
: commands.account.subcommands.clean.confirm.other(accountsToRemove.length);
|
|
69
|
-
const accountOverride =
|
|
65
|
+
const accountOverride = getDefaultAccountOverrideAccountId();
|
|
70
66
|
const overrideFilePath = getDefaultAccountOverrideFilePath();
|
|
71
|
-
const accountOverrideMatches = accountsToRemove.some(account => account.
|
|
72
|
-
// @ts-expect-error: Default account override files can only exist with global config
|
|
73
|
-
account.accountId === accountOverride);
|
|
67
|
+
const accountOverrideMatches = accountsToRemove.some(account => account.accountId === accountOverride);
|
|
74
68
|
if (overrideFilePath && accountOverride && accountOverrideMatches) {
|
|
75
69
|
promptMessage = `${promptMessage}${commands.account.subcommands.clean.defaultAccountOverride(overrideFilePath)}`;
|
|
76
70
|
}
|
|
@@ -92,17 +86,15 @@ async function handler(args) {
|
|
|
92
86
|
logError(error);
|
|
93
87
|
}
|
|
94
88
|
for (const accountToRemove of accountsToRemove) {
|
|
95
|
-
|
|
89
|
+
removeAccountFromConfig(accountToRemove.accountId);
|
|
96
90
|
uiLogger.log(commands.account.subcommands.clean.removeSuccess(accountToRemove.name));
|
|
97
91
|
}
|
|
98
|
-
|
|
99
|
-
loadConfig(getConfigPath());
|
|
100
|
-
const defaultAccount = getConfigDefaultAccount();
|
|
92
|
+
const defaultAccount = getConfigDefaultAccountIfExists();
|
|
101
93
|
if (defaultAccount &&
|
|
102
|
-
accountsToRemove.some(p => p.name === defaultAccount)) {
|
|
94
|
+
accountsToRemove.some(p => p.name === defaultAccount.name)) {
|
|
103
95
|
uiLogger.log(commands.account.subcommands.clean.replaceDefaultAccount);
|
|
104
96
|
const newDefaultAccount = await selectAccountFromConfig();
|
|
105
|
-
|
|
97
|
+
setConfigAccountAsDefault(newDefaultAccount);
|
|
106
98
|
}
|
|
107
99
|
}
|
|
108
100
|
}
|
|
@@ -2,8 +2,8 @@ import fs from 'fs-extra';
|
|
|
2
2
|
import path from 'path';
|
|
3
3
|
import { getCwd } from '@hubspot/local-dev-lib/path';
|
|
4
4
|
import { DEFAULT_ACCOUNT_OVERRIDE_FILE_NAME } from '@hubspot/local-dev-lib/constants/config';
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
5
|
+
import { getConfigFilePath, getConfigAccountIfExists, globalConfigFileExists, } from '@hubspot/local-dev-lib/config';
|
|
6
|
+
import { getDefaultAccountOverrideAccountId, getDefaultAccountOverrideFilePath, } from '@hubspot/local-dev-lib/config/defaultAccountOverride';
|
|
7
7
|
import { promptUser } from '../../lib/prompts/promptUtils.js';
|
|
8
8
|
import { EXIT_CODES } from '../../lib/enums/exitCodes.js';
|
|
9
9
|
import { trackCommandUsage } from '../../lib/usageTracking.js';
|
|
@@ -16,15 +16,15 @@ const command = 'create-override [account]';
|
|
|
16
16
|
const describe = commands.account.subcommands.createOverride.describe(DEFAULT_ACCOUNT_OVERRIDE_FILE_NAME);
|
|
17
17
|
async function handler(args) {
|
|
18
18
|
let overrideDefaultAccount = args.account;
|
|
19
|
-
const
|
|
20
|
-
if (!
|
|
19
|
+
const globalConfigExists = globalConfigFileExists();
|
|
20
|
+
if (!globalConfigExists) {
|
|
21
21
|
uiLogger.error(commands.account.subcommands.createOverride.errors.globalConfigNotFound);
|
|
22
22
|
process.exit(EXIT_CODES.ERROR);
|
|
23
23
|
}
|
|
24
|
-
const
|
|
24
|
+
const accountOverrideId = getDefaultAccountOverrideAccountId();
|
|
25
25
|
const overrideFilePath = getDefaultAccountOverrideFilePath();
|
|
26
|
-
if (
|
|
27
|
-
uiLogger.log(commands.account.subcommands.createOverride.accountOverride(overrideFilePath,
|
|
26
|
+
if (accountOverrideId && overrideFilePath) {
|
|
27
|
+
uiLogger.log(commands.account.subcommands.createOverride.accountOverride(overrideFilePath, accountOverrideId.toString()));
|
|
28
28
|
const { replaceOverrideFile } = await promptUser({
|
|
29
29
|
type: 'confirm',
|
|
30
30
|
name: 'replaceOverrideFile',
|
|
@@ -38,11 +38,15 @@ async function handler(args) {
|
|
|
38
38
|
if (!overrideDefaultAccount) {
|
|
39
39
|
overrideDefaultAccount = await selectAccountFromConfig();
|
|
40
40
|
}
|
|
41
|
-
else
|
|
42
|
-
|
|
43
|
-
|
|
41
|
+
else {
|
|
42
|
+
const account = getConfigAccountIfExists(overrideDefaultAccount);
|
|
43
|
+
if (!account) {
|
|
44
|
+
uiLogger.error(commands.account.subcommands.createOverride.errors.accountNotFound(getConfigFilePath() || ''));
|
|
45
|
+
overrideDefaultAccount = await selectAccountFromConfig();
|
|
46
|
+
}
|
|
44
47
|
}
|
|
45
|
-
const
|
|
48
|
+
const account = getConfigAccountIfExists(overrideDefaultAccount);
|
|
49
|
+
const accountId = account?.accountId;
|
|
46
50
|
trackCommandUsage('account-createOverride', undefined, accountId);
|
|
47
51
|
try {
|
|
48
52
|
const overrideFilePath = path.join(getCwd(), DEFAULT_ACCOUNT_OVERRIDE_FILE_NAME);
|
package/commands/account/info.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getConfigAccountById, getConfigDefaultAccount, getConfigFilePath, } from '@hubspot/local-dev-lib/config';
|
|
2
|
+
import { getDefaultAccountOverrideFilePath } from '@hubspot/local-dev-lib/config/defaultAccountOverride';
|
|
2
3
|
import { getAccessToken } from '@hubspot/local-dev-lib/personalAccessKey';
|
|
3
4
|
import { makeYargsBuilder } from '../../lib/yargsUtils.js';
|
|
4
5
|
import { indent } from '../../lib/ui/index.js';
|
|
@@ -9,7 +10,7 @@ const describe = commands.account.subcommands.info.describe;
|
|
|
9
10
|
const command = 'info [account]';
|
|
10
11
|
async function handler(args) {
|
|
11
12
|
const { derivedAccountId } = args;
|
|
12
|
-
const config =
|
|
13
|
+
const config = getConfigAccountById(derivedAccountId);
|
|
13
14
|
// check if the provided account is using a personal access key, if not, show an error
|
|
14
15
|
if (config && config.authType === 'personalaccesskey') {
|
|
15
16
|
const { name, personalAccessKey, env } = config;
|
|
@@ -17,11 +18,12 @@ async function handler(args) {
|
|
|
17
18
|
const response = await getAccessToken(personalAccessKey, env, derivedAccountId);
|
|
18
19
|
scopeGroups = response.scopeGroups.map(s => [s]);
|
|
19
20
|
// If a default account is present in the config, display it
|
|
20
|
-
const configPath =
|
|
21
|
+
const configPath = getConfigFilePath();
|
|
21
22
|
if (configPath) {
|
|
22
23
|
uiLogger.log(commands.account.subcommands.info.defaultAccountTitle);
|
|
23
24
|
uiLogger.log(`${indent(1)}${commands.account.subcommands.info.configPath(configPath)}`);
|
|
24
|
-
|
|
25
|
+
const defaultAccount = getConfigDefaultAccount();
|
|
26
|
+
uiLogger.log(`${indent(1)}${commands.account.subcommands.info.defaultAccount(defaultAccount.name)}`);
|
|
25
27
|
}
|
|
26
28
|
// If a default account override is present, display it
|
|
27
29
|
const overrideFilePath = getDefaultAccountOverrideFilePath();
|
|
@@ -29,7 +31,8 @@ async function handler(args) {
|
|
|
29
31
|
uiLogger.log('');
|
|
30
32
|
uiLogger.log(commands.account.subcommands.info.overrideFilePathTitle);
|
|
31
33
|
uiLogger.log(`${indent(1)}${commands.account.subcommands.info.overrideFilePath(overrideFilePath)}`);
|
|
32
|
-
|
|
34
|
+
const defaultAccount = getConfigDefaultAccount();
|
|
35
|
+
uiLogger.log(`${indent(1)}${commands.account.subcommands.info.overrideAccount(defaultAccount.name)}`);
|
|
33
36
|
}
|
|
34
37
|
uiLogger.log('');
|
|
35
38
|
uiLogger.log(commands.account.subcommands.info.name(name));
|
package/commands/account/list.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { getConfigFilePath, getAllConfigAccounts, getConfigDefaultAccountIfExists, } from '@hubspot/local-dev-lib/config';
|
|
2
|
+
import { getDefaultAccountOverrideFilePath } from '@hubspot/local-dev-lib/config/defaultAccountOverride';
|
|
3
3
|
import { indent } from '../../lib/ui/index.js';
|
|
4
4
|
import { getTableContents, getTableHeader } from '../../lib/ui/table.js';
|
|
5
5
|
import { trackCommandUsage } from '../../lib/usageTracking.js';
|
|
@@ -18,10 +18,7 @@ function sortAndMapAccounts(accounts) {
|
|
|
18
18
|
(p.accountType === HUBSPOT_ACCOUNT_TYPES.STANDARD ||
|
|
19
19
|
p.accountType === HUBSPOT_ACCOUNT_TYPES.APP_DEVELOPER))
|
|
20
20
|
.forEach(account => {
|
|
21
|
-
|
|
22
|
-
if (accountId) {
|
|
23
|
-
mappedAccountData[accountId] = [account];
|
|
24
|
-
}
|
|
21
|
+
mappedAccountData[account.accountId] = [account];
|
|
25
22
|
});
|
|
26
23
|
// Non-standard accounts (sandbox, developer test account)
|
|
27
24
|
accounts
|
|
@@ -34,10 +31,7 @@ function sortAndMapAccounts(accounts) {
|
|
|
34
31
|
];
|
|
35
32
|
}
|
|
36
33
|
else {
|
|
37
|
-
|
|
38
|
-
if (accountId) {
|
|
39
|
-
mappedAccountData[accountId] = [p];
|
|
40
|
-
}
|
|
34
|
+
mappedAccountData[p.accountId] = [p];
|
|
41
35
|
}
|
|
42
36
|
});
|
|
43
37
|
return mappedAccountData;
|
|
@@ -46,7 +40,7 @@ function getAccountData(mappedAccountData) {
|
|
|
46
40
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
47
41
|
const accountData = [];
|
|
48
42
|
Object.entries(mappedAccountData).forEach(([key, set]) => {
|
|
49
|
-
const hasParentAccount = set.filter(p =>
|
|
43
|
+
const hasParentAccount = set.filter(p => p.accountId === parseInt(key, 10))[0];
|
|
50
44
|
set.forEach(account => {
|
|
51
45
|
let name = `${account.name} [${HUBSPOT_ACCOUNT_TYPE_STRINGS[account.accountType]}]`;
|
|
52
46
|
if (isSandbox(account)) {
|
|
@@ -59,7 +53,7 @@ function getAccountData(mappedAccountData) {
|
|
|
59
53
|
name = `↳ ${name}`;
|
|
60
54
|
}
|
|
61
55
|
}
|
|
62
|
-
accountData.push([name,
|
|
56
|
+
accountData.push([name, account.accountId, account.authType]);
|
|
63
57
|
});
|
|
64
58
|
});
|
|
65
59
|
return accountData;
|
|
@@ -67,8 +61,8 @@ function getAccountData(mappedAccountData) {
|
|
|
67
61
|
async function handler(args) {
|
|
68
62
|
const { derivedAccountId } = args;
|
|
69
63
|
trackCommandUsage('accounts-list', undefined, derivedAccountId);
|
|
70
|
-
const configPath =
|
|
71
|
-
const accountsList =
|
|
64
|
+
const configPath = getConfigFilePath();
|
|
65
|
+
const accountsList = getAllConfigAccounts();
|
|
72
66
|
const mappedAccountData = sortAndMapAccounts(accountsList);
|
|
73
67
|
const accountData = getAccountData(mappedAccountData);
|
|
74
68
|
accountData.unshift(getTableHeader([
|
|
@@ -76,19 +70,21 @@ async function handler(args) {
|
|
|
76
70
|
commands.account.subcommands.list.labels.accountId,
|
|
77
71
|
commands.account.subcommands.list.labels.authType,
|
|
78
72
|
]));
|
|
73
|
+
const defaultAccount = getConfigDefaultAccountIfExists();
|
|
74
|
+
const accountId = defaultAccount?.accountId;
|
|
75
|
+
const overrideFilePath = getDefaultAccountOverrideFilePath();
|
|
79
76
|
// If a default account is present in the config, display it
|
|
80
|
-
if (configPath) {
|
|
77
|
+
if (configPath && accountId) {
|
|
81
78
|
uiLogger.log(commands.account.subcommands.list.defaultAccountTitle);
|
|
82
79
|
uiLogger.log(`${indent(1)}${commands.account.subcommands.list.configPath(configPath)}`);
|
|
83
|
-
uiLogger.log(`${indent(1)}${commands.account.subcommands.list.
|
|
80
|
+
uiLogger.log(`${indent(1)}${commands.account.subcommands.list.currentResolvedDefaultAccount(accountId)}`);
|
|
84
81
|
uiLogger.log('');
|
|
85
82
|
}
|
|
86
83
|
// If a default account override is present, display it
|
|
87
|
-
|
|
88
|
-
if (overrideFilePath) {
|
|
84
|
+
if (overrideFilePath && accountId) {
|
|
89
85
|
uiLogger.log(commands.account.subcommands.list.overrideFilePathTitle);
|
|
90
86
|
uiLogger.log(`${indent(1)}${commands.account.subcommands.list.overrideFilePath(overrideFilePath)}`);
|
|
91
|
-
uiLogger.log(`${indent(1)}${commands.account.subcommands.list.
|
|
87
|
+
uiLogger.log(`${indent(1)}${commands.account.subcommands.list.currentResolvedDefaultAccount(accountId)}`);
|
|
92
88
|
uiLogger.log('');
|
|
93
89
|
}
|
|
94
90
|
uiLogger.log(commands.account.subcommands.list.accounts);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import fs from 'fs';
|
|
2
|
-
import {
|
|
2
|
+
import { getConfigFilePath, removeAccountFromConfig, getConfigDefaultAccountIfExists, getConfigAccountIfExists, getConfigAccountById, setConfigAccountAsDefault, } from '@hubspot/local-dev-lib/config';
|
|
3
|
+
import { getDefaultAccountOverrideAccountId, getDefaultAccountOverrideFilePath, } from '@hubspot/local-dev-lib/config/defaultAccountOverride';
|
|
3
4
|
import { trackCommandUsage } from '../../lib/usageTracking.js';
|
|
4
5
|
import { promptUser } from '../../lib/prompts/promptUtils.js';
|
|
5
6
|
import { logError } from '../../lib/errorHandlers/index.js';
|
|
@@ -10,25 +11,29 @@ import { commands } from '../../lang/en.js';
|
|
|
10
11
|
const command = 'remove [account]';
|
|
11
12
|
const describe = commands.account.subcommands.remove.describe;
|
|
12
13
|
async function handler(args) {
|
|
13
|
-
const { account } = args;
|
|
14
|
-
let
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
const { account: accountFlag } = args;
|
|
15
|
+
let accountToRemoveConfig = accountFlag
|
|
16
|
+
? getConfigAccountIfExists(accountFlag)
|
|
17
|
+
: undefined;
|
|
18
|
+
let accountToRemoveId = accountToRemoveConfig?.accountId;
|
|
19
|
+
if (accountFlag && !accountToRemoveConfig) {
|
|
20
|
+
uiLogger.error(commands.account.subcommands.remove.errors.accountNotFound(accountFlag, getConfigFilePath()));
|
|
17
21
|
}
|
|
18
|
-
if (!
|
|
19
|
-
|
|
22
|
+
if (!accountToRemoveId) {
|
|
23
|
+
accountToRemoveId = await selectAccountFromConfig(commands.account.subcommands.remove.prompts.selectAccountToRemove);
|
|
20
24
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
const
|
|
25
|
+
accountToRemoveConfig = getConfigAccountById(accountToRemoveId);
|
|
26
|
+
trackCommandUsage('accounts-remove', undefined, accountToRemoveId);
|
|
27
|
+
const currentDefaultAccount = getConfigDefaultAccountIfExists();
|
|
28
|
+
const accountOverride = getDefaultAccountOverrideAccountId();
|
|
24
29
|
const overrideFilePath = getDefaultAccountOverrideFilePath();
|
|
25
30
|
if (overrideFilePath &&
|
|
26
31
|
accountOverride &&
|
|
27
|
-
accountOverride ===
|
|
32
|
+
accountOverride === accountToRemoveConfig?.accountId) {
|
|
28
33
|
const { deleteOverrideFile } = await promptUser({
|
|
29
34
|
type: 'confirm',
|
|
30
35
|
name: 'deleteOverrideFile',
|
|
31
|
-
message: commands.account.subcommands.remove.prompts.deleteOverrideFile(overrideFilePath,
|
|
36
|
+
message: commands.account.subcommands.remove.prompts.deleteOverrideFile(overrideFilePath, accountToRemoveConfig.name),
|
|
32
37
|
});
|
|
33
38
|
try {
|
|
34
39
|
if (deleteOverrideFile) {
|
|
@@ -39,20 +44,16 @@ async function handler(args) {
|
|
|
39
44
|
logError(error);
|
|
40
45
|
}
|
|
41
46
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
// Get updated version of the config
|
|
45
|
-
loadConfig(getConfigPath());
|
|
46
|
-
const accountToRemoveId = getAccountId(accountToRemove);
|
|
47
|
-
let defaultAccountId;
|
|
48
|
-
if (currentDefaultAccount) {
|
|
49
|
-
defaultAccountId = getAccountId(currentDefaultAccount);
|
|
47
|
+
if (accountToRemoveConfig) {
|
|
48
|
+
removeAccountFromConfig(accountToRemoveConfig.accountId);
|
|
50
49
|
}
|
|
51
|
-
|
|
50
|
+
uiLogger.success(commands.account.subcommands.remove.success.accountRemoved(accountToRemoveConfig.name));
|
|
51
|
+
if (currentDefaultAccount &&
|
|
52
|
+
accountToRemoveConfig?.accountId === currentDefaultAccount.accountId) {
|
|
52
53
|
uiLogger.log('');
|
|
53
54
|
uiLogger.log(commands.account.subcommands.remove.logs.replaceDefaultAccount);
|
|
54
55
|
const newDefaultAccount = await selectAccountFromConfig();
|
|
55
|
-
|
|
56
|
+
setConfigAccountAsDefault(newDefaultAccount);
|
|
56
57
|
}
|
|
57
58
|
}
|
|
58
59
|
function accountRemoveBuilder(yargs) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import fs from 'fs-extra';
|
|
2
|
-
import {
|
|
2
|
+
import { globalConfigFileExists } from '@hubspot/local-dev-lib/config';
|
|
3
|
+
import { getDefaultAccountOverrideAccountId, getDefaultAccountOverrideFilePath, } from '@hubspot/local-dev-lib/config/defaultAccountOverride';
|
|
3
4
|
import { DEFAULT_ACCOUNT_OVERRIDE_FILE_NAME } from '@hubspot/local-dev-lib/constants/config';
|
|
4
|
-
import { getGlobalConfig } from '@hubspot/local-dev-lib/config/migrate';
|
|
5
5
|
import { promptUser } from '../../lib/prompts/promptUtils.js';
|
|
6
6
|
import { trackCommandUsage } from '../../lib/usageTracking.js';
|
|
7
7
|
import { EXIT_CODES } from '../../lib/enums/exitCodes.js';
|
|
@@ -13,15 +13,15 @@ const command = 'remove-override';
|
|
|
13
13
|
const describe = commands.account.subcommands.removeOverride.describe(DEFAULT_ACCOUNT_OVERRIDE_FILE_NAME);
|
|
14
14
|
async function handler(args) {
|
|
15
15
|
const { force } = args;
|
|
16
|
-
const
|
|
17
|
-
if (!
|
|
16
|
+
const globalConfigExists = globalConfigFileExists();
|
|
17
|
+
if (!globalConfigExists) {
|
|
18
18
|
uiLogger.error(commands.account.subcommands.removeOverride.errors.globalConfigNotFound);
|
|
19
19
|
process.exit(EXIT_CODES.ERROR);
|
|
20
20
|
}
|
|
21
|
-
const accountOverride =
|
|
21
|
+
const accountOverride = getDefaultAccountOverrideAccountId();
|
|
22
22
|
const overrideFilePath = getDefaultAccountOverrideFilePath();
|
|
23
23
|
if (accountOverride && overrideFilePath) {
|
|
24
|
-
const accountId =
|
|
24
|
+
const accountId = accountOverride;
|
|
25
25
|
trackCommandUsage('account-removeOverride', undefined, accountId);
|
|
26
26
|
if (!force) {
|
|
27
27
|
uiLogger.log(commands.account.subcommands.removeOverride.accountOverride(overrideFilePath, accountOverride.toString()));
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { renameConfigAccount } from '@hubspot/local-dev-lib/config';
|
|
2
2
|
import { trackCommandUsage } from '../../lib/usageTracking.js';
|
|
3
3
|
import { commands } from '../../lang/en.js';
|
|
4
4
|
import { uiLogger } from '../../lib/ui/logger.js';
|
|
@@ -14,7 +14,7 @@ async function handler(args) {
|
|
|
14
14
|
const newNameKebabCase = toKebabCase(newName);
|
|
15
15
|
const nameWasSanitized = newNameKebabCase !== newName;
|
|
16
16
|
try {
|
|
17
|
-
|
|
17
|
+
renameConfigAccount(accountName, newNameKebabCase);
|
|
18
18
|
}
|
|
19
19
|
catch (error) {
|
|
20
20
|
logError(error);
|
package/commands/account/use.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getConfigFilePath, setConfigAccountAsDefault, getConfigAccountIfExists, getConfigAccountByName, getConfigAccountById, } from '@hubspot/local-dev-lib/config';
|
|
2
|
+
import { getDefaultAccountOverrideAccountId, getDefaultAccountOverrideFilePath, } from '@hubspot/local-dev-lib/config/defaultAccountOverride';
|
|
2
3
|
import { trackCommandUsage } from '../../lib/usageTracking.js';
|
|
3
4
|
import { commands } from '../../lang/en.js';
|
|
4
5
|
import { uiLogger } from '../../lib/ui/logger.js';
|
|
@@ -11,20 +12,30 @@ async function handler(args) {
|
|
|
11
12
|
if (!newDefaultAccount) {
|
|
12
13
|
newDefaultAccount = await selectAccountFromConfig();
|
|
13
14
|
}
|
|
14
|
-
else
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
else {
|
|
16
|
+
const account = getConfigAccountIfExists(newDefaultAccount);
|
|
17
|
+
if (!account) {
|
|
18
|
+
uiLogger.error(commands.account.subcommands.use.errors.accountNotFound(newDefaultAccount, getConfigFilePath()));
|
|
19
|
+
newDefaultAccount = await selectAccountFromConfig();
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
let account;
|
|
23
|
+
if (!isNaN(Number(newDefaultAccount))) {
|
|
24
|
+
account = getConfigAccountById(Number(newDefaultAccount));
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
account = getConfigAccountByName(String(newDefaultAccount));
|
|
17
28
|
}
|
|
18
|
-
trackCommandUsage('accounts-use', undefined,
|
|
19
|
-
const accountOverride =
|
|
29
|
+
trackCommandUsage('accounts-use', undefined, account?.accountId);
|
|
30
|
+
const accountOverride = getDefaultAccountOverrideAccountId();
|
|
20
31
|
const overrideFilePath = getDefaultAccountOverrideFilePath();
|
|
21
32
|
if (accountOverride && overrideFilePath) {
|
|
22
33
|
uiLogger.warn(commands.account.subcommands.use.accountOverride(accountOverride.toString()));
|
|
23
34
|
uiLogger.log(commands.account.subcommands.use.accountOverrideCommands);
|
|
24
35
|
uiLogger.log('');
|
|
25
36
|
}
|
|
26
|
-
|
|
27
|
-
return uiLogger.success(commands.account.subcommands.use.success.defaultAccountUpdated(
|
|
37
|
+
setConfigAccountAsDefault(newDefaultAccount);
|
|
38
|
+
return uiLogger.success(commands.account.subcommands.use.success.defaultAccountUpdated(account.name));
|
|
28
39
|
}
|
|
29
40
|
function accountUseBuilder(yargs) {
|
|
30
41
|
yargs.positional('account', {
|