@hubspot/cli 7.8.12-experimental.0 → 7.8.12-experimental.1

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.
Files changed (244) hide show
  1. package/bin/cli.js +31 -25
  2. package/commands/__tests__/auth.test.js +5 -0
  3. package/commands/__tests__/doctor.test.js +16 -16
  4. package/commands/account/clean.js +18 -27
  5. package/commands/account/createOverride.js +13 -31
  6. package/commands/account/info.js +20 -31
  7. package/commands/account/list.js +16 -22
  8. package/commands/account/remove.js +12 -20
  9. package/commands/account/removeOverride.js +11 -21
  10. package/commands/account/rename.js +6 -9
  11. package/commands/account/use.js +12 -26
  12. package/commands/account.js +2 -2
  13. package/commands/app/__tests__/migrate.test.js +5 -5
  14. package/commands/app/migrate.js +13 -18
  15. package/commands/app.js +1 -6
  16. package/commands/auth.d.ts +1 -0
  17. package/commands/auth.js +16 -7
  18. package/commands/cms/convertFields.js +7 -9
  19. package/commands/cms/getReactModule.js +9 -14
  20. package/commands/cms/lighthouseScore.js +33 -36
  21. package/commands/cms.js +2 -2
  22. package/commands/completion.js +3 -3
  23. package/commands/config/set.d.ts +1 -1
  24. package/commands/config/set.js +64 -36
  25. package/commands/config.js +2 -2
  26. package/commands/create.js +2 -2
  27. package/commands/customObject/create.js +10 -12
  28. package/commands/customObject/schema/create.js +9 -11
  29. package/commands/customObject/schema/delete.js +16 -16
  30. package/commands/customObject/schema/fetch-all.js +12 -11
  31. package/commands/customObject/schema/fetch.js +15 -15
  32. package/commands/customObject/schema/list.js +4 -4
  33. package/commands/customObject/schema/update.js +13 -13
  34. package/commands/customObject/schema.js +2 -2
  35. package/commands/customObject.js +6 -7
  36. package/commands/doctor.js +8 -11
  37. package/commands/feedback.js +6 -11
  38. package/commands/fetch.js +8 -8
  39. package/commands/filemanager/fetch.js +7 -7
  40. package/commands/filemanager/upload.js +15 -34
  41. package/commands/filemanager.js +2 -2
  42. package/commands/function/deploy.js +11 -29
  43. package/commands/function/list.js +8 -8
  44. package/commands/function/server.js +9 -11
  45. package/commands/function.d.ts +1 -1
  46. package/commands/function.js +2 -2
  47. package/commands/getStarted.js +2 -2
  48. package/commands/hubdb/clear.js +7 -15
  49. package/commands/hubdb/create.js +9 -15
  50. package/commands/hubdb/delete.js +8 -15
  51. package/commands/hubdb/fetch.js +6 -9
  52. package/commands/hubdb.d.ts +1 -1
  53. package/commands/hubdb.js +2 -2
  54. package/commands/init.js +2 -3
  55. package/commands/lint.js +16 -16
  56. package/commands/list.js +8 -14
  57. package/commands/logs.js +14 -20
  58. package/commands/mv.js +6 -17
  59. package/commands/open.js +5 -5
  60. package/commands/project/__tests__/add.test.js +4 -2
  61. package/commands/project/__tests__/deploy.test.js +3 -4
  62. package/commands/project/__tests__/installDeps.test.js +8 -8
  63. package/commands/project/__tests__/logs.test.js +1 -1
  64. package/commands/project/__tests__/migrate.test.js +5 -5
  65. package/commands/project/__tests__/migrateApp.test.js +2 -5
  66. package/commands/project/__tests__/validate.test.js +98 -0
  67. package/commands/project/add.js +3 -3
  68. package/commands/project/cloneApp.js +14 -19
  69. package/commands/project/create.js +0 -1
  70. package/commands/project/deploy.js +3 -3
  71. package/commands/project/dev/deprecatedFlow.js +7 -16
  72. package/commands/project/dev/index.js +14 -12
  73. package/commands/project/dev/unifiedFlow.js +3 -1
  74. package/commands/project/download.js +10 -13
  75. package/commands/project/installDeps.js +8 -8
  76. package/commands/project/listBuilds.js +11 -20
  77. package/commands/project/logs.js +21 -24
  78. package/commands/project/migrateApp.js +9 -15
  79. package/commands/project/open.js +6 -13
  80. package/commands/project/upload.d.ts +2 -2
  81. package/commands/project/upload.js +17 -26
  82. package/commands/project/validate.js +6 -6
  83. package/commands/project/watch.js +13 -22
  84. package/commands/project.js +2 -2
  85. package/commands/sandbox/__tests__/create.test.js +5 -5
  86. package/commands/sandbox/create.js +22 -32
  87. package/commands/sandbox/delete.js +38 -63
  88. package/commands/sandbox.js +2 -2
  89. package/commands/secret/addSecret.js +7 -17
  90. package/commands/secret/deleteSecret.js +10 -20
  91. package/commands/secret/listSecret.js +8 -10
  92. package/commands/secret/updateSecret.js +9 -17
  93. package/commands/secret.js +2 -2
  94. package/commands/testAccount/__tests__/delete.test.js +2 -4
  95. package/commands/testAccount/create.js +0 -3
  96. package/commands/testAccount/delete.d.ts +4 -3
  97. package/commands/testAccount/delete.js +155 -14
  98. package/commands/theme/preview.js +1 -4
  99. package/lang/en.d.ts +310 -124
  100. package/lang/en.js +351 -169
  101. package/lang/en.lyaml +2 -2
  102. package/lib/__tests__/buildAccount.test.js +2 -1
  103. package/lib/__tests__/commonOpts.test.js +1 -1
  104. package/lib/__tests__/dependencyManagement.test.js +1 -1
  105. package/lib/__tests__/developerTestAccounts.test.js +3 -3
  106. package/lib/__tests__/npm.test.js +1 -1
  107. package/lib/__tests__/oauth.test.js +4 -4
  108. package/lib/__tests__/process.test.js +10 -5
  109. package/lib/__tests__/sandboxSync.test.js +8 -8
  110. package/lib/__tests__/sandboxes.test.js +8 -8
  111. package/lib/__tests__/serverlessLogs.test.js +1 -1
  112. package/lib/__tests__/usageTracking.test.js +5 -5
  113. package/lib/__tests__/validation.test.js +2 -1
  114. package/lib/__tests__/yargsUtils.test.js +83 -9
  115. package/lib/app/__tests__/migrate.test.js +5 -5
  116. package/lib/app/__tests__/migrate_legacy.test.js +1 -1
  117. package/lib/app/migrate.js +1 -1
  118. package/lib/app/migrate_legacy.js +20 -24
  119. package/lib/buildAccount.js +25 -57
  120. package/lib/commonOpts.d.ts +1 -1
  121. package/lib/commonOpts.js +25 -22
  122. package/lib/configOptions.js +7 -0
  123. package/lib/constants.d.ts +6 -1
  124. package/lib/constants.js +10 -1
  125. package/lib/dependencyManagement.js +9 -27
  126. package/lib/developerTestAccounts.js +9 -23
  127. package/lib/doctor/Diagnosis.js +11 -23
  128. package/lib/doctor/DiagnosticInfoBuilder.js +12 -11
  129. package/lib/doctor/Doctor.js +42 -90
  130. package/lib/doctor/__tests__/Doctor.test.js +4 -4
  131. package/lib/errorHandlers/index.js +12 -20
  132. package/lib/errorHandlers/suppressError.js +11 -18
  133. package/lib/lang.js +6 -5
  134. package/lib/links.js +4 -4
  135. package/lib/middleware/__test__/commandTargetingUtils.test.js +99 -0
  136. package/lib/middleware/__test__/configMiddleware.test.js +11 -11
  137. package/lib/middleware/__test__/yargsChecksMiddleware.test.js +6 -8
  138. package/lib/middleware/commandTargetingUtils.d.ts +8 -0
  139. package/lib/middleware/commandTargetingUtils.js +78 -0
  140. package/lib/middleware/configMiddleware.d.ts +1 -1
  141. package/lib/middleware/configMiddleware.js +21 -81
  142. package/lib/middleware/gitMiddleware.js +5 -1
  143. package/lib/middleware/notificationsMiddleware.js +5 -11
  144. package/lib/middleware/yargsChecksMiddleware.js +6 -9
  145. package/lib/npm.js +2 -2
  146. package/lib/oauth.js +5 -5
  147. package/lib/process.js +5 -4
  148. package/lib/projectProfiles.d.ts +1 -1
  149. package/lib/projectProfiles.js +2 -10
  150. package/lib/projects/__tests__/AppDevModeInterface.test.js +14 -34
  151. package/lib/projects/__tests__/LocalDevWebsocketServer.test.js +70 -39
  152. package/lib/projects/__tests__/localDevProjectHelpers.test.js +2 -0
  153. package/lib/projects/__tests__/platformVersion.test.js +8 -8
  154. package/lib/projects/__tests__/projects.test.js +12 -12
  155. package/lib/projects/__tests__/structure.test.js +3 -3
  156. package/lib/projects/__tests__/upload.test.d.ts +1 -0
  157. package/lib/projects/__tests__/upload.test.js +82 -0
  158. package/lib/projects/add/__tests__/legacyAddComponent.test.js +6 -6
  159. package/lib/projects/add/__tests__/v3AddComponent.test.js +4 -4
  160. package/lib/projects/create/__tests__/legacy.test.js +5 -5
  161. package/lib/projects/create/__tests__/v3.test.js +1 -1
  162. package/lib/projects/create/index.js +2 -2
  163. package/lib/projects/create/legacy.js +2 -2
  164. package/lib/projects/create/v3.js +2 -2
  165. package/lib/projects/localDev/AppDevModeInterface.d.ts +2 -0
  166. package/lib/projects/localDev/AppDevModeInterface.js +22 -20
  167. package/lib/projects/localDev/LocalDevLogger.js +10 -11
  168. package/lib/projects/localDev/LocalDevManager.js +4 -5
  169. package/lib/projects/localDev/LocalDevWebsocketServer.d.ts +0 -1
  170. package/lib/projects/localDev/LocalDevWebsocketServer.js +7 -10
  171. package/lib/projects/localDev/helpers/project.d.ts +1 -0
  172. package/lib/projects/localDev/helpers/project.js +37 -0
  173. package/lib/projects/platformVersion.d.ts +1 -1
  174. package/lib/projects/platformVersion.js +1 -1
  175. package/lib/projects/structure.d.ts +2 -2
  176. package/lib/projects/structure.js +6 -6
  177. package/lib/projects/upload.d.ts +2 -3
  178. package/lib/projects/upload.js +17 -9
  179. package/lib/prompts/__tests__/downloadProjectPrompt.test.js +1 -0
  180. package/lib/prompts/accountNamePrompt.js +14 -19
  181. package/lib/prompts/accountsPrompt.js +2 -2
  182. package/lib/prompts/cmsFieldPrompt.js +2 -2
  183. package/lib/prompts/createApiSamplePrompt.js +5 -5
  184. package/lib/prompts/createDeveloperTestAccountConfigPrompt.js +10 -1
  185. package/lib/prompts/createFunctionPrompt.js +14 -14
  186. package/lib/prompts/createModulePrompt.js +9 -9
  187. package/lib/prompts/createTemplatePrompt.js +2 -2
  188. package/lib/prompts/downloadProjectPrompt.js +5 -8
  189. package/lib/prompts/personalAccessKeyPrompt.js +3 -3
  190. package/lib/prompts/previewPrompt.js +6 -6
  191. package/lib/prompts/projectAddPrompt.js +6 -0
  192. package/lib/prompts/projectDevTargetAccountPrompt.js +20 -32
  193. package/lib/prompts/projectNamePrompt.js +4 -8
  194. package/lib/prompts/projectsLogsPrompt.js +2 -4
  195. package/lib/prompts/promptUtils.js +27 -9
  196. package/lib/prompts/sandboxesPrompt.js +7 -7
  197. package/lib/prompts/secretPrompt.js +3 -3
  198. package/lib/prompts/selectAppPrompt.js +3 -3
  199. package/lib/prompts/selectHubDBTablePrompt.js +9 -13
  200. package/lib/prompts/selectPublicAppForMigrationPrompt.js +15 -19
  201. package/lib/prompts/setAsDefaultAccountPrompt.js +4 -8
  202. package/lib/prompts/uploadPrompt.js +5 -5
  203. package/lib/sandboxSync.js +24 -41
  204. package/lib/sandboxes.js +19 -47
  205. package/lib/schema.js +3 -3
  206. package/lib/serverlessLogs.js +11 -13
  207. package/lib/theme/__tests__/migrate.test.js +3 -3
  208. package/lib/theme/migrate.js +2 -2
  209. package/lib/ui/SpinniesManager.d.ts +2 -0
  210. package/lib/ui/SpinniesManager.js +7 -0
  211. package/lib/ui/boxen.js +1 -2
  212. package/lib/ui/git.js +13 -10
  213. package/lib/ui/index.d.ts +4 -0
  214. package/lib/ui/index.js +47 -38
  215. package/lib/ui/serverlessFunctionLogs.js +9 -7
  216. package/lib/ui/uiMessages.d.ts +68 -0
  217. package/lib/ui/uiMessages.js +71 -0
  218. package/lib/usageTracking.js +7 -7
  219. package/lib/validation.js +20 -23
  220. package/lib/yargsUtils.d.ts +1 -1
  221. package/lib/yargsUtils.js +12 -5
  222. package/mcp-server/tools/cms/HsCreateModuleTool.d.ts +2 -2
  223. package/mcp-server/tools/index.js +4 -0
  224. package/mcp-server/tools/project/GetApiUsagePatternsByAppIdTool.d.ts +23 -0
  225. package/mcp-server/tools/project/GetApiUsagePatternsByAppIdTool.js +68 -0
  226. package/mcp-server/tools/project/GetApplicationInfoTool.d.ts +11 -0
  227. package/mcp-server/tools/project/GetApplicationInfoTool.js +49 -0
  228. package/mcp-server/tools/project/GetConfigValuesTool.js +2 -2
  229. package/mcp-server/tools/project/GuidedWalkthroughTool.d.ts +2 -2
  230. package/mcp-server/tools/project/__tests__/GetApiUsagePatternsByAppIdTool.test.d.ts +1 -0
  231. package/mcp-server/tools/project/__tests__/GetApiUsagePatternsByAppIdTool.test.js +169 -0
  232. package/mcp-server/tools/project/__tests__/GetApplicationInfoTool.test.d.ts +1 -0
  233. package/mcp-server/tools/project/__tests__/GetApplicationInfoTool.test.js +115 -0
  234. package/mcp-server/utils/toolUsageTracking.js +2 -2
  235. package/package.json +6 -6
  236. package/types/Yargs.d.ts +1 -1
  237. package/commands/app/__tests__/install.test.js +0 -47
  238. package/commands/app/install.d.ts +0 -8
  239. package/commands/app/install.js +0 -122
  240. package/lib/middleware/__test__/utils.test.js +0 -51
  241. package/lib/middleware/utils.d.ts +0 -8
  242. package/lib/middleware/utils.js +0 -14
  243. /package/commands/{app/__tests__/install.test.d.ts → project/__tests__/validate.test.d.ts} +0 -0
  244. /package/lib/middleware/__test__/{utils.test.d.ts → commandTargetingUtils.test.d.ts} +0 -0
@@ -0,0 +1,99 @@
1
+ import * as cliConfig from '@hubspot/local-dev-lib/config';
2
+ import { isTargetedCommand, shouldLoadConfigForCommand, shouldRunAccountValidationForCommand, shouldRunConfigValidationForCommand, } from '../commandTargetingUtils.js';
3
+ vi.mock('@hubspot/local-dev-lib/config');
4
+ const configFileExistsSpy = vi.spyOn(cliConfig, 'configFileExists');
5
+ const targetCommandMap = {
6
+ init: true,
7
+ account: {
8
+ use: true,
9
+ },
10
+ project: {
11
+ deploy: true,
12
+ },
13
+ };
14
+ describe('lib/middleware/commandTargetingUtils', () => {
15
+ describe('isTargetedCommand()', () => {
16
+ it('should return true for a direct target command', () => {
17
+ const result = isTargetedCommand(['init'], targetCommandMap);
18
+ expect(result).toBe(true);
19
+ });
20
+ it('should return false for a command with a subcommand', () => {
21
+ const result = isTargetedCommand(['account'], targetCommandMap);
22
+ expect(result).toBe(false);
23
+ });
24
+ it('should return true for a nested target command', () => {
25
+ const result = isTargetedCommand(['project', 'deploy'], targetCommandMap);
26
+ expect(result).toBe(true);
27
+ });
28
+ it('should return false for a non-existent command', () => {
29
+ const result = isTargetedCommand(['nonexistent'], targetCommandMap);
30
+ expect(result).toBe(false);
31
+ });
32
+ it('should return false for a non-targeted command', () => {
33
+ const result = isTargetedCommand(['auth'], targetCommandMap);
34
+ expect(result).toBe(false);
35
+ });
36
+ it('should return false for a command with a targeted subcommand', () => {
37
+ const result = isTargetedCommand(['project'], targetCommandMap);
38
+ expect(result).toBe(false);
39
+ });
40
+ it('should return false for a non-existent subcommand', () => {
41
+ const result = isTargetedCommand(['auth', 'nonexistent'], targetCommandMap);
42
+ expect(result).toBe(false);
43
+ });
44
+ it('should return false for an empty command array', () => {
45
+ const result = isTargetedCommand([], targetCommandMap);
46
+ expect(result).toBe(false);
47
+ });
48
+ });
49
+ describe('shouldLoadConfigForCommand()', () => {
50
+ it('should return true for a command that requires a config file', () => {
51
+ const result = shouldLoadConfigForCommand(['account', 'use']);
52
+ expect(result).toBe(true);
53
+ });
54
+ it('should return false for a command that does not require a config file', () => {
55
+ const result = shouldLoadConfigForCommand(['init']);
56
+ expect(result).toBe(false);
57
+ });
58
+ it('should return false when the user is trying to migrate the global config', () => {
59
+ configFileExistsSpy.mockReturnValue(false);
60
+ const result = shouldLoadConfigForCommand(['config', 'migrate']);
61
+ expect(result).toBe(false);
62
+ });
63
+ it('should return true when the global config file does exist', () => {
64
+ configFileExistsSpy.mockReturnValue(true);
65
+ const result = shouldLoadConfigForCommand(['account', 'use']);
66
+ expect(result).toBe(true);
67
+ });
68
+ });
69
+ describe('shouldRunAccountValidationForCommand()', () => {
70
+ it('should return true for a command that requires a config file', () => {
71
+ const result = shouldRunAccountValidationForCommand([
72
+ 'project',
73
+ 'upload',
74
+ ]);
75
+ expect(result).toBe(true);
76
+ });
77
+ it('should return false for a command that does not require account validation', () => {
78
+ const result1 = shouldRunAccountValidationForCommand(['init']);
79
+ const result2 = shouldRunAccountValidationForCommand(['auth']);
80
+ const result3 = shouldRunAccountValidationForCommand([
81
+ 'accounts',
82
+ 'list',
83
+ ]);
84
+ expect(result1).toBe(false);
85
+ expect(result2).toBe(false);
86
+ expect(result3).toBe(false);
87
+ });
88
+ });
89
+ describe('shouldRunConfigValidationForCommand()', () => {
90
+ it('should return true for a command that requires a config file', () => {
91
+ const result = shouldRunConfigValidationForCommand(['account', 'use']);
92
+ expect(result).toBe(true);
93
+ });
94
+ it('should return false for a command that does not require config validation', () => {
95
+ const result = shouldRunConfigValidationForCommand(['init']);
96
+ expect(result).toBe(false);
97
+ });
98
+ });
99
+ });
@@ -1,10 +1,10 @@
1
- import { logger } from '@hubspot/local-dev-lib/logger';
1
+ import { uiLogger } from '../../ui/logger.js';
2
2
  import * as cliConfig from '@hubspot/local-dev-lib/config';
3
3
  import * as validation from '../../validation.js';
4
4
  import { EXIT_CODES } from '../../enums/exitCodes.js';
5
- import { handleDeprecatedEnvVariables, injectAccountIdMiddleware, loadConfigMiddleware, validateAccountOptions, } from '../configMiddleware.js';
6
- vi.mock('@hubspot/local-dev-lib/logger', () => ({
7
- logger: {
5
+ import { handleDeprecatedEnvVariables, injectAccountIdMiddleware, loadAndValidateConfigMiddleware, validateAccountOptions, } from '../configMiddleware.js';
6
+ vi.mock('../../ui/logger.js', () => ({
7
+ uiLogger: {
8
8
  error: vi.fn(),
9
9
  log: vi.fn(),
10
10
  },
@@ -39,7 +39,7 @@ describe('lib/middleware/configMiddleware', () => {
39
39
  $0: 'hs',
40
40
  };
41
41
  handleDeprecatedEnvVariables(argv);
42
- expect(logger.log).toHaveBeenCalledWith(expect.stringContaining('The HUBSPOT_PORTAL_ID environment variable is deprecated. Please use HUBSPOT_ACCOUNT_ID instead.'));
42
+ expect(uiLogger.log).toHaveBeenCalledWith(expect.stringContaining('The HUBSPOT_PORTAL_ID environment variable is deprecated. Please use HUBSPOT_ACCOUNT_ID instead.'));
43
43
  expect(process.env.HUBSPOT_ACCOUNT_ID).toBe('123');
44
44
  process.env = originalEnv;
45
45
  });
@@ -56,7 +56,7 @@ describe('lib/middleware/configMiddleware', () => {
56
56
  $0: 'hs',
57
57
  };
58
58
  handleDeprecatedEnvVariables(argv);
59
- expect(logger.log).not.toHaveBeenCalled();
59
+ expect(uiLogger.log).not.toHaveBeenCalled();
60
60
  expect(process.env.HUBSPOT_ACCOUNT_ID).toBe('456');
61
61
  process.env = originalEnv;
62
62
  });
@@ -93,7 +93,7 @@ describe('lib/middleware/configMiddleware', () => {
93
93
  expect(getAccountIdSpy).toHaveBeenCalledWith('test-account');
94
94
  });
95
95
  });
96
- describe('loadConfigMiddleware()', () => {
96
+ describe('loadAndValidateConfigMiddleware()', () => {
97
97
  it('should exit with error when config file exists and --config flag is used', async () => {
98
98
  configFileExistsSpy.mockReturnValue(true);
99
99
  const argv = {
@@ -101,9 +101,9 @@ describe('lib/middleware/configMiddleware', () => {
101
101
  config: 'custom-config.json',
102
102
  $0: 'hs',
103
103
  };
104
- await expect(loadConfigMiddleware(argv)).rejects.toThrow();
104
+ await expect(loadAndValidateConfigMiddleware(argv)).rejects.toThrow();
105
105
  expect(processExitSpy).toHaveBeenCalledWith(EXIT_CODES.ERROR);
106
- expect(logger.error).toHaveBeenCalledWith('A configuration file already exists at /path/to/config. To specify a new configuration file, delete the existing one and try again.');
106
+ expect(uiLogger.error).toHaveBeenCalledWith('A configuration file already exists at /path/to/config. To specify a new configuration file, delete the existing one and try again.');
107
107
  });
108
108
  it('should load config and validate for non-init commands', async () => {
109
109
  configFileExistsSpy.mockReturnValue(false);
@@ -113,7 +113,7 @@ describe('lib/middleware/configMiddleware', () => {
113
113
  _: ['some-command'],
114
114
  $0: 'hs',
115
115
  };
116
- await loadConfigMiddleware(argv);
116
+ await loadAndValidateConfigMiddleware(argv);
117
117
  expect(loadConfigSpy).toHaveBeenCalled();
118
118
  expect(validateConfigSpy).toHaveBeenCalled();
119
119
  });
@@ -123,7 +123,7 @@ describe('lib/middleware/configMiddleware', () => {
123
123
  _: ['init'],
124
124
  $0: 'hs',
125
125
  };
126
- await loadConfigMiddleware(argv);
126
+ await loadAndValidateConfigMiddleware(argv);
127
127
  expect(loadConfigSpy).not.toHaveBeenCalled();
128
128
  expect(validateConfigSpy).not.toHaveBeenCalled();
129
129
  });
@@ -1,16 +1,14 @@
1
- import { logger } from '@hubspot/local-dev-lib/logger';
2
1
  import { EXIT_CODES } from '../../enums/exitCodes.js';
3
2
  import * as projectsConfig from '../../projects/config.js';
4
3
  import { performChecks } from '../yargsChecksMiddleware.js';
5
- vi.mock('@hubspot/local-dev-lib/logger', () => ({
6
- logger: {
4
+ import { uiLogger } from '../../ui/logger.js';
5
+ import { commands } from '../../../lang/en.js';
6
+ vi.mock('../../ui/logger', () => ({
7
+ uiLogger: {
7
8
  error: vi.fn(),
8
9
  },
9
10
  }));
10
11
  vi.mock('../../projects/config');
11
- vi.mock('../../lang', () => ({
12
- i18n: vi.fn(key => key),
13
- }));
14
12
  const getIsInProjectSpy = vi.spyOn(projectsConfig, 'getIsInProject');
15
13
  const processExitSpy = vi.spyOn(process, 'exit');
16
14
  describe('lib/middleware/yargsChecksMiddleware', () => {
@@ -29,7 +27,7 @@ describe('lib/middleware/yargsChecksMiddleware', () => {
29
27
  getIsInProjectSpy.mockReturnValue(true);
30
28
  expect(() => performChecks(argv)).toThrow();
31
29
  expect(processExitSpy).toHaveBeenCalledWith(EXIT_CODES.ERROR);
32
- expect(logger.error).toHaveBeenCalledWith('commands.generalErrors.srcIsProject');
30
+ expect(uiLogger.error).toHaveBeenCalledWith(commands.generalErrors.srcIsProject(argv.src, argv._.toString()));
33
31
  });
34
32
  it('should return true when no checks fail', () => {
35
33
  const argv = {
@@ -40,7 +38,7 @@ describe('lib/middleware/yargsChecksMiddleware', () => {
40
38
  getIsInProjectSpy.mockReturnValue(false);
41
39
  expect(performChecks(argv)).toBe(true);
42
40
  expect(processExitSpy).not.toHaveBeenCalled();
43
- expect(logger.error).not.toHaveBeenCalled();
41
+ expect(uiLogger.error).not.toHaveBeenCalled();
44
42
  });
45
43
  });
46
44
  });
@@ -0,0 +1,8 @@
1
+ type TargetCommandMap = {
2
+ [key: string]: boolean | TargetCommandMap;
3
+ };
4
+ export declare function isTargetedCommand(commandParts: (string | number)[], targetCommandMap: TargetCommandMap): boolean;
5
+ export declare function shouldLoadConfigForCommand(commandParts: (string | number)[]): boolean;
6
+ export declare function shouldRunAccountValidationForCommand(commandParts: (string | number)[]): boolean;
7
+ export declare function shouldRunConfigValidationForCommand(commandParts: (string | number)[]): boolean;
8
+ export {};
@@ -0,0 +1,78 @@
1
+ import { configFileExists } from '@hubspot/local-dev-lib/config';
2
+ export function isTargetedCommand(commandParts, targetCommandMap) {
3
+ const currentCommandPart = commandParts[0];
4
+ if (!targetCommandMap[currentCommandPart]) {
5
+ return false;
6
+ }
7
+ if (typeof targetCommandMap[currentCommandPart] === 'boolean' &&
8
+ targetCommandMap[currentCommandPart]) {
9
+ return true;
10
+ }
11
+ if (commandParts.length > 1) {
12
+ const targetSubCommandMap = targetCommandMap[currentCommandPart];
13
+ if (!targetSubCommandMap) {
14
+ return false;
15
+ }
16
+ return isTargetedCommand(commandParts.slice(1), targetSubCommandMap);
17
+ }
18
+ return false;
19
+ }
20
+ const SKIP_CONFIG_LOADING_COMMANDS = {
21
+ init: true,
22
+ feedback: true,
23
+ };
24
+ // Returns true if the command requires a config file to be present
25
+ export function shouldLoadConfigForCommand(commandParts) {
26
+ const globalConfigExists = configFileExists(true);
27
+ // the user is trying to migrate the global config
28
+ const isGlobalConfigMigration = !globalConfigExists &&
29
+ isTargetedCommand(commandParts, {
30
+ account: { auth: true },
31
+ config: { migrate: true },
32
+ });
33
+ return (!isGlobalConfigMigration &&
34
+ !isTargetedCommand(commandParts, SKIP_CONFIG_LOADING_COMMANDS));
35
+ }
36
+ const accountsSubCommands = {
37
+ auth: true,
38
+ clean: true,
39
+ list: true,
40
+ ls: true,
41
+ remove: true,
42
+ use: true,
43
+ };
44
+ const sandboxesSubCommands = {
45
+ delete: true,
46
+ };
47
+ const SKIP_ACCOUNT_VALIDATION_COMMANDS = {
48
+ init: true,
49
+ auth: true,
50
+ mcp: {
51
+ setup: true,
52
+ start: true,
53
+ },
54
+ account: accountsSubCommands,
55
+ accounts: accountsSubCommands,
56
+ sandbox: sandboxesSubCommands,
57
+ sandboxes: sandboxesSubCommands,
58
+ config: {
59
+ migrate: true,
60
+ },
61
+ feedback: true,
62
+ };
63
+ // Returns true if the command requires a valid account to be set in the config
64
+ export function shouldRunAccountValidationForCommand(commandParts) {
65
+ return !isTargetedCommand(commandParts, SKIP_ACCOUNT_VALIDATION_COMMANDS);
66
+ }
67
+ const SKIP_CONFIG_VALIDATION_COMMANDS = {
68
+ init: true,
69
+ auth: true,
70
+ mcp: {
71
+ setup: true,
72
+ start: true,
73
+ },
74
+ };
75
+ // Returns true if the command requires a valid config file to be present
76
+ export function shouldRunConfigValidationForCommand(commandParts) {
77
+ return !isTargetedCommand(commandParts, SKIP_CONFIG_VALIDATION_COMMANDS);
78
+ }
@@ -9,5 +9,5 @@ export declare function handleDeprecatedEnvVariables(argv: Arguments<{
9
9
  export declare function injectAccountIdMiddleware(argv: Arguments<{
10
10
  account?: string;
11
11
  }>): Promise<void>;
12
- export declare function loadConfigMiddleware(argv: Arguments<CLIOptions>): Promise<void>;
12
+ export declare function loadAndValidateConfigMiddleware(argv: Arguments<CLIOptions>): Promise<void>;
13
13
  export declare function validateAccountOptions(argv: Arguments): Promise<void>;
@@ -1,10 +1,9 @@
1
- import { logger } from '@hubspot/local-dev-lib/logger';
2
1
  import { loadConfig, getAccountId, configFileExists, getConfigPath, validateConfig, } from '@hubspot/local-dev-lib/config';
3
2
  import { validateAccount } from '../validation.js';
4
3
  import { EXIT_CODES } from '../enums/exitCodes.js';
5
- import { i18n } from '../lang.js';
4
+ import { commands } from '../../lang/en.js';
6
5
  import { uiDeprecatedTag } from '../ui/index.js';
7
- import { isTargetedCommand } from './utils.js';
6
+ import { isTargetedCommand, shouldLoadConfigForCommand, shouldRunAccountValidationForCommand, shouldRunConfigValidationForCommand, } from './commandTargetingUtils.js';
8
7
  import { parseStringToNumber } from '../parsing.js';
9
8
  import { uiLogger } from '../ui/logger.js';
10
9
  import { lib } from '../../lang/en.js';
@@ -14,9 +13,7 @@ export function handleDeprecatedEnvVariables(argv) {
14
13
  if (argv.useEnv &&
15
14
  process.env.HUBSPOT_PORTAL_ID &&
16
15
  !process.env.HUBSPOT_ACCOUNT_ID) {
17
- uiDeprecatedTag(i18n(`commands.generalErrors.handleDeprecatedEnvVariables.portalEnvVarDeprecated`, {
18
- configPath: getConfigPath(),
19
- }));
16
+ uiDeprecatedTag(commands.generalErrors.handleDeprecatedEnvVariables.portalEnvVarDeprecated);
20
17
  process.env.HUBSPOT_ACCOUNT_ID = process.env.HUBSPOT_PORTAL_ID;
21
18
  }
22
19
  }
@@ -39,99 +36,42 @@ export async function injectAccountIdMiddleware(argv) {
39
36
  argv.derivedAccountId = getAccountId(account);
40
37
  }
41
38
  }
42
- const SKIP_CONFIG_VALIDATION = {
43
- init: { target: true },
44
- auth: { target: true },
45
- mcp: {
46
- target: false,
47
- subCommands: {
48
- setup: { target: true },
49
- start: { target: true },
50
- },
51
- },
52
- };
53
- export async function loadConfigMiddleware(argv) {
39
+ export async function loadAndValidateConfigMiddleware(argv) {
54
40
  // Skip this when no command is provided
55
41
  if (!argv._.length || argv.help) {
56
42
  return;
57
43
  }
58
- const maybeValidateConfig = () => {
59
- if (!isTargetedCommand(argv._, SKIP_CONFIG_VALIDATION) &&
60
- !validateConfig()) {
61
- process.exit(EXIT_CODES.ERROR);
62
- }
63
- };
64
- if (!configFileExists(true) &&
65
- isTargetedCommand(argv._, {
66
- account: { target: false, subCommands: { auth: { target: true } } },
67
- config: { target: false, subCommands: { migrate: { target: true } } },
68
- })) {
44
+ // Do not load or validate the config for the commands that do not require it
45
+ if (!shouldLoadConfigForCommand(argv._)) {
69
46
  return;
70
47
  }
48
+ // If the config file exists and the --config flag is used, exit with an error
71
49
  if (configFileExists(true) &&
72
50
  argv.config &&
73
- !isTargetedCommand(argv._, {
74
- config: { target: false, subCommands: { migrate: { target: true } } },
75
- })) {
76
- logger.error(i18n(`commands.generalErrors.loadConfigMiddleware.configFileExists`, {
77
- configPath: getConfigPath(),
78
- }));
51
+ !isTargetedCommand(argv._, { config: { migrate: true } })) {
52
+ uiLogger.error(commands.generalErrors.loadConfigMiddleware.configFileExists(getConfigPath()));
53
+ process.exit(EXIT_CODES.ERROR);
54
+ }
55
+ const config = loadConfig(argv.config, argv);
56
+ // We don't run validation for auth because users should be able to run it when
57
+ // no accounts are configured, but we still want to exit if the config file is not found
58
+ if (isTargetedCommand(argv._, { auth: true }) && !config) {
79
59
  process.exit(EXIT_CODES.ERROR);
80
60
  }
81
- else if (!isTargetedCommand(argv._, { init: { target: true } })) {
82
- const config = loadConfig(argv.config, argv);
83
- // We don't run validateConfig() for auth because users should be able to run it when
84
- // no accounts are configured, but we still want to exit if the config file is not found
85
- if (isTargetedCommand(argv._, { auth: { target: true } }) && !config) {
61
+ // Only validate the config if the command requires it
62
+ if (shouldRunConfigValidationForCommand(argv._)) {
63
+ const configIsValid = validateConfig();
64
+ if (!configIsValid) {
86
65
  process.exit(EXIT_CODES.ERROR);
87
66
  }
88
67
  }
89
- maybeValidateConfig();
90
68
  }
91
- const accountsSubCommands = {
92
- target: false,
93
- subCommands: {
94
- auth: { target: true },
95
- clean: { target: true },
96
- list: { target: true },
97
- ls: { target: true },
98
- remove: { target: true },
99
- use: { target: true },
100
- },
101
- };
102
- const sandboxesSubCommands = {
103
- target: false,
104
- subCommands: {
105
- delete: { target: true },
106
- },
107
- };
108
- const configSubCommands = {
109
- target: false,
110
- subCommands: {
111
- migrate: { target: true },
112
- },
113
- };
114
- const SKIP_ACCOUNT_VALIDATION = {
115
- init: { target: true },
116
- auth: { target: true },
117
- mcp: {
118
- target: false,
119
- subCommands: {
120
- setup: { target: true },
121
- start: { target: true },
122
- },
123
- },
124
- account: accountsSubCommands,
125
- accounts: accountsSubCommands,
126
- sandbox: sandboxesSubCommands,
127
- sandboxes: sandboxesSubCommands,
128
- config: configSubCommands,
129
- };
130
69
  export async function validateAccountOptions(argv) {
131
70
  // Skip this when no command is provided
132
71
  if (argv._.length && !argv.help) {
133
72
  let validAccount = true;
134
- if (!isTargetedCommand(argv._, SKIP_ACCOUNT_VALIDATION)) {
73
+ // Only validate the account if the command requires it
74
+ if (shouldRunAccountValidationForCommand(argv._)) {
135
75
  validAccount = await validateAccount(argv);
136
76
  }
137
77
  if (!validAccount) {
@@ -1,8 +1,12 @@
1
- import { getConfigPath } from '@hubspot/local-dev-lib/config';
1
+ import { getConfigPath, configFileExists } from '@hubspot/local-dev-lib/config';
2
2
  import { checkAndWarnGitInclusion } from '../ui/git.js';
3
3
  export function checkAndWarnGitInclusionMiddleware(argv) {
4
4
  // Skip this when no command is provided
5
5
  if (argv._.length) {
6
+ // Skip if using global config
7
+ if (configFileExists(true)) {
8
+ return;
9
+ }
6
10
  const configPath = getConfigPath();
7
11
  if (configPath) {
8
12
  checkAndWarnGitInclusion(configPath);
@@ -1,8 +1,7 @@
1
1
  import updateNotifier from 'update-notifier';
2
- import chalk from 'chalk';
3
2
  import pkg from '../../package.json' with { type: 'json' };
4
- import { UI_COLORS, uiCommandReference } from '../ui/index.js';
5
- import { i18n } from '../lang.js';
3
+ import { UI_COLORS } from '../ui/index.js';
4
+ import { lib } from '../../lang/en.js';
6
5
  const notifier = updateNotifier({
7
6
  pkg: { ...pkg, name: '@hubspot/cli' },
8
7
  distTag: 'latest',
@@ -12,13 +11,8 @@ const CMS_CLI_PACKAGE_NAME = '@hubspot/cms-cli';
12
11
  export function notifyAboutUpdates() {
13
12
  notifier.notify({
14
13
  message: pkg.name === CMS_CLI_PACKAGE_NAME
15
- ? i18n(`commands.generalErrors.updateNotify.cmsUpdateNotification`, {
16
- packageName: CMS_CLI_PACKAGE_NAME,
17
- updateCommand: uiCommandReference('{updateCommand}'),
18
- })
19
- : i18n(`commands.generalErrors.updateNotify.cliUpdateNotification`, {
20
- updateCommand: uiCommandReference('{updateCommand}'),
21
- }),
14
+ ? lib.middleware.updateNotification.cmsUpdateNotification(CMS_CLI_PACKAGE_NAME)
15
+ : lib.middleware.updateNotification.cliUpdateNotification,
22
16
  defer: false,
23
17
  boxenOptions: {
24
18
  borderColor: UI_COLORS.MARIGOLD_DARK,
@@ -28,7 +22,7 @@ export function notifyAboutUpdates() {
28
22
  borderStyle: 'round',
29
23
  title: pkg.name === CMS_CLI_PACKAGE_NAME
30
24
  ? undefined
31
- : chalk.bold(i18n(`commands.generalErrors.updateNotify.notifyTitle`)),
25
+ : lib.middleware.updateNotification.notifyTitle,
32
26
  },
33
27
  });
34
28
  }
@@ -1,20 +1,17 @@
1
- import { logger } from '@hubspot/local-dev-lib/logger';
1
+ import { uiLogger } from '../ui/logger.js';
2
2
  import { EXIT_CODES } from '../enums/exitCodes.js';
3
- import { i18n } from '../lang.js';
3
+ import { commands } from '../../lang/en.js';
4
4
  import { getIsInProject } from '../projects/config.js';
5
- import { isTargetedCommand } from './utils.js';
5
+ import { isTargetedCommand } from './commandTargetingUtils.js';
6
6
  const UPLOAD_AND_WATCH_COMMANDS = {
7
- upload: { target: true },
8
- watch: { target: true },
7
+ upload: true,
8
+ watch: true,
9
9
  };
10
10
  export function performChecks(argv) {
11
11
  // Require "project" command when running upload/watch inside of a project
12
12
  if (isTargetedCommand(argv._, UPLOAD_AND_WATCH_COMMANDS) &&
13
13
  getIsInProject(argv.src)) {
14
- logger.error(i18n(`commands.generalErrors.srcIsProject`, {
15
- src: argv.src || './',
16
- command: argv._.join(' '),
17
- }));
14
+ uiLogger.error(commands.generalErrors.srcIsProject(argv.src || './', argv._.join(' ')));
18
15
  process.exit(EXIT_CODES.ERROR);
19
16
  }
20
17
  return true;
package/lib/npm.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { exec as execAsync } from 'node:child_process';
2
2
  import util from 'util';
3
- import { logger } from '@hubspot/local-dev-lib/logger';
3
+ import { uiLogger } from './ui/logger.js';
4
4
  import pkg from '../package.json' with { type: 'json' };
5
5
  export const DEFAULT_PACKAGE_MANAGER = 'npm';
6
6
  export async function isGloballyInstalled(packageName) {
@@ -21,7 +21,7 @@ export async function getLatestCliVersion() {
21
21
  }
22
22
  export async function executeInstall(packages = [], flags, options) {
23
23
  const installCommand = `${DEFAULT_PACKAGE_MANAGER} install${flags ? ` ${flags}` : ''} ${packages.join(' ')}`;
24
- logger.debug('Running ', installCommand);
24
+ uiLogger.debug('Running', installCommand);
25
25
  const exec = util.promisify(execAsync);
26
26
  await exec(installCommand, options);
27
27
  }
package/lib/oauth.js CHANGED
@@ -5,11 +5,11 @@ import { getAccountConfig } from '@hubspot/local-dev-lib/config';
5
5
  import { getAccountIdentifier } from '@hubspot/local-dev-lib/config/getAccountIdentifier';
6
6
  import { addOauthToAccountConfig } from '@hubspot/local-dev-lib/oauth';
7
7
  import { getHubSpotWebsiteOrigin } from '@hubspot/local-dev-lib/urls';
8
- import { logger } from '@hubspot/local-dev-lib/logger';
8
+ import { uiLogger } from './ui/logger.js';
9
9
  import { ENVIRONMENTS } from '@hubspot/local-dev-lib/constants/environments';
10
10
  import { DEFAULT_OAUTH_SCOPES } from '@hubspot/local-dev-lib/constants/auth';
11
11
  import { handleExit } from './process.js';
12
- import { i18n } from './lang.js';
12
+ import { lib } from '../lang/en.js';
13
13
  import { EXIT_CODES } from './enums/exitCodes.js';
14
14
  const PORT = 3000;
15
15
  const redirectUri = `http://localhost:${PORT}/oauth-callback`;
@@ -18,7 +18,7 @@ function buildAuthUrl(oauthManager) {
18
18
  const env = accountEnv || ENVIRONMENTS.PROD;
19
19
  const scopes = accountScopes || DEFAULT_OAUTH_SCOPES;
20
20
  if (!clientId) {
21
- logger.error(i18n(`lib.oauth.missingClientId`));
21
+ uiLogger.error(lib.oauth.missingClientId);
22
22
  process.exit(EXIT_CODES.ERROR);
23
23
  }
24
24
  return (`${getHubSpotWebsiteOrigin(env)}/oauth/${oauthManager.account.accountId}/authorize` +
@@ -77,7 +77,7 @@ async function authorize(oauthManager) {
77
77
  reject();
78
78
  }
79
79
  });
80
- server = app.listen(PORT, () => logger.log(`Waiting for authorization...`));
80
+ server = app.listen(PORT, () => uiLogger.log(`Waiting for authorization...`));
81
81
  handleServerOnProcessEnd(server);
82
82
  });
83
83
  }
@@ -91,7 +91,7 @@ function setupOauth(accountConfig) {
91
91
  }
92
92
  export async function authenticateWithOauth(accountConfig) {
93
93
  const oauthManager = setupOauth(accountConfig);
94
- logger.log('Authorizing');
94
+ uiLogger.log('Authorizing');
95
95
  await authorize(oauthManager);
96
96
  addOauthToAccountConfig(oauthManager);
97
97
  }
package/lib/process.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import readline from 'readline';
2
- import { logger, setLogLevel, LOG_LEVEL } from '@hubspot/local-dev-lib/logger';
3
- import { i18n } from './lang.js';
2
+ import { setLogLevel, LOG_LEVEL } from '@hubspot/local-dev-lib/logger';
3
+ import { uiLogger } from './ui/logger.js';
4
+ import { lib } from '../lang/en.js';
4
5
  import { logError } from './errorHandlers/index.js';
5
6
  const SIGHUP = 'SIGHUP';
6
7
  const uncaughtException = 'uncaughtException';
@@ -26,13 +27,13 @@ export function handleExit(callback) {
26
27
  if (isSIGHUP) {
27
28
  setLogLevel(LOG_LEVEL.NONE);
28
29
  }
29
- logger.debug(i18n(`lib.process.exitDebug`, { signal }));
30
+ uiLogger.debug(lib.process.exitDebug(signal));
30
31
  if (signal === uncaughtException && args && args.length > 0) {
31
32
  try {
32
33
  logError(args[0]);
33
34
  }
34
35
  catch (e) {
35
- logger.error(args[0]);
36
+ uiLogger.error(String(args[0]));
36
37
  }
37
38
  }
38
39
  await callback({ isSIGHUP });
@@ -4,4 +4,4 @@ export declare function logProfileHeader(profileName: string): void;
4
4
  export declare function logProfileFooter(profile: HsProfileFile, includeVariables?: boolean): void;
5
5
  export declare function loadProfile(projectConfig: ProjectConfig | null, projectDir: string | null, profileName: string): HsProfileFile | undefined;
6
6
  export declare function exitIfUsingProfiles(projectConfig: ProjectConfig | null, projectDir: string | null): Promise<void>;
7
- export declare function loadAndValidateProfile(projectConfig: ProjectConfig | null, projectDir: string | null, argsProfile: string | undefined, useEnv?: boolean): Promise<number | undefined>;
7
+ export declare function loadAndValidateProfile(projectConfig: ProjectConfig | null, projectDir: string | null, argsProfile: string | undefined): Promise<number | undefined>;
@@ -38,12 +38,7 @@ export function loadProfile(projectConfig, projectDir, profileName) {
38
38
  uiLogger.error(lib.projectProfiles.loadProfile.errors.missingAccountId(profileFilename));
39
39
  return;
40
40
  }
41
- return {
42
- ...profile,
43
- accountId: process.env.HUBSPOT_ACCOUNT_ID
44
- ? Number(process.env.HUBSPOT_ACCOUNT_ID)
45
- : profile.accountId,
46
- };
41
+ return profile;
47
42
  }
48
43
  catch (e) {
49
44
  uiLogger.error(lib.projectProfiles.loadProfile.errors.failedToLoadProfile(profileFilename));
@@ -59,7 +54,7 @@ export async function exitIfUsingProfiles(projectConfig, projectDir) {
59
54
  }
60
55
  }
61
56
  }
62
- export async function loadAndValidateProfile(projectConfig, projectDir, argsProfile, useEnv = false) {
57
+ export async function loadAndValidateProfile(projectConfig, projectDir, argsProfile) {
63
58
  if (argsProfile) {
64
59
  logProfileHeader(argsProfile);
65
60
  const profile = loadProfile(projectConfig, projectDir, argsProfile);
@@ -68,9 +63,6 @@ export async function loadAndValidateProfile(projectConfig, projectDir, argsProf
68
63
  process.exit(EXIT_CODES.ERROR);
69
64
  }
70
65
  logProfileFooter(profile, true);
71
- if (useEnv) {
72
- return Number(process.env.HUBSPOT_ACCOUNT_ID);
73
- }
74
66
  return profile.accountId;
75
67
  }
76
68
  else {