Skip to content

Commit

Permalink
Merge pull request #296 from contentstack/development
Browse files Browse the repository at this point in the history
DX | 08-08-2024 | Release
  • Loading branch information
cs-raj authored Aug 6, 2024
2 parents 8872060 + 845d2d7 commit 3e81b2a
Show file tree
Hide file tree
Showing 15 changed files with 352 additions and 261 deletions.
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ $ npm install -g @contentstack/apps-cli
$ csdx COMMAND
running command...
$ csdx (--version|-v)
@contentstack/apps-cli/1.3.1 darwin-arm64 node-v18.20.2
@contentstack/apps-cli/1.3.2 darwin-arm64 node-v18.20.2
$ csdx --help [COMMAND]
USAGE
$ csdx COMMAND
Expand Down Expand Up @@ -69,7 +69,7 @@ EXAMPLES
$ csdx app:update
```

_See code: [src/commands/app/index.ts](https://github.com/contentstack/apps-cli/blob/v1.3.1/src/commands/app/index.ts)_
_See code: [src/commands/app/index.ts](https://github.com/contentstack/apps-cli/blob/v1.3.2/src/commands/app/index.ts)_

## `csdx app:create`

Expand Down Expand Up @@ -109,7 +109,7 @@ EXAMPLES
$ csdx app:create --name App-4 --app-type organization --org <UID> --boilerplate <Ecommerce App Boilerplate>
```

_See code: [src/commands/app/create.ts](https://github.com/contentstack/apps-cli/blob/v1.3.1/src/commands/app/create.ts)_
_See code: [src/commands/app/create.ts](https://github.com/contentstack/apps-cli/blob/v1.3.2/src/commands/app/create.ts)_

## `csdx app:delete`

Expand All @@ -134,7 +134,7 @@ EXAMPLES
$ csdx app:delete --app-uid <value> --org <value> -d ./boilerplate
```

_See code: [src/commands/app/delete.ts](https://github.com/contentstack/apps-cli/blob/v1.3.1/src/commands/app/delete.ts)_
_See code: [src/commands/app/delete.ts](https://github.com/contentstack/apps-cli/blob/v1.3.2/src/commands/app/delete.ts)_

## `csdx app:deploy`

Expand Down Expand Up @@ -172,7 +172,7 @@ EXAMPLES
$ csdx app:deploy --org <UID> --app-uid <APP-UID-1> --hosting-type <Hosting with Launch> --launch-project <new> --config <config-path>
```

_See code: [src/commands/app/deploy.ts](https://github.com/contentstack/apps-cli/blob/v1.3.1/src/commands/app/deploy.ts)_
_See code: [src/commands/app/deploy.ts](https://github.com/contentstack/apps-cli/blob/v1.3.2/src/commands/app/deploy.ts)_

## `csdx app:get`

Expand Down Expand Up @@ -202,7 +202,7 @@ EXAMPLES
$ csdx app:get --org <value> --app-uid <value> --app-type organization
```

_See code: [src/commands/app/get.ts](https://github.com/contentstack/apps-cli/blob/v1.3.1/src/commands/app/get.ts)_
_See code: [src/commands/app/get.ts](https://github.com/contentstack/apps-cli/blob/v1.3.2/src/commands/app/get.ts)_

## `csdx app:install`

Expand All @@ -228,7 +228,7 @@ EXAMPLES
$ csdx app:install --org <UID> --app-uid <APP-UID-1> --stack-api-key <STACK-API-KEY-1>
```

_See code: [src/commands/app/install.ts](https://github.com/contentstack/apps-cli/blob/v1.3.1/src/commands/app/install.ts)_
_See code: [src/commands/app/install.ts](https://github.com/contentstack/apps-cli/blob/v1.3.2/src/commands/app/install.ts)_

## `csdx app:reinstall`

Expand All @@ -254,7 +254,7 @@ EXAMPLES
$ csdx app:reinstall --org <UID> --app-uid <APP-UID-1> --stack-api-key <STACK-API-KEY-1>
```

_See code: [src/commands/app/reinstall.ts](https://github.com/contentstack/apps-cli/blob/v1.3.1/src/commands/app/reinstall.ts)_
_See code: [src/commands/app/reinstall.ts](https://github.com/contentstack/apps-cli/blob/v1.3.2/src/commands/app/reinstall.ts)_

## `csdx app:uninstall`

Expand All @@ -281,7 +281,7 @@ EXAMPLES
$ csdx app:uninstall --org <UID> --app-uid <APP-UID-1> --installation-uid <INSTALLATION-UID-1>
```

_See code: [src/commands/app/uninstall.ts](https://github.com/contentstack/apps-cli/blob/v1.3.1/src/commands/app/uninstall.ts)_
_See code: [src/commands/app/uninstall.ts](https://github.com/contentstack/apps-cli/blob/v1.3.2/src/commands/app/uninstall.ts)_

## `csdx app:update`

Expand All @@ -304,5 +304,5 @@ EXAMPLES
$ csdx app:update --app-manifest ./boilerplate/manifest.json
```

_See code: [src/commands/app/update.ts](https://github.com/contentstack/apps-cli/blob/v1.3.1/src/commands/app/update.ts)_
_See code: [src/commands/app/update.ts](https://github.com/contentstack/apps-cli/blob/v1.3.2/src/commands/app/update.ts)_
<!-- commandsstop -->
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@contentstack/apps-cli",
"version": "1.3.1",
"version": "1.3.2",
"description": "App ClI",
"author": "Contentstack CLI",
"homepage": "https://github.com/contentstack/contentstack-apps-cli",
Expand Down
9 changes: 9 additions & 0 deletions src/commands/app/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,15 @@ export default class Create extends BaseCommand<typeof Create> {
) {
await this.boilerplateFlow();
} else {
if(this.sharedConfig.folderPath === undefined) {
const dataDir = this.flags["data-dir"] ?? process.cwd();
let targetPath = resolve(dataDir, this.sharedConfig.defaultAppName);
if (existsSync(targetPath)) {
this.log(this.messages.DIR_EXIST, "warn");
targetPath = await getDirName(targetPath);
}
this.sharedConfig.folderPath = targetPath;
}
this.manageManifestToggeling();
await this.registerTheAppOnDeveloperHub(false);
}
Expand Down
21 changes: 12 additions & 9 deletions src/commands/app/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,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 @@ -90,14 +90,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 @@ -285,11 +289,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,
});
}
}
}
}
11 changes: 4 additions & 7 deletions src/commands/app/reinstall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,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 All @@ -121,7 +118,7 @@ export default class Reinstall extends AppCLIBaseCommand {
this.displayStackUrl();
} catch (error: any) {
this.log(error?.errorMessage || error?.message || error, "error");
process.exit(1);
this.exit(1);
}
}

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
Loading

0 comments on commit 3e81b2a

Please sign in to comment.