Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
3f66ba3
feat: app deploy command
aman19K Jun 11, 2024
d783fe2
update launch version
aman19K Jun 11, 2024
5335578
Merge pull request #253 from contentstack/staging
cs-raj Jun 11, 2024
5df4ce5
fix org type def issue
aman19K Jun 11, 2024
43b0570
Merge pull request #250 from contentstack/feat/DX-541
aman19K Jun 11, 2024
3683642
feat: config based launch project creation
aman19K Jun 17, 2024
b2bda01
Merge pull request #254 from contentstack/feat/DX-785
aman19K Jun 17, 2024
8403398
refactor: updated examples
aman19K Jun 18, 2024
e4bfc23
updated readme
aman19K Jun 18, 2024
b4950f2
fix: snyk issues
aman19K Jun 18, 2024
dd1e7dc
updated utilities version
aman19K Jun 18, 2024
83b96dc
version bump
aman19K Jun 18, 2024
fabe102
Merge pull request #255 from contentstack/feat/app-deploy-command
aman19K Jun 18, 2024
09754e4
fix: deploy command
aman19K Jun 19, 2024
335f067
refactor: launch project flag
aman19K Jun 19, 2024
2f923bc
refactor: app disconnect
aman19K Jun 19, 2024
cef7d91
Merge pull request #256 from contentstack/fix/deploy-command
aman19K Jun 19, 2024
8eba9b7
fix: launch project query, removed duplicate yes flag & updated readm…
aman19K Jun 19, 2024
b9cf987
Merge pull request #257 from contentstack/fix/launch-project-query
aman19K Jun 19, 2024
4cd7cc6
fix: app uid issue
aman19K Jun 19, 2024
99f75d8
added check for app-uid
aman19K Jun 19, 2024
e008e13
updated reademe file
aman19K Jun 19, 2024
5c9d2ca
Merge branch 'development' into fix/app-uid-issue
aman19K Jun 19, 2024
f327429
Merge pull request #258 from contentstack/fix/app-uid-issue
aman19K Jun 19, 2024
75dfe08
build: updated oclif/test version to 2.5.6
harshithad0703 Jun 24, 2024
6b18665
test: deploy command unit test
harshithad0703 Jun 24, 2024
57afe40
test: :adhesive_bandage: deploy command unit test update
harshithad0703 Jun 24, 2024
57af772
chore: updated test script in package.json
harshithad0703 Jun 24, 2024
d342cb5
refactor: deploy command ui text
aman19K Jun 26, 2024
b9ed523
Merge pull request #261 from contentstack/refactor/deploy-command-ui-…
aman19K Jun 26, 2024
6f7b5f5
test: added hosting with launch test case for deploy
harshithad0703 Jun 26, 2024
43e2bb6
refactor: deploy command ui text
aman19K Jun 26, 2024
cf74caa
test: added mock data for deploy unit test
harshithad0703 Jun 26, 2024
9d7bb0f
Merge branch 'development' into test/DX-543-deploy-command-unit-tests
harshithad0703 Jun 27, 2024
2feb7d0
test: added 1 more test case using flags in command
harshithad0703 Jun 27, 2024
6afde49
Merge pull request #260 from contentstack/test/DX-543-deploy-command-…
harshithad0703 Jun 28, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
115 changes: 54 additions & 61 deletions src/commands/app/deploy.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { ApolloClient } from "@apollo/client/core";
import { Flags, FlagInput, cliux } from "@contentstack/cli-utilities";
import { Flags, FlagInput } from "@contentstack/cli-utilities";
import config from "@contentstack/cli-launch/dist/config";
import { GraphqlApiClient } from "@contentstack/cli-launch/dist/util";
import Launch from "@contentstack/cli-launch/dist/commands/launch/index";

import { UpdateHostingParams } from "../../types";
import { LaunchProjectRes, UpdateHostingParams } from "../../types";
import { commonMsg, deployAppMsg } from "../../messages";
import { AppCLIBaseCommand } from "../../app-cli-base-command";
import {
Expand All @@ -31,8 +31,9 @@ export default class Deploy extends AppCLIBaseCommand {
"$ <%= config.bin %> <%= command.id %>",
"$ <%= config.bin %> <%= command.id %> --org <UID> --app-uid <APP-UID-1>",
"$ <%= config.bin %> <%= command.id %> --org <UID> --app-uid <APP-UID-1> --hosting-type <Custom Hosting> --app-url <https://localhost:3000>",
"$ <%= config.bin %> <%= command.id %> --org <UID> --app-uid <APP-UID-1> --hosting-type <Hosting with Launch> --launch-project-type <existing-project>",
"$ <%= config.bin %> <%= command.id %> --org <UID> --app-uid <APP-UID-1> --hosting-type <Hosting with Launch> --launch-project-type <existing-project> --config <config-path>",
"$ <%= config.bin %> <%= command.id %> --org <UID> --app-uid <APP-UID-1> --hosting-type <Hosting with Launch> --launch-project <existing>",
"$ <%= config.bin %> <%= command.id %> --org <UID> --app-uid <APP-UID-1> --hosting-type <Hosting with Launch> --launch-project <new>",
"$ <%= config.bin %> <%= command.id %> --org <UID> --app-uid <APP-UID-1> --hosting-type <Hosting with Launch> --launch-project <new> --config <config-path>",
];

static flags: FlagInput = {
Expand All @@ -50,10 +51,10 @@ export default class Deploy extends AppCLIBaseCommand {
description: deployAppMsg.FORCE_DISCONNECT,
default: false,
}),
"launch-project-type": Flags.string({
"launch-project": Flags.string({
multiple: false,
options: ["existing-project", "new-project"],
description: deployAppMsg.LAUNCH_PROJECT_TYPE,
options: ["existing", "new"],
description: deployAppMsg.LAUNCH_PROJECT,
}),
config: Flags.string({
char: "c",
Expand All @@ -68,42 +69,44 @@ export default class Deploy extends AppCLIBaseCommand {
this.sharedConfig.org = await this.getOrganization();
const app = await this.fetchAppDetails();

const apolloClient = await this.getApolloClient();
const projects = await getProjects(apolloClient);
await this.handleAppDisconnect(projects);

flags["hosting-type"] = flags["hosting-type"] || (await getHostingType());
const updateHostingPayload: UpdateHostingParams = {
provider: "external",
deployment_url: "",
environment_uid: "",
project_uid: "",
};

switch (flags["hosting-type"]) {
case "Custom Hosting":
flags["app-url"] = flags["app-url"] || (await getAppUrl());
this.flags["app-url"] = formatUrl(flags["app-url"]);
updateHostingPayload["deployment_url"] = this.flags["app-url"];
break;
case "Hosting with Launch":
updateHostingPayload["provider"] = "launch";
const config = setupConfig(flags["config"]);
config["name"] = config["name"] || app?.name;
await this.handleHostingWithLaunch(config, updateHostingPayload);
this.flags["launch-project"] =
this.flags["launch-project"] || (await askProjectType());
await this.handleHostingWithLaunch(config, updateHostingPayload, projects);
break;
default:
this.log("Invalid hosting type", "error");
return;
}

if (flags["app-url"]) {
const spinner = cliux.loaderV2("Updating App...");
await updateApp(
flags,
this.sharedConfig.org,
{
managementSdk: this.managementAppSdk,
log: this.log,
},
updateHostingPayload
);
cliux.loaderV2("done", spinner);
}
await updateApp(
flags,
this.sharedConfig.org,
{
managementSdk: this.managementAppSdk,
log: this.log,
},
updateHostingPayload
);

this.log(
this.$t(deployAppMsg.APP_DEPLOYED, {
Expand Down Expand Up @@ -173,58 +176,23 @@ export default class Deploy extends AppCLIBaseCommand {
}).apolloClient;
}

/**
* Handles hosting with launch for the application deployment.
*
* @param config - The configuration object.
* @param updateHostingPayload - The payload for updating hosting.
* @returns A Promise that resolves when the hosting with launch is handled.
*/
async handleHostingWithLaunch(
config: Record<string, string>,
updateHostingPayload: UpdateHostingParams
): Promise<void> {
const apolloClient = await this.getApolloClient();
const projects = await getProjects(apolloClient);
const isProjectConnected = projects.filter(
(project) => project?.developerHubAppUid === this.flags["app-uid"]
);

if (isProjectConnected?.length) {
this.flags["yes"] = this.flags["yes"] || (await askConfirmation());
if (!this.flags["yes"]) {
throw new Error(deployAppMsg.APP_UPDATE_TERMINATION_MSG);
}
const spinner = cliux.loaderV2("Disconnecting launch project...");
await disconnectApp(
this.flags,
this.sharedConfig.org,
this.developerHubBaseUrl
);
cliux.loaderV2("disconnected...", spinner);
}
this.flags["launch-project-type"] =
this.flags["launch-project-type"] || (await askProjectType());
await this.handleProjectType(config, updateHostingPayload, projects);
}

/**
* Handles the project type based on the provided configuration, update hosting payload, and projects.
* @param config - The configuration object.
* @param updateHostingPayload - The update hosting payload.
* @param projects - The list of projects.
* @returns A Promise that resolves to void.
*/
async handleProjectType(
async handleHostingWithLaunch(
config: Record<string, string>,
updateHostingPayload: UpdateHostingParams,
projects: any[]
): Promise<void> {
let url: string = "";

if (this.flags["launch-project-type"] === "existing-project") {
if (this.flags["launch-project"] === "existing") {
url = await this.handleExistingProject(updateHostingPayload, projects);
} else if (this.flags["launch-project-type"] === "new-project") {
} else if (this.flags["launch-project"] === "new") {
config["name"] = await handleProjectNameConflict(
config["name"],
projects
Expand Down Expand Up @@ -298,4 +266,29 @@ export default class Deploy extends AppCLIBaseCommand {
}
return "";
}

/**
* Handles the disconnection of an app from projects.
*
* @param projects - An array of LaunchProjectRes objects representing the projects.
* @returns {Promise<void>} - A promise that resolves when the disconnection is complete.
* @throws {Error} - Throws an error if the user chooses not to disconnect the app.
*/
async handleAppDisconnect(projects: LaunchProjectRes[]): Promise<void> {
const isProjectConnected = projects.filter(
(project) => project?.developerHubAppUid === this.flags["app-uid"]
);

if (isProjectConnected?.length) {
this.flags["yes"] = this.flags["yes"] || (await askConfirmation());
if (!this.flags["yes"]) {
throw new Error(deployAppMsg.APP_UPDATE_TERMINATION_MSG);
}
await disconnectApp(
this.flags,
this.sharedConfig.org,
this.developerHubBaseUrl
);
}
}
}
2 changes: 1 addition & 1 deletion src/messages/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ const reinstallAppMsg = {
const deployAppMsg = {
APP_DEPLOYED: "{app} deployed successfully.",
FORCE_DISCONNECT: "Force disconnect launch project by skipping the confirmation",
LAUNCH_PROJECT_TYPE: "Launch Project Type",
LAUNCH_PROJECT: "Launch Project",
APP_URL: "App URL",
HOSTING_TYPE: "Hosting Type",
CONFIG_FILE: "[optional] path of config file",
Expand Down
4 changes: 2 additions & 2 deletions src/types/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ export interface ReinstallParams {
export interface UpdateHostingParams {
provider: string;
deployment_url: string;
environment_uid: string;
project_uid: string;
environment_uid?: string;
project_uid?: string;
}

export interface LaunchProjectRes {
Expand Down
8 changes: 4 additions & 4 deletions src/util/inquirer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -349,11 +349,11 @@ async function selectProject(
const askProjectType = async (): Promise<string> => {
return await cliux.inquire<string>({
type: "list",
name: "selected_project_type",
message: "Launch Project type",
name: "selected_launch_project",
message: "Launch Project",
choices: [
{ name: "Existing", value: "existing-project" },
{ name: "New", value: "new-project" },
{ name: "Existing", value: "existing" },
{ name: "New", value: "new" },
],
});
};
Expand Down