Skip to content

Commit 3913bce

Browse files
Merge pull request #84 from contentstack/development
Main <- Development
2 parents ffcfe15 + e7f5b5d commit 3913bce

File tree

13 files changed

+103
-49
lines changed

13 files changed

+103
-49
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@ dependabot.yml
1717
/bkp
1818
.editorconfig
1919
oclif.manifest.json
20-
*.env
20+
*.env
21+
.vscode/

.vscode/launch.json

Lines changed: 0 additions & 18 deletions
This file was deleted.

README.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ $ npm install -g @contentstack/apps-cli
2020
$ csdx COMMAND
2121
running command...
2222
$ csdx (--version|-v)
23-
@contentstack/apps-cli/1.0.0 darwin-arm64 node-v20.3.1
23+
@contentstack/apps-cli/1.0.1 darwin-arm64 node-v20.3.1
2424
$ csdx --help [COMMAND]
2525
USAGE
2626
$ csdx COMMAND
@@ -66,7 +66,7 @@ EXAMPLES
6666
$ csdx app:create --name App-3 --app-type organization --org <UID> -d ./boilerplate -c ./external-config.json
6767
```
6868

69-
_See code: [src/commands/app/create.ts](https://github.com/contentstack/apps-cli/blob/v1.0.0/src/commands/app/create.ts)_
69+
_See code: [src/commands/app/create.ts](https://github.com/contentstack/apps-cli/blob/v1.0.1/src/commands/app/create.ts)_
7070

7171
## `csdx app:delete`
7272

@@ -91,7 +91,7 @@ EXAMPLES
9191
$ csdx app:delete --app-uid <value> --org <value> -d ./boilerplate
9292
```
9393

94-
_See code: [src/commands/app/delete.ts](https://github.com/contentstack/apps-cli/blob/v1.0.0/src/commands/app/delete.ts)_
94+
_See code: [src/commands/app/delete.ts](https://github.com/contentstack/apps-cli/blob/v1.0.1/src/commands/app/delete.ts)_
9595

9696
## `csdx app:get`
9797

@@ -121,7 +121,7 @@ EXAMPLES
121121
$ csdx app:get --org <value> --app-uid <value> --app-type organization
122122
```
123123

124-
_See code: [src/commands/app/get.ts](https://github.com/contentstack/apps-cli/blob/v1.0.0/src/commands/app/get.ts)_
124+
_See code: [src/commands/app/get.ts](https://github.com/contentstack/apps-cli/blob/v1.0.1/src/commands/app/get.ts)_
125125

126126
## `csdx app:install`
127127

@@ -147,20 +147,21 @@ EXAMPLES
147147
$ csdx app:install --org <UID> --app-uid <APP-UID-1> --stack-api-key <STACK-API-KEY-1>
148148
```
149149

150-
_See code: [src/commands/app/install.ts](https://github.com/contentstack/apps-cli/blob/v1.0.0/src/commands/app/install.ts)_
150+
_See code: [src/commands/app/install.ts](https://github.com/contentstack/apps-cli/blob/v1.0.1/src/commands/app/install.ts)_
151151

152152
## `csdx app:uninstall`
153153

154154
Uninstall an app
155155

156156
```
157157
USAGE
158-
$ csdx app:uninstall [--org <value>] [--app-uid <value>] [--installation-uid <value>]
158+
$ csdx app:uninstall [--org <value>] [--app-uid <value>] [--installation-uid <value>] [--uninstall-all]
159159
160160
FLAGS
161161
--app-uid=<value> Provide the app UID
162162
--installation-uid=<value> Provide the installation ID of the app that needs to be uninstalled.
163163
--org=<value> Provide the organization UID
164+
--uninstall-all Please select stacks from where the app must be uninstalled.
164165
165166
DESCRIPTION
166167
Uninstall an app
@@ -173,7 +174,7 @@ EXAMPLES
173174
$ csdx app:uninstall --org <UID> --app-uid <APP-UID-1> --installation-uid <INSTALLATION-UID-1>
174175
```
175176

176-
_See code: [src/commands/app/uninstall.ts](https://github.com/contentstack/apps-cli/blob/v1.0.0/src/commands/app/uninstall.ts)_
177+
_See code: [src/commands/app/uninstall.ts](https://github.com/contentstack/apps-cli/blob/v1.0.1/src/commands/app/uninstall.ts)_
177178

178179
## `csdx app:update`
179180

@@ -196,5 +197,5 @@ EXAMPLES
196197
$ csdx app:update --app-manifest ./boilerplate/manifest.json
197198
```
198199

199-
_See code: [src/commands/app/update.ts](https://github.com/contentstack/apps-cli/blob/v1.0.0/src/commands/app/update.ts)_
200+
_See code: [src/commands/app/update.ts](https://github.com/contentstack/apps-cli/blob/v1.0.1/src/commands/app/update.ts)_
200201
<!-- commandsstop -->

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@contentstack/apps-cli",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"description": "App ClI",
55
"author": "Contentstack CLI",
66
"homepage": "https://github.com/contentstack/contentstack-apps-cli",

src/commands/app/uninstall.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { BaseCommand } from "./base-command";
22
import { flags } from "@contentstack/cli-utilities";
3-
import { getOrg, getApp, fetchApp, getInstallation, uninstallApp } from "../../util";
3+
import { getOrg, getApp, fetchApp } from "../../util";
44
import { commonMsg, uninstallAppMsg } from "../../messages";
5+
import { UninstallAppFactory } from "../../factories/uninstall-app-factory";
56

67
export default class Uninstall extends BaseCommand<typeof Uninstall> {
78
static description = "Uninstall an app";
@@ -19,6 +20,9 @@ export default class Uninstall extends BaseCommand<typeof Uninstall> {
1920
}),
2021
'installation-uid': flags.string({
2122
description: uninstallAppMsg.INSTALLATION_UID
23+
}),
24+
'uninstall-all': flags.boolean({
25+
description: uninstallAppMsg.UNINSTALL_ALL,
2226
})
2327
}
2428

@@ -34,17 +38,14 @@ export default class Uninstall extends BaseCommand<typeof Uninstall> {
3438
} else {
3539
app = await fetchApp(this.flags, this.sharedConfig.org, {managementSdk: this.managementAppSdk, log: this.log})
3640
}
37-
41+
3842
this.flags['app-uid'] = app?.uid;
3943
appType = app?.['target_type']
4044

41-
// select installation uid to uninstall
42-
if (!this.flags['installation-uid']) {
43-
this.flags['installation-uid'] = await getInstallation(this.flags, this.sharedConfig.org, this.managementSdk, appType, {managementSdk: this.managementAppSdk, log: this.log})
44-
}
45-
46-
// uninstall app
47-
await uninstallApp(this.flags, this.sharedConfig.org, {managementSdk: this.managementAppSdk, log: this.log})
45+
const factory = new UninstallAppFactory()
46+
const strategy = factory.getStrategyInstance(this.flags['uninstall-all'])
47+
await strategy.run(this.flags, this.sharedConfig.org, this.managementSdk, {managementSdk: this.managementAppSdk, log: this.log}, appType)
48+
4849
this.log(this.$t(uninstallAppMsg.APP_UNINSTALLED, { app: app?.name || this.flags["app-uid"] }), "info")
4950

5051
} catch (error: any) {
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { UninstallApp } from "../interfaces/uninstall-app";
2+
import { UninstallAll } from "../strategies/uninstall-all";
3+
import { UninstallSelected } from "../strategies/uninstall-selected";
4+
5+
export class UninstallAppFactory {
6+
public getStrategyInstance(uninstallAll: boolean): UninstallApp {
7+
let strategy: UninstallApp;
8+
if (uninstallAll) {
9+
strategy = new UninstallAll()
10+
} else {
11+
strategy = new UninstallSelected()
12+
}
13+
return strategy
14+
}
15+
}

src/interfaces/uninstall-app.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { ContentstackClient, FlagInput } from "@contentstack/cli-utilities";
2+
import { CommonOptions } from "../util";
3+
import { AppTarget } from "@contentstack/management/types/app/index"
4+
5+
export interface UninstallApp {
6+
run(flags: FlagInput, org: string, managementSdk: ContentstackClient, options: CommonOptions, appType: AppTarget): Promise<void>;
7+
}

src/messages/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ const uninstallAppMsg = {
9595
INSTALLATION_UID: "Provide the installation ID of the app that needs to be uninstalled.",
9696
NO_INSTALLATIONS_FOUND: "Cannot find any installations for this app.",
9797
APP_UNINSTALLED: "{app} uninstalled successfully.",
98-
UNINSTALLING_APP: "Uninstalling app from {type}..."
98+
UNINSTALLING_APP: "Uninstalling app from {type}...",
99+
UNINSTALL_ALL: "Please select stacks from where the app must be uninstalled.",
99100
}
100101

101102
const messages: typeof errors &

src/strategies/uninstall-all.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { ContentstackClient, FlagInput } from "@contentstack/cli-utilities";
2+
import { UninstallApp } from "../interfaces/uninstall-app";
3+
import { CommonOptions, getInstallation, uninstallApp } from "../util";
4+
import { AppTarget } from "@contentstack/management/types/app/index"
5+
6+
export class UninstallAll implements UninstallApp {
7+
public async run(flags: FlagInput, org: string, managementSdk: ContentstackClient, options: CommonOptions, appType: AppTarget): Promise<void> {
8+
// get all installation uids to uninstall
9+
const installationUids = await this.getInstallations(flags, org, managementSdk, options, appType)
10+
for (const installationUid of installationUids) {
11+
await uninstallApp(flags, org, options, installationUid)
12+
}
13+
}
14+
15+
public async getInstallations(flags: FlagInput, org: string, managementSdk: ContentstackClient, options: CommonOptions, appType: AppTarget): Promise<string[]> {
16+
let installationUids: string = await getInstallation(flags, org, managementSdk, appType, options, true)
17+
return installationUids.split(',')
18+
}
19+
}

0 commit comments

Comments
 (0)