@hubspot/cli 7.5.11-experimental.0 → 7.7.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 -6
- package/bin/hsmcp.d.ts +2 -0
- package/bin/hsmcp.js +13 -0
- package/commands/account/auth.d.ts +3 -7
- package/commands/account/auth.js +19 -9
- package/commands/account/clean.d.ts +3 -7
- package/commands/account/clean.js +16 -9
- package/commands/account/createOverride.d.ts +3 -7
- package/commands/account/createOverride.js +23 -6
- package/commands/account/info.d.ts +3 -7
- package/commands/account/info.js +13 -5
- package/commands/account/list.d.ts +3 -7
- package/commands/account/list.js +15 -8
- package/commands/account/remove.d.ts +3 -7
- package/commands/account/remove.js +21 -9
- package/commands/account/removeOverride.d.ts +3 -7
- package/commands/account/removeOverride.js +23 -6
- package/commands/account/rename.d.ts +3 -7
- package/commands/account/rename.js +16 -9
- package/commands/account/use.d.ts +5 -9
- package/commands/account/use.js +14 -6
- package/commands/account.d.ts +3 -4
- package/commands/account.js +35 -58
- package/commands/app/migrate.d.ts +1 -2
- package/commands/app/migrate.js +7 -8
- package/commands/app/secret/add.d.ts +7 -0
- package/commands/app/secret/add.js +64 -0
- package/commands/app/secret/delete.d.ts +8 -0
- package/commands/app/secret/delete.js +87 -0
- package/commands/app/secret/list.d.ts +6 -0
- package/commands/app/secret/list.js +64 -0
- package/commands/app/secret/update.d.ts +7 -0
- package/commands/app/secret/update.js +77 -0
- package/commands/app/secret.d.ts +3 -0
- package/commands/app/secret.js +30 -0
- package/commands/app.d.ts +2 -5
- package/commands/app.js +12 -8
- package/commands/auth.d.ts +3 -7
- package/commands/auth.js +12 -5
- package/commands/cms/convertFields.d.ts +7 -1
- package/commands/cms/convertFields.js +57 -41
- package/commands/cms/getReactModule.d.ts +7 -1
- package/commands/cms/getReactModule.js +52 -34
- package/commands/cms/lighthouseScore.d.ts +8 -1
- package/commands/cms/lighthouseScore.js +129 -100
- package/commands/cms.d.ts +3 -1
- package/commands/cms.js +24 -15
- package/commands/completion.d.ts +3 -1
- package/commands/completion.js +25 -12
- package/commands/config/migrate.d.ts +3 -7
- package/commands/config/migrate.js +25 -15
- package/commands/config/set.d.ts +5 -6
- package/commands/config/set.js +38 -14
- package/commands/config.d.ts +3 -4
- package/commands/config.js +20 -44
- package/commands/create/api-sample.d.ts +3 -1
- package/commands/create/api-sample.js +34 -38
- package/commands/create/app.d.ts +3 -1
- package/commands/create/app.js +9 -7
- package/commands/create/function.d.ts +3 -1
- package/commands/create/function.js +11 -10
- package/commands/create/index.d.ts +5 -1
- package/commands/create/index.js +23 -11
- package/commands/create/module.d.ts +3 -1
- package/commands/create/module.js +14 -13
- package/commands/create/react-app.d.ts +3 -1
- package/commands/create/react-app.js +10 -7
- package/commands/create/template.d.ts +3 -1
- package/commands/create/template.js +14 -14
- package/commands/create/vue-app.d.ts +3 -1
- package/commands/create/vue-app.js +10 -7
- package/commands/create/webpack-serverless.d.ts +3 -1
- package/commands/create/webpack-serverless.js +10 -7
- package/commands/create/website-theme.d.ts +3 -1
- package/commands/create/website-theme.js +10 -9
- package/commands/create.d.ts +4 -24
- package/commands/create.js +64 -74
- package/commands/customObject/create.d.ts +4 -9
- package/commands/customObject/create.js +17 -10
- package/commands/customObject/schema/create.d.ts +4 -9
- package/commands/customObject/schema/create.js +18 -11
- package/commands/customObject/schema/delete.d.ts +4 -9
- package/commands/customObject/schema/delete.js +17 -10
- package/commands/customObject/schema/fetch-all.d.ts +4 -9
- package/commands/customObject/schema/fetch-all.js +17 -10
- package/commands/customObject/schema/fetch.d.ts +4 -9
- package/commands/customObject/schema/fetch.js +17 -10
- package/commands/customObject/schema/list.d.ts +4 -8
- package/commands/customObject/schema/list.js +17 -10
- package/commands/customObject/schema/update.d.ts +4 -9
- package/commands/customObject/schema/update.js +18 -11
- package/commands/customObject/schema.d.ts +3 -5
- package/commands/customObject/schema.js +27 -54
- package/commands/customObject.d.ts +3 -4
- package/commands/customObject.js +20 -45
- package/commands/doctor.d.ts +6 -8
- package/commands/doctor.js +32 -21
- package/commands/feedback.d.ts +4 -1
- package/commands/feedback.js +40 -47
- package/commands/fetch.d.ts +12 -1
- package/commands/fetch.js +49 -33
- package/commands/filemanager/fetch.d.ts +4 -9
- package/commands/filemanager/fetch.js +18 -11
- package/commands/filemanager/upload.d.ts +4 -9
- package/commands/filemanager/upload.js +17 -11
- package/commands/filemanager.d.ts +3 -4
- package/commands/filemanager.js +20 -41
- package/commands/function/deploy.d.ts +6 -1
- package/commands/function/deploy.js +70 -50
- package/commands/function/list.d.ts +6 -1
- package/commands/function/list.js +44 -32
- package/commands/function/server.d.ts +10 -1
- package/commands/function/server.js +49 -38
- package/commands/function.d.ts +5 -1
- package/commands/function.js +24 -10
- package/commands/hubdb/clear.d.ts +4 -9
- package/commands/hubdb/clear.js +17 -10
- package/commands/hubdb/create.d.ts +4 -9
- package/commands/hubdb/create.js +17 -10
- package/commands/hubdb/delete.d.ts +4 -9
- package/commands/hubdb/delete.js +17 -10
- package/commands/hubdb/fetch.d.ts +4 -9
- package/commands/hubdb/fetch.js +17 -10
- package/commands/hubdb.d.ts +3 -2
- package/commands/hubdb.js +23 -45
- package/commands/init.d.ts +3 -7
- package/commands/init.js +12 -5
- package/commands/lint.d.ts +6 -4
- package/commands/lint.js +44 -43
- package/commands/list.d.ts +3 -7
- package/commands/list.js +19 -11
- package/commands/logs.d.ts +10 -1
- package/commands/logs.js +53 -44
- package/commands/module/marketplace-validate.d.ts +6 -1
- package/commands/module/marketplace-validate.js +39 -27
- package/commands/module.d.ts +3 -1
- package/commands/module.js +22 -10
- package/commands/mv.d.ts +3 -7
- package/commands/mv.js +19 -11
- package/commands/open.d.ts +3 -7
- package/commands/open.js +19 -11
- package/commands/project/cloneApp.d.ts +1 -1
- package/commands/project/cloneApp.js +2 -2
- package/commands/project/create.js +3 -3
- package/commands/project/deploy.d.ts +1 -0
- package/commands/project/deploy.js +40 -12
- package/commands/project/dev/index.d.ts +1 -4
- package/commands/project/dev/index.js +48 -16
- package/commands/project/dev/unifiedFlow.d.ts +2 -1
- package/commands/project/dev/unifiedFlow.js +85 -30
- package/commands/project/migrate.d.ts +1 -0
- package/commands/project/profile/add.d.ts +7 -0
- package/commands/project/profile/add.js +209 -0
- package/commands/project/profile/delete.d.ts +6 -0
- package/commands/project/profile/delete.js +123 -0
- package/commands/project/profile.d.ts +3 -0
- package/commands/project/profile.js +25 -0
- package/commands/project/upload.d.ts +1 -0
- package/commands/project/upload.js +38 -8
- package/commands/project/validate.d.ts +4 -0
- package/commands/project/validate.js +53 -0
- package/commands/project.js +4 -0
- package/commands/remove.d.ts +3 -7
- package/commands/remove.js +19 -11
- package/commands/sandbox/create.d.ts +4 -9
- package/commands/sandbox/create.js +18 -11
- package/commands/sandbox/delete.d.ts +4 -9
- package/commands/sandbox/delete.js +18 -11
- package/commands/sandbox.d.ts +3 -4
- package/commands/sandbox.js +20 -43
- package/commands/secret/addSecret.d.ts +4 -9
- package/commands/secret/addSecret.js +17 -10
- package/commands/secret/deleteSecret.d.ts +4 -9
- package/commands/secret/deleteSecret.js +17 -10
- package/commands/secret/listSecret.d.ts +4 -9
- package/commands/secret/listSecret.js +17 -10
- package/commands/secret/updateSecret.d.ts +4 -9
- package/commands/secret/updateSecret.js +17 -10
- package/commands/secret.d.ts +3 -4
- package/commands/secret.js +25 -48
- package/commands/setupMcp.d.ts +8 -0
- package/commands/setupMcp.js +229 -0
- package/commands/theme/generate-selectors.d.ts +3 -7
- package/commands/theme/generate-selectors.js +14 -6
- package/commands/theme/marketplace-validate.d.ts +4 -9
- package/commands/theme/marketplace-validate.js +17 -10
- package/commands/theme/preview.d.ts +4 -9
- package/commands/theme/preview.js +16 -9
- package/commands/theme.d.ts +3 -4
- package/commands/theme.js +23 -46
- package/commands/upload.d.ts +12 -1
- package/commands/upload.js +118 -97
- package/commands/watch.d.ts +14 -1
- package/commands/watch.js +76 -65
- package/lang/en.d.ts +838 -574
- package/lang/en.js +630 -373
- package/lang/en.lyaml +30 -23
- package/lib/accountTypes.js +2 -1
- package/lib/app/migrate.d.ts +23 -0
- package/lib/app/migrate.js +14 -3
- package/lib/app/migrate_legacy.js +7 -7
- package/lib/app/urls.d.ts +16 -0
- package/lib/app/urls.js +16 -0
- package/lib/configMigrate.js +24 -10
- package/lib/configOptions.d.ts +4 -0
- package/lib/configOptions.js +41 -46
- package/lib/constants.d.ts +6 -0
- package/lib/constants.js +7 -1
- package/lib/dependencyManagement.d.ts +0 -5
- package/lib/dependencyManagement.js +13 -39
- package/lib/doctor/Doctor.js +2 -1
- package/lib/filesystem.d.ts +1 -1
- package/lib/interpolation.d.ts +2 -3
- package/lib/lang.d.ts +2 -3
- package/lib/middleware/autoUpdateMiddleware.d.ts +1 -0
- package/lib/middleware/autoUpdateMiddleware.js +89 -0
- package/lib/middleware/configMiddleware.js +8 -0
- package/lib/npm.d.ts +9 -0
- package/lib/npm.js +36 -0
- package/lib/projectProfiles.d.ts +6 -0
- package/lib/projectProfiles.js +65 -0
- package/lib/projects/buildAndDeploy.js +17 -2
- package/lib/projects/localDev/AppDevModeInterface.d.ts +26 -0
- package/lib/projects/localDev/AppDevModeInterface.js +156 -0
- package/lib/projects/localDev/DevServerManagerV2.d.ts +11 -22
- package/lib/projects/localDev/DevServerManagerV2.js +19 -15
- package/lib/projects/localDev/LocalDevLogger.d.ts +30 -0
- package/lib/projects/localDev/LocalDevLogger.js +158 -0
- package/lib/projects/localDev/LocalDevManager.js +12 -5
- package/lib/projects/localDev/LocalDevProcess.d.ts +27 -0
- package/lib/projects/localDev/LocalDevProcess.js +171 -0
- package/lib/projects/localDev/LocalDevState.d.ts +37 -0
- package/lib/projects/localDev/LocalDevState.js +78 -0
- package/lib/projects/localDev/LocalDevWatcher.d.ts +10 -0
- package/lib/projects/localDev/LocalDevWatcher.js +56 -0
- package/lib/projects/localDev/LocalDevWebsocketServer.d.ts +17 -0
- package/lib/projects/localDev/LocalDevWebsocketServer.js +92 -0
- package/lib/projects/localDev/helpers.d.ts +3 -2
- package/lib/projects/localDev/helpers.js +32 -2
- package/lib/projects/upload.d.ts +2 -1
- package/lib/projects/upload.js +2 -2
- package/lib/prompts/createApiSamplePrompt.d.ts +2 -10
- package/lib/prompts/createTemplatePrompt.d.ts +22 -4
- package/lib/prompts/installAppPrompt.d.ts +1 -0
- package/lib/prompts/installAppPrompt.js +35 -0
- package/lib/prompts/projectDevTargetAccountPrompt.d.ts +6 -1
- package/lib/prompts/projectDevTargetAccountPrompt.js +6 -6
- package/lib/prompts/promptUtils.d.ts +2 -1
- package/lib/prompts/promptUtils.js +2 -1
- package/lib/prompts/selectAppPrompt.d.ts +2 -0
- package/lib/prompts/selectAppPrompt.js +40 -0
- package/lib/prompts/{selectPublicAppPrompt.d.ts → selectPublicAppForMigrationPrompt.d.ts} +1 -1
- package/lib/prompts/{selectPublicAppPrompt.js → selectPublicAppForMigrationPrompt.js} +8 -8
- package/lib/testUtils.d.ts +3 -3
- package/lib/testUtils.js +8 -9
- package/lib/ui/index.js +4 -1
- package/lib/upload.d.ts +1 -1
- package/lib/validation.js +4 -5
- package/lib/yargsUtils.d.ts +4 -0
- package/lib/yargsUtils.js +6 -0
- package/mcp-server/index.d.ts +1 -0
- package/mcp-server/index.js +17 -0
- package/mcp-server/mcpLoader.d.ts +5 -0
- package/mcp-server/mcpLoader.js +24 -0
- package/mcp-server/tools/ExplainProjectStructureTool.d.ts +33 -0
- package/mcp-server/tools/ExplainProjectStructureTool.js +266 -0
- package/mcp-server/tools/GenerateAppComponentTool.d.ts +99 -0
- package/mcp-server/tools/GenerateAppComponentTool.js +193 -0
- package/mcp-server/tools/GenerateCardComponentTool.d.ts +74 -0
- package/mcp-server/tools/GenerateCardComponentTool.js +146 -0
- package/mcp-server/tools/GenerateProjectConfigTool.d.ts +32 -0
- package/mcp-server/tools/GenerateProjectConfigTool.js +40 -0
- package/mcp-server/tools/HubSpotCLIHelper.d.ts +16 -0
- package/mcp-server/tools/HubSpotCLIHelper.js +74 -0
- package/mcp-server/tools/UploadProjectTool.d.ts +44 -0
- package/mcp-server/tools/UploadProjectTool.js +149 -0
- package/mcp-server/tools/ValidateProjectTool.d.ts +62 -0
- package/mcp-server/tools/ValidateProjectTool.js +315 -0
- package/package.json +13 -6
- package/types/Cms.d.ts +30 -0
- package/types/Cms.js +2 -0
- package/types/LocalDev.d.ts +24 -0
- package/types/LocalDev.js +2 -0
- package/types/Prompts.d.ts +0 -7
- package/types/Yargs.d.ts +8 -1
- package/lib/projects/localDev/LocalDevManagerV2.d.ts +0 -64
- package/lib/projects/localDev/LocalDevManagerV2.js +0 -345
- package/lib/prompts/installPublicAppPrompt.d.ts +0 -1
- package/lib/prompts/installPublicAppPrompt.js +0 -41
|
@@ -21,6 +21,7 @@ const ui_1 = require("../../lib/ui");
|
|
|
21
21
|
const exitCodes_1 = require("../../lib/enums/exitCodes");
|
|
22
22
|
const ui_2 = require("../../lib/ui");
|
|
23
23
|
const yargsUtils_1 = require("../../lib/yargsUtils");
|
|
24
|
+
const projectProfiles_1 = require("../../lib/projectProfiles");
|
|
24
25
|
const command = 'deploy';
|
|
25
26
|
const describe = (0, ui_1.uiBetaTag)((0, lang_1.i18n)(`commands.project.subcommands.deploy.describe`), false);
|
|
26
27
|
function validateBuildId(buildId, deployedBuildId, latestBuildId, projectName, accountId) {
|
|
@@ -40,29 +41,48 @@ function validateBuildId(buildId, deployedBuildId, latestBuildId, projectName, a
|
|
|
40
41
|
return true;
|
|
41
42
|
}
|
|
42
43
|
async function handler(args) {
|
|
43
|
-
const { derivedAccountId } = args;
|
|
44
|
+
const { derivedAccountId, project: projectOption, buildId: buildIdOption, } = args;
|
|
44
45
|
const accountConfig = (0, config_1.getAccountConfig)(derivedAccountId);
|
|
45
|
-
const { project: projectOption, buildId: buildIdOption } = args;
|
|
46
46
|
const accountType = accountConfig && accountConfig.accountType;
|
|
47
|
-
|
|
48
|
-
const { projectConfig } = await (0, config_2.getProjectConfig)();
|
|
47
|
+
let targetAccountId;
|
|
48
|
+
const { projectConfig, projectDir } = await (0, config_2.getProjectConfig)();
|
|
49
|
+
if ((0, buildAndDeploy_1.useV3Api)(projectConfig?.platformVersion)) {
|
|
50
|
+
if (args.profile) {
|
|
51
|
+
(0, projectProfiles_1.logProfileHeader)(args.profile);
|
|
52
|
+
const profile = (0, projectProfiles_1.loadProfile)(projectConfig, projectDir, args.profile);
|
|
53
|
+
if (!profile) {
|
|
54
|
+
(0, ui_1.uiLine)();
|
|
55
|
+
process.exit(exitCodes_1.EXIT_CODES.ERROR);
|
|
56
|
+
}
|
|
57
|
+
targetAccountId = profile.accountId;
|
|
58
|
+
(0, projectProfiles_1.logProfileFooter)(profile);
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
// A profile must be specified if this project has profiles configured
|
|
62
|
+
await (0, projectProfiles_1.exitIfUsingProfiles)(projectConfig, projectDir);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
if (!targetAccountId) {
|
|
66
|
+
targetAccountId = derivedAccountId;
|
|
67
|
+
}
|
|
68
|
+
(0, usageTracking_1.trackCommandUsage)('project-deploy', accountType ? { type: accountType } : undefined, targetAccountId);
|
|
49
69
|
let projectName = projectOption;
|
|
50
70
|
if (!projectOption && projectConfig) {
|
|
51
71
|
projectName = projectConfig.name;
|
|
52
72
|
}
|
|
53
|
-
const namePromptResponse = await (0, projectNamePrompt_1.projectNamePrompt)(
|
|
73
|
+
const namePromptResponse = await (0, projectNamePrompt_1.projectNamePrompt)(targetAccountId, {
|
|
54
74
|
project: projectName,
|
|
55
75
|
});
|
|
56
76
|
projectName = namePromptResponse.projectName;
|
|
57
77
|
let buildIdToDeploy = buildIdOption;
|
|
58
78
|
try {
|
|
59
|
-
const { data: { latestBuild, deployedBuildId }, } = await (0, projects_1.fetchProject)(
|
|
79
|
+
const { data: { latestBuild, deployedBuildId }, } = await (0, projects_1.fetchProject)(targetAccountId, projectName);
|
|
60
80
|
if (!latestBuild || !latestBuild.buildId) {
|
|
61
81
|
logger_1.logger.error((0, lang_1.i18n)(`commands.project.subcommands.deploy.errors.noBuilds`));
|
|
62
82
|
return process.exit(exitCodes_1.EXIT_CODES.ERROR);
|
|
63
83
|
}
|
|
64
84
|
if (buildIdToDeploy) {
|
|
65
|
-
const validationResult = validateBuildId(buildIdToDeploy, deployedBuildId, latestBuild.buildId, projectName,
|
|
85
|
+
const validationResult = validateBuildId(buildIdToDeploy, deployedBuildId, latestBuild.buildId, projectName, targetAccountId);
|
|
66
86
|
if (validationResult !== true) {
|
|
67
87
|
logger_1.logger.error(validationResult);
|
|
68
88
|
return process.exit(exitCodes_1.EXIT_CODES.ERROR);
|
|
@@ -75,7 +95,7 @@ async function handler(args) {
|
|
|
75
95
|
default: latestBuild.buildId === deployedBuildId
|
|
76
96
|
? undefined
|
|
77
97
|
: latestBuild.buildId,
|
|
78
|
-
validate: buildId => validateBuildId(buildId, deployedBuildId, latestBuild.buildId, projectName,
|
|
98
|
+
validate: buildId => validateBuildId(buildId, deployedBuildId, latestBuild.buildId, projectName, targetAccountId),
|
|
79
99
|
});
|
|
80
100
|
buildIdToDeploy = deployBuildIdPromptResponse.buildId;
|
|
81
101
|
}
|
|
@@ -83,18 +103,18 @@ async function handler(args) {
|
|
|
83
103
|
logger_1.logger.error((0, lang_1.i18n)(`commands.project.subcommands.deploy.errors.noBuildId`));
|
|
84
104
|
return process.exit(exitCodes_1.EXIT_CODES.ERROR);
|
|
85
105
|
}
|
|
86
|
-
const { data: deployResp } = await (0, projects_1.deployProject)(
|
|
106
|
+
const { data: deployResp } = await (0, projects_1.deployProject)(targetAccountId, projectName, buildIdToDeploy, (0, buildAndDeploy_1.useV3Api)(projectConfig?.platformVersion));
|
|
87
107
|
if (!deployResp) {
|
|
88
108
|
logger_1.logger.error((0, lang_1.i18n)(`commands.project.subcommands.deploy.errors.deploy`));
|
|
89
109
|
return process.exit(exitCodes_1.EXIT_CODES.ERROR);
|
|
90
110
|
}
|
|
91
|
-
await (0, buildAndDeploy_2.pollDeployStatus)(
|
|
111
|
+
await (0, buildAndDeploy_2.pollDeployStatus)(targetAccountId, projectName, Number(deployResp.id), buildIdToDeploy);
|
|
92
112
|
}
|
|
93
113
|
catch (e) {
|
|
94
114
|
if ((0, index_1.isHubSpotHttpError)(e) && e.status === 404) {
|
|
95
115
|
logger_1.logger.error((0, lang_1.i18n)(`commands.project.subcommands.deploy.errors.projectNotFound`, {
|
|
96
116
|
projectName: chalk_1.default.bold(projectName),
|
|
97
|
-
accountIdentifier: (0, ui_2.uiAccountDescription)(
|
|
117
|
+
accountIdentifier: (0, ui_2.uiAccountDescription)(targetAccountId),
|
|
98
118
|
command: (0, ui_2.uiCommandReference)('hs project upload'),
|
|
99
119
|
}));
|
|
100
120
|
}
|
|
@@ -103,7 +123,7 @@ async function handler(args) {
|
|
|
103
123
|
}
|
|
104
124
|
else {
|
|
105
125
|
(0, index_2.logError)(e, new index_2.ApiErrorContext({
|
|
106
|
-
accountId:
|
|
126
|
+
accountId: targetAccountId,
|
|
107
127
|
request: 'project deploy',
|
|
108
128
|
}));
|
|
109
129
|
}
|
|
@@ -121,7 +141,15 @@ function projectDeployBuilder(yargs) {
|
|
|
121
141
|
describe: (0, lang_1.i18n)(`commands.project.subcommands.deploy.options.build.describe`),
|
|
122
142
|
type: 'number',
|
|
123
143
|
},
|
|
144
|
+
profile: {
|
|
145
|
+
alias: ['p'],
|
|
146
|
+
describe: (0, lang_1.i18n)(`commands.project.subcommands.deploy.options.profile.describe`),
|
|
147
|
+
type: 'string',
|
|
148
|
+
hidden: true,
|
|
149
|
+
},
|
|
124
150
|
});
|
|
151
|
+
yargs.conflicts('profile', 'project');
|
|
152
|
+
yargs.conflicts('profile', 'account');
|
|
125
153
|
yargs.example([
|
|
126
154
|
[
|
|
127
155
|
'$0 project deploy',
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Argv, CommandModule } from 'yargs';
|
|
2
2
|
import { ProjectDevArgs } from '../../../types/Yargs';
|
|
3
|
-
export declare const command = "dev";
|
|
4
|
-
export declare const describe: string;
|
|
5
|
-
export declare function handler(args: ArgumentsCamelCase<ProjectDevArgs>): Promise<void>;
|
|
6
3
|
export declare const builder: (yargs: Argv) => Promise<Argv<ProjectDevArgs>>;
|
|
7
4
|
declare const projectDevCommand: CommandModule<unknown, ProjectDevArgs>;
|
|
8
5
|
export default projectDevCommand;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.builder =
|
|
4
|
-
exports.handler = handler;
|
|
3
|
+
exports.builder = void 0;
|
|
5
4
|
const usageTracking_1 = require("../../../lib/usageTracking");
|
|
6
5
|
const lang_1 = require("../../../lib/lang");
|
|
7
6
|
const logger_1 = require("@hubspot/local-dev-lib/logger");
|
|
@@ -13,52 +12,85 @@ const deprecatedFlow_1 = require("./deprecatedFlow");
|
|
|
13
12
|
const unifiedFlow_1 = require("./unifiedFlow");
|
|
14
13
|
const buildAndDeploy_1 = require("../../../lib/projects/buildAndDeploy");
|
|
15
14
|
const yargsUtils_1 = require("../../../lib/yargsUtils");
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
const projectProfiles_1 = require("../../../lib/projectProfiles");
|
|
16
|
+
const command = 'dev';
|
|
17
|
+
const describe = (0, ui_1.uiBetaTag)((0, lang_1.i18n)(`commands.project.subcommands.dev.describe`), false);
|
|
18
18
|
async function handler(args) {
|
|
19
|
-
const { derivedAccountId } = args;
|
|
20
|
-
const accountConfig = (0, config_1.getAccountConfig)(derivedAccountId);
|
|
21
|
-
(0, usageTracking_1.trackCommandUsage)('project-dev', {}, derivedAccountId);
|
|
19
|
+
const { derivedAccountId, providedAccountId } = args;
|
|
22
20
|
const { projectConfig, projectDir } = await (0, config_2.getProjectConfig)();
|
|
23
|
-
(0,
|
|
24
|
-
|
|
25
|
-
if (!projectConfig || !projectDir) {
|
|
21
|
+
(0, config_2.validateProjectConfig)(projectConfig, projectDir);
|
|
22
|
+
if (!projectDir) {
|
|
26
23
|
logger_1.logger.error((0, lang_1.i18n)(`commands.project.subcommands.dev.errors.noProjectConfig`, {
|
|
27
24
|
accountId: derivedAccountId,
|
|
28
25
|
authCommand: (0, ui_1.uiCommandReference)('hs auth'),
|
|
29
26
|
}));
|
|
30
27
|
process.exit(exitCodes_1.EXIT_CODES.ERROR);
|
|
31
28
|
}
|
|
29
|
+
let targetAccountId = providedAccountId;
|
|
30
|
+
let profile;
|
|
31
|
+
if (!targetAccountId && (0, buildAndDeploy_1.useV3Api)(projectConfig.platformVersion)) {
|
|
32
|
+
if (args.profile) {
|
|
33
|
+
(0, projectProfiles_1.logProfileHeader)(args.profile);
|
|
34
|
+
profile = (0, projectProfiles_1.loadProfile)(projectConfig, projectDir, args.profile);
|
|
35
|
+
if (!profile) {
|
|
36
|
+
(0, ui_1.uiLine)();
|
|
37
|
+
process.exit(exitCodes_1.EXIT_CODES.ERROR);
|
|
38
|
+
}
|
|
39
|
+
targetAccountId = profile.accountId;
|
|
40
|
+
(0, projectProfiles_1.logProfileFooter)(profile);
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
// A profile must be specified if this project has profiles configured
|
|
44
|
+
await (0, projectProfiles_1.exitIfUsingProfiles)(projectConfig, projectDir);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
if (!targetAccountId) {
|
|
48
|
+
// The user is not using profiles, so we can use the derived accountId
|
|
49
|
+
targetAccountId = derivedAccountId;
|
|
50
|
+
}
|
|
51
|
+
(0, usageTracking_1.trackCommandUsage)('project-dev', {}, targetAccountId);
|
|
52
|
+
const accountConfig = (0, config_1.getAccountConfig)(targetAccountId);
|
|
53
|
+
(0, ui_1.uiBetaTag)((0, lang_1.i18n)(`commands.project.subcommands.dev.logs.betaMessage`));
|
|
54
|
+
logger_1.logger.log((0, ui_1.uiLink)((0, lang_1.i18n)(`commands.project.subcommands.dev.logs.learnMoreLocalDevServer`), 'https://developers.hubspot.com/docs/platform/project-cli-commands#start-a-local-development-server'));
|
|
32
55
|
if (!accountConfig) {
|
|
33
|
-
logger_1.logger.error((0, lang_1.i18n)(`commands.project.subcommands.dev.errors.noAccount
|
|
56
|
+
logger_1.logger.error((0, lang_1.i18n)(`commands.project.subcommands.dev.errors.noAccount`, {
|
|
57
|
+
accountId: (0, ui_1.uiAccountDescription)(targetAccountId),
|
|
58
|
+
authCommand: (0, ui_1.uiCommandReference)('hs auth'),
|
|
59
|
+
}));
|
|
34
60
|
process.exit(exitCodes_1.EXIT_CODES.ERROR);
|
|
35
61
|
}
|
|
36
|
-
(0, config_2.validateProjectConfig)(projectConfig, projectDir);
|
|
37
62
|
if ((0, buildAndDeploy_1.useV3Api)(projectConfig.platformVersion)) {
|
|
38
|
-
await (0, unifiedFlow_1.unifiedProjectDevFlow)(args, accountConfig, projectConfig, projectDir);
|
|
63
|
+
await (0, unifiedFlow_1.unifiedProjectDevFlow)(args, accountConfig, projectConfig, projectDir, profile);
|
|
39
64
|
}
|
|
40
65
|
else {
|
|
41
66
|
await (0, deprecatedFlow_1.deprecatedProjectDevFlow)(args, accountConfig, projectConfig, projectDir);
|
|
42
67
|
}
|
|
43
68
|
}
|
|
44
69
|
function projectDevBuilder(yargs) {
|
|
70
|
+
yargs.option('profile', {
|
|
71
|
+
type: 'string',
|
|
72
|
+
alias: 'p',
|
|
73
|
+
description: (0, lang_1.i18n)(`commands.project.subcommands.dev.options.profile`),
|
|
74
|
+
hidden: true,
|
|
75
|
+
});
|
|
45
76
|
yargs.example([
|
|
46
77
|
[
|
|
47
78
|
'$0 project dev',
|
|
48
79
|
(0, lang_1.i18n)(`commands.project.subcommands.dev.examples.default`),
|
|
49
80
|
],
|
|
50
81
|
]);
|
|
82
|
+
yargs.conflicts('profile', 'account');
|
|
51
83
|
return yargs;
|
|
52
84
|
}
|
|
53
|
-
exports.builder = (0, yargsUtils_1.makeYargsBuilder)(projectDevBuilder,
|
|
85
|
+
exports.builder = (0, yargsUtils_1.makeYargsBuilder)(projectDevBuilder, command, describe, {
|
|
54
86
|
useGlobalOptions: true,
|
|
55
87
|
useAccountOptions: true,
|
|
56
88
|
useConfigOptions: true,
|
|
57
89
|
useEnvironmentOptions: true,
|
|
58
90
|
});
|
|
59
91
|
const projectDevCommand = {
|
|
60
|
-
command
|
|
61
|
-
describe
|
|
92
|
+
command,
|
|
93
|
+
describe,
|
|
62
94
|
handler,
|
|
63
95
|
builder: exports.builder,
|
|
64
96
|
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ArgumentsCamelCase } from 'yargs';
|
|
2
|
+
import { HsProfileFile } from '@hubspot/project-parsing-lib/src/lib/types';
|
|
2
3
|
import { CLIAccount } from '@hubspot/local-dev-lib/types/Accounts';
|
|
3
4
|
import { ProjectDevArgs } from '../../../types/Yargs';
|
|
4
5
|
import { ProjectConfig } from '../../../types/Projects';
|
|
5
|
-
export declare function unifiedProjectDevFlow(args: ArgumentsCamelCase<ProjectDevArgs>, accountConfig: CLIAccount, projectConfig: ProjectConfig, projectDir: string): Promise<void>;
|
|
6
|
+
export declare function unifiedProjectDevFlow(args: ArgumentsCamelCase<ProjectDevArgs>, accountConfig: CLIAccount, projectConfig: ProjectConfig, projectDir: string, profileConfig?: HsProfileFile): Promise<void>;
|
|
@@ -7,9 +7,11 @@ exports.unifiedProjectDevFlow = unifiedProjectDevFlow;
|
|
|
7
7
|
const path_1 = __importDefault(require("path"));
|
|
8
8
|
const util_1 = __importDefault(require("util"));
|
|
9
9
|
const logger_1 = require("@hubspot/local-dev-lib/logger");
|
|
10
|
+
const getAccountIdentifier_1 = require("@hubspot/local-dev-lib/config/getAccountIdentifier");
|
|
11
|
+
const config_1 = require("@hubspot/local-dev-lib/constants/config");
|
|
10
12
|
const errors_1 = require("@hubspot/project-parsing-lib/src/lib/errors");
|
|
11
13
|
const project_parsing_lib_1 = require("@hubspot/project-parsing-lib");
|
|
12
|
-
const
|
|
14
|
+
const config_2 = require("@hubspot/local-dev-lib/config");
|
|
13
15
|
const environment_1 = require("@hubspot/local-dev-lib/environment");
|
|
14
16
|
const errorHandlers_1 = require("../../../lib/errorHandlers");
|
|
15
17
|
const exitCodes_1 = require("../../../lib/enums/exitCodes");
|
|
@@ -17,15 +19,19 @@ const ensureProjectExists_1 = require("../../../lib/projects/ensureProjectExists
|
|
|
17
19
|
const helpers_1 = require("../../../lib/projects/localDev/helpers");
|
|
18
20
|
const projectDevTargetAccountPrompt_1 = require("../../../lib/prompts/projectDevTargetAccountPrompt");
|
|
19
21
|
const SpinniesManager_1 = __importDefault(require("../../../lib/ui/SpinniesManager"));
|
|
20
|
-
const
|
|
22
|
+
const LocalDevProcess_1 = __importDefault(require("../../../lib/projects/localDev/LocalDevProcess"));
|
|
23
|
+
const LocalDevWatcher_1 = __importDefault(require("../../../lib/projects/localDev/LocalDevWatcher"));
|
|
21
24
|
const process_1 = require("../../../lib/process");
|
|
22
25
|
const accountTypes_1 = require("../../../lib/accountTypes");
|
|
23
26
|
const ui_1 = require("../../../lib/ui");
|
|
24
27
|
const lang_1 = require("../../../lib/lang");
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const targetProjectAccountId =
|
|
28
|
-
const env = (0, environment_1.getValidEnv)((0,
|
|
28
|
+
// import LocalDevWebsocketServer from '../../../lib/projects/localDev/LocalDevWebsocketServer';
|
|
29
|
+
async function unifiedProjectDevFlow(args, accountConfig, projectConfig, projectDir, profileConfig) {
|
|
30
|
+
const targetProjectAccountId = (0, getAccountIdentifier_1.getAccountIdentifier)(accountConfig);
|
|
31
|
+
const env = (0, environment_1.getValidEnv)((0, config_2.getEnv)(targetProjectAccountId));
|
|
32
|
+
if (!targetProjectAccountId) {
|
|
33
|
+
process.exit(exitCodes_1.EXIT_CODES.ERROR);
|
|
34
|
+
}
|
|
29
35
|
let projectNodes;
|
|
30
36
|
// Get IR
|
|
31
37
|
try {
|
|
@@ -33,7 +39,7 @@ async function unifiedProjectDevFlow(args, accountConfig, projectConfig, project
|
|
|
33
39
|
projectSourceDir: path_1.default.join(projectDir, projectConfig.srcDir),
|
|
34
40
|
platformVersion: projectConfig.platformVersion,
|
|
35
41
|
accountId: targetProjectAccountId,
|
|
36
|
-
});
|
|
42
|
+
}, { profile: args.profile });
|
|
37
43
|
projectNodes = intermediateRepresentation.intermediateNodesIndexedByUid;
|
|
38
44
|
logger_1.logger.debug(util_1.default.inspect(projectNodes, false, null, true));
|
|
39
45
|
}
|
|
@@ -55,27 +61,55 @@ async function unifiedProjectDevFlow(args, accountConfig, projectConfig, project
|
|
|
55
61
|
process.exit(exitCodes_1.EXIT_CODES.SUCCESS);
|
|
56
62
|
}
|
|
57
63
|
// @TODO Validate component types (i.e. previously you could not have both private and public apps)
|
|
58
|
-
const accounts = (0,
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
process.exit(exitCodes_1.EXIT_CODES.SUCCESS);
|
|
64
|
+
const accounts = (0, config_2.getConfigAccounts)();
|
|
65
|
+
const accountIsCombined = await (0, accountTypes_1.isUnifiedAccount)(accountConfig);
|
|
66
|
+
if (!accountIsCombined && !profileConfig) {
|
|
67
|
+
logger_1.logger.log('');
|
|
68
|
+
logger_1.logger.error((0, lang_1.i18n)(`commands.project.subcommands.dev.errors.accountNotCombined`, {
|
|
69
|
+
accountUseCommand: (0, ui_1.uiCommandReference)('hs account use'),
|
|
70
|
+
}));
|
|
71
|
+
process.exit(exitCodes_1.EXIT_CODES.ERROR);
|
|
67
72
|
}
|
|
68
73
|
let targetTestingAccountId = null;
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
// When the developer test account isn't configured in the CLI config yet
|
|
73
|
-
// Walk the user through adding the account's PAK to the config
|
|
74
|
-
await (0, helpers_1.useExistingDevTestAccount)(env, devAccountPromptResponse.notInConfigAccount);
|
|
74
|
+
if (profileConfig) {
|
|
75
|
+
// Bypass the prompt for the testing account if the user has a profile configured
|
|
76
|
+
targetTestingAccountId = profileConfig.accountId;
|
|
75
77
|
}
|
|
76
|
-
else if (
|
|
77
|
-
//
|
|
78
|
-
targetTestingAccountId =
|
|
78
|
+
else if (args.providedAccountId) {
|
|
79
|
+
// By pass the prompt if the user explicitly provides an --account flag.
|
|
80
|
+
targetTestingAccountId = targetProjectAccountId;
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
logger_1.logger.log('');
|
|
84
|
+
(0, ui_1.uiLine)();
|
|
85
|
+
logger_1.logger.log((0, lang_1.i18n)(`commands.project.subcommands.dev.logs.accountTypeInformation`));
|
|
86
|
+
logger_1.logger.log('');
|
|
87
|
+
logger_1.logger.log((0, lang_1.i18n)(`commands.project.subcommands.dev.logs.learnMoreMessage`, {
|
|
88
|
+
learnMoreLink: (0, ui_1.uiLink)((0, lang_1.i18n)(`commands.project.subcommands.dev.logs.learnMoreLink`), 'https://developers.hubspot.com/docs/getting-started/account-types'),
|
|
89
|
+
}));
|
|
90
|
+
(0, ui_1.uiLine)();
|
|
91
|
+
logger_1.logger.log('');
|
|
92
|
+
const accountType = await (0, helpers_1.selectAccountTypePrompt)(accountConfig);
|
|
93
|
+
if (accountType === config_1.HUBSPOT_ACCOUNT_TYPES.DEVELOPER_TEST) {
|
|
94
|
+
const devAccountPromptResponse = await (0, projectDevTargetAccountPrompt_1.selectDeveloperTestTargetAccountPrompt)(accounts, accountConfig);
|
|
95
|
+
targetTestingAccountId = devAccountPromptResponse.targetAccountId;
|
|
96
|
+
if (!!devAccountPromptResponse.notInConfigAccount) {
|
|
97
|
+
// When the developer test account isn't configured in the CLI config yet
|
|
98
|
+
// Walk the user through adding the account's PAK to the config
|
|
99
|
+
await (0, helpers_1.useExistingDevTestAccount)(env, devAccountPromptResponse.notInConfigAccount);
|
|
100
|
+
}
|
|
101
|
+
else if (devAccountPromptResponse.createNestedAccount) {
|
|
102
|
+
// Create a new developer test account and automatically add it to the CLI config
|
|
103
|
+
targetTestingAccountId = await (0, helpers_1.createDeveloperTestAccountForLocalDev)(targetProjectAccountId, accountConfig, env);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
else if (accountType === config_1.HUBSPOT_ACCOUNT_TYPES.DEVELOPMENT_SANDBOX) {
|
|
107
|
+
const sandboxAccountPromptResponse = await (0, projectDevTargetAccountPrompt_1.selectSandboxTargetAccountPrompt)(accounts, accountConfig);
|
|
108
|
+
targetTestingAccountId = sandboxAccountPromptResponse.targetAccountId;
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
targetTestingAccountId = targetProjectAccountId;
|
|
112
|
+
}
|
|
79
113
|
}
|
|
80
114
|
// Check if project exists in HubSpot
|
|
81
115
|
const { projectExists, project: uploadedProject } = await (0, ensureProjectExists_1.ensureProjectExists)(targetProjectAccountId, projectConfig.name, {
|
|
@@ -92,10 +126,11 @@ async function unifiedProjectDevFlow(args, accountConfig, projectConfig, project
|
|
|
92
126
|
}
|
|
93
127
|
else {
|
|
94
128
|
project = await (0, helpers_1.createNewProjectForLocalDev)(projectConfig, targetProjectAccountId, false, false);
|
|
95
|
-
deployedBuild = await (0, helpers_1.createInitialBuildForNewProject)(projectConfig, projectDir, targetProjectAccountId, true);
|
|
129
|
+
deployedBuild = await (0, helpers_1.createInitialBuildForNewProject)(projectConfig, projectDir, targetProjectAccountId, true, args.profile);
|
|
96
130
|
}
|
|
97
|
-
|
|
98
|
-
|
|
131
|
+
// End setup, start local dev process
|
|
132
|
+
const localDevProcess = new LocalDevProcess_1.default({
|
|
133
|
+
initialProjectNodes: projectNodes,
|
|
99
134
|
debug: args.debug,
|
|
100
135
|
deployedBuild,
|
|
101
136
|
isGithubLinked,
|
|
@@ -106,6 +141,26 @@ async function unifiedProjectDevFlow(args, accountConfig, projectConfig, project
|
|
|
106
141
|
projectId: project.id,
|
|
107
142
|
env,
|
|
108
143
|
});
|
|
109
|
-
await
|
|
110
|
-
|
|
144
|
+
await localDevProcess.start();
|
|
145
|
+
const watcher = new LocalDevWatcher_1.default(localDevProcess);
|
|
146
|
+
watcher.start();
|
|
147
|
+
// const websocketServer = new LocalDevWebsocketServer(
|
|
148
|
+
// localDevProcess,
|
|
149
|
+
// args.debug
|
|
150
|
+
// );
|
|
151
|
+
// await websocketServer.start();
|
|
152
|
+
(0, process_1.handleKeypress)(async (key) => {
|
|
153
|
+
if ((key.ctrl && key.name === 'c') || key.name === 'q') {
|
|
154
|
+
await Promise.all([
|
|
155
|
+
localDevProcess.stop(),
|
|
156
|
+
watcher.stop(),
|
|
157
|
+
// websocketServer.shutdown(),
|
|
158
|
+
]);
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
(0, process_1.handleExit)(({ isSIGHUP }) => {
|
|
162
|
+
localDevProcess.stop(!isSIGHUP);
|
|
163
|
+
watcher.stop();
|
|
164
|
+
// websocketServer.shutdown();
|
|
165
|
+
});
|
|
111
166
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { AccountArgs, CommonArgs, ConfigArgs, EnvironmentArgs, YargsCommandModule } from '../../types/Yargs';
|
|
2
2
|
export type ProjectMigrateArgs = CommonArgs & AccountArgs & EnvironmentArgs & ConfigArgs & {
|
|
3
3
|
platformVersion: string;
|
|
4
|
+
unstable: boolean;
|
|
4
5
|
};
|
|
5
6
|
declare const migrateCommand: YargsCommandModule<unknown, ProjectMigrateArgs>;
|
|
6
7
|
export default migrateCommand;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { YargsCommandModule, CommonArgs } from '../../../types/Yargs';
|
|
2
|
+
type ProjectProfileAddArgs = CommonArgs & {
|
|
3
|
+
name?: string;
|
|
4
|
+
targetAccount?: number;
|
|
5
|
+
};
|
|
6
|
+
declare const projectProfileAddCommand: YargsCommandModule<unknown, ProjectProfileAddArgs>;
|
|
7
|
+
export default projectProfileAddCommand;
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const path_1 = __importDefault(require("path"));
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const config_1 = require("@hubspot/local-dev-lib/config");
|
|
9
|
+
const getAccountIdentifier_1 = require("@hubspot/local-dev-lib/config/getAccountIdentifier");
|
|
10
|
+
const project_parsing_lib_1 = require("@hubspot/project-parsing-lib");
|
|
11
|
+
const usageTracking_1 = require("../../../lib/usageTracking");
|
|
12
|
+
const config_2 = require("../../../lib/projects/config");
|
|
13
|
+
const ui_1 = require("../../../lib/ui");
|
|
14
|
+
const logger_1 = require("../../../lib/ui/logger");
|
|
15
|
+
const exitCodes_1 = require("../../../lib/enums/exitCodes");
|
|
16
|
+
const yargsUtils_1 = require("../../../lib/yargsUtils");
|
|
17
|
+
const en_1 = require("../../../lang/en");
|
|
18
|
+
const promptUtils_1 = require("../../../lib/prompts/promptUtils");
|
|
19
|
+
const validation_1 = require("../../../lib/validation");
|
|
20
|
+
const errorHandlers_1 = require("../../../lib/errorHandlers");
|
|
21
|
+
const command = 'add [name]';
|
|
22
|
+
const describe = (0, ui_1.uiBetaTag)(en_1.commands.project.profile.add.describe, false);
|
|
23
|
+
const verboseDescribe = (0, ui_1.uiBetaTag)(en_1.commands.project.profile.add.verboseDescribe, false);
|
|
24
|
+
async function selectProfileToCopyVariablesFrom(existingProfiles) {
|
|
25
|
+
let profileToCopyVariablesFrom;
|
|
26
|
+
if (existingProfiles.length == 1) {
|
|
27
|
+
logger_1.uiLogger.log('');
|
|
28
|
+
logger_1.uiLogger.log(en_1.commands.project.profile.add.logs.copyExistingProfile((0, project_parsing_lib_1.getHsProfileFilename)(existingProfiles[0])));
|
|
29
|
+
const shouldCopyVariables = await (0, promptUtils_1.confirmPrompt)('Copy profile variables?', {
|
|
30
|
+
defaultAnswer: true,
|
|
31
|
+
});
|
|
32
|
+
if (shouldCopyVariables) {
|
|
33
|
+
profileToCopyVariablesFrom = existingProfiles[0];
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
else if (existingProfiles.length > 1) {
|
|
37
|
+
logger_1.uiLogger.log('');
|
|
38
|
+
logger_1.uiLogger.log(en_1.commands.project.profile.add.logs.copyExistingProfiles);
|
|
39
|
+
const emptyChoice = {
|
|
40
|
+
name: en_1.commands.project.profile.add.prompts.copyExistingProfilePromptEmpty,
|
|
41
|
+
value: undefined,
|
|
42
|
+
};
|
|
43
|
+
const promptResponse = await (0, promptUtils_1.listPrompt)(en_1.commands.project.profile.add.prompts.copyExistingProfilePrompt, {
|
|
44
|
+
choices: [
|
|
45
|
+
...existingProfiles.map(profile => ({
|
|
46
|
+
name: (0, project_parsing_lib_1.getHsProfileFilename)(profile),
|
|
47
|
+
value: profile,
|
|
48
|
+
})),
|
|
49
|
+
emptyChoice,
|
|
50
|
+
],
|
|
51
|
+
});
|
|
52
|
+
if (promptResponse) {
|
|
53
|
+
profileToCopyVariablesFrom = promptResponse;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return profileToCopyVariablesFrom;
|
|
57
|
+
}
|
|
58
|
+
async function handler(args) {
|
|
59
|
+
const { derivedAccountId } = args;
|
|
60
|
+
(0, usageTracking_1.trackCommandUsage)('project-profile-add', undefined, derivedAccountId);
|
|
61
|
+
const { projectConfig, projectDir } = await (0, config_2.getProjectConfig)();
|
|
62
|
+
if (!projectConfig || !projectDir) {
|
|
63
|
+
logger_1.uiLogger.error(en_1.commands.project.profile.add.errors.noProjectConfig);
|
|
64
|
+
process.exit(exitCodes_1.EXIT_CODES.ERROR);
|
|
65
|
+
}
|
|
66
|
+
const projectSourceDir = path_1.default.join(projectDir, projectConfig.srcDir);
|
|
67
|
+
let profileName = args.name;
|
|
68
|
+
let targetAccountId = args.targetAccount;
|
|
69
|
+
function checkIfProfileExists(profileName) {
|
|
70
|
+
return (0, validation_1.fileExists)(path_1.default.join(projectSourceDir, (0, project_parsing_lib_1.getHsProfileFilename)(profileName)));
|
|
71
|
+
}
|
|
72
|
+
function isValidProfileName(profileName) {
|
|
73
|
+
const trimmedProfileName = profileName.trim();
|
|
74
|
+
if (trimmedProfileName === '') {
|
|
75
|
+
return en_1.commands.project.profile.add.prompts.emptyName;
|
|
76
|
+
}
|
|
77
|
+
if (!/^[a-zA-Z0-9]+$/.test(trimmedProfileName)) {
|
|
78
|
+
return en_1.commands.project.profile.add.prompts.invalidProfileName;
|
|
79
|
+
}
|
|
80
|
+
if (checkIfProfileExists(trimmedProfileName)) {
|
|
81
|
+
return en_1.commands.project.profile.add.errors.profileExists(trimmedProfileName);
|
|
82
|
+
}
|
|
83
|
+
return true;
|
|
84
|
+
}
|
|
85
|
+
if (profileName) {
|
|
86
|
+
if (checkIfProfileExists(profileName)) {
|
|
87
|
+
logger_1.uiLogger.error(en_1.commands.project.profile.add.errors.profileExists((0, project_parsing_lib_1.getHsProfileFilename)(profileName)));
|
|
88
|
+
logger_1.uiLogger.log('');
|
|
89
|
+
profileName = undefined;
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
const validationResult = isValidProfileName(profileName);
|
|
93
|
+
if (validationResult !== true) {
|
|
94
|
+
logger_1.uiLogger.error(validationResult);
|
|
95
|
+
logger_1.uiLogger.log('');
|
|
96
|
+
profileName = undefined;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
if (!profileName) {
|
|
101
|
+
const promptResponse = await (0, promptUtils_1.promptUser)({
|
|
102
|
+
type: 'input',
|
|
103
|
+
name: 'name',
|
|
104
|
+
message: en_1.commands.project.profile.add.prompts.namePrompt,
|
|
105
|
+
validate: isValidProfileName,
|
|
106
|
+
});
|
|
107
|
+
profileName = promptResponse.name;
|
|
108
|
+
}
|
|
109
|
+
if (targetAccountId) {
|
|
110
|
+
const accountId = (0, config_1.getAccountId)(targetAccountId);
|
|
111
|
+
if (accountId) {
|
|
112
|
+
targetAccountId = accountId;
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
logger_1.uiLogger.error(en_1.commands.project.profile.add.errors.invalidTargetAccount);
|
|
116
|
+
logger_1.uiLogger.log('');
|
|
117
|
+
targetAccountId = undefined;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
if (!targetAccountId) {
|
|
121
|
+
const configuredAccounts = (0, config_1.getConfigAccounts)();
|
|
122
|
+
if (!configuredAccounts || !configuredAccounts.length) {
|
|
123
|
+
logger_1.uiLogger.error(en_1.commands.project.profile.add.errors.noAccountsConfigured);
|
|
124
|
+
process.exit(exitCodes_1.EXIT_CODES.ERROR);
|
|
125
|
+
}
|
|
126
|
+
const promptResponse = await (0, promptUtils_1.listPrompt)(en_1.commands.project.profile.add.prompts.targetAccountPrompt, {
|
|
127
|
+
choices: configuredAccounts.map(account => {
|
|
128
|
+
const accountId = (0, getAccountIdentifier_1.getAccountIdentifier)(account);
|
|
129
|
+
return {
|
|
130
|
+
name: (0, ui_1.uiAccountDescription)(accountId),
|
|
131
|
+
value: accountId,
|
|
132
|
+
};
|
|
133
|
+
}),
|
|
134
|
+
});
|
|
135
|
+
if (promptResponse) {
|
|
136
|
+
targetAccountId = promptResponse;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
const existingProfiles = await (0, project_parsing_lib_1.getAllHsProfiles)(projectSourceDir);
|
|
140
|
+
let existingTargetAccountIdSelected = false;
|
|
141
|
+
for (const profile of existingProfiles) {
|
|
142
|
+
try {
|
|
143
|
+
const loadedProfile = (0, project_parsing_lib_1.loadHsProfileFile)(projectSourceDir, profile);
|
|
144
|
+
if (loadedProfile?.accountId === targetAccountId) {
|
|
145
|
+
existingTargetAccountIdSelected = true;
|
|
146
|
+
break;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
catch (err) {
|
|
150
|
+
// Skip profiles that can't be loaded
|
|
151
|
+
(0, errorHandlers_1.debugError)(err);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
if (existingTargetAccountIdSelected) {
|
|
155
|
+
logger_1.uiLogger.log('');
|
|
156
|
+
logger_1.uiLogger.warn(en_1.commands.project.profile.add.warnings.duplicateTargetAccount(targetAccountId));
|
|
157
|
+
}
|
|
158
|
+
const profileFileContent = {
|
|
159
|
+
accountId: targetAccountId,
|
|
160
|
+
variables: {},
|
|
161
|
+
};
|
|
162
|
+
const profileToCopyVariablesFrom = await selectProfileToCopyVariablesFrom(existingProfiles);
|
|
163
|
+
if (profileToCopyVariablesFrom) {
|
|
164
|
+
try {
|
|
165
|
+
const profileToCopyFileContent = (0, project_parsing_lib_1.loadHsProfileFile)(projectSourceDir, profileToCopyVariablesFrom);
|
|
166
|
+
if (profileToCopyFileContent?.variables) {
|
|
167
|
+
profileFileContent.variables = profileToCopyFileContent.variables;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
catch (err) {
|
|
171
|
+
logger_1.uiLogger.error(en_1.commands.project.profile.add.errors.failedToLoadProfile(profileToCopyVariablesFrom));
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
const profileFilename = (0, project_parsing_lib_1.getHsProfileFilename)(profileName);
|
|
175
|
+
try {
|
|
176
|
+
fs_1.default.writeFileSync(path_1.default.join(projectSourceDir, profileFilename), JSON.stringify(profileFileContent, null, 2), 'utf8');
|
|
177
|
+
}
|
|
178
|
+
catch (err) {
|
|
179
|
+
logger_1.uiLogger.error(en_1.commands.project.profile.add.errors.failedToCreateProfile);
|
|
180
|
+
process.exit(exitCodes_1.EXIT_CODES.ERROR);
|
|
181
|
+
}
|
|
182
|
+
logger_1.uiLogger.log('');
|
|
183
|
+
logger_1.uiLogger.log(en_1.commands.project.profile.add.logs.profileAdded(profileFilename));
|
|
184
|
+
process.exit(exitCodes_1.EXIT_CODES.SUCCESS);
|
|
185
|
+
}
|
|
186
|
+
function projectProfileAddBuilder(yargs) {
|
|
187
|
+
yargs.positional('name', {
|
|
188
|
+
describe: en_1.commands.project.profile.add.positionals.name,
|
|
189
|
+
type: 'string',
|
|
190
|
+
});
|
|
191
|
+
yargs.option('target-account', {
|
|
192
|
+
describe: en_1.commands.project.profile.add.options.targetAccount,
|
|
193
|
+
type: 'number',
|
|
194
|
+
});
|
|
195
|
+
yargs.example([
|
|
196
|
+
['$0 project profile add qa', en_1.commands.project.profile.add.example],
|
|
197
|
+
]);
|
|
198
|
+
return yargs;
|
|
199
|
+
}
|
|
200
|
+
const builder = (0, yargsUtils_1.makeYargsBuilder)(projectProfileAddBuilder, command, verboseDescribe, {
|
|
201
|
+
useGlobalOptions: true,
|
|
202
|
+
});
|
|
203
|
+
const projectProfileAddCommand = {
|
|
204
|
+
command,
|
|
205
|
+
describe,
|
|
206
|
+
handler,
|
|
207
|
+
builder,
|
|
208
|
+
};
|
|
209
|
+
exports.default = projectProfileAddCommand;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { YargsCommandModule, CommonArgs } from '../../../types/Yargs';
|
|
2
|
+
type ProjectProfileDeleteArgs = CommonArgs & {
|
|
3
|
+
name?: string;
|
|
4
|
+
};
|
|
5
|
+
declare const projectProfileDeleteCommand: YargsCommandModule<unknown, ProjectProfileDeleteArgs>;
|
|
6
|
+
export default projectProfileDeleteCommand;
|