Skip to content

Commit

Permalink
updated reinstall and deploy with marketplace calls
Browse files Browse the repository at this point in the history
  • Loading branch information
harshithad0703 committed Jul 26, 2024
1 parent 02ce60c commit 515bb4a
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 56 deletions.
21 changes: 12 additions & 9 deletions src/commands/app/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export default class Deploy extends AppCLIBaseCommand {
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",
Expand All @@ -89,14 +89,18 @@ export default class Deploy extends AppCLIBaseCommand {
config["name"] = config["name"] || app?.name;
this.flags["launch-project"] =
this.flags["launch-project"] || (await askProjectType());
await this.handleHostingWithLaunch(config, updateHostingPayload, projects);
await this.handleHostingWithLaunch(
config,
updateHostingPayload,
projects
);
break;
default:
this.log("Please provide a valid Hosting Type.", "error");
return;
}

if(this.flags["app-uid"]){
if (this.flags["app-uid"]) {
await updateApp(
flags,
this.sharedConfig.org,
Expand Down Expand Up @@ -284,11 +288,10 @@ export default class Deploy extends AppCLIBaseCommand {
if (!this.flags["yes"]) {
throw new Error(deployAppMsg.APP_UPDATE_TERMINATION_MSG);
}
await disconnectApp(
this.flags,
this.sharedConfig.org,
this.developerHubBaseUrl
);
await disconnectApp(this.flags, this.sharedConfig.org, {
marketplaceSdk: this.marketplaceAppSdk,
log: this.log,
});
}
}
}
}
9 changes: 3 additions & 6 deletions src/commands/app/reinstall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,9 @@ export default class Reinstall extends AppCLIBaseCommand {
}),
"info"
);
await reinstallApp({
flags: this.flags,
type: appType,
developerHubBaseUrl: this.developerHubBaseUrl,
orgUid: this.sharedConfig.org,
manifestUid: this.flags["app-uid"],
await reinstallApp(this.flags, this.sharedConfig.org, appType, {
marketplaceSdk: this.marketplaceAppSdk,
log: this.log,
});
this.log(
$t(reinstallAppMsg.APP_REINSTALLED_SUCCESSFULLY, {
Expand Down
63 changes: 22 additions & 41 deletions src/util/common-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
HttpClient,
} from "@contentstack/cli-utilities";
import { projectsQuery } from "../graphql/queries";
import { apiRequestHandler } from "./api-request-handler";
import {
AppLocation,
Extension,
Expand Down Expand Up @@ -166,34 +165,23 @@ function installApp(
});
}

async function reinstallApp(params: {
flags: FlagInput;
type: string;
developerHubBaseUrl: string;
orgUid: string;
manifestUid: string;
}): Promise<void> {
const { type, developerHubBaseUrl, flags, orgUid, manifestUid } = params;
const payload = {
target_type: type,
target_uid: (flags["stack-api-key"] as any) || orgUid,
};

const url = `https://${developerHubBaseUrl}/manifests/${manifestUid}/reinstall`;
try {
const result = await apiRequestHandler({
orgUid,
payload,
url,
method: "PUT",
function reinstallApp(
flags: FlagInput,
orgUid: string,
type: string,
options: MarketPlaceOptions
) {
const { marketplaceSdk } = options;
return marketplaceSdk
.marketplace(orgUid)
.app(flags["app-uid"] as any)
.reinstall({
targetUid: (flags["stack-api-key"] as any) || orgUid,
targetType: type as any,
});
return result;
} catch (err) {
throw err;
}
}

function fetchStack(flags: FlagInput, options: CommonOptions) {
function fetchStack(flags: FlagInput, options: CommonOptions): Promise<any> {
const { managementSdk } = options;
return managementSdk
.stack({ api_key: flags["stack-api-key"] as any })
Expand Down Expand Up @@ -363,21 +351,14 @@ function setupConfig(configPath: string) {
async function disconnectApp(
flags: FlagInput,
orgUid: string,
developerHubBaseUrl: string
) {
const appUid: any = flags["app-uid"];
const url = `https://${developerHubBaseUrl}/manifests/${appUid}/hosting/disconnect`;
try {
const result = await apiRequestHandler({
orgUid,
payload: { provider: "launch" },
url,
method: "PATCH",
});
return result;
} catch (err) {
throw err;
}
options: MarketPlaceOptions
): Promise<any> {
const { marketplaceSdk } = options;
return marketplaceSdk
.marketplace(orgUid)
.app(flags["app-uid"] as any)
.hosting()
.disconnect({ provider: "launch" });
}

function formatUrl(url: string): string {
Expand Down

0 comments on commit 515bb4a

Please sign in to comment.