@hubspot/cli 7.7.35-experimental.0 → 7.8.0-beta.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 +31 -25
- package/commands/__tests__/auth.test.js +5 -0
- package/commands/__tests__/doctor.test.js +16 -16
- package/commands/__tests__/getStarted.test.js +2 -2
- package/commands/__tests__/mcp.test.js +1 -1
- package/commands/__tests__/project.test.js +0 -3
- package/commands/account/clean.js +18 -27
- package/commands/account/createOverride.js +13 -31
- package/commands/account/info.js +20 -31
- package/commands/account/list.js +16 -22
- package/commands/account/remove.js +12 -20
- package/commands/account/removeOverride.js +11 -21
- package/commands/account/rename.js +6 -9
- package/commands/account/use.js +12 -26
- package/commands/account.js +2 -2
- package/commands/app/__tests__/migrate.test.js +5 -6
- package/commands/app/migrate.js +13 -19
- package/commands/app/secret/add.js +2 -1
- package/commands/app/secret/delete.js +2 -1
- package/commands/app/secret/list.js +2 -1
- package/commands/app/secret/update.js +2 -1
- package/commands/app/secret.js +2 -1
- package/commands/app.js +2 -2
- package/commands/auth.d.ts +1 -0
- package/commands/auth.js +16 -7
- package/commands/cms/convertFields.js +7 -9
- package/commands/cms/getReactModule.js +9 -14
- package/commands/cms/lighthouseScore.js +33 -36
- package/commands/cms.js +2 -2
- package/commands/completion.js +3 -3
- package/commands/config/set.d.ts +1 -1
- package/commands/config/set.js +64 -37
- package/commands/config.js +2 -2
- package/commands/create.js +2 -2
- package/commands/customObject/create.js +10 -12
- package/commands/customObject/schema/create.js +9 -11
- package/commands/customObject/schema/delete.js +16 -16
- package/commands/customObject/schema/fetch-all.js +12 -11
- package/commands/customObject/schema/fetch.js +15 -15
- package/commands/customObject/schema/list.js +4 -4
- package/commands/customObject/schema/update.js +13 -13
- package/commands/customObject/schema.js +2 -2
- package/commands/customObject.js +6 -7
- package/commands/doctor.js +8 -11
- package/commands/feedback.js +7 -12
- package/commands/fetch.js +8 -8
- package/commands/filemanager/fetch.js +7 -7
- package/commands/filemanager/upload.js +15 -34
- package/commands/filemanager.js +2 -2
- package/commands/function/deploy.js +11 -29
- package/commands/function/list.js +8 -8
- package/commands/function/server.js +9 -11
- package/commands/function.d.ts +1 -1
- package/commands/function.js +2 -2
- package/commands/getStarted.d.ts +0 -2
- package/commands/getStarted.js +4 -4
- package/commands/hubdb/clear.js +7 -15
- package/commands/hubdb/create.js +9 -15
- package/commands/hubdb/delete.js +8 -15
- package/commands/hubdb/fetch.js +6 -9
- package/commands/hubdb.d.ts +1 -1
- package/commands/hubdb.js +2 -2
- package/commands/init.js +2 -3
- package/commands/lint.js +16 -16
- package/commands/list.js +8 -14
- package/commands/logs.js +14 -20
- package/commands/mcp/__tests__/setup.test.js +2 -2
- package/commands/mcp/setup.js +11 -2
- package/commands/mcp.js +3 -3
- package/commands/mv.js +6 -17
- package/commands/open.js +5 -5
- package/commands/project/__tests__/add.test.js +4 -2
- package/commands/project/__tests__/create.test.js +6 -6
- package/commands/project/__tests__/deploy.test.js +3 -7
- package/commands/project/__tests__/devUnifiedFlow.test.js +2 -4
- package/commands/project/__tests__/installDeps.test.js +8 -8
- package/commands/project/__tests__/logs.test.js +1 -4
- package/commands/project/__tests__/migrate.test.js +6 -7
- package/commands/project/__tests__/migrateApp.test.js +3 -7
- package/commands/project/__tests__/profile.test.js +1 -1
- package/commands/project/__tests__/validate.test.js +98 -0
- package/commands/project/add.js +4 -8
- package/commands/project/cloneApp.js +14 -19
- package/commands/project/create.js +2 -9
- package/commands/project/deploy.js +5 -5
- package/commands/project/dev/deprecatedFlow.js +7 -16
- package/commands/project/dev/index.js +16 -13
- package/commands/project/dev/unifiedFlow.js +8 -4
- package/commands/project/download.js +10 -14
- package/commands/project/installDeps.js +8 -9
- package/commands/project/listBuilds.js +12 -21
- package/commands/project/logs.js +21 -24
- package/commands/project/migrate.js +41 -13
- package/commands/project/migrateApp.js +10 -17
- package/commands/project/open.js +6 -14
- package/commands/project/profile/add.js +3 -3
- package/commands/project/profile/delete.js +1 -2
- package/commands/project/profile.js +2 -3
- package/commands/project/upload.js +16 -25
- package/commands/project/validate.js +7 -7
- package/commands/project/watch.js +13 -22
- package/commands/project.js +2 -3
- package/commands/sandbox/__tests__/create.test.js +5 -5
- package/commands/sandbox/create.js +22 -32
- package/commands/sandbox/delete.js +35 -63
- package/commands/sandbox.js +2 -2
- package/commands/secret/addSecret.js +7 -17
- package/commands/secret/deleteSecret.js +10 -20
- package/commands/secret/listSecret.js +8 -10
- package/commands/secret/updateSecret.js +9 -17
- package/commands/secret.js +2 -2
- package/commands/testAccount/__tests__/delete.test.js +2 -4
- package/commands/testAccount/delete.d.ts +4 -3
- package/commands/testAccount/delete.js +155 -14
- package/commands/testAccount/importData.d.ts +1 -1
- package/commands/testAccount/importData.js +1 -1
- package/commands/testAccount.js +1 -1
- package/lang/en.d.ts +317 -98
- package/lang/en.js +312 -96
- package/lang/en.lyaml +2 -2
- package/lib/__tests__/buildAccount.test.js +2 -1
- package/lib/__tests__/commonOpts.test.js +1 -1
- package/lib/__tests__/dependencyManagement.test.js +1 -1
- package/lib/__tests__/developerTestAccounts.test.js +3 -3
- package/lib/__tests__/npm.test.js +1 -1
- package/lib/__tests__/oauth.test.js +4 -4
- package/lib/__tests__/process.test.js +10 -5
- package/lib/__tests__/sandboxSync.test.js +8 -8
- package/lib/__tests__/sandboxes.test.js +8 -8
- package/lib/__tests__/serverlessLogs.test.js +1 -1
- package/lib/__tests__/usageTracking.test.js +5 -5
- package/lib/__tests__/validation.test.js +2 -1
- package/lib/__tests__/yargsUtils.test.js +83 -9
- package/lib/app/__tests__/migrate.test.js +19 -56
- package/lib/app/__tests__/migrate_legacy.test.js +1 -1
- package/lib/app/migrate.d.ts +2 -8
- package/lib/app/migrate.js +5 -80
- package/lib/app/migrate_legacy.js +20 -24
- package/lib/buildAccount.js +25 -57
- package/lib/commonOpts.d.ts +1 -1
- package/lib/commonOpts.js +25 -22
- package/lib/configOptions.js +7 -0
- package/lib/constants.d.ts +13 -0
- package/lib/constants.js +17 -0
- package/lib/dependencyManagement.js +9 -27
- package/lib/developerTestAccounts.js +9 -23
- package/lib/doctor/Diagnosis.js +11 -23
- package/lib/doctor/DiagnosticInfoBuilder.js +12 -11
- package/lib/doctor/Doctor.js +42 -90
- package/lib/doctor/__tests__/Doctor.test.js +4 -4
- package/lib/errorHandlers/index.js +12 -20
- package/lib/errorHandlers/suppressError.js +10 -17
- package/lib/lang.js +6 -5
- package/lib/links.d.ts +1 -0
- package/lib/links.js +14 -7
- package/lib/mcp/setup.js +1 -1
- package/lib/middleware/__test__/commandTargetingUtils.test.d.ts +1 -0
- package/lib/middleware/__test__/commandTargetingUtils.test.js +99 -0
- package/lib/middleware/__test__/configMiddleware.test.js +11 -11
- package/lib/middleware/__test__/yargsChecksMiddleware.test.js +6 -8
- package/lib/middleware/commandTargetingUtils.d.ts +8 -0
- package/lib/middleware/commandTargetingUtils.js +78 -0
- package/lib/middleware/configMiddleware.d.ts +1 -1
- package/lib/middleware/configMiddleware.js +21 -81
- package/lib/middleware/fireAlarmMiddleware.js +15 -5
- package/lib/middleware/gitMiddleware.js +5 -1
- package/lib/middleware/notificationsMiddleware.js +5 -11
- package/lib/middleware/yargsChecksMiddleware.js +6 -9
- package/lib/npm.js +2 -2
- package/lib/oauth.js +5 -5
- package/lib/process.js +5 -4
- package/lib/projects/__tests__/AppDevModeInterface.test.js +2 -0
- package/lib/projects/__tests__/LocalDevProcess.test.js +227 -16
- package/lib/projects/__tests__/LocalDevWebsocketServer.test.js +86 -60
- package/lib/projects/__tests__/deploy.test.js +71 -6
- package/lib/projects/__tests__/localDevProjectHelpers.test.js +6 -2
- package/lib/projects/__tests__/platformVersion.test.js +8 -8
- package/lib/projects/__tests__/projects.test.js +12 -12
- package/lib/projects/__tests__/structure.test.js +3 -3
- package/lib/projects/__tests__/upload.test.d.ts +1 -0
- package/lib/projects/__tests__/upload.test.js +82 -0
- package/lib/projects/add/__tests__/legacyAddComponent.test.js +6 -6
- package/lib/projects/add/__tests__/v3AddComponent.test.js +4 -4
- package/lib/projects/create/__tests__/legacy.test.js +5 -5
- package/lib/projects/create/__tests__/v3.test.js +80 -5
- package/lib/projects/create/index.js +2 -2
- package/lib/projects/create/legacy.js +2 -2
- package/lib/projects/create/v3.js +10 -8
- package/lib/projects/localDev/AppDevModeInterface.d.ts +2 -0
- package/lib/projects/localDev/AppDevModeInterface.js +21 -12
- package/lib/projects/localDev/LocalDevLogger.d.ts +4 -0
- package/lib/projects/localDev/LocalDevLogger.js +27 -6
- package/lib/projects/localDev/LocalDevManager.js +4 -5
- package/lib/projects/localDev/LocalDevProcess.d.ts +7 -5
- package/lib/projects/localDev/LocalDevProcess.js +90 -19
- package/lib/projects/localDev/LocalDevState.d.ts +9 -8
- package/lib/projects/localDev/LocalDevState.js +18 -17
- package/lib/projects/localDev/LocalDevWebsocketServer.d.ts +2 -1
- package/lib/projects/localDev/LocalDevWebsocketServer.js +62 -33
- package/lib/projects/localDev/helpers/project.d.ts +1 -0
- package/lib/projects/localDev/helpers/project.js +42 -1
- package/lib/projects/localDev/localDevWebsocketServerUtils.d.ts +4 -0
- package/lib/projects/localDev/localDevWebsocketServerUtils.js +10 -0
- package/lib/projects/platformVersion.d.ts +1 -1
- package/lib/projects/platformVersion.js +1 -1
- package/lib/projects/pollProjectBuildAndDeploy.js +4 -4
- package/lib/projects/structure.js +6 -6
- package/lib/projects/upload.d.ts +1 -1
- package/lib/projects/upload.js +17 -8
- package/lib/prompts/accountNamePrompt.js +14 -19
- package/lib/prompts/accountsPrompt.js +2 -2
- package/lib/prompts/cmsFieldPrompt.js +2 -2
- package/lib/prompts/createApiSamplePrompt.js +5 -5
- package/lib/prompts/createDeveloperTestAccountConfigPrompt.js +10 -1
- package/lib/prompts/createFunctionPrompt.js +14 -14
- package/lib/prompts/createModulePrompt.js +9 -9
- package/lib/prompts/createTemplatePrompt.js +2 -2
- package/lib/prompts/downloadProjectPrompt.js +5 -8
- package/lib/prompts/personalAccessKeyPrompt.js +3 -3
- package/lib/prompts/previewPrompt.js +6 -6
- package/lib/prompts/projectAddPrompt.js +8 -1
- package/lib/prompts/projectDevTargetAccountPrompt.js +20 -32
- package/lib/prompts/projectNamePrompt.js +4 -8
- package/lib/prompts/projectsLogsPrompt.js +2 -4
- package/lib/prompts/promptUtils.js +30 -9
- package/lib/prompts/sandboxesPrompt.js +7 -7
- package/lib/prompts/secretPrompt.js +3 -3
- package/lib/prompts/selectAppPrompt.js +3 -3
- package/lib/prompts/selectHubDBTablePrompt.js +9 -13
- package/lib/prompts/selectProjectTemplatePrompt.js +2 -0
- package/lib/prompts/selectPublicAppForMigrationPrompt.js +15 -19
- package/lib/prompts/setAsDefaultAccountPrompt.js +4 -8
- package/lib/prompts/uploadPrompt.js +5 -5
- package/lib/sandboxSync.js +24 -41
- package/lib/sandboxes.js +19 -47
- package/lib/schema.js +3 -3
- package/lib/serverlessLogs.js +11 -13
- package/lib/theme/__tests__/migrate.test.d.ts +1 -0
- package/lib/theme/__tests__/migrate.test.js +233 -0
- package/lib/theme/migrate.d.ts +13 -0
- package/lib/theme/migrate.js +90 -0
- package/lib/ui/SpinniesManager.d.ts +2 -0
- package/lib/ui/SpinniesManager.js +7 -0
- package/lib/ui/boxen.js +1 -2
- package/lib/ui/git.js +13 -10
- package/lib/ui/index.js +38 -37
- package/lib/ui/serverlessFunctionLogs.js +9 -7
- package/lib/ui/uiMessages.d.ts +68 -0
- package/lib/ui/uiMessages.js +71 -0
- package/lib/usageTracking.js +8 -8
- package/lib/validation.js +20 -23
- package/lib/yargsUtils.d.ts +1 -1
- package/lib/yargsUtils.js +12 -5
- package/mcp-server/tools/cms/HsCreateModuleTool.d.ts +2 -2
- package/mcp-server/tools/index.js +4 -0
- package/mcp-server/tools/project/AddFeatureToProjectTool.d.ts +2 -2
- package/mcp-server/tools/project/CreateProjectTool.d.ts +2 -2
- package/mcp-server/tools/project/DocsSearchTool.d.ts +4 -1
- package/mcp-server/tools/project/DocsSearchTool.js +5 -5
- package/mcp-server/tools/project/GetApiUsagePatternsByAppIdTool.d.ts +23 -0
- package/mcp-server/tools/project/GetApiUsagePatternsByAppIdTool.js +68 -0
- package/mcp-server/tools/project/GetApplicationInfoTool.d.ts +11 -0
- package/mcp-server/tools/project/GetApplicationInfoTool.js +49 -0
- package/mcp-server/tools/project/GetConfigValuesTool.d.ts +4 -1
- package/mcp-server/tools/project/GetConfigValuesTool.js +12 -6
- package/mcp-server/tools/project/GuidedWalkthroughTool.d.ts +2 -2
- package/mcp-server/tools/project/__tests__/DocsSearchTool.test.js +12 -10
- package/mcp-server/tools/project/__tests__/GetApiUsagePatternsByAppIdTool.test.d.ts +1 -0
- package/mcp-server/tools/project/__tests__/GetApiUsagePatternsByAppIdTool.test.js +169 -0
- package/mcp-server/tools/project/__tests__/GetApplicationInfoTool.test.d.ts +1 -0
- package/mcp-server/tools/project/__tests__/GetApplicationInfoTool.test.js +115 -0
- package/mcp-server/tools/project/__tests__/GetConfigValuesTool.test.js +8 -7
- package/mcp-server/utils/__tests__/cliConfig.test.d.ts +1 -0
- package/mcp-server/utils/__tests__/cliConfig.test.js +110 -0
- package/mcp-server/utils/cliConfig.d.ts +1 -0
- package/mcp-server/utils/cliConfig.js +12 -0
- package/mcp-server/utils/toolUsageTracking.js +2 -2
- package/package.json +4 -4
- package/types/LocalDev.d.ts +19 -3
- package/ui/index.js +1 -1
- package/lib/middleware/__test__/utils.test.js +0 -51
- package/lib/middleware/utils.d.ts +0 -8
- package/lib/middleware/utils.js +0 -14
- /package/{lib/middleware/__test__/utils.test.d.ts → commands/project/__tests__/validate.test.d.ts} +0 -0
|
@@ -126,9 +126,9 @@ describe('lib/projects/deploy', () => {
|
|
|
126
126
|
data: mockDeployResponseData,
|
|
127
127
|
});
|
|
128
128
|
mockPollDeployStatus.mockResolvedValue(mockDeployResult);
|
|
129
|
-
const
|
|
129
|
+
const deploy = await handleProjectDeploy(targetAccountId, projectName, buildId, useV3Api, force);
|
|
130
130
|
expect(mockDeployProject).toHaveBeenCalledWith(targetAccountId, projectName, buildId, useV3Api, force);
|
|
131
|
-
expect(
|
|
131
|
+
expect(deploy).toEqual(mockDeployResult);
|
|
132
132
|
});
|
|
133
133
|
it('handles blocked deploy with warnings', async () => {
|
|
134
134
|
const mockBlockedResponse = {
|
|
@@ -150,15 +150,80 @@ describe('lib/projects/deploy', () => {
|
|
|
150
150
|
mockDeployProject.mockResolvedValue({
|
|
151
151
|
data: mockBlockedResponse,
|
|
152
152
|
});
|
|
153
|
-
|
|
153
|
+
await handleProjectDeploy(targetAccountId, projectName, buildId, useV3Api, force);
|
|
154
154
|
expect(mockUiLogger.warn).toHaveBeenCalledWith(commands.project.deploy.errors.deployWarningsHeader);
|
|
155
|
-
|
|
155
|
+
});
|
|
156
|
+
it('handles blocked deploy with errors (cannot be forced)', async () => {
|
|
157
|
+
const mockBlockedResponse = {
|
|
158
|
+
buildResultType: 'DEPLOY_BLOCKED',
|
|
159
|
+
issues: [
|
|
160
|
+
{
|
|
161
|
+
uid: 'component-1',
|
|
162
|
+
componentTypeName: 'module',
|
|
163
|
+
errorMessages: [],
|
|
164
|
+
blockingMessages: [
|
|
165
|
+
{
|
|
166
|
+
message: 'This is an error',
|
|
167
|
+
isWarning: false,
|
|
168
|
+
},
|
|
169
|
+
],
|
|
170
|
+
},
|
|
171
|
+
],
|
|
172
|
+
};
|
|
173
|
+
mockDeployProject.mockResolvedValue({
|
|
174
|
+
data: mockBlockedResponse,
|
|
175
|
+
});
|
|
176
|
+
await handleProjectDeploy(targetAccountId, projectName, buildId, useV3Api, force);
|
|
177
|
+
expect(mockUiLogger.error).toHaveBeenCalledWith(commands.project.deploy.errors.deployBlockedHeader);
|
|
178
|
+
expect(mockUiLogger.log).toHaveBeenCalledWith(commands.project.deploy.errors.deployIssueComponentWarning('component-1', 'module', 'This is an error'));
|
|
179
|
+
});
|
|
180
|
+
it('handles blocked deploy with no blocking messages', async () => {
|
|
181
|
+
const mockBlockedResponse = {
|
|
182
|
+
buildResultType: 'DEPLOY_BLOCKED',
|
|
183
|
+
issues: [
|
|
184
|
+
{
|
|
185
|
+
uid: 'component-1',
|
|
186
|
+
componentTypeName: 'module',
|
|
187
|
+
errorMessages: [],
|
|
188
|
+
blockingMessages: [],
|
|
189
|
+
},
|
|
190
|
+
],
|
|
191
|
+
};
|
|
192
|
+
mockDeployProject.mockResolvedValue({
|
|
193
|
+
data: mockBlockedResponse,
|
|
194
|
+
});
|
|
195
|
+
await handleProjectDeploy(targetAccountId, projectName, buildId, useV3Api, force);
|
|
196
|
+
expect(mockUiLogger.warn).toHaveBeenCalledWith(commands.project.deploy.errors.deployWarningsHeader);
|
|
197
|
+
expect(mockUiLogger.log).toHaveBeenCalledWith(commands.project.deploy.errors.deployIssueComponentGeneric('component-1', 'module'));
|
|
156
198
|
});
|
|
157
199
|
it('handles general deploy failure', async () => {
|
|
158
200
|
mockDeployProject.mockResolvedValue({ data: null });
|
|
159
|
-
const
|
|
201
|
+
const deploy = await handleProjectDeploy(targetAccountId, projectName, buildId, useV3Api, force);
|
|
202
|
+
expect(mockUiLogger.error).toHaveBeenCalledWith(commands.project.deploy.errors.deploy);
|
|
203
|
+
expect(deploy).toBeUndefined();
|
|
204
|
+
});
|
|
205
|
+
it('handles undefined deploy response', async () => {
|
|
206
|
+
mockDeployProject.mockResolvedValue({ data: undefined });
|
|
207
|
+
const deploy = await handleProjectDeploy(targetAccountId, projectName, buildId, useV3Api, force);
|
|
160
208
|
expect(mockUiLogger.error).toHaveBeenCalledWith(commands.project.deploy.errors.deploy);
|
|
161
|
-
expect(
|
|
209
|
+
expect(deploy).toBeUndefined();
|
|
210
|
+
});
|
|
211
|
+
it('passes correct parameters to deployProject', async () => {
|
|
212
|
+
const mockDeployResponseData = {
|
|
213
|
+
id: 'deploy-123',
|
|
214
|
+
buildResultType: 'DEPLOY_QUEUED',
|
|
215
|
+
links: {
|
|
216
|
+
status: 'http://status-url',
|
|
217
|
+
},
|
|
218
|
+
};
|
|
219
|
+
mockDeployProject.mockResolvedValue({
|
|
220
|
+
data: mockDeployResponseData,
|
|
221
|
+
});
|
|
222
|
+
mockPollDeployStatus.mockResolvedValue({});
|
|
223
|
+
await handleProjectDeploy(targetAccountId, projectName, buildId, false, true);
|
|
224
|
+
expect(mockDeployProject).toHaveBeenCalledWith(targetAccountId, projectName, buildId, false, // useV3Api
|
|
225
|
+
true // force
|
|
226
|
+
);
|
|
162
227
|
});
|
|
163
228
|
});
|
|
164
229
|
});
|
|
@@ -30,6 +30,8 @@ describe('isDeployedProjectUpToDateWithLocal', () => {
|
|
|
30
30
|
componentRoot: '/local/path',
|
|
31
31
|
componentConfigPath: '/local/path/config.json',
|
|
32
32
|
configUpdatedSinceLastUpload: false,
|
|
33
|
+
removed: false,
|
|
34
|
+
parsingErrors: [],
|
|
33
35
|
},
|
|
34
36
|
componentDeps: {},
|
|
35
37
|
metaFilePath: '/local/path',
|
|
@@ -99,7 +101,8 @@ describe('isDeployedProjectUpToDateWithLocal', () => {
|
|
|
99
101
|
it('should clean up temp directory even when errors occur', async () => {
|
|
100
102
|
// Mock downloadProject to throw an error after temp dir is created
|
|
101
103
|
downloadProject.mockRejectedValue(new Error('Download Error'));
|
|
102
|
-
await
|
|
104
|
+
const result = await isDeployedProjectUpToDateWithLocal(mockProjectConfig, mockAccountId, mockBuildId, mockLocalProjectNodes);
|
|
105
|
+
expect(result).toBe(false);
|
|
103
106
|
expect(fs.remove).toHaveBeenCalledWith(mockTempDir);
|
|
104
107
|
});
|
|
105
108
|
it('should handle translateForLocalDev errors', async () => {
|
|
@@ -111,7 +114,8 @@ describe('isDeployedProjectUpToDateWithLocal', () => {
|
|
|
111
114
|
extractZipArchive.mockResolvedValue(undefined);
|
|
112
115
|
// Mock translate to throw an error
|
|
113
116
|
translate.mockRejectedValue(new Error('Translation Error'));
|
|
114
|
-
await
|
|
117
|
+
const result = await isDeployedProjectUpToDateWithLocal(mockProjectConfig, mockAccountId, mockBuildId, mockLocalProjectNodes);
|
|
118
|
+
expect(result).toBe(false);
|
|
115
119
|
expect(fs.remove).toHaveBeenCalledWith(mockTempDir);
|
|
116
120
|
});
|
|
117
121
|
});
|
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { isV2Project } from '../platformVersion.js';
|
|
2
2
|
describe('platformVersion', () => {
|
|
3
|
-
describe('
|
|
3
|
+
describe('isV2Project', () => {
|
|
4
4
|
it('returns true if platform version is UNSTABLE', () => {
|
|
5
|
-
expect(
|
|
5
|
+
expect(isV2Project('UNSTABLE')).toBe(true);
|
|
6
6
|
});
|
|
7
7
|
it('returns true if platform version is equal to the minimum', () => {
|
|
8
|
-
expect(
|
|
8
|
+
expect(isV2Project('2025.2')).toBe(true);
|
|
9
9
|
});
|
|
10
10
|
it('returns true if platform version is greater than the minimum', () => {
|
|
11
|
-
expect(
|
|
11
|
+
expect(isV2Project('2026.2')).toBe(true);
|
|
12
12
|
});
|
|
13
13
|
it('returns false if platform version is less than the minimum', () => {
|
|
14
|
-
expect(
|
|
14
|
+
expect(isV2Project('2025.0')).toBe(false);
|
|
15
15
|
});
|
|
16
16
|
it('returns false if platform version is invalid', () => {
|
|
17
|
-
expect(
|
|
17
|
+
expect(isV2Project(null)).toBe(false);
|
|
18
18
|
});
|
|
19
19
|
it('returns false for an invalid platform version', () => {
|
|
20
|
-
expect(
|
|
20
|
+
expect(isV2Project('notplaformversion')).toBe(false);
|
|
21
21
|
});
|
|
22
22
|
});
|
|
23
23
|
});
|
|
@@ -3,8 +3,8 @@ import os from 'os';
|
|
|
3
3
|
import path from 'path';
|
|
4
4
|
import { EXIT_CODES } from '../../enums/exitCodes.js';
|
|
5
5
|
import { validateProjectConfig } from '../../projects/config.js';
|
|
6
|
-
import {
|
|
7
|
-
vi.mock('
|
|
6
|
+
import { uiLogger } from '../../ui/logger.js';
|
|
7
|
+
vi.mock('../../ui/logger.js');
|
|
8
8
|
describe('lib/projects', () => {
|
|
9
9
|
describe('validateProjectConfig()', () => {
|
|
10
10
|
let projectDir;
|
|
@@ -26,58 +26,58 @@ describe('lib/projects', () => {
|
|
|
26
26
|
// @ts-ignore Testing invalid input
|
|
27
27
|
validateProjectConfig(null, projectDir);
|
|
28
28
|
expect(exitMock).toHaveBeenCalledWith(EXIT_CODES.ERROR);
|
|
29
|
-
expect(
|
|
29
|
+
expect(uiLogger.error).toHaveBeenCalledWith(expect.stringMatching(/.*Unable to locate a project configuration file. Try running again from a project directory, or run*/));
|
|
30
30
|
});
|
|
31
31
|
it('rejects configuration with missing name', () => {
|
|
32
32
|
// @ts-ignore Testing invalid input
|
|
33
33
|
validateProjectConfig({ srcDir: '.' }, projectDir);
|
|
34
34
|
expect(exitMock).toHaveBeenCalledWith(EXIT_CODES.ERROR);
|
|
35
|
-
expect(
|
|
35
|
+
expect(uiLogger.error).toHaveBeenCalledWith(expect.stringMatching(/.*missing required fields*/));
|
|
36
36
|
});
|
|
37
37
|
it('rejects configuration with missing srcDir', () => {
|
|
38
38
|
// @ts-ignore Testing invalid input
|
|
39
39
|
validateProjectConfig({ name: 'hello' }, projectDir);
|
|
40
40
|
expect(exitMock).toHaveBeenCalledWith(EXIT_CODES.ERROR);
|
|
41
|
-
expect(
|
|
41
|
+
expect(uiLogger.error).toHaveBeenCalledWith(expect.stringMatching(/.*missing required fields.*/));
|
|
42
42
|
});
|
|
43
43
|
describe('rejects configuration with srcDir outside project directory', () => {
|
|
44
44
|
it('for parent directory', () => {
|
|
45
45
|
validateProjectConfig({ name: 'hello', srcDir: '..', platformVersion: '' }, projectDir);
|
|
46
46
|
expect(exitMock).toHaveBeenCalledWith(EXIT_CODES.ERROR);
|
|
47
|
-
expect(
|
|
47
|
+
expect(uiLogger.error).toHaveBeenCalledWith(expect.stringContaining('srcDir: ".."'));
|
|
48
48
|
});
|
|
49
49
|
it('for root directory', () => {
|
|
50
50
|
validateProjectConfig({ name: 'hello', srcDir: '/', platformVersion: '' }, projectDir);
|
|
51
51
|
expect(exitMock).toHaveBeenCalledWith(EXIT_CODES.ERROR);
|
|
52
|
-
expect(
|
|
52
|
+
expect(uiLogger.error).toHaveBeenCalledWith(expect.stringContaining('srcDir: "/"'));
|
|
53
53
|
});
|
|
54
54
|
it('for complicated directory', () => {
|
|
55
55
|
const srcDir = './src/././../src/../../src';
|
|
56
56
|
validateProjectConfig({ name: 'hello', srcDir, platformVersion: '' }, projectDir);
|
|
57
57
|
expect(exitMock).toHaveBeenCalledWith(EXIT_CODES.ERROR);
|
|
58
|
-
expect(
|
|
58
|
+
expect(uiLogger.error).toHaveBeenCalledWith(expect.stringContaining(`srcDir: "${srcDir}"`));
|
|
59
59
|
});
|
|
60
60
|
});
|
|
61
61
|
it('rejects configuration with srcDir that does not exist', () => {
|
|
62
62
|
validateProjectConfig({ name: 'hello', srcDir: 'foo', platformVersion: '' }, projectDir);
|
|
63
63
|
expect(exitMock).toHaveBeenCalledWith(EXIT_CODES.ERROR);
|
|
64
|
-
expect(
|
|
64
|
+
expect(uiLogger.error).toHaveBeenCalledWith(expect.stringMatching(/.*could not be found in.*/));
|
|
65
65
|
});
|
|
66
66
|
describe('accepts configuration with valid srcDir', () => {
|
|
67
67
|
it('for current directory', () => {
|
|
68
68
|
validateProjectConfig({ name: 'hello', srcDir: '.', platformVersion: '' }, projectDir);
|
|
69
69
|
expect(exitMock).not.toHaveBeenCalled();
|
|
70
|
-
expect(
|
|
70
|
+
expect(uiLogger.error).not.toHaveBeenCalled();
|
|
71
71
|
});
|
|
72
72
|
it('for relative directory', () => {
|
|
73
73
|
validateProjectConfig({ name: 'hello', srcDir: './src', platformVersion: '' }, projectDir);
|
|
74
74
|
expect(exitMock).not.toHaveBeenCalled();
|
|
75
|
-
expect(
|
|
75
|
+
expect(uiLogger.error).not.toHaveBeenCalled();
|
|
76
76
|
});
|
|
77
77
|
it('for implied relative directory', () => {
|
|
78
78
|
validateProjectConfig({ name: 'hello', srcDir: 'src', platformVersion: '' }, projectDir);
|
|
79
79
|
expect(exitMock).not.toHaveBeenCalled();
|
|
80
|
-
expect(
|
|
80
|
+
expect(uiLogger.error).not.toHaveBeenCalled();
|
|
81
81
|
});
|
|
82
82
|
});
|
|
83
83
|
});
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import fs from 'fs';
|
|
2
2
|
import * as HSfs from '@hubspot/local-dev-lib/fs';
|
|
3
|
-
import {
|
|
3
|
+
import { uiLogger } from '../../ui/logger.js';
|
|
4
4
|
import { getComponentTypeFromConfigFile, loadConfigFile, getAppCardConfigs, getIsLegacyApp, componentIsApp, findProjectComponents, getProjectComponentTypes, getComponentUid, componentIsPublicApp, } from '../structure.js';
|
|
5
5
|
import { ComponentTypes } from '../../../types/Projects.js';
|
|
6
6
|
vi.mock('fs');
|
|
7
7
|
vi.mock('@hubspot/local-dev-lib/fs');
|
|
8
|
-
vi.mock('
|
|
8
|
+
vi.mock('../../ui/logger.js');
|
|
9
9
|
const mockedReadFileSync = fs.readFileSync;
|
|
10
10
|
const mockedWalk = HSfs.walk;
|
|
11
11
|
const getMockPrivateAppConfig = (cards = []) => ({
|
|
@@ -46,7 +46,7 @@ describe('lib/projects/structure', () => {
|
|
|
46
46
|
throw new Error('File not found');
|
|
47
47
|
});
|
|
48
48
|
expect(loadConfigFile('nonexistent/path/app.json')).toBeNull();
|
|
49
|
-
expect(
|
|
49
|
+
expect(uiLogger.debug).toHaveBeenCalled();
|
|
50
50
|
});
|
|
51
51
|
});
|
|
52
52
|
describe('getAppCardConfigs()', () => {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import fs from 'fs-extra';
|
|
2
|
+
import os from 'os';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import { vi } from 'vitest';
|
|
5
|
+
import { validateSourceDirectory } from '../upload.js';
|
|
6
|
+
import { uiLogger } from '../../ui/logger.js';
|
|
7
|
+
import { lib } from '../../../lang/en.js';
|
|
8
|
+
import { isV2Project } from '../platformVersion.js';
|
|
9
|
+
import ProjectValidationError from '../../errors/ProjectValidationError.js';
|
|
10
|
+
import { walk } from '@hubspot/local-dev-lib/fs';
|
|
11
|
+
// Mock dependencies
|
|
12
|
+
vi.mock('../../ui/logger.js');
|
|
13
|
+
vi.mock('../platformVersion.js');
|
|
14
|
+
vi.mock('@hubspot/local-dev-lib/fs');
|
|
15
|
+
describe('lib/projects/upload', () => {
|
|
16
|
+
describe('validateSourceDirectory', () => {
|
|
17
|
+
let tempDir;
|
|
18
|
+
let srcDir;
|
|
19
|
+
let projectConfig;
|
|
20
|
+
beforeEach(() => {
|
|
21
|
+
tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'upload-test-'));
|
|
22
|
+
srcDir = path.join(tempDir, 'src');
|
|
23
|
+
fs.mkdirSync(srcDir, { recursive: true });
|
|
24
|
+
projectConfig = {
|
|
25
|
+
name: 'test-project',
|
|
26
|
+
srcDir: 'src',
|
|
27
|
+
platformVersion: '2025.2',
|
|
28
|
+
};
|
|
29
|
+
vi.clearAllMocks();
|
|
30
|
+
});
|
|
31
|
+
afterEach(() => {
|
|
32
|
+
fs.removeSync(tempDir);
|
|
33
|
+
});
|
|
34
|
+
it('should throw ProjectValidationError when source directory is empty', async () => {
|
|
35
|
+
vi.mocked(walk).mockResolvedValue([]);
|
|
36
|
+
await expect(validateSourceDirectory(srcDir, projectConfig, tempDir)).rejects.toThrow(ProjectValidationError);
|
|
37
|
+
expect(walk).toHaveBeenCalledWith(srcDir, ['node_modules']);
|
|
38
|
+
});
|
|
39
|
+
it('should warn about legacy files in V3 projects', async () => {
|
|
40
|
+
vi.mocked(isV2Project).mockReturnValue(true);
|
|
41
|
+
const legacyFilePath = path.join(srcDir, 'app', 'serverless.json');
|
|
42
|
+
vi.mocked(walk).mockResolvedValue([legacyFilePath]);
|
|
43
|
+
await validateSourceDirectory(srcDir, projectConfig, tempDir);
|
|
44
|
+
expect(uiLogger.warn).toHaveBeenCalledWith(lib.projectUpload.handleProjectUpload.legacyFileDetected('src/app/serverless.json', '2025.2'));
|
|
45
|
+
});
|
|
46
|
+
it('should warn about multiple legacy files', async () => {
|
|
47
|
+
vi.mocked(isV2Project).mockReturnValue(true);
|
|
48
|
+
const filePaths = [
|
|
49
|
+
path.join(srcDir, 'app1', 'serverless.json'),
|
|
50
|
+
path.join(srcDir, 'app2', 'app.json'),
|
|
51
|
+
path.join(srcDir, 'app3', 'public-app.json'),
|
|
52
|
+
];
|
|
53
|
+
vi.mocked(walk).mockResolvedValue(filePaths);
|
|
54
|
+
await validateSourceDirectory(srcDir, projectConfig, tempDir);
|
|
55
|
+
expect(uiLogger.warn).toHaveBeenCalledTimes(3);
|
|
56
|
+
expect(uiLogger.warn).toHaveBeenCalledWith(lib.projectUpload.handleProjectUpload.legacyFileDetected('src/app1/serverless.json', '2025.2'));
|
|
57
|
+
expect(uiLogger.warn).toHaveBeenCalledWith(lib.projectUpload.handleProjectUpload.legacyFileDetected('src/app2/app.json', '2025.2'));
|
|
58
|
+
expect(uiLogger.warn).toHaveBeenCalledWith(lib.projectUpload.handleProjectUpload.legacyFileDetected('src/app3/public-app.json', '2025.2'));
|
|
59
|
+
});
|
|
60
|
+
it('should not warn about non-legacy files', async () => {
|
|
61
|
+
vi.mocked(isV2Project).mockReturnValue(true);
|
|
62
|
+
const filePaths = [
|
|
63
|
+
path.join(srcDir, 'component.js'),
|
|
64
|
+
path.join(srcDir, 'config.json'),
|
|
65
|
+
];
|
|
66
|
+
vi.mocked(walk).mockResolvedValue(filePaths);
|
|
67
|
+
await validateSourceDirectory(srcDir, projectConfig, tempDir);
|
|
68
|
+
expect(uiLogger.warn).not.toHaveBeenCalled();
|
|
69
|
+
});
|
|
70
|
+
it('should not warn about legacy files in non-V3 projects', async () => {
|
|
71
|
+
vi.mocked(isV2Project).mockReturnValue(false);
|
|
72
|
+
projectConfig.platformVersion = '2025.1';
|
|
73
|
+
const filePaths = [
|
|
74
|
+
path.join(srcDir, 'app', 'serverless.json'),
|
|
75
|
+
path.join(srcDir, 'app', 'app.json'),
|
|
76
|
+
];
|
|
77
|
+
vi.mocked(walk).mockResolvedValue(filePaths);
|
|
78
|
+
await validateSourceDirectory(srcDir, projectConfig, tempDir);
|
|
79
|
+
expect(uiLogger.warn).not.toHaveBeenCalled();
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
});
|
|
@@ -2,7 +2,7 @@ import { legacyAddComponent } from '../legacyAddComponent.js';
|
|
|
2
2
|
import { findProjectComponents } from '../../structure.js';
|
|
3
3
|
import { getProjectComponentListFromRepo } from '../../create/legacy.js';
|
|
4
4
|
import { projectAddPrompt } from '../../../prompts/projectAddPrompt.js';
|
|
5
|
-
import {
|
|
5
|
+
import { uiLogger } from '../../../ui/logger.js';
|
|
6
6
|
import { cloneGithubRepo } from '@hubspot/local-dev-lib/github';
|
|
7
7
|
import { trackCommandUsage } from '../../../usageTracking.js';
|
|
8
8
|
import { ComponentTypes, } from '../../../../types/Projects.js';
|
|
@@ -10,13 +10,13 @@ import { commands } from '../../../../lang/en.js';
|
|
|
10
10
|
vi.mock('../../structure');
|
|
11
11
|
vi.mock('../../create/legacy');
|
|
12
12
|
vi.mock('../../../prompts/projectAddPrompt');
|
|
13
|
-
vi.mock('
|
|
13
|
+
vi.mock('../../../ui/logger.js');
|
|
14
14
|
vi.mock('@hubspot/local-dev-lib/github');
|
|
15
15
|
vi.mock('../../../usageTracking.js');
|
|
16
16
|
const mockedFindProjectComponents = vi.mocked(findProjectComponents);
|
|
17
17
|
const mockedGetProjectComponentListFromRepo = vi.mocked(getProjectComponentListFromRepo);
|
|
18
18
|
const mockedProjectAddPrompt = vi.mocked(projectAddPrompt);
|
|
19
|
-
const
|
|
19
|
+
const mockedUiLogger = vi.mocked(uiLogger);
|
|
20
20
|
const mockedCloneGithubRepo = vi.mocked(cloneGithubRepo);
|
|
21
21
|
const mockedTrackCommandUsage = vi.mocked(trackCommandUsage);
|
|
22
22
|
describe('lib/projects/add/legacyAddComponent', () => {
|
|
@@ -75,8 +75,8 @@ describe('lib/projects/add/legacyAddComponent', () => {
|
|
|
75
75
|
expect(mockedTrackCommandUsage).toHaveBeenCalledWith('project-add', {
|
|
76
76
|
type: 'module',
|
|
77
77
|
}, accountId);
|
|
78
|
-
expect(
|
|
79
|
-
expect(
|
|
78
|
+
expect(mockedUiLogger.log).toHaveBeenCalledWith(commands.project.add.creatingComponent('test-project'));
|
|
79
|
+
expect(mockedUiLogger.success).toHaveBeenCalledWith(commands.project.add.success('new-component'));
|
|
80
80
|
});
|
|
81
81
|
it('throws an error when project contains a public app', async () => {
|
|
82
82
|
const mockComponents = [
|
|
@@ -206,7 +206,7 @@ describe('lib/projects/add/legacyAddComponent', () => {
|
|
|
206
206
|
mockedCloneGithubRepo.mockRejectedValue(new Error('Clone failed'));
|
|
207
207
|
await expect(legacyAddComponent(mockArgs, projectDir, mockProjectConfig, accountId)).rejects.toThrow(commands.project.add.error.failedToDownloadComponent);
|
|
208
208
|
expect(mockedCloneGithubRepo).toHaveBeenCalled();
|
|
209
|
-
expect(
|
|
209
|
+
expect(mockedUiLogger.success).not.toHaveBeenCalled();
|
|
210
210
|
});
|
|
211
211
|
it('calls trackCommandUsage with correct component type', async () => {
|
|
212
212
|
const mockComponents = [
|
|
@@ -5,7 +5,7 @@ import { createV3App } from '../../create/v3.js';
|
|
|
5
5
|
import { confirmPrompt } from '../../../prompts/promptUtils.js';
|
|
6
6
|
import { projectAddPromptV3 } from '../../../prompts/projectAddPrompt.js';
|
|
7
7
|
import { cloneGithubRepo } from '@hubspot/local-dev-lib/github';
|
|
8
|
-
import {
|
|
8
|
+
import { uiLogger } from '../../../ui/logger.js';
|
|
9
9
|
import { getProjectMetadata } from '@hubspot/project-parsing-lib/src/lib/project.js';
|
|
10
10
|
import { trackCommandUsage } from '../../../usageTracking.js';
|
|
11
11
|
import { commands } from '../../../../lang/en.js';
|
|
@@ -15,7 +15,7 @@ vi.mock('../../create/legacy');
|
|
|
15
15
|
vi.mock('../../create/v3');
|
|
16
16
|
vi.mock('../../../prompts/projectAddPrompt');
|
|
17
17
|
vi.mock('@hubspot/local-dev-lib/github');
|
|
18
|
-
vi.mock('
|
|
18
|
+
vi.mock('../../../ui/logger.js');
|
|
19
19
|
vi.mock('@hubspot/project-parsing-lib/src/lib/project');
|
|
20
20
|
vi.mock('../../../usageTracking');
|
|
21
21
|
const mockedFs = vi.mocked(fs);
|
|
@@ -24,7 +24,7 @@ const mockedConfirmPrompt = vi.mocked(confirmPrompt);
|
|
|
24
24
|
const mockedCreateV3App = vi.mocked(createV3App);
|
|
25
25
|
const mockedProjectAddPromptV3 = vi.mocked(projectAddPromptV3);
|
|
26
26
|
const mockedCloneGithubRepo = vi.mocked(cloneGithubRepo);
|
|
27
|
-
const
|
|
27
|
+
const mockedUiLogger = vi.mocked(uiLogger);
|
|
28
28
|
const mockedGetProjectMetadata = vi.mocked(getProjectMetadata);
|
|
29
29
|
const mockedTrackCommandUsage = vi.mocked(trackCommandUsage);
|
|
30
30
|
describe('lib/projects/add/v3AddComponent', () => {
|
|
@@ -100,7 +100,7 @@ describe('lib/projects/add/v3AddComponent', () => {
|
|
|
100
100
|
hideLogs: true,
|
|
101
101
|
branch: 'main',
|
|
102
102
|
}));
|
|
103
|
-
expect(
|
|
103
|
+
expect(mockedUiLogger.success).toHaveBeenCalled();
|
|
104
104
|
});
|
|
105
105
|
it('creates an app when no app exists and user confirms', async () => {
|
|
106
106
|
const mockProjectMetadataNoApps = {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { uiLogger } from '../../../ui/logger.js';
|
|
2
2
|
import * as github from '@hubspot/local-dev-lib/api/github';
|
|
3
3
|
import { EXIT_CODES } from '../../../enums/exitCodes.js';
|
|
4
4
|
import { getProjectComponentListFromRepo, getProjectTemplateListFromRepo, } from '../legacy.js';
|
|
5
5
|
import { PROJECT_COMPONENT_TYPES, HUBSPOT_PROJECT_COMPONENTS_GITHUB_PATH, } from '../../../constants.js';
|
|
6
|
-
vi.mock('
|
|
6
|
+
vi.mock('../../../ui/logger.js');
|
|
7
7
|
vi.mock('@hubspot/local-dev-lib/api/github');
|
|
8
8
|
const mockedFetchRepoFile = vi.mocked(github.fetchRepoFile);
|
|
9
9
|
const repoConfig = {
|
|
@@ -60,14 +60,14 @@ describe('lib/projects/create/legacy', () => {
|
|
|
60
60
|
it('Logs an error and exits the process if the request for the template list fails', async () => {
|
|
61
61
|
mockedFetchRepoFile.mockRejectedValue(new Error('Not found'));
|
|
62
62
|
await getProjectTemplateListFromRepo(HUBSPOT_PROJECT_COMPONENTS_GITHUB_PATH, 'gh-ref');
|
|
63
|
-
expect(
|
|
63
|
+
expect(uiLogger.error).toHaveBeenCalledWith(expect.stringMatching(/Failed to fetch the config.json file from the target repository/));
|
|
64
64
|
expect(exitMock).toHaveBeenCalledWith(EXIT_CODES.ERROR);
|
|
65
65
|
});
|
|
66
66
|
it('Logs an error and exits the process if there are no projects listed in the repo config', async () => {
|
|
67
67
|
// @ts-expect-error - Mocking AxiosResponse
|
|
68
68
|
mockedFetchRepoFile.mockResolvedValue({});
|
|
69
69
|
await getProjectTemplateListFromRepo(HUBSPOT_PROJECT_COMPONENTS_GITHUB_PATH, 'gh-ref');
|
|
70
|
-
expect(
|
|
70
|
+
expect(uiLogger.error).toHaveBeenCalledWith(expect.stringMatching(/Unable to find any projects in the target repository's config.json file/));
|
|
71
71
|
expect(exitMock).toHaveBeenCalledWith(EXIT_CODES.ERROR);
|
|
72
72
|
});
|
|
73
73
|
it('Logs an error and exits the process if any of the projects in the repo config are missing required properties', async () => {
|
|
@@ -84,7 +84,7 @@ describe('lib/projects/create/legacy', () => {
|
|
|
84
84
|
},
|
|
85
85
|
});
|
|
86
86
|
await getProjectTemplateListFromRepo(HUBSPOT_PROJECT_COMPONENTS_GITHUB_PATH, 'gh-ref');
|
|
87
|
-
expect(
|
|
87
|
+
expect(uiLogger.error).toHaveBeenCalledWith(expect.stringMatching(/Found misconfigured projects in the target repository's config.json file/));
|
|
88
88
|
expect(exitMock).toHaveBeenCalledWith(EXIT_CODES.ERROR);
|
|
89
89
|
});
|
|
90
90
|
});
|
|
@@ -1,8 +1,17 @@
|
|
|
1
1
|
import { calculateComponentTemplateChoices } from '../v3.js';
|
|
2
|
-
|
|
2
|
+
import { hasFeature } from '../../../hasFeature.js';
|
|
3
|
+
vi.mock('../../ui/logger.js');
|
|
3
4
|
vi.mock('@hubspot/local-dev-lib/api/github');
|
|
5
|
+
vi.mock('../../../hasFeature.js');
|
|
6
|
+
const mockHasFeature = vi.mocked(hasFeature);
|
|
4
7
|
describe('lib/projects/create/v3', () => {
|
|
8
|
+
beforeEach(() => {
|
|
9
|
+
mockHasFeature.mockResolvedValue(true);
|
|
10
|
+
});
|
|
5
11
|
describe('calculateComponentTemplateChoices()', () => {
|
|
12
|
+
beforeEach(() => {
|
|
13
|
+
mockHasFeature.mockClear();
|
|
14
|
+
});
|
|
6
15
|
const mockComponents = [
|
|
7
16
|
{
|
|
8
17
|
label: 'Module Component',
|
|
@@ -30,7 +39,7 @@ describe('lib/projects/create/v3', () => {
|
|
|
30
39
|
const choices = await calculateComponentTemplateChoices(mockComponents, 'oauth', 'private', 123, mockProjectMetadataForChoices);
|
|
31
40
|
expect(choices).toHaveLength(4); // includes separator
|
|
32
41
|
expect(choices[0]).toEqual({
|
|
33
|
-
name: 'Module Component',
|
|
42
|
+
name: 'Module Component [module]',
|
|
34
43
|
value: mockComponents[0],
|
|
35
44
|
});
|
|
36
45
|
expect(choices[2]).toEqual({
|
|
@@ -70,7 +79,7 @@ describe('lib/projects/create/v3', () => {
|
|
|
70
79
|
components: { module: { count: 0, maxCount: 5, hsMetaFiles: [] } },
|
|
71
80
|
});
|
|
72
81
|
expect(choices[0]).toEqual({
|
|
73
|
-
name: 'Unrestricted Component',
|
|
82
|
+
name: 'Unrestricted Component [module]',
|
|
74
83
|
value: componentsWithoutRestrictions[0],
|
|
75
84
|
});
|
|
76
85
|
});
|
|
@@ -94,7 +103,7 @@ describe('lib/projects/create/v3', () => {
|
|
|
94
103
|
const choices = await calculateComponentTemplateChoices(componentWithCliSelector, 'oauth', 'private', 213, projectMetadataWithWorkflowAction);
|
|
95
104
|
expect(choices).toHaveLength(1); // no disabled components
|
|
96
105
|
expect(choices[0]).toEqual({
|
|
97
|
-
name: 'Workflow Action Tool',
|
|
106
|
+
name: 'Workflow Action Tool [workflow-action-tool]',
|
|
98
107
|
value: componentWithCliSelector[0],
|
|
99
108
|
});
|
|
100
109
|
});
|
|
@@ -137,7 +146,7 @@ describe('lib/projects/create/v3', () => {
|
|
|
137
146
|
const choices = await calculateComponentTemplateChoices(componentWithCliSelector, 'oauth', 'private', 123, undefined);
|
|
138
147
|
expect(choices).toHaveLength(1); // no disabled components
|
|
139
148
|
expect(choices[0]).toEqual({
|
|
140
|
-
name: 'Workflow Action Tool',
|
|
149
|
+
name: 'Workflow Action Tool [workflow-action-tool]',
|
|
141
150
|
value: componentWithCliSelector[0],
|
|
142
151
|
});
|
|
143
152
|
});
|
|
@@ -162,5 +171,71 @@ describe('lib/projects/create/v3', () => {
|
|
|
162
171
|
// @ts-expect-error breaking stuff on purpose
|
|
163
172
|
projectMetadataWithoutComponents)).rejects.toThrow();
|
|
164
173
|
});
|
|
174
|
+
it('disables gated components when hasFeature returns false', async () => {
|
|
175
|
+
mockHasFeature.mockResolvedValue(false);
|
|
176
|
+
const gatedComponent = [
|
|
177
|
+
{
|
|
178
|
+
label: 'Workflow Action Tool',
|
|
179
|
+
path: 'workflow-action-tool',
|
|
180
|
+
type: 'workflow-action',
|
|
181
|
+
cliSelector: 'workflow-action-tool',
|
|
182
|
+
supportedAuthTypes: ['oauth'],
|
|
183
|
+
supportedDistributions: ['private'],
|
|
184
|
+
},
|
|
185
|
+
];
|
|
186
|
+
const choices = await calculateComponentTemplateChoices(gatedComponent, 'oauth', 'private', 123, mockProjectMetadataForChoices);
|
|
187
|
+
expect(choices).toHaveLength(3); // includes separators
|
|
188
|
+
expect(choices[1]).toEqual({
|
|
189
|
+
name: expect.stringContaining('Workflow Action Tool'),
|
|
190
|
+
value: gatedComponent[0],
|
|
191
|
+
disabled: expect.stringContaining('does not have access to this feature'),
|
|
192
|
+
});
|
|
193
|
+
expect(mockHasFeature).toHaveBeenCalledWith(123, expect.any(String));
|
|
194
|
+
});
|
|
195
|
+
it('enables gated components when hasFeature returns true', async () => {
|
|
196
|
+
mockHasFeature.mockResolvedValue(true);
|
|
197
|
+
const gatedComponent = [
|
|
198
|
+
{
|
|
199
|
+
label: 'Workflow Action Tool',
|
|
200
|
+
path: 'workflow-action-tool',
|
|
201
|
+
type: 'workflow-action',
|
|
202
|
+
cliSelector: 'workflow-action-tool',
|
|
203
|
+
supportedAuthTypes: ['oauth'],
|
|
204
|
+
supportedDistributions: ['private'],
|
|
205
|
+
},
|
|
206
|
+
];
|
|
207
|
+
const projectMetadataWithWorkflowAction = {
|
|
208
|
+
hsMetaFiles: [],
|
|
209
|
+
components: {
|
|
210
|
+
'workflow-action': { count: 0, maxCount: 3, hsMetaFiles: [] },
|
|
211
|
+
},
|
|
212
|
+
};
|
|
213
|
+
const choices = await calculateComponentTemplateChoices(gatedComponent, 'oauth', 'private', 123, projectMetadataWithWorkflowAction);
|
|
214
|
+
expect(choices).toHaveLength(1); // no disabled components
|
|
215
|
+
expect(choices[0]).toEqual({
|
|
216
|
+
name: 'Workflow Action Tool [workflow-action-tool]',
|
|
217
|
+
value: gatedComponent[0],
|
|
218
|
+
});
|
|
219
|
+
expect(mockHasFeature).toHaveBeenCalledWith(123, expect.any(String));
|
|
220
|
+
});
|
|
221
|
+
it('handles non-gated components without calling hasFeature', async () => {
|
|
222
|
+
const nonGatedComponent = [
|
|
223
|
+
{
|
|
224
|
+
label: 'Regular Component',
|
|
225
|
+
path: 'regular',
|
|
226
|
+
type: 'module',
|
|
227
|
+
supportedAuthTypes: ['oauth'],
|
|
228
|
+
supportedDistributions: ['private'],
|
|
229
|
+
},
|
|
230
|
+
];
|
|
231
|
+
const choices = await calculateComponentTemplateChoices(nonGatedComponent, 'oauth', 'private', 123, mockProjectMetadataForChoices);
|
|
232
|
+
expect(choices).toHaveLength(1);
|
|
233
|
+
expect(choices[0]).toEqual({
|
|
234
|
+
name: 'Regular Component [module]',
|
|
235
|
+
value: nonGatedComponent[0],
|
|
236
|
+
});
|
|
237
|
+
// hasFeature should not be called for non-gated components
|
|
238
|
+
expect(mockHasFeature).not.toHaveBeenCalled();
|
|
239
|
+
});
|
|
165
240
|
});
|
|
166
241
|
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { selectProjectTemplatePrompt, } from '../../prompts/selectProjectTemplatePrompt.js';
|
|
2
2
|
import { projectNameAndDestPrompt } from '../../prompts/projectNameAndDestPrompt.js';
|
|
3
3
|
import { DEFAULT_PROJECT_TEMPLATE_BRANCH, HUBSPOT_PROJECT_COMPONENTS_GITHUB_PATH, EMPTY_PROJECT, } from '../../constants.js';
|
|
4
|
-
import {
|
|
4
|
+
import { isV2Project } from '../platformVersion.js';
|
|
5
5
|
import { v3ComponentFlow } from './v3.js';
|
|
6
6
|
import { getProjectTemplateListFromRepo } from './legacy.js';
|
|
7
7
|
import { uiLogger } from '../../ui/logger.js';
|
|
@@ -11,7 +11,7 @@ export async function handleProjectCreationFlow(args) {
|
|
|
11
11
|
const { platformVersion, templateSource, projectBase, auth: providedAuth, distribution: providedDistribution, } = args;
|
|
12
12
|
const repo = templateSource || HUBSPOT_PROJECT_COMPONENTS_GITHUB_PATH;
|
|
13
13
|
const projectNameAndDestPromptResponse = await projectNameAndDestPrompt(args);
|
|
14
|
-
if (
|
|
14
|
+
if (isV2Project(platformVersion)) {
|
|
15
15
|
const { componentTemplateChoices, authType, distribution, repoConfig, projectContents, } = await v3ComponentFlow(platformVersion, projectBase, providedAuth, providedDistribution, args.derivedAccountId);
|
|
16
16
|
const selectProjectTemplatePromptResponse = await selectProjectTemplatePrompt(args, undefined, projectContents !== EMPTY_PROJECT ? componentTemplateChoices : undefined);
|
|
17
17
|
return {
|
|
@@ -3,13 +3,13 @@ import { DEFAULT_PROJECT_TEMPLATE_BRANCH, HUBSPOT_PROJECT_COMPONENTS_GITHUB_PATH
|
|
|
3
3
|
import { EXIT_CODES } from '../../enums/exitCodes.js';
|
|
4
4
|
import { debugError } from '../../errorHandlers/index.js';
|
|
5
5
|
import { uiLogger } from '../../ui/logger.js';
|
|
6
|
-
import {
|
|
6
|
+
import { isV2Project } from '../platformVersion.js';
|
|
7
7
|
import { lib } from '../../../lang/en.js';
|
|
8
8
|
const PROJECT_TEMPLATE_PROPERTIES = ['name', 'label', 'path'];
|
|
9
9
|
export const EMPTY_PROJECT_TEMPLATE_NAME = 'no-template';
|
|
10
10
|
export async function getConfigForPlatformVersion(platformVersion) {
|
|
11
11
|
let path = '';
|
|
12
|
-
if (
|
|
12
|
+
if (isV2Project(platformVersion)) {
|
|
13
13
|
path = `${platformVersion}/`;
|
|
14
14
|
}
|
|
15
15
|
const { data } = await fetchRepoFile(HUBSPOT_PROJECT_COMPONENTS_GITHUB_PATH, `${path}config.json`, DEFAULT_PROJECT_TEMPLATE_BRANCH);
|